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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [host/] [wbregs.cpp] - Blame information for rev 31

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

Line No. Rev Author Line
1 8 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    wbregs.cpp
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
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
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14
////////////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
17
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28
// You should have received a copy of the GNU General Public License along
29
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
30
// target there if the PDF file isn't present.)  If not, see
31
// <http://www.gnu.org/licenses/> for a copy.
32
//
33
// License:     GPL, v3, as defined and found on www.gnu.org,
34
//              http://www.gnu.org/licenses/gpl.html
35
//
36
//
37
////////////////////////////////////////////////////////////////////////////////
38
//
39
//
40
//
41
//
42
#include <stdio.h>
43
#include <stdlib.h>
44
#include <unistd.h>
45
#include <strings.h>
46
#include <ctype.h>
47
#include <string.h>
48
#include <signal.h>
49
#include <assert.h>
50
 
51 11 dgisselq
#include "devbus.h"
52
 
53
#ifdef  SIMPLE_DEPPBUS
54
# include "deppbus.h"
55
#else
56
# include "llcomms.h"
57
# include "deppi.h"
58
# include "ttybus.h"
59
 
60
#endif
61
 
62 8 dgisselq
// #include "port.h"
63
#include "regdefs.h"
64
 
65 11 dgisselq
#ifdef  SIMPLE_DEPPBUS
66
# define        FPGAOPEN(SN)    new DEPPBUS(SN);
67
#else
68
# define        FPGAOPEN(SN)    new FPGA(new DEPPI(SN))
69
#endif
70 8 dgisselq
 
71
FPGA    *m_fpga;
72
void    closeup(int v) {
73
        m_fpga->kill();
74
        exit(0);
75
}
76
 
77
int main(int argc, char **argv) {
78
        int     skp=0;
79
 
80
        skp=1;
81
        for(int argn=0; argn<argc-skp; argn++) {
82
                if (argv[argn+skp][0] == '-') {
83
                        // switch(argv[argn+skp][j]) {
84
                        // default:
85
                                // break;
86
                        // }
87
                        skp++; argn--;
88
                } else
89
                        argv[argn] = argv[argn+skp];
90
        } argc -= skp;
91
 
92
        signal(SIGSTOP, closeup);
93
        signal(SIGHUP, closeup);
94
 
95
        if ((argc < 1)||(argc > 2)) {
96
                // usage();
97
                printf("USAGE: wbregs address [value]\n");
98
                exit(-1);
99
        }
100
 
101
        const char *nm;
102
        unsigned address = addrdecode(argv[0]), value;
103
        nm = addrname(address);
104
        if (nm == NULL)
105
                nm = "no name";
106
 
107 11 dgisselq
        char    szSel[64];
108
        strcpy(szSel, "SN:210282768825");
109
        m_fpga = FPGAOPEN(szSel);
110
 
111 8 dgisselq
        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
                        printf("%08x (%8s) : [%c%c%c%c] %08x\n", address, nm,
121
                                isgraph(a)?a:'.', isgraph(b)?b:'.',
122
                                isgraph(c)?c:'.', isgraph(d)?d:'.', v);
123
                } catch(BUSERR b) {
124
                        printf("%08x (%8s) : BUS-ERROR\n", address, nm);
125
                }
126
        } else {
127
                value = strtoul(argv[1], NULL, 0);
128
                m_fpga->writeio(address, value);
129
                printf("%08x (%8s)-> %08x\n", address, nm, value);
130
        }
131
 
132
        if (m_fpga->poll())
133
                printf("FPGA was interrupted\n");
134
        delete  m_fpga;
135
}
136
 

powered by: WebSVN 2.1.0

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