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

Subversion Repositories wbscope

[/] [wbscope/] [trunk/] [sw/] [cfgscope.cpp] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 2 dgisselq
//
3
// Filename:    cfgscope.cpp
4
//
5 12 dgisselq
// Project:     WBScope, a wishbone hosted scope
6 2 dgisselq
//
7
// Purpose:     To read out, and decompose, the results of the wishbone scope
8
//              as applied to the ICAPE2 interaction.
9
//
10 12 dgisselq
//      This is provided together with the wbscope project as an example of
11
//      what might be done with the wishbone scope.  The intermediate details,
12
//      though, between this and the wishbone scope are not part of the
13
//      wishbone scope project.
14 2 dgisselq
//
15 12 dgisselq
//      Using this particular scope made it a *lot* easier to get the ICAPE2
16
//      interface up and running, since I was able to see what was going right
17
//      (or wrong) with the interface as I was developing it.  Sure, it
18
//      would've been better to get it to work under a simulator instead of
19
//      with the scope, but not being certain of how the interface was
20
//      supposed to work made building a simulator difficult.
21 2 dgisselq
//
22
// Creator:     Dan Gisselquist, Ph.D.
23 11 dgisselq
//              Gisselquist Technology, LLC
24 2 dgisselq
//
25 12 dgisselq
////////////////////////////////////////////////////////////////////////////////
26 2 dgisselq
//
27 12 dgisselq
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
28 2 dgisselq
//
29
// This program is free software (firmware): you can redistribute it and/or
30
// modify it under the terms of  the GNU General Public License as published
31
// by the Free Software Foundation, either version 3 of the License, or (at
32
// your option) any later version.
33
//
34
// This program is distributed in the hope that it will be useful, but WITHOUT
35
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
36
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
37
// for more details.
38
//
39
// You should have received a copy of the GNU General Public License along
40 12 dgisselq
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
41 2 dgisselq
// target there if the PDF file isn't present.)  If not, see
42
// <http://www.gnu.org/licenses/> for a copy.
43
//
44
// License:     GPL, v3, as defined and found on www.gnu.org,
45
//              http://www.gnu.org/licenses/gpl.html
46
//
47
//
48 12 dgisselq
////////////////////////////////////////////////////////////////////////////////
49
//
50
//
51
#include "devbus.h"
52
#include "scopecls.h"
53 2 dgisselq
 
54 12 dgisselq
//
55
// CFGSCOPE
56
//
57
// When you wish to build your own scope, you'll need to build a version of this
58
// class to do so.  This class has two particular functions to it: one
59
// (optional) one to define the traces used incase we wish to split these apart
60
// for output to a VCD file.  The other function is for use with debug-by-printf
61
// approaches.  As a result, it provides for a more flexible (textual) output.
62
//
63
class   CFGSCOPE : public SCOPE {
64 2 dgisselq
 
65 12 dgisselq
        virtual void    define_traces(void) {
66
                // Heres the interface for VCD files: We need to tell the VCD
67
                // writer the names of all of our traces, how many bits each
68
                // trace uses, and where the location of the value exists within
69
                // the 32-bit trace word.
70
                register_trace("cs_n",   1, 31);
71
                register_trace("we_n",   1, 30);
72
                register_trace("code",   6, 24);
73
                register_trace("value", 24,  0);
74
        }
75 2 dgisselq
 
76 12 dgisselq
        //
77
        // decode
78
        //
79
        // Decode the value to the standard-output stream.  How you decode this
80
        // value is up to you.  Prior to the value being printed, a prefix
81
        // identifying the clock number (as counted by the scope, with the
82
        // internal clock enable on), and the raw value will be printed out.
83
        // Further, after doing whatever printing you wish to do here, a newline
84
        // will be printed before going to the next value.
85
        //
86
        virtual void    decode(DEVBUS::BUSW v) const {
87
                // Now, let's decompose our 32-bit wires into something ...
88
                // meaningful and dump it to stdout.  This section will change
89
                // from project to project, scope to scope, depending on what
90
                // wires are placed into the scope.
91
                printf("%s %s ", (v&0x80000000)?"  ":"CS",
92
                                (v&0x40000000)?"RD":"WR");
93 2 dgisselq
 
94 12 dgisselq
                unsigned cw = (v>>24)&0x03f;
95
                switch(cw) {
96
                        case    0x20: printf("DUMMY"); break;
97
                        case    0x10: printf("NOOP "); break;
98
                        case    0x08: printf("SYNC "); break;
99
                        case    0x04: printf("CMD  "); break;
100
                        case    0x02: printf("IPROG"); break;
101
                        case    0x01: printf("DSYNC"); break;
102
                        default:      printf("OTHER"); break;
103
                }
104
                printf(" -> %02x", v & 0x0ffffff);
105
        }
106
};
107
 
108 2 dgisselq
int main(int argc, char **argv) {
109 12 dgisselq
        // The DEVBUS structure encapsulates wishbone accesses, so that this
110
        // code can access the wishbone bus on the FPGA.
111
        DEVBUS  *m_fpga;
112
 
113 2 dgisselq
        // Open up a port to talk to the FPGA ...
114 12 dgisselq
        //
115
        // This may be unique to your FPGA, so feel free to adjust these lines
116
        // for your setup.  The result, though, must be a DEVBUS structure
117
        // giving you access to the FPGA.
118 2 dgisselq
#ifndef FORCE_UART
119
        m_fpga = new FPGA(new NETCOMMS("lazarus",PORT));
120
#else
121
        m_fpga = new FPGA(new TTYCOMMS("/dev/ttyUSB2"));
122
#endif
123
 
124 12 dgisselq
        // 
125
        CFGSCOPE *scope = new CFGSCOPE(m_fpga, WBSCOPE);
126 2 dgisselq
 
127
        // Check to see whether or not the scope has captured the data we need
128 12 dgisselq
        // yet or not.
129
        if (scope->ready()) {
130
                // If the data has been captured, we call print().  This
131
                // function will print all our values to the standard output,
132
                // and it will call the decode() function above to do it.
133
                scope->print();
134 2 dgisselq
 
135 12 dgisselq
                // You can also write the results to a VCD trace file.  To do
136
                // this, just call writevcd and pass it the name you wish your
137
                // VCD file to have.
138
                scope->writevcd("cfgtrace.vcd");
139 2 dgisselq
        } else {
140 12 dgisselq
                // If the scope isnt yet ready, print a message, decode its
141
                // current state, and exit kindly.
142
                printf("Scope is not (yet) ready:\n");
143
                scope->decode_control();
144 2 dgisselq
        }
145
 
146
        // Clean up our interface, now, and we're done.
147
        delete  m_fpga;
148
}

powered by: WebSVN 2.1.0

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