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

Subversion Repositories wbscope

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

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

Line No. Rev Author Line
1 2 dgisselq
///////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    cfgscope.cpp
4
//
5
// Project:     FPGA library development (Basys-3 development board)
6
//
7
// Purpose:     To read out, and decompose, the results of the wishbone scope
8
//              as applied to the ICAPE2 interaction.
9
//
10
//              This is provided together with the wbscope project as an
11
//              example of what might be done with the wishbone scope.
12
//              The intermediate details, though, between this and the
13
//              wishbone scope are not part of the wishbone scope project.
14
//
15
//              Using this particular scope made it a *lot* easier to get the
16
//              ICAPE2 interface up and running, since I was able to see what
17
//              was going right (or wrong) with the interface as I was 
18
//              developing it.  Sure, it would've been better to get it to work
19
//              under a simulator instead of with the scope, but not being
20
//              certain of how the interface was supposed to work made building
21
//              a simulator difficult.
22
//
23
// Creator:     Dan Gisselquist, Ph.D.
24 11 dgisselq
//              Gisselquist Technology, LLC
25 2 dgisselq
//
26
///////////////////////////////////////////////////////////////////////////
27
//
28
// Copyright (C) 2015, Gisselquist Technology, LLC
29
//
30
// This program is free software (firmware): you can redistribute it and/or
31
// modify it under the terms of  the GNU General Public License as published
32
// by the Free Software Foundation, either version 3 of the License, or (at
33
// your option) any later version.
34
//
35
// This program is distributed in the hope that it will be useful, but WITHOUT
36
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
37
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
38
// for more details.
39
//
40
// You should have received a copy of the GNU General Public License along
41
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
42
// target there if the PDF file isn't present.)  If not, see
43
// <http://www.gnu.org/licenses/> for a copy.
44
//
45
// License:     GPL, v3, as defined and found on www.gnu.org,
46
//              http://www.gnu.org/licenses/gpl.html
47
//
48
//
49
///////////////////////////////////////////////////////////////////////////
50
#include <stdio.h>
51
#include <stdlib.h>
52
#include <unistd.h>
53
#include <strings.h>
54
#include <ctype.h>
55
#include <string.h>
56
#include <signal.h>
57
#include <assert.h>
58
 
59
#include "port.h"
60
#include "llcomms.h"    // This defines how we talk to the device over wishbone
61
#include "regdefs.h"
62
 
63
// Here are the two registers needed for accessing our scope: A control register
64
// and a data register.  
65
#define WBSCOPE         R_CFGSCOPE
66
#define WBSCOPEDATA     R_CFGSCOPED
67
 
68
//
69
// The DEVBUS structure encapsulates wishbone accesses, so that this code can
70
// access the wishbone bus on the FPGA.
71
DEVBUS  *m_fpga;
72
void    closeup(int v) {
73
        m_fpga->kill();
74
        exit(0);
75
}
76
 
77
int main(int argc, char **argv) {
78
        // Open up a port to talk to the FPGA ...
79
#ifndef FORCE_UART
80
        m_fpga = new FPGA(new NETCOMMS("lazarus",PORT));
81
#else
82
        m_fpga = new FPGA(new TTYCOMMS("/dev/ttyUSB2"));
83
#endif
84
 
85
        signal(SIGSTOP, closeup);
86
        signal(SIGHUP, closeup);
87
 
88
        // Check to see whether or not the scope has captured the data we need
89
        // yet or not.  If not, exit kindly.
90
        unsigned        v, lgln, scoplen;
91
        v = m_fpga->readio(WBSCOPE);
92
        if (0x60000000 != (v & 0x60000000)) {
93
                printf("Scope is not yet ready:\n");
94
                printf("\tRESET:\t\t%s\n", (v&0x80000000)?"Ongoing":"Complete");
95
                printf("\tSTOPPED:\t%s\n", (v&0x40000000)?"Yes":"No");
96
                printf("\tTRIGGERED:\t%s\n", (v&0x20000000)?"Yes":"No");
97
                printf("\tPRIMED:\t\t%s\n", (v&0x10000000)?"Yes":"No");
98
                printf("\tMANUAL:\t\t%s\n", (v&0x08000000)?"Yes":"No");
99
                printf("\tDISABLED:\t%s\n", (v&0x04000000)?"Yes":"No");
100
                printf("\tZERO:\t\t%s\n", (v&0x02000000)?"Yes":"No");
101
                exit(0);
102
        }
103
 
104
        // Since the length of the scope memory is a configuration parameter
105
        // internal to the scope, we read it here to find out how it was
106
        // configured.
107
        lgln = (v>>20) & 0x1f;
108
        scoplen = (1<<lgln);
109
 
110
        DEVBUS::BUSW    *buf;
111
        buf = new DEVBUS::BUSW[scoplen];
112
 
113
        // There are two means of reading from a DEVBUS interface: The first
114
        // is a vector read, optimized so that the address and read command
115
        // only needs to be sent once.  This is the optimal means.  However,
116
        // if the bus isn't (yet) trustworthy, it may be more reliable to access
117
        // the port by reading one register at a time--hence the second method.
118
        // If the bus works, you'll want to use readz(): read scoplen values
119
        // into the buffer, from the address WBSCOPEDATA, without incrementing
120
        // the address each time (hence the 'z' in readz--for zero increment).
121
        if (true) {
122
                m_fpga->readz(WBSCOPEDATA, scoplen, buf);
123
 
124
                printf("Vector read complete\n");
125
        } else {
126
                for(int i=0; i<scoplen; i++)
127
                        buf[i] = m_fpga->readio(WBSCOPEDATA);
128
        }
129
 
130
        // Now, let's decompose our 32-bit wires into something ... meaningful.
131
        // This section will change from project to project, scope to scope,
132
        // depending on what wires are placed into the scope.
133
        for(int i=0; i<scoplen; i++) {
134
                if ((i>0)&&(buf[i] == buf[i-1])&&
135
                                (i<scoplen-1)&&(buf[i] == buf[i+1]))
136
                        continue;
137
                printf("%6d %08x:", i, buf[i]);
138
                printf("%s %s ", (buf[i]&0x80000000)?"  ":"CS",
139
                                 (buf[i]&0x40000000)?"RD":"WR");
140
                unsigned cw = (buf[i]>>24)&0x03f;
141
                switch(cw) {
142
                        case    0x20: printf("DUMMY"); break;
143
                        case    0x10: printf("NOOP "); break;
144
                        case    0x08: printf("SYNC "); break;
145
                        case    0x04: printf("CMD  "); break;
146
                        case    0x02: printf("IPROG"); break;
147
                        case    0x01: printf("DSYNC"); break;
148
                        default:      printf("OTHER"); break;
149
                }
150
                printf(" -> %02x\n", buf[i] & 0x0ffffff);
151
        }
152
 
153
        // Clean up our interface, now, and we're done.
154
        delete  m_fpga;
155
}
156
 

powered by: WebSVN 2.1.0

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