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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sw/] [host/] [wbregs.cpp] - Blame information for rev 34

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

Line No. Rev Author Line
1 4 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    wbregs.cpp
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
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-2016, 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
// You should have received a copy of the GNU General Public License along
30
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
31
// target there if the PDF file isn't present.)  If not, see
32
// <http://www.gnu.org/licenses/> for a copy.
33
//
34
// License:     GPL, v3, as defined and found on www.gnu.org,
35
//              http://www.gnu.org/licenses/gpl.html
36
//
37
//
38
////////////////////////////////////////////////////////////////////////////////
39
//
40
//
41
#include <stdio.h>
42
#include <stdlib.h>
43
#include <unistd.h>
44
#include <strings.h>
45
#include <ctype.h>
46
#include <string.h>
47
#include <signal.h>
48
#include <assert.h>
49
 
50
#include "port.h"
51
#include "regdefs.h"
52
 
53
FPGA    *m_fpga;
54
void    closeup(int v) {
55
        m_fpga->kill();
56
        exit(0);
57
}
58
 
59
void    usage(void) {
60
        printf("USAGE: wbregs address [value]\n"
61
"\n"
62
"\tWBREGS stands for Wishbone registers.  It is designed to allow a\n"
63
"\tuser to peek and poke at registers within a given FPGA design, so\n"
64
"\tlong as those registers have addresses on the wishbone bus.  The\n"
65
"\taddress may reference peripherals or memory, depending upon how the\n"
66
"\tbus is configured.\n"
67
"\n"
68
"\tAddress is either a 32-bit value with the syntax of strtoul, or a\n"
69
"\tregister name.  Register names can be found in regdefs.cpp\n"
70
"\n"
71
"\tIf a value is given, that value will be written to the indicated\n"
72
"\taddress, otherwise the result from reading the address will be \n"
73
"\twritten to the screen.\n");
74
}
75
 
76
int main(int argc, char **argv) {
77
        int     skp=0, port = FPGAPORT;
78
        bool    use_usb = true, use_decimal = false;
79
 
80
        skp=1;
81
        for(int argn=0; argn<argc-skp; argn++) {
82
                if (argv[argn+skp][0] == '-') {
83
                        if (argv[argn+skp][1] == 'd') {
84
                                use_decimal = true;
85
                        } else {
86
                                usage();
87
                                exit(EXIT_SUCCESS);
88
                        }
89
                        skp++; argn--;
90
                } else
91
                        argv[argn] = argv[argn+skp];
92
        } argc -= skp;
93
 
94
        FPGAOPEN(m_fpga);
95
 
96
        signal(SIGSTOP, closeup);
97
        signal(SIGHUP, closeup);
98
 
99
        if ((argc < 1)||(argc > 2)) {
100
                // usage();
101
                printf("USAGE: wbregs address [value]\n");
102
                exit(-1);
103
        }
104
 
105
        const char *nm;
106
        unsigned address = addrdecode(argv[0]), value;
107
        nm = addrname(address);
108
        if (nm == NULL)
109
                nm = "no name";
110
 
111
        if (argc < 2) {
112
                FPGA::BUSW      v;
113
                try {
114
                        unsigned char a, b, c, d;
115
                        v = m_fpga->readio(address);
116
                        a = (v>>24)&0x0ff;
117
                        b = (v>>16)&0x0ff;
118
                        c = (v>> 8)&0x0ff;
119
                        d = (v    )&0x0ff;
120
                        if (use_decimal)
121
                                printf("%d\n", v);
122
                        else
123
                        printf("%08x (%8s) : [%c%c%c%c] %08x\n", address, nm,
124
                                isgraph(a)?a:'.', isgraph(b)?b:'.',
125
                                isgraph(c)?c:'.', isgraph(d)?d:'.', v);
126
                } catch(BUSERR b) {
127
                        printf("%08x (%8s) : BUS-ERROR\n", address, nm);
128
                }
129
        } else {
130
                value = strtoul(argv[1], NULL, 0);
131
                m_fpga->writeio(address, value);
132
                printf("%08x (%8s)-> %08x\n", address, nm, value);
133
        }
134
 
135
        if (m_fpga->poll())
136
                printf("FPGA was interrupted\n");
137
        delete  m_fpga;
138
}
139
 

powered by: WebSVN 2.1.0

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