1 |
21 |
dgisselq |
///////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: wbscopc.v
|
4 |
|
|
//
|
5 |
|
|
// Project: FPGA Library of Routines
|
6 |
|
|
//
|
7 |
|
|
// Purpose: This scope is identical in function to the wishbone scope
|
8 |
|
|
// found in wbscope, save that the output is compressed and that (as a
|
9 |
|
|
// result) it can only handle recording 31 bits at a time. This allows
|
10 |
|
|
// the top bit to indicate an 'address difference'. Okay, there's
|
11 |
|
|
// another difference as well: this version only works in a synchronous
|
12 |
|
|
// fashion with the clock from the WB bus. You cannot have a separate
|
13 |
|
|
// bus and data clock.
|
14 |
|
|
//
|
15 |
|
|
// Reading/decompressing the output of this scope works in this fashion:
|
16 |
|
|
// Once the scope has stopped, read from the port. Any time the high
|
17 |
|
|
// order bit is set, the other 31 bits tell you how many times to repeat
|
18 |
|
|
// the last value. If the high order bit is not set, then the value
|
19 |
|
|
// is a new data value.
|
20 |
|
|
//
|
21 |
|
|
// I've provided this version of a compressed scope to OpenCores for
|
22 |
|
|
// discussion purposes. While wbscope.v works and works well by itself,
|
23 |
|
|
// this compressed scope has a couple of fundamental flaw that I have
|
24 |
|
|
// yet to fix. One of them is that it is impossible to know when the
|
25 |
|
|
// trigger took place. The second problem is that it may be impossible
|
26 |
|
|
// to know the state of the scope at the beginning of the buffer--should
|
27 |
|
|
// the buffer begin with an address difference value instead of a data
|
28 |
|
|
// value.
|
29 |
|
|
//
|
30 |
|
|
// Ideally, the first item read out of the scope should be a data value,
|
31 |
|
|
// even if the scope was skipping values to a new address at the time.
|
32 |
|
|
// If it was in the middle of a skip, the next item out of the scope
|
33 |
|
|
// should be the skip length. This, though, violates the rule that there
|
34 |
|
|
// are (1<<LGMEMLEN) items in the memory, and that the trigger took place
|
35 |
|
|
// on the last item of memory ... so that portion of this compressed
|
36 |
|
|
// scope is still to be defined.
|
37 |
|
|
//
|
38 |
|
|
// Like I said, this version is placed here for discussion purposes,
|
39 |
|
|
// not because it runs well nor because I have recognized that it has any
|
40 |
|
|
// particular value (yet).
|
41 |
|
|
//
|
42 |
|
|
// Well, I take that back. When dealing with an interface such as the
|
43 |
|
|
// PS/2 interface, or even the 16x2 LCD interface, it is often true
|
44 |
|
|
// that things change _very_ slowly. They could change so slowly that
|
45 |
|
|
// the other approach to the scope doesn't work. This then gives you
|
46 |
|
|
// a working scope, by only capturing the changes. You'll still need
|
47 |
|
|
// to figure out (after the fact) when the trigge took place. Perhaps
|
48 |
|
|
// you'll wish to add the trigger as another data line, so you can find
|
49 |
|
|
// when it took place in your own data?
|
50 |
|
|
//
|
51 |
|
|
// Okay, I take that back twice: I'm finding this compressed scope very
|
52 |
|
|
// valuable for evaluating the timing associated with a GPS PPS and
|
53 |
|
|
// associated NMEA stream. I need to collect over a seconds worth of
|
54 |
|
|
// data, and I don't have enough memory to handle one memory value per
|
55 |
|
|
// clock, yet I still want to know exactly when the GPS PPS goes high,
|
56 |
|
|
// when it goes low, when I'm adjusting my clock, and when the clock's
|
57 |
|
|
// PPS output goes high. Did I synchronize them well? Oh, and when does
|
58 |
|
|
// the NMEA time string show up when compared with the PPS? All of those
|
59 |
|
|
// are valuable, but could never be done if the scope wasn't compressed.
|
60 |
|
|
//
|
61 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
62 |
|
|
// Gisselquist Technology, LLC
|
63 |
|
|
//
|
64 |
|
|
///////////////////////////////////////////////////////////////////////////
|
65 |
|
|
//
|
66 |
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
67 |
|
|
//
|
68 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
69 |
|
|
// modify it under the terms of the GNU General Public License as published
|
70 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
71 |
|
|
// your option) any later version.
|
72 |
|
|
//
|
73 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
74 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
75 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
76 |
|
|
// for more details.
|
77 |
|
|
//
|
78 |
|
|
// You should have received a copy of the GNU General Public License along
|
79 |
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
80 |
|
|
// target there if the PDF file isn't present.) If not, see
|
81 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
82 |
|
|
//
|
83 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
84 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
85 |
|
|
//
|
86 |
|
|
//
|
87 |
|
|
/////////////////////////////////////////////////////////////////////////////
|
88 |
|
|
//
|
89 |
|
|
//
|
90 |
|
|
module wbscopc(i_clk, i_ce, i_trigger, i_data,
|
91 |
|
|
i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
|
92 |
|
|
o_wb_ack, o_wb_stall, o_wb_data,
|
93 |
|
|
o_interrupt);
|
94 |
44 |
dgisselq |
parameter LGMEM = 5'd10, NELM=31, BUSW = 32, SYNCHRONOUS=1;
|
95 |
21 |
dgisselq |
// The input signals that we wish to record
|
96 |
|
|
input i_clk, i_ce, i_trigger;
|
97 |
|
|
input [(NELM-1):0] i_data;
|
98 |
|
|
// The WISHBONE bus for reading and configuring this scope
|
99 |
|
|
input i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we;
|
100 |
|
|
input i_wb_addr; // One address line only
|
101 |
|
|
input [(BUSW-1):0] i_wb_data;
|
102 |
|
|
output wire o_wb_ack, o_wb_stall;
|
103 |
|
|
output wire [(BUSW-1):0] o_wb_data;
|
104 |
|
|
// And, finally, for a final flair --- offer to interrupt the CPU after
|
105 |
|
|
// our trigger has gone off. This line is equivalent to the scope
|
106 |
|
|
// being stopped. It is not maskable here.
|
107 |
|
|
output wire o_interrupt;
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
// Let's first see how far we can get by cheating. We'll use the
|
111 |
|
|
// wbscope program, and suffer a lack of several features
|
112 |
|
|
|
113 |
|
|
// When is the full scope reset? Capture that reset bit from any
|
114 |
|
|
// write.
|
115 |
|
|
wire lcl_reset;
|
116 |
|
|
assign lcl_reset = (i_wb_cyc)&&(i_wb_stb)&&(~i_wb_addr)&&(i_wb_we)
|
117 |
|
|
&&(~i_wb_data[31]);
|
118 |
|
|
|
119 |
|
|
// A big part of this scope is the 'address' of any particular
|
120 |
|
|
// data value. As of this current version, the 'address' changed
|
121 |
|
|
// in definition from an absolute time (which had all kinds of
|
122 |
|
|
// problems) to a difference in time. Hence, when the address line
|
123 |
|
|
// is high on decompression, the 'address' field will record an
|
124 |
|
|
// address difference.
|
125 |
|
|
//
|
126 |
|
|
// To implement this, we set our 'address' to zero any time the
|
127 |
|
|
// data changes, but increment it on all other clocks. Should the
|
128 |
|
|
// address difference get to our maximum value, we let it saturate
|
129 |
|
|
// rather than overflow.
|
130 |
|
|
reg [(BUSW-2):0] ck_addr;
|
131 |
|
|
reg [(NELM-1):0] lst_dat;
|
132 |
|
|
initial ck_addr = 0;
|
133 |
|
|
always @(posedge i_clk)
|
134 |
|
|
if ((lcl_reset)||((i_ce)&&(i_data != lst_dat)))
|
135 |
|
|
ck_addr <= 0;
|
136 |
|
|
else if (&ck_addr)
|
137 |
|
|
; // Saturated (non-overflowing) address diff
|
138 |
|
|
else
|
139 |
|
|
ck_addr <= ck_addr + 1;
|
140 |
|
|
|
141 |
|
|
//
|
142 |
|
|
// To do our compression, we keep track of two registers: the most
|
143 |
|
|
// recent data to the device (imm_ prefix) and the data from one
|
144 |
|
|
// clock ago. This allows us to suppress writes to the scope which
|
145 |
|
|
// would otherwise be two address writes in a row.
|
146 |
|
|
reg imm_adr, lst_adr; // Is this an address (1'b1) or data value?
|
147 |
|
|
reg [(BUSW-2):0] lst_val, // Data for the scope, delayed by one
|
148 |
|
|
imm_val; // Data to write to the scope
|
149 |
|
|
initial lst_dat = 0;
|
150 |
|
|
initial lst_adr = 1'b1;
|
151 |
|
|
initial imm_adr = 1'b1;
|
152 |
|
|
always @(posedge i_clk)
|
153 |
|
|
if (lcl_reset)
|
154 |
|
|
begin
|
155 |
|
|
imm_val <= 31'h0;
|
156 |
|
|
imm_adr <= 1'b1;
|
157 |
|
|
lst_val <= 31'h0;
|
158 |
|
|
lst_adr <= 1'b1;
|
159 |
|
|
lst_dat <= 0;
|
160 |
|
|
end else if ((i_ce)&&(i_data != lst_dat))
|
161 |
|
|
begin
|
162 |
|
|
imm_val <= { {(BUSW-1-NELM){1'b0}}, i_data };
|
163 |
|
|
imm_adr <= 1'b0;
|
164 |
|
|
lst_val <= imm_val;
|
165 |
|
|
lst_adr <= imm_adr;
|
166 |
|
|
lst_dat <= i_data;
|
167 |
|
|
end else begin
|
168 |
|
|
imm_val <= ck_addr; // Minimum value here is '1'
|
169 |
|
|
imm_adr <= 1'b1;
|
170 |
|
|
lst_val <= imm_val;
|
171 |
|
|
lst_adr <= imm_adr;
|
172 |
|
|
end
|
173 |
|
|
|
174 |
|
|
//
|
175 |
|
|
// Here's where we suppress writing pairs of address words to the
|
176 |
|
|
// scope at once.
|
177 |
|
|
//
|
178 |
|
|
reg r_ce;
|
179 |
|
|
reg [(BUSW-1):0] r_data;
|
180 |
|
|
initial r_ce = 1'b0;
|
181 |
|
|
always @(posedge i_clk)
|
182 |
|
|
r_ce <= (~lst_adr)||(~imm_adr);
|
183 |
|
|
always @(posedge i_clk)
|
184 |
|
|
r_data <= ((~lst_adr)||(~imm_adr))
|
185 |
|
|
? { lst_adr, lst_val }
|
186 |
|
|
: { {(32 - NELM){1'b0}}, i_data };
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
//
|
190 |
|
|
// The trigger needs some extra attention, in order to keep triggers
|
191 |
|
|
// that happen between events from being ignored.
|
192 |
|
|
//
|
193 |
|
|
wire w_trigger;
|
194 |
|
|
assign w_trigger = (r_trigger)||(i_trigger);
|
195 |
|
|
|
196 |
|
|
reg r_trigger;
|
197 |
|
|
initial r_trigger = 1'b0;
|
198 |
|
|
always @(posedge i_clk)
|
199 |
|
|
if (lcl_reset)
|
200 |
|
|
r_trigger <= 1'b0;
|
201 |
|
|
else
|
202 |
|
|
r_trigger <= w_trigger;
|
203 |
|
|
|
204 |
|
|
//
|
205 |
|
|
// Call the regular wishbone scope to do all of our real work, now
|
206 |
|
|
// that we've compressed the input.
|
207 |
|
|
//
|
208 |
|
|
wbscope #(.SYNCHRONOUS(1), .LGMEM(LGMEM),
|
209 |
|
|
.BUSW(BUSW)) cheatersscope(i_clk, r_ce, w_trigger, r_data,
|
210 |
|
|
i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
|
211 |
|
|
o_wb_ack, o_wb_stall, o_wb_data, o_interrupt);
|
212 |
|
|
endmodule
|