Line 1... |
Line 1... |
///////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Filename: cfgscope.cpp
|
// Filename: cfgscope.cpp
|
//
|
//
|
// Project: FPGA library development (Basys-3 development board)
|
// Project: WBScope, a wishbone hosted scope
|
//
|
//
|
// Purpose: To read out, and decompose, the results of the wishbone scope
|
// Purpose: To read out, and decompose, the results of the wishbone scope
|
// as applied to the ICAPE2 interaction.
|
// as applied to the ICAPE2 interaction.
|
//
|
//
|
// This is provided together with the wbscope project as an
|
// This is provided together with the wbscope project as an example of
|
// example of what might be done with the wishbone scope.
|
// what might be done with the wishbone scope. The intermediate details,
|
// The intermediate details, though, between this and the
|
// though, between this and the wishbone scope are not part of the
|
// wishbone scope are not part of the wishbone scope project.
|
// wishbone scope project.
|
//
|
//
|
// Using this particular scope made it a *lot* easier to get the
|
// Using this particular scope made it a *lot* easier to get the ICAPE2
|
// ICAPE2 interface up and running, since I was able to see what
|
// interface up and running, since I was able to see what was going right
|
// was going right (or wrong) with the interface as I was
|
// (or wrong) with the interface as I was developing it. Sure, it
|
// developing it. Sure, it would've been better to get it to work
|
// would've been better to get it to work under a simulator instead of
|
// under a simulator instead of with the scope, but not being
|
// with the scope, but not being certain of how the interface was
|
// certain of how the interface was supposed to work made building
|
// supposed to work made building a simulator difficult.
|
// a simulator difficult.
|
|
//
|
//
|
// Creator: Dan Gisselquist, Ph.D.
|
// Creator: Dan Gisselquist, Ph.D.
|
// Gisselquist Technology, LLC
|
// Gisselquist Technology, LLC
|
//
|
//
|
///////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
|
//
|
//
|
// This program is free software (firmware): you can redistribute it and/or
|
// This program is free software (firmware): you can redistribute it and/or
|
// modify it under the terms of the GNU General Public License as published
|
// modify it under the terms of the GNU General Public License as published
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
// your option) any later version.
|
// your option) any later version.
|
Line 36... |
Line 35... |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// for more details.
|
// for more details.
|
//
|
//
|
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
// with this program. (It's in the $(ROOT)/doc directory. Run make with no
|
// target there if the PDF file isn't present.) If not, see
|
// target there if the PDF file isn't present.) If not, see
|
// <http://www.gnu.org/licenses/> for a copy.
|
// <http://www.gnu.org/licenses/> for a copy.
|
//
|
//
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
// http://www.gnu.org/licenses/gpl.html
|
// http://www.gnu.org/licenses/gpl.html
|
//
|
//
|
//
|
//
|
///////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <strings.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
#include <signal.h>
|
|
#include <assert.h>
|
|
|
|
#include "port.h"
|
|
#include "llcomms.h" // This defines how we talk to the device over wishbone
|
|
#include "regdefs.h"
|
|
|
|
// Here are the two registers needed for accessing our scope: A control register
|
|
// and a data register.
|
|
#define WBSCOPE R_CFGSCOPE
|
|
#define WBSCOPEDATA R_CFGSCOPED
|
|
|
|
//
|
//
|
// The DEVBUS structure encapsulates wishbone accesses, so that this code can
|
//
|
// access the wishbone bus on the FPGA.
|
#include "devbus.h"
|
DEVBUS *m_fpga;
|
#include "scopecls.h"
|
void closeup(int v) {
|
|
m_fpga->kill();
|
|
exit(0);
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
// Open up a port to talk to the FPGA ...
|
|
#ifndef FORCE_UART
|
|
m_fpga = new FPGA(new NETCOMMS("lazarus",PORT));
|
|
#else
|
|
m_fpga = new FPGA(new TTYCOMMS("/dev/ttyUSB2"));
|
|
#endif
|
|
|
|
signal(SIGSTOP, closeup);
|
//
|
signal(SIGHUP, closeup);
|
// CFGSCOPE
|
|
//
|
|
// When you wish to build your own scope, you'll need to build a version of this
|
|
// class to do so. This class has two particular functions to it: one
|
|
// (optional) one to define the traces used incase we wish to split these apart
|
|
// for output to a VCD file. The other function is for use with debug-by-printf
|
|
// approaches. As a result, it provides for a more flexible (textual) output.
|
|
//
|
|
class CFGSCOPE : public SCOPE {
|
|
|
// Check to see whether or not the scope has captured the data we need
|
virtual void define_traces(void) {
|
// yet or not. If not, exit kindly.
|
// Heres the interface for VCD files: We need to tell the VCD
|
unsigned v, lgln, scoplen;
|
// writer the names of all of our traces, how many bits each
|
v = m_fpga->readio(WBSCOPE);
|
// trace uses, and where the location of the value exists within
|
if (0x60000000 != (v & 0x60000000)) {
|
// the 32-bit trace word.
|
printf("Scope is not yet ready:\n");
|
register_trace("cs_n", 1, 31);
|
printf("\tRESET:\t\t%s\n", (v&0x80000000)?"Ongoing":"Complete");
|
register_trace("we_n", 1, 30);
|
printf("\tSTOPPED:\t%s\n", (v&0x40000000)?"Yes":"No");
|
register_trace("code", 6, 24);
|
printf("\tTRIGGERED:\t%s\n", (v&0x20000000)?"Yes":"No");
|
register_trace("value", 24, 0);
|
printf("\tPRIMED:\t\t%s\n", (v&0x10000000)?"Yes":"No");
|
|
printf("\tMANUAL:\t\t%s\n", (v&0x08000000)?"Yes":"No");
|
|
printf("\tDISABLED:\t%s\n", (v&0x04000000)?"Yes":"No");
|
|
printf("\tZERO:\t\t%s\n", (v&0x02000000)?"Yes":"No");
|
|
exit(0);
|
|
}
|
}
|
|
|
// Since the length of the scope memory is a configuration parameter
|
//
|
// internal to the scope, we read it here to find out how it was
|
// decode
|
// configured.
|
//
|
lgln = (v>>20) & 0x1f;
|
// Decode the value to the standard-output stream. How you decode this
|
scoplen = (1<<lgln);
|
// value is up to you. Prior to the value being printed, a prefix
|
|
// identifying the clock number (as counted by the scope, with the
|
DEVBUS::BUSW *buf;
|
// internal clock enable on), and the raw value will be printed out.
|
buf = new DEVBUS::BUSW[scoplen];
|
// Further, after doing whatever printing you wish to do here, a newline
|
|
// will be printed before going to the next value.
|
// There are two means of reading from a DEVBUS interface: The first
|
//
|
// is a vector read, optimized so that the address and read command
|
virtual void decode(DEVBUS::BUSW v) const {
|
// only needs to be sent once. This is the optimal means. However,
|
// Now, let's decompose our 32-bit wires into something ...
|
// if the bus isn't (yet) trustworthy, it may be more reliable to access
|
// meaningful and dump it to stdout. This section will change
|
// the port by reading one register at a time--hence the second method.
|
// from project to project, scope to scope, depending on what
|
// If the bus works, you'll want to use readz(): read scoplen values
|
// wires are placed into the scope.
|
// into the buffer, from the address WBSCOPEDATA, without incrementing
|
printf("%s %s ", (v&0x80000000)?" ":"CS",
|
// the address each time (hence the 'z' in readz--for zero increment).
|
(v&0x40000000)?"RD":"WR");
|
if (true) {
|
|
m_fpga->readz(WBSCOPEDATA, scoplen, buf);
|
|
|
|
printf("Vector read complete\n");
|
|
} else {
|
|
for(int i=0; i<scoplen; i++)
|
|
buf[i] = m_fpga->readio(WBSCOPEDATA);
|
|
}
|
|
|
|
// Now, let's decompose our 32-bit wires into something ... meaningful.
|
unsigned cw = (v>>24)&0x03f;
|
// This section will change from project to project, scope to scope,
|
|
// depending on what wires are placed into the scope.
|
|
for(int i=0; i<scoplen; i++) {
|
|
if ((i>0)&&(buf[i] == buf[i-1])&&
|
|
(i<scoplen-1)&&(buf[i] == buf[i+1]))
|
|
continue;
|
|
printf("%6d %08x:", i, buf[i]);
|
|
printf("%s %s ", (buf[i]&0x80000000)?" ":"CS",
|
|
(buf[i]&0x40000000)?"RD":"WR");
|
|
unsigned cw = (buf[i]>>24)&0x03f;
|
|
switch(cw) {
|
switch(cw) {
|
case 0x20: printf("DUMMY"); break;
|
case 0x20: printf("DUMMY"); break;
|
case 0x10: printf("NOOP "); break;
|
case 0x10: printf("NOOP "); break;
|
case 0x08: printf("SYNC "); break;
|
case 0x08: printf("SYNC "); break;
|
case 0x04: printf("CMD "); break;
|
case 0x04: printf("CMD "); break;
|
case 0x02: printf("IPROG"); break;
|
case 0x02: printf("IPROG"); break;
|
case 0x01: printf("DSYNC"); break;
|
case 0x01: printf("DSYNC"); break;
|
default: printf("OTHER"); break;
|
default: printf("OTHER"); break;
|
}
|
}
|
printf(" -> %02x\n", buf[i] & 0x0ffffff);
|
printf(" -> %02x", v & 0x0ffffff);
|
|
}
|
|
};
|
|
|
|
int main(int argc, char **argv) {
|
|
// The DEVBUS structure encapsulates wishbone accesses, so that this
|
|
// code can access the wishbone bus on the FPGA.
|
|
DEVBUS *m_fpga;
|
|
|
|
// Open up a port to talk to the FPGA ...
|
|
//
|
|
// This may be unique to your FPGA, so feel free to adjust these lines
|
|
// for your setup. The result, though, must be a DEVBUS structure
|
|
// giving you access to the FPGA.
|
|
#ifndef FORCE_UART
|
|
m_fpga = new FPGA(new NETCOMMS("lazarus",PORT));
|
|
#else
|
|
m_fpga = new FPGA(new TTYCOMMS("/dev/ttyUSB2"));
|
|
#endif
|
|
|
|
//
|
|
CFGSCOPE *scope = new CFGSCOPE(m_fpga, WBSCOPE);
|
|
|
|
// Check to see whether or not the scope has captured the data we need
|
|
// yet or not.
|
|
if (scope->ready()) {
|
|
// If the data has been captured, we call print(). This
|
|
// function will print all our values to the standard output,
|
|
// and it will call the decode() function above to do it.
|
|
scope->print();
|
|
|
|
// You can also write the results to a VCD trace file. To do
|
|
// this, just call writevcd and pass it the name you wish your
|
|
// VCD file to have.
|
|
scope->writevcd("cfgtrace.vcd");
|
|
} else {
|
|
// If the scope isnt yet ready, print a message, decode its
|
|
// current state, and exit kindly.
|
|
printf("Scope is not (yet) ready:\n");
|
|
scope->decode_control();
|
}
|
}
|
|
|
// Clean up our interface, now, and we're done.
|
// Clean up our interface, now, and we're done.
|
delete m_fpga;
|
delete m_fpga;
|
}
|
}
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|