1 |
30 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
2 |
3 |
dgisselq |
//
|
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 |
30 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
65 |
3 |
dgisselq |
//
|
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 |
30 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
88 |
3 |
dgisselq |
//
|
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 |
|
|
parameter LGMEM = 5'd10, NELM=31, BUSW = 32, SYNCHRONOUS=1;
|
95 |
|
|
// 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 |
|
|
wire [(BUSW-2):0] w_data;
|
142 |
|
|
generate
|
143 |
|
|
if (NELM == BUSW-1)
|
144 |
|
|
assign w_data = i_data;
|
145 |
|
|
else
|
146 |
|
|
assign w_data = { {(BUSW-NELM-1){1'b0}}, i_data };
|
147 |
|
|
endgenerate
|
148 |
|
|
|
149 |
|
|
//
|
150 |
|
|
// To do our compression, we keep track of two registers: the most
|
151 |
|
|
// recent data to the device (imm_ prefix) and the data from one
|
152 |
|
|
// clock ago. This allows us to suppress writes to the scope which
|
153 |
|
|
// would otherwise be two address writes in a row.
|
154 |
|
|
reg imm_adr, lst_adr; // Is this an address (1'b1) or data value?
|
155 |
|
|
reg [(BUSW-2):0] lst_val, // Data for the scope, delayed by one
|
156 |
|
|
imm_val; // Data to write to the scope
|
157 |
|
|
initial lst_dat = 0;
|
158 |
|
|
initial lst_adr = 1'b1;
|
159 |
|
|
initial imm_adr = 1'b1;
|
160 |
|
|
always @(posedge i_clk)
|
161 |
|
|
if (lcl_reset)
|
162 |
|
|
begin
|
163 |
|
|
imm_val <= 31'h0;
|
164 |
|
|
imm_adr <= 1'b1;
|
165 |
|
|
lst_val <= 31'h0;
|
166 |
|
|
lst_adr <= 1'b1;
|
167 |
|
|
lst_dat <= 0;
|
168 |
|
|
end else if ((i_ce)&&(i_data != lst_dat))
|
169 |
|
|
begin
|
170 |
|
|
imm_val <= w_data;
|
171 |
|
|
imm_adr <= 1'b0;
|
172 |
|
|
lst_val <= imm_val;
|
173 |
|
|
lst_adr <= imm_adr;
|
174 |
|
|
lst_dat <= i_data;
|
175 |
|
|
end else begin
|
176 |
|
|
imm_val <= ck_addr; // Minimum value here is '1'
|
177 |
|
|
imm_adr <= 1'b1;
|
178 |
|
|
lst_val <= imm_val;
|
179 |
|
|
lst_adr <= imm_adr;
|
180 |
|
|
end
|
181 |
|
|
|
182 |
|
|
//
|
183 |
|
|
// Here's where we suppress writing pairs of address words to the
|
184 |
|
|
// scope at once.
|
185 |
|
|
//
|
186 |
|
|
reg r_ce;
|
187 |
|
|
reg [(BUSW-1):0] r_data;
|
188 |
|
|
initial r_ce = 1'b0;
|
189 |
|
|
always @(posedge i_clk)
|
190 |
|
|
r_ce <= (~lst_adr)||(~imm_adr);
|
191 |
|
|
always @(posedge i_clk)
|
192 |
|
|
r_data <= ((~lst_adr)||(~imm_adr))
|
193 |
|
|
? { lst_adr, lst_val }
|
194 |
|
|
: { {(32 - NELM){1'b0}}, i_data };
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
//
|
198 |
|
|
// The trigger needs some extra attention, in order to keep triggers
|
199 |
|
|
// that happen between events from being ignored.
|
200 |
|
|
//
|
201 |
|
|
wire w_trigger;
|
202 |
|
|
assign w_trigger = (r_trigger)||(i_trigger);
|
203 |
|
|
|
204 |
|
|
reg r_trigger;
|
205 |
|
|
initial r_trigger = 1'b0;
|
206 |
|
|
always @(posedge i_clk)
|
207 |
|
|
if (lcl_reset)
|
208 |
|
|
r_trigger <= 1'b0;
|
209 |
|
|
else
|
210 |
|
|
r_trigger <= w_trigger;
|
211 |
|
|
|
212 |
|
|
//
|
213 |
|
|
// Call the regular wishbone scope to do all of our real work, now
|
214 |
|
|
// that we've compressed the input.
|
215 |
|
|
//
|
216 |
|
|
wbscope #(.SYNCHRONOUS(1), .LGMEM(LGMEM),
|
217 |
|
|
.BUSW(BUSW)) cheatersscope(i_clk, r_ce, w_trigger, r_data,
|
218 |
|
|
i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
|
219 |
|
|
o_wb_ack, o_wb_stall, o_wb_data, o_interrupt);
|
220 |
|
|
endmodule
|