1 |
3 |
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
|
9 |
|
|
// (as a result) it can only handle recording 31 bits at a time.
|
10 |
|
|
// This allows the top bit to indicate an 'address'.
|
11 |
|
|
//
|
12 |
|
|
// Reading/decompressing the output of this scope works in this
|
13 |
|
|
// fashion: clear a memory. Then, once the scope has stopped,
|
14 |
|
|
// read from the port. If it's an address (high bit set), then
|
15 |
|
|
// jump to that address. If it's not, then write into that
|
16 |
|
|
// memory location and increment the memory address after writing.
|
17 |
|
|
//
|
18 |
|
|
// I've provided this version of a compressed scope to OpenCores for
|
19 |
|
|
// discussion purposes. While wbscope.v works and works well by itself,
|
20 |
|
|
// this compressed scope has a fundamental flaw that I have yet to fix:
|
21 |
|
|
// The first values out of the scope take place at an unknown address.
|
22 |
|
|
//
|
23 |
|
|
// Ideally, the first item read out of the scope should be a data value,
|
24 |
|
|
// even if the scope was skipping values to a new address at the time.
|
25 |
|
|
// If it was in the middle of a skip, the next item out of the scope
|
26 |
|
|
// should be the skip length. This, though, violates the rule that there
|
27 |
|
|
// are (1<<LGMEMLEN) items in the memory, and that the trigger took place
|
28 |
|
|
// on the last item of memory ... so that portion of this compressed
|
29 |
|
|
// scope is still to be defined.
|
30 |
|
|
//
|
31 |
|
|
// Like I said, this version is placed here for discussion purposes,
|
32 |
|
|
// not because it runs nor because I have recognized that it has any
|
33 |
|
|
// particular value (yet).
|
34 |
|
|
//
|
35 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
36 |
|
|
// Gisselquist Tecnology, LLC
|
37 |
|
|
//
|
38 |
|
|
///////////////////////////////////////////////////////////////////////////
|
39 |
|
|
//
|
40 |
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
41 |
|
|
//
|
42 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
43 |
|
|
// modify it under the terms of the GNU General Public License as published
|
44 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
45 |
|
|
// your option) any later version.
|
46 |
|
|
//
|
47 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
48 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
49 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
50 |
|
|
// for more details.
|
51 |
|
|
//
|
52 |
|
|
// You should have received a copy of the GNU General Public License along
|
53 |
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
54 |
|
|
// target there if the PDF file isn't present.) If not, see
|
55 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
56 |
|
|
//
|
57 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
58 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
59 |
|
|
//
|
60 |
|
|
//
|
61 |
|
|
/////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
//
|
63 |
|
|
//
|
64 |
|
|
module wbscopc(i_clk, i_ce, i_trigger, i_data,
|
65 |
|
|
i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
|
66 |
|
|
o_wb_ack, o_wb_stall, o_wb_data,
|
67 |
|
|
o_interrupt);
|
68 |
|
|
parameter LGMEM = 5'd10, BUSW = 32, SYNCHRONOUS=1;
|
69 |
|
|
// The input signals that we wish to record
|
70 |
|
|
input i_clk, i_ce, i_trigger;
|
71 |
|
|
input [(BUSW-2):0] i_data;
|
72 |
|
|
// The WISHBONE bus for reading and configuring this scope
|
73 |
|
|
input i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we;
|
74 |
|
|
input i_wb_addr; // One address line only
|
75 |
|
|
input [(BUSW-1):0] i_wb_data;
|
76 |
|
|
output wire o_wb_ack, o_wb_stall;
|
77 |
|
|
output wire [(BUSW-1):0] o_wb_data;
|
78 |
|
|
// And, finally, for a final flair --- offer to interrupt the CPU after
|
79 |
|
|
// our trigger has gone off. This line is equivalent to the scope
|
80 |
|
|
// being stopped. It is not maskable here.
|
81 |
|
|
output wire o_interrupt;
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
// Let's first see how far we can get by cheating. We'll use the
|
85 |
|
|
// wbscope program, and suffer a lack of several features
|
86 |
|
|
wire lcl_reset;
|
87 |
|
|
assign lcl_reset = (i_wb_cyc)&&(i_wb_stb)&&(~i_wb_addr)&&(i_wb_we)
|
88 |
|
|
&&(~i_wb_data[31]);
|
89 |
|
|
|
90 |
|
|
reg [(BUSW-2):0] ck_addr;
|
91 |
|
|
initial ck_addr = 0;
|
92 |
|
|
always @(posedge i_clk)
|
93 |
|
|
if (lcl_reset)
|
94 |
|
|
ck_addr <= 0;
|
95 |
|
|
else
|
96 |
|
|
ck_addr <= ck_addr + 1;
|
97 |
|
|
|
98 |
|
|
reg imm_adr, lst_adr;
|
99 |
|
|
reg [(BUSW-2):0] lst_dat, lst_val, imm_val;
|
100 |
|
|
initial lst_dat = 0;
|
101 |
|
|
initial lst_adr = 1'b1;
|
102 |
|
|
initial imm_adr = 1'b1;
|
103 |
|
|
always @(posedge i_clk)
|
104 |
|
|
if (lcl_reset)
|
105 |
|
|
begin
|
106 |
|
|
imm_val <= 31'h0;
|
107 |
|
|
imm_adr <= 1'b1;
|
108 |
|
|
lst_val <= 31'h0;
|
109 |
|
|
lst_adr <= 1'b1;
|
110 |
|
|
lst_dat <= 31'b0;
|
111 |
|
|
end else if ((i_ce)&&(i_data != lst_dat))
|
112 |
|
|
begin
|
113 |
|
|
imm_val <= i_data;
|
114 |
|
|
imm_adr <= 1'b0;
|
115 |
|
|
lst_val <= imm_val;
|
116 |
|
|
lst_adr <= imm_adr;
|
117 |
|
|
lst_dat <= i_data;
|
118 |
|
|
end else begin
|
119 |
|
|
imm_val <= ck_addr;
|
120 |
|
|
imm_adr <= 1'b1;
|
121 |
|
|
lst_val <= imm_val;
|
122 |
|
|
lst_adr <= imm_adr;
|
123 |
|
|
end
|
124 |
|
|
|
125 |
|
|
reg r_ce;
|
126 |
|
|
reg [(BUSW-1):0] r_data;
|
127 |
|
|
initial r_ce = 1'b0;
|
128 |
|
|
always @(posedge i_clk)
|
129 |
|
|
r_ce <= (~lst_adr)||(~imm_adr);
|
130 |
|
|
always @(posedge i_clk)
|
131 |
|
|
r_data <= ((~lst_adr)||(~imm_adr))
|
132 |
|
|
? { lst_adr, lst_val }
|
133 |
|
|
: { 1'b0, i_data };
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
wbscope #(.SYNCHRONOUS(1),
|
137 |
|
|
.LGMEM(LGMEM),
|
138 |
|
|
.BUSW(BUSW)) cheatersscope(i_clk, r_ce, i_trigger, r_data,
|
139 |
|
|
i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
|
140 |
|
|
o_wb_ack, o_wb_stall, o_wb_data, o_interrupt);
|
141 |
|
|
endmodule
|