OpenCores
URL https://opencores.org/ocsvn/xulalx25soc/xulalx25soc/trunk

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [wbregs.cpp] - Blame information for rev 116

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    wbregs.cpp
4
//
5
// Project:     XuLA2 board
6
//
7
// Purpose:     To give a user access, via a command line program, to read
8
//              and write wishbone registers one at a time.  Thus this program
9
//              implements readio() and writeio() but nothing more.
10
//
11
//
12
// Creator:     Dan Gisselquist, Ph.D.
13
//              Gisselquist Technology, LLC
14
//
15
////////////////////////////////////////////////////////////////////////////////
16
//
17
// Copyright (C) 2015, Gisselquist Technology, LLC
18
//
19
// This program is free software (firmware): you can redistribute it and/or
20
// modify it under the terms of  the GNU General Public License as published
21
// by the Free Software Foundation, either version 3 of the License, or (at
22
// your option) any later version.
23
//
24
// This program is distributed in the hope that it will be useful, but WITHOUT
25
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
26
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27
// for more details.
28
//
29
// License:     GPL, v3, as defined and found on www.gnu.org,
30
//              http://www.gnu.org/licenses/gpl.html
31
//
32
//
33
////////////////////////////////////////////////////////////////////////////////
34
//
35
//
36
//
37
//
38
#include <stdio.h>
39
#include <stdlib.h>
40
#include <unistd.h>
41
#include <strings.h>
42
#include <ctype.h>
43
#include <string.h>
44
#include <signal.h>
45
#include <assert.h>
46
 
47
#include "llcomms.h"
48
#include "usbi.h"
49
#include "port.h"
50
#include "regdefs.h"
51
 
52
FPGA    *m_fpga;
53
void    closeup(int v) {
54
        m_fpga->kill();
55
        exit(0);
56
}
57
 
58
int main(int argc, char **argv) {
59
        int     skp=0, port = FPGAPORT;
60
        bool    use_usb = true;
61
 
62
        skp=1;
63
        for(int argn=0; argn<argc-skp; argn++) {
64
                if (argv[argn+skp][0] == '-') {
65
                        if (argv[argn+skp][1] == 'u')
66
                                use_usb = true;
67
                        else if (argv[argn+skp][1] == 'p') {
68
                                use_usb = false;
69
                                if (isdigit(argv[argn+skp][2]))
70
                                        port = atoi(&argv[argn+skp][2]);
71
                        }
72
                        skp++; argn--;
73
                } else
74
                        argv[argn] = argv[argn+skp];
75
        } argc -= skp;
76
 
77
        if (use_usb)
78
                m_fpga = new FPGA(new USBI());
79
        else
80
                m_fpga = new FPGA(new NETCOMMS(FPGAHOST, port));
81
 
82
        signal(SIGSTOP, closeup);
83
        signal(SIGHUP, closeup);
84
 
85
        if ((argc < 1)||(argc > 2)) {
86
                // usage();
87
                printf("USAGE: wbregs address [value]\n");
88
                exit(-1);
89
        }
90
 
91
        const char *nm;
92
        unsigned address = addrdecode(argv[0]), value;
93
        nm = addrname(address);
94
        if (nm == NULL)
95
                nm = "no name";
96
 
97
        if (argc < 2) {
98
                FPGA::BUSW      v;
99
                try {
100
                        unsigned char a, b, c, d;
101
                        v = m_fpga->readio(address);
102
                        a = (v>>24)&0x0ff;
103
                        b = (v>>16)&0x0ff;
104
                        c = (v>> 8)&0x0ff;
105
                        d = (v    )&0x0ff;
106
                        printf("%08x (%8s) : [%c%c%c%c] %08x\n", address, nm,
107
                                isgraph(a)?a:'.', isgraph(b)?b:'.',
108
                                isgraph(c)?c:'.', isgraph(d)?d:'.', v);
109
                } catch(BUSERR b) {
110
                        printf("%08x (%8s) : BUS-ERROR\n", address, nm);
111
                }
112
        } else {
113
                value = strtoul(argv[1], NULL, 0);
114
                m_fpga->writeio(address, value);
115
                printf("%08x (%8s)-> %08x\n", address, nm, value);
116
        }
117
 
118
        if (m_fpga->poll())
119
                printf("FPGA was interrupted\n");
120
        delete  m_fpga;
121
}
122
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.