1 |
131 |
jt_eaton |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// adbg_wb_module.v ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// ////
|
6 |
|
|
//// This file is part of the SoC Advanced Debug Interface. ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Author(s): ////
|
9 |
|
|
//// Nathan Yawn (nathan.yawn@opencores.org) ////
|
10 |
|
|
//// ////
|
11 |
|
|
//// ////
|
12 |
|
|
//// ////
|
13 |
|
|
//////////////////////////////////////////////////////////////////////
|
14 |
|
|
//// ////
|
15 |
|
|
//// Copyright (C) 2008-2010 Authors ////
|
16 |
|
|
//// ////
|
17 |
|
|
//// This source file may be used and distributed without ////
|
18 |
|
|
//// restriction provided that this copyright statement is not ////
|
19 |
|
|
//// removed from the file and that any derivative work contains ////
|
20 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
21 |
|
|
//// ////
|
22 |
|
|
//// This source file is free software; you can redistribute it ////
|
23 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
24 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
25 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
26 |
|
|
//// later version. ////
|
27 |
|
|
//// ////
|
28 |
|
|
//// This source is distributed in the hope that it will be ////
|
29 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
30 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
31 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
32 |
|
|
//// details. ////
|
33 |
|
|
//// ////
|
34 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
35 |
|
|
//// Public License along with this source; if not, download it ////
|
36 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
37 |
|
|
//// ////
|
38 |
|
|
//////////////////////////////////////////////////////////////////////
|
39 |
|
|
//
|
40 |
|
|
// CVS Revision History
|
41 |
|
|
//
|
42 |
|
|
// $Log: adbg_wb_module.v,v $
|
43 |
|
|
// Revision 1.5 2010-01-13 00:55:45 Nathan
|
44 |
|
|
// Created hi-speed mode for burst reads. This will probably be most beneficial to the OR1K module, as GDB does a burst read of all the GPRs each time a microinstruction is single-stepped.
|
45 |
|
|
//
|
46 |
|
|
// Revision 1.2 2009/05/17 20:54:57 Nathan
|
47 |
|
|
// Changed email address to opencores.org
|
48 |
|
|
//
|
49 |
|
|
// Revision 1.1 2008/07/22 20:28:33 Nathan
|
50 |
|
|
// Changed names of all files and modules (prefixed an a, for advanced). Cleanup, indenting. No functional changes.
|
51 |
|
|
//
|
52 |
|
|
// Revision 1.12 2008/07/11 08:13:30 Nathan
|
53 |
|
|
// Latch opcode on posedge, like other signals. This fixes a problem when
|
54 |
|
|
// the module is used with a Xilinx BSCAN TAP. Added signals to allow modules
|
55 |
|
|
// to inhibit latching of a new active module by the top module. This allows
|
56 |
|
|
// the sub-modules to force the top level module to ignore the command present
|
57 |
|
|
// in the input shift register after e.g. a burst read.
|
58 |
|
|
//
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
// Top module
|
64 |
|
|
module `VARIANT`WB_MODULE (
|
65 |
|
|
// JTAG signals
|
66 |
|
|
tck_i,
|
67 |
|
|
module_tdo_o,
|
68 |
|
|
tdi_i,
|
69 |
|
|
|
70 |
|
|
// TAP states
|
71 |
|
|
capture_dr_i,
|
72 |
|
|
shift_dr_i,
|
73 |
|
|
update_dr_i,
|
74 |
|
|
|
75 |
|
|
data_register_i, // the data register is at top level, shared between all modules
|
76 |
|
|
module_select_i,
|
77 |
|
|
top_inhibit_o,
|
78 |
|
|
rst_i,
|
79 |
|
|
|
80 |
|
|
// WISHBONE common signals
|
81 |
|
|
wb_clk_i,
|
82 |
|
|
|
83 |
|
|
// WISHBONE master interface
|
84 |
|
|
wb_adr_o, wb_dat_o, wb_dat_i, wb_cyc_o, wb_stb_o, wb_sel_o,
|
85 |
|
|
wb_we_o, wb_ack_i, wb_cab_o, wb_err_i, wb_cti_o, wb_bte_o
|
86 |
|
|
|
87 |
|
|
);
|
88 |
|
|
|
89 |
|
|
// JTAG signals
|
90 |
|
|
input tck_i;
|
91 |
|
|
output module_tdo_o;
|
92 |
|
|
input tdi_i; // This is only used by the CRC module - data_register_i[MSB] is delayed a cycle
|
93 |
|
|
|
94 |
|
|
// TAP states
|
95 |
|
|
input capture_dr_i;
|
96 |
|
|
input shift_dr_i;
|
97 |
|
|
input update_dr_i;
|
98 |
|
|
|
99 |
|
|
input [52:0] data_register_i;
|
100 |
|
|
input module_select_i;
|
101 |
|
|
output top_inhibit_o;
|
102 |
|
|
input rst_i;
|
103 |
|
|
|
104 |
|
|
// WISHBONE master interface
|
105 |
|
|
input wb_clk_i;
|
106 |
|
|
output [31:0] wb_adr_o;
|
107 |
|
|
output [31:0] wb_dat_o;
|
108 |
|
|
input [31:0] wb_dat_i;
|
109 |
|
|
output wb_cyc_o;
|
110 |
|
|
output wb_stb_o;
|
111 |
|
|
output [3:0] wb_sel_o;
|
112 |
|
|
output wb_we_o;
|
113 |
|
|
input wb_ack_i;
|
114 |
|
|
output wb_cab_o;
|
115 |
|
|
input wb_err_i;
|
116 |
|
|
output [2:0] wb_cti_o;
|
117 |
|
|
output [1:0] wb_bte_o;
|
118 |
|
|
//reg wb_cyc_o;
|
119 |
|
|
|
120 |
|
|
// Declare inputs / outputs as wires / registers
|
121 |
|
|
reg module_tdo_o;
|
122 |
|
|
reg top_inhibit_o;
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
// Registers to hold state etc.
|
126 |
|
|
reg [31:0] address_counter; // Holds address for next Wishbone access
|
127 |
|
|
reg [5:0] bit_count; // How many bits have been shifted in/out
|
128 |
|
|
reg [15:0] word_count; // bytes remaining in current burst command
|
129 |
|
|
reg [3:0] operation; // holds the current command (rd/wr, word size)
|
130 |
|
|
reg [32:0] data_out_shift_reg; // 32 bits to accomodate the internal_reg_error
|
131 |
|
|
reg [`DBG_WB_REGSELECT_SIZE-1:0] internal_register_select; // Holds index of currently selected register
|
132 |
|
|
reg [32:0] internal_reg_error; // WB error module internal register. 32 bit address + error bit (LSB)
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
// Control signals for the various counters / registers / state machines
|
136 |
|
|
reg addr_sel; // Selects data for address_counter. 0 = data_register_i, 1 = incremented address count
|
137 |
|
|
reg addr_ct_en; // Enable signal for address counter register
|
138 |
|
|
reg op_reg_en; // Enable signal for 'operation' register
|
139 |
|
|
reg bit_ct_en; // enable bit counter
|
140 |
|
|
reg bit_ct_rst; // reset (zero) bit count register
|
141 |
|
|
reg word_ct_sel; // Selects data for byte counter. 0 = data_register_i, 1 = decremented byte count
|
142 |
|
|
reg word_ct_en; // Enable byte counter register
|
143 |
|
|
reg out_reg_ld_en; // Enable parallel load of data_out_shift_reg
|
144 |
|
|
reg out_reg_shift_en; // Enable shift of data_out_shift_reg
|
145 |
|
|
reg out_reg_data_sel; // 0 = BIU data, 1 = internal register data
|
146 |
|
|
reg [1:0] tdo_output_sel; // Selects signal to send to TDO. 0 = ready bit, 1 = output register, 2 = CRC match, 3 = CRC shift reg.
|
147 |
|
|
reg biu_strobe; // Indicates that the bus unit should latch data and start a transaction
|
148 |
|
|
reg crc_clr; // resets CRC module
|
149 |
|
|
reg crc_en; // does 1-bit iteration in CRC module
|
150 |
|
|
reg crc_in_sel; // selects incoming write data (=0) or outgoing read data (=1)as input to CRC module
|
151 |
|
|
reg crc_shift_en; // CRC reg is also it's own output shift register; this enables a shift
|
152 |
|
|
reg regsel_ld_en; // Reg. select register load enable
|
153 |
|
|
reg intreg_ld_en; // load enable for internal registers
|
154 |
|
|
reg error_reg_en; // Tells the error register to check for and latch a bus error
|
155 |
|
|
reg biu_clr_err; // Allows FSM to reset BIU, to clear the biu_err bit which may have been set on the last transaction of the last burst.
|
156 |
|
|
|
157 |
|
|
// Status signals
|
158 |
|
|
wire word_count_zero; // true when byte counter is zero
|
159 |
|
|
wire bit_count_max; // true when bit counter is equal to current word size
|
160 |
|
|
wire module_cmd; // inverse of MSB of data_register_i. 1 means current cmd not for top level (but is for us)
|
161 |
|
|
wire biu_ready; // indicates that the BIU has finished the last command
|
162 |
|
|
wire biu_err; // indicates wishbone error during BIU transaction
|
163 |
|
|
wire burst_instruction; // True when the input_data_i reg has a valid burst instruction for this module
|
164 |
|
|
wire intreg_instruction; // True when the input_data_i reg has a valid internal register instruction
|
165 |
|
|
wire intreg_write; // True when the input_data_i reg has an internal register write op
|
166 |
|
|
reg rd_op; // True when operation in the opcode reg is a read, false when a write
|
167 |
|
|
wire crc_match; // indicates whether data_register_i matches computed CRC
|
168 |
|
|
wire bit_count_32; // true when bit count register == 32, for CRC after burst writes
|
169 |
|
|
|
170 |
|
|
// Intermediate signals
|
171 |
|
|
reg [5:0] word_size_bits; // 8,16, or 32. Decoded from 'operation'
|
172 |
|
|
reg [2:0] word_size_bytes; // 1,2, or 4
|
173 |
|
|
wire [32:0] incremented_address; // value of address counter plus 'word_size'
|
174 |
|
|
wire [31:0] data_to_addr_counter; // output of the mux in front of the address counter inputs
|
175 |
|
|
wire [15:0] data_to_word_counter; // output of the mux in front of the byte counter input
|
176 |
|
|
wire [15:0] decremented_word_count;
|
177 |
|
|
wire [31:0] address_data_in; // from data_register_i
|
178 |
|
|
wire [15:0] count_data_in; // from data_register_i
|
179 |
|
|
wire [3:0] operation_in; // from data_register_i
|
180 |
|
|
wire [31:0] data_to_biu; // from data_register_i
|
181 |
|
|
wire [31:0] data_from_biu; // to data_out_shift_register
|
182 |
|
|
wire [31:0] crc_data_out; // output of CRC module, to output shift register
|
183 |
|
|
wire crc_data_in; // input to CRC module, either data_register_i[52] or data_out_shift_reg[0]
|
184 |
|
|
wire crc_serial_out;
|
185 |
|
|
wire [`DBG_WB_REGSELECT_SIZE-1:0] reg_select_data; // from data_register_i, input to internal register select register
|
186 |
|
|
wire [32:0] out_reg_data; // parallel input to the output shift register
|
187 |
|
|
reg [32:0] data_from_internal_reg; // data from internal reg. MUX to output shift register
|
188 |
|
|
wire biu_rst; // logical OR of rst_i and biu_clr_err
|
189 |
|
|
|
190 |
|
|
/////////////////////////////////////////////////
|
191 |
|
|
// Combinatorial assignments
|
192 |
|
|
|
193 |
|
|
assign module_cmd = ~(data_register_i[52]);
|
194 |
|
|
assign operation_in = data_register_i[51:48];
|
195 |
|
|
assign address_data_in = data_register_i[47:16];
|
196 |
|
|
assign count_data_in = data_register_i[15:0];
|
197 |
|
|
`ifdef ADBG_USE_HISPEED
|
198 |
|
|
assign data_to_biu = {tdi_i,data_register_i[52:22]};
|
199 |
|
|
`else
|
200 |
|
|
assign data_to_biu = data_register_i[52:21];
|
201 |
|
|
`endif
|
202 |
|
|
assign reg_select_data = data_register_i[47:(47-(`DBG_WB_REGSELECT_SIZE-1))];
|
203 |
|
|
|
204 |
|
|
////////////////////////////////////////////////
|
205 |
|
|
// Operation decoder
|
206 |
|
|
|
207 |
|
|
// These are only used before the operation is latched, so decode them from operation_in
|
208 |
|
|
assign burst_instruction = (~operation_in[3]) & (operation_in[0] | operation_in[1]);
|
209 |
|
|
assign intreg_instruction = ((operation_in == `DBG_WB_CMD_IREG_WR) | (operation_in == `DBG_WB_CMD_IREG_SEL));
|
210 |
|
|
assign intreg_write = (operation_in == `DBG_WB_CMD_IREG_WR);
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
// This is decoded from the registered operation
|
214 |
|
|
always @ (operation)
|
215 |
|
|
begin
|
216 |
|
|
case(operation)
|
217 |
|
|
`DBG_WB_CMD_BWRITE8:
|
218 |
|
|
begin
|
219 |
|
|
word_size_bits = 6'd7; // Bits is actually bits-1, to make the FSM easier
|
220 |
|
|
word_size_bytes = 3'd1;
|
221 |
|
|
rd_op = 1'b0;
|
222 |
|
|
end
|
223 |
|
|
`DBG_WB_CMD_BWRITE16:
|
224 |
|
|
begin
|
225 |
|
|
word_size_bits = 6'd15; // Bits is actually bits-1, to make the FSM easier
|
226 |
|
|
word_size_bytes = 3'd2;
|
227 |
|
|
rd_op = 1'b0;
|
228 |
|
|
end
|
229 |
|
|
`DBG_WB_CMD_BWRITE32:
|
230 |
|
|
begin
|
231 |
|
|
word_size_bits = 6'd31; // Bits is actually bits-1, to make the FSM easier
|
232 |
|
|
word_size_bytes = 3'd4;
|
233 |
|
|
rd_op = 1'b0;
|
234 |
|
|
end
|
235 |
|
|
`DBG_WB_CMD_BREAD8:
|
236 |
|
|
begin
|
237 |
|
|
word_size_bits = 6'd7; // Bits is actually bits-1, to make the FSM easier
|
238 |
|
|
word_size_bytes = 3'd1;
|
239 |
|
|
rd_op = 1'b1;
|
240 |
|
|
end
|
241 |
|
|
`DBG_WB_CMD_BREAD16:
|
242 |
|
|
begin
|
243 |
|
|
word_size_bits = 6'd15; // Bits is actually bits-1, to make the FSM easier
|
244 |
|
|
word_size_bytes = 3'd2;
|
245 |
|
|
rd_op = 1'b1;
|
246 |
|
|
end
|
247 |
|
|
`DBG_WB_CMD_BREAD32:
|
248 |
|
|
begin
|
249 |
|
|
word_size_bits = 6'd31; // Bits is actually bits-1, to make the FSM easier
|
250 |
|
|
word_size_bytes = 3'd4;
|
251 |
|
|
rd_op = 1'b1;
|
252 |
|
|
end
|
253 |
|
|
default:
|
254 |
|
|
begin
|
255 |
|
|
word_size_bits = 6'hXX;
|
256 |
|
|
word_size_bytes = 3'hX;
|
257 |
|
|
rd_op = 1'bX;
|
258 |
|
|
end
|
259 |
|
|
endcase
|
260 |
|
|
end
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
////////////////////////////////////////////////
|
264 |
|
|
// Module-internal register select register (no, that's not redundant.)
|
265 |
|
|
// Also internal register output MUX
|
266 |
|
|
|
267 |
|
|
always @ (posedge tck_i or posedge rst_i)
|
268 |
|
|
begin
|
269 |
|
|
if(rst_i) internal_register_select <= 1'h0;
|
270 |
|
|
else if(regsel_ld_en) internal_register_select <= reg_select_data;
|
271 |
|
|
end
|
272 |
|
|
|
273 |
|
|
// This is completely unnecessary here, since the WB module has only 1 internal
|
274 |
|
|
// register. However, to make the module expandable, it is included anyway.
|
275 |
|
|
always @ (internal_register_select or internal_reg_error)
|
276 |
|
|
begin
|
277 |
|
|
case(internal_register_select)
|
278 |
|
|
`DBG_WB_INTREG_ERROR: data_from_internal_reg = internal_reg_error;
|
279 |
|
|
default: data_from_internal_reg = internal_reg_error;
|
280 |
|
|
endcase
|
281 |
|
|
end
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
////////////////////////////////////////////////////////////////////
|
286 |
|
|
// Module-internal registers
|
287 |
|
|
// These have generic read/write/select code, but
|
288 |
|
|
// individual registers may have special behavior, defined here.
|
289 |
|
|
|
290 |
|
|
// This is the bus error register, which traps WB errors
|
291 |
|
|
// We latch every new BIU address in the upper 32 bits, so we always have the address for the transaction which
|
292 |
|
|
// generated the error (the address counter might increment, esp. for writes)
|
293 |
|
|
// We stop latching addresses when the error bit (bit 0) is set. Keep the error bit set until it is
|
294 |
|
|
// manually cleared by a module internal register write.
|
295 |
|
|
// Note we use reg_select_data straight from data_register_i, rather than the latched version -
|
296 |
|
|
// otherwise, we would write the previously selected register.
|
297 |
|
|
|
298 |
|
|
|
299 |
|
|
always @ (posedge tck_i or posedge rst_i)
|
300 |
|
|
begin
|
301 |
|
|
if(rst_i) internal_reg_error <= 33'h0;
|
302 |
|
|
else if(intreg_ld_en && (reg_select_data == `DBG_WB_INTREG_ERROR)) // do load from data input register
|
303 |
|
|
begin
|
304 |
|
|
if(data_register_i[46]) internal_reg_error[0] <= 1'b0; // if write data is 1, reset the error bit
|
305 |
|
|
end
|
306 |
|
|
else if(error_reg_en && !internal_reg_error[0])
|
307 |
|
|
begin
|
308 |
|
|
`ifdef ADBG_USE_HISPEED
|
309 |
|
|
if(biu_err || (!biu_ready)) internal_reg_error[0] <= 1'b1;
|
310 |
|
|
`else
|
311 |
|
|
if(biu_err) internal_reg_error[0] <= 1'b1;
|
312 |
|
|
`endif
|
313 |
|
|
else if(biu_strobe) internal_reg_error[32:1] <= address_counter;
|
314 |
|
|
end
|
315 |
|
|
else if(biu_strobe && !internal_reg_error[0]) internal_reg_error[32:1] <= address_counter; // When no error, latch this whether error_reg_en or not
|
316 |
|
|
end
|
317 |
|
|
|
318 |
|
|
///////////////////////////////////////////////
|
319 |
|
|
// Address counter
|
320 |
|
|
|
321 |
|
|
assign data_to_addr_counter = (addr_sel) ? incremented_address[31:0] : address_data_in;
|
322 |
|
|
assign incremented_address = {1'b0,address_counter} +{30'b0, word_size_bytes};
|
323 |
|
|
|
324 |
|
|
// Technically, since this data (sometimes) comes from the input shift reg, we should latch on
|
325 |
|
|
// negedge, per the JTAG spec. But that makes things difficult when incrementing.
|
326 |
|
|
always @ (posedge tck_i or posedge rst_i) // JTAG spec specifies latch on negative edge in UPDATE_DR state
|
327 |
|
|
begin
|
328 |
|
|
if(rst_i)
|
329 |
|
|
address_counter <= 32'h0;
|
330 |
|
|
else if(addr_ct_en)
|
331 |
|
|
address_counter <= data_to_addr_counter;
|
332 |
|
|
end
|
333 |
|
|
|
334 |
|
|
////////////////////////////////////////
|
335 |
|
|
// Opcode latch
|
336 |
|
|
|
337 |
|
|
always @ (posedge tck_i or posedge rst_i) // JTAG spec specifies latch on negative edge in UPDATE_DR state
|
338 |
|
|
begin
|
339 |
|
|
if(rst_i)
|
340 |
|
|
operation <= 4'h0;
|
341 |
|
|
else if(op_reg_en)
|
342 |
|
|
operation <= operation_in;
|
343 |
|
|
end
|
344 |
|
|
|
345 |
|
|
//////////////////////////////////////
|
346 |
|
|
// Bit counter
|
347 |
|
|
|
348 |
|
|
always @ (posedge tck_i or posedge rst_i)
|
349 |
|
|
begin
|
350 |
|
|
|
351 |
|
|
if(rst_i) bit_count <= 6'h0;
|
352 |
|
|
else if(bit_ct_rst) bit_count <= 6'h0;
|
353 |
|
|
else if(bit_ct_en) bit_count <= bit_count + 6'h1;
|
354 |
|
|
|
355 |
|
|
end
|
356 |
|
|
|
357 |
|
|
assign bit_count_max = (bit_count == word_size_bits) ? 1'b1 : 1'b0 ;
|
358 |
|
|
assign bit_count_32 = (bit_count == 6'h20) ? 1'b1 : 1'b0;
|
359 |
|
|
|
360 |
|
|
////////////////////////////////////////
|
361 |
|
|
// Word counter
|
362 |
|
|
|
363 |
|
|
assign data_to_word_counter = (word_ct_sel) ? decremented_word_count : count_data_in;
|
364 |
|
|
assign decremented_word_count = word_count - 16'h1;
|
365 |
|
|
|
366 |
|
|
// Technically, since this data (sometimes) comes from the input shift reg, we should latch on
|
367 |
|
|
// negedge, per the JTAG spec. But that makes things difficult when incrementing.
|
368 |
|
|
always @ (posedge tck_i or posedge rst_i) // JTAG spec specifies latch on negative edge in UPDATE_DR state
|
369 |
|
|
begin
|
370 |
|
|
if(rst_i)
|
371 |
|
|
word_count <= 16'h0;
|
372 |
|
|
else if(word_ct_en)
|
373 |
|
|
word_count <= data_to_word_counter;
|
374 |
|
|
end
|
375 |
|
|
|
376 |
|
|
assign word_count_zero = (word_count == 16'h0);
|
377 |
|
|
|
378 |
|
|
/////////////////////////////////////////////////////
|
379 |
|
|
// Output register and TDO output MUX
|
380 |
|
|
|
381 |
|
|
assign out_reg_data = (out_reg_data_sel) ? data_from_internal_reg : {1'b0,data_from_biu};
|
382 |
|
|
|
383 |
|
|
always @ (posedge tck_i or posedge rst_i)
|
384 |
|
|
begin
|
385 |
|
|
if(rst_i) data_out_shift_reg <= 33'h0;
|
386 |
|
|
else if(out_reg_ld_en) data_out_shift_reg <= out_reg_data;
|
387 |
|
|
else if(out_reg_shift_en) data_out_shift_reg <= {1'b0, data_out_shift_reg[32:1]};
|
388 |
|
|
end
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
always @ (tdo_output_sel or data_out_shift_reg[0] or biu_ready or crc_match or crc_serial_out)
|
392 |
|
|
begin
|
393 |
|
|
if(tdo_output_sel == 2'h0) module_tdo_o = biu_ready;
|
394 |
|
|
else if(tdo_output_sel == 2'h1) module_tdo_o = data_out_shift_reg[0];
|
395 |
|
|
else if(tdo_output_sel == 2'h2) module_tdo_o = crc_match;
|
396 |
|
|
else module_tdo_o = crc_serial_out;
|
397 |
|
|
end
|
398 |
|
|
|
399 |
|
|
////////////////////////////////////////
|
400 |
|
|
// Bus Interface Unit
|
401 |
|
|
// It is assumed that the BIU has internal registers, and will
|
402 |
|
|
// latch address, operation, and write data on rising clock edge
|
403 |
|
|
// when strobe is asserted
|
404 |
|
|
|
405 |
|
|
assign biu_rst = rst_i | biu_clr_err;
|
406 |
|
|
|
407 |
|
|
`VARIANT`WB_BIU wb_biu_i
|
408 |
|
|
(
|
409 |
|
|
// Debug interface signals
|
410 |
|
|
.tck_i (tck_i),
|
411 |
|
|
.rst_i (biu_rst),
|
412 |
|
|
.data_i (data_to_biu),
|
413 |
|
|
.data_o (data_from_biu),
|
414 |
|
|
.addr_i (address_counter),
|
415 |
|
|
.strobe_i (biu_strobe),
|
416 |
|
|
.rd_wrn_i (rd_op), // If 0, then write op
|
417 |
|
|
.rdy_o (biu_ready),
|
418 |
|
|
.err_o (biu_err),
|
419 |
|
|
.word_size_i (word_size_bytes),
|
420 |
|
|
|
421 |
|
|
// Wishbone signals
|
422 |
|
|
.wb_clk_i (wb_clk_i),
|
423 |
|
|
.wb_adr_o (wb_adr_o),
|
424 |
|
|
.wb_dat_o (wb_dat_o),
|
425 |
|
|
.wb_dat_i (wb_dat_i),
|
426 |
|
|
.wb_cyc_o (wb_cyc_o),
|
427 |
|
|
.wb_stb_o (wb_stb_o),
|
428 |
|
|
.wb_sel_o (wb_sel_o),
|
429 |
|
|
.wb_we_o (wb_we_o),
|
430 |
|
|
.wb_ack_i (wb_ack_i),
|
431 |
|
|
.wb_cab_o (wb_cab_o),
|
432 |
|
|
.wb_err_i (wb_err_i),
|
433 |
|
|
.wb_cti_o (wb_cti_o),
|
434 |
|
|
.wb_bte_o (wb_bte_o)
|
435 |
|
|
);
|
436 |
|
|
|
437 |
|
|
/////////////////////////////////////
|
438 |
|
|
// CRC module
|
439 |
|
|
|
440 |
|
|
assign crc_data_in = (crc_in_sel) ? tdi_i : data_out_shift_reg[0]; // MUX, write or read data
|
441 |
|
|
|
442 |
|
|
`VARIANT`CRC32 wb_crc_i
|
443 |
|
|
(
|
444 |
|
|
.clk(tck_i),
|
445 |
|
|
.data(crc_data_in),
|
446 |
|
|
.enable(crc_en),
|
447 |
|
|
.shift(crc_shift_en),
|
448 |
|
|
.clr(crc_clr),
|
449 |
|
|
.rst(rst_i),
|
450 |
|
|
.crc_out(crc_data_out),
|
451 |
|
|
.serial_out(crc_serial_out)
|
452 |
|
|
);
|
453 |
|
|
|
454 |
|
|
assign crc_match = (data_register_i[52:21] == crc_data_out) ? 1'b1 : 1'b0;
|
455 |
|
|
|
456 |
|
|
////////////////////////////////////////
|
457 |
|
|
// Control FSM
|
458 |
|
|
|
459 |
|
|
// Definition of machine state values.
|
460 |
|
|
// Don't worry too much about the state encoding, the synthesis tool
|
461 |
|
|
// will probably re-encode it anyway.
|
462 |
|
|
|
463 |
|
|
`define STATE_idle 4'h0
|
464 |
|
|
`define STATE_Rbegin 4'h1
|
465 |
|
|
`define STATE_Rready 4'h2
|
466 |
|
|
`define STATE_Rstatus 4'h3
|
467 |
|
|
`define STATE_Rburst 4'h4
|
468 |
|
|
`define STATE_Wready 4'h5
|
469 |
|
|
`define STATE_Wwait 4'h6
|
470 |
|
|
`define STATE_Wburst 4'h7
|
471 |
|
|
`define STATE_Wstatus 4'h8
|
472 |
|
|
`define STATE_Rcrc 4'h9
|
473 |
|
|
`define STATE_Wcrc 4'ha
|
474 |
|
|
`define STATE_Wmatch 4'hb
|
475 |
|
|
|
476 |
|
|
reg [3:0] module_state; // FSM state
|
477 |
|
|
reg [3:0] module_next_state; // combinatorial signal, not actually a register
|
478 |
|
|
|
479 |
|
|
|
480 |
|
|
|
481 |
|
|
// sequential part of the FSM
|
482 |
|
|
always @ (posedge tck_i or posedge rst_i)
|
483 |
|
|
begin
|
484 |
|
|
if(rst_i)
|
485 |
|
|
module_state <= `STATE_idle;
|
486 |
|
|
else
|
487 |
|
|
module_state <= module_next_state;
|
488 |
|
|
end
|
489 |
|
|
|
490 |
|
|
|
491 |
|
|
// Determination of next state; purely combinatorial
|
492 |
|
|
always @ (module_state or module_select_i or module_cmd or update_dr_i or capture_dr_i or operation_in[2]
|
493 |
|
|
or word_count_zero or bit_count_max or data_register_i[52] or bit_count_32 or biu_ready or burst_instruction)
|
494 |
|
|
begin
|
495 |
|
|
case(module_state)
|
496 |
|
|
`STATE_idle:
|
497 |
|
|
begin
|
498 |
|
|
if(module_cmd && module_select_i && update_dr_i && burst_instruction && operation_in[2]) module_next_state = `STATE_Rbegin;
|
499 |
|
|
else if(module_cmd && module_select_i && update_dr_i && burst_instruction) module_next_state = `STATE_Wready;
|
500 |
|
|
else module_next_state = `STATE_idle;
|
501 |
|
|
end
|
502 |
|
|
|
503 |
|
|
`STATE_Rbegin:
|
504 |
|
|
begin
|
505 |
|
|
if(word_count_zero) module_next_state = `STATE_idle; // set up a burst of size 0, illegal.
|
506 |
|
|
else module_next_state = `STATE_Rready;
|
507 |
|
|
end
|
508 |
|
|
`STATE_Rready:
|
509 |
|
|
begin
|
510 |
|
|
if(module_select_i && capture_dr_i) module_next_state = `STATE_Rstatus;
|
511 |
|
|
else module_next_state = `STATE_Rready;
|
512 |
|
|
end
|
513 |
|
|
`STATE_Rstatus:
|
514 |
|
|
begin
|
515 |
|
|
if(update_dr_i) module_next_state = `STATE_idle;
|
516 |
|
|
else if (biu_ready) module_next_state = `STATE_Rburst;
|
517 |
|
|
else module_next_state = `STATE_Rstatus;
|
518 |
|
|
end
|
519 |
|
|
`STATE_Rburst:
|
520 |
|
|
begin
|
521 |
|
|
if(update_dr_i) module_next_state = `STATE_idle;
|
522 |
|
|
else if(bit_count_max && word_count_zero) module_next_state = `STATE_Rcrc;
|
523 |
|
|
`ifndef ADBG_USE_HISPEED
|
524 |
|
|
else if(bit_count_max) module_next_state = `STATE_Rstatus;
|
525 |
|
|
`endif
|
526 |
|
|
else module_next_state = `STATE_Rburst;
|
527 |
|
|
end
|
528 |
|
|
`STATE_Rcrc:
|
529 |
|
|
begin
|
530 |
|
|
if(update_dr_i) module_next_state = `STATE_idle;
|
531 |
|
|
// This doubles as the 'recovery' state, so stay here until update_dr_i.
|
532 |
|
|
else module_next_state = `STATE_Rcrc;
|
533 |
|
|
end
|
534 |
|
|
|
535 |
|
|
`STATE_Wready:
|
536 |
|
|
begin
|
537 |
|
|
if(word_count_zero) module_next_state = `STATE_idle;
|
538 |
|
|
else if(module_select_i && capture_dr_i) module_next_state = `STATE_Wwait;
|
539 |
|
|
else module_next_state = `STATE_Wready;
|
540 |
|
|
end
|
541 |
|
|
`STATE_Wwait:
|
542 |
|
|
begin
|
543 |
|
|
if(update_dr_i) module_next_state = `STATE_idle; // client terminated early
|
544 |
|
|
else if(module_select_i && data_register_i[52]) module_next_state = `STATE_Wburst; // Got a start bit
|
545 |
|
|
else module_next_state = `STATE_Wwait;
|
546 |
|
|
end
|
547 |
|
|
`STATE_Wburst:
|
548 |
|
|
begin
|
549 |
|
|
if(update_dr_i) module_next_state = `STATE_idle; // client terminated early
|
550 |
|
|
else if(bit_count_max)
|
551 |
|
|
begin
|
552 |
|
|
`ifdef ADBG_USE_HISPEED
|
553 |
|
|
if(word_count_zero) module_next_state = `STATE_Wcrc;
|
554 |
|
|
else module_next_state = `STATE_Wburst;
|
555 |
|
|
`else
|
556 |
|
|
module_next_state = `STATE_Wstatus;
|
557 |
|
|
`endif
|
558 |
|
|
end
|
559 |
|
|
else module_next_state = `STATE_Wburst;
|
560 |
|
|
end
|
561 |
|
|
`STATE_Wstatus:
|
562 |
|
|
begin
|
563 |
|
|
if(update_dr_i) module_next_state = `STATE_idle; // client terminated early
|
564 |
|
|
else if(word_count_zero) module_next_state = `STATE_Wcrc;
|
565 |
|
|
// can't wait until bus ready if multiple devices in chain...
|
566 |
|
|
// Would have to read postfix_bits, then send another start bit and push it through
|
567 |
|
|
// prefix_bits...potentially very inefficient.
|
568 |
|
|
else module_next_state = `STATE_Wburst;
|
569 |
|
|
end
|
570 |
|
|
|
571 |
|
|
`STATE_Wcrc:
|
572 |
|
|
begin
|
573 |
|
|
if(update_dr_i) module_next_state = `STATE_idle; // client terminated early
|
574 |
|
|
else if(bit_count_32) module_next_state = `STATE_Wmatch;
|
575 |
|
|
else module_next_state = `STATE_Wcrc;
|
576 |
|
|
end
|
577 |
|
|
|
578 |
|
|
`STATE_Wmatch:
|
579 |
|
|
begin
|
580 |
|
|
if(update_dr_i) module_next_state = `STATE_idle;
|
581 |
|
|
// This doubles as our recovery state, stay here until update_dr_i
|
582 |
|
|
else module_next_state = `STATE_Wmatch;
|
583 |
|
|
end
|
584 |
|
|
|
585 |
|
|
default: module_next_state = `STATE_idle; // shouldn't actually happen...
|
586 |
|
|
endcase
|
587 |
|
|
end
|
588 |
|
|
|
589 |
|
|
|
590 |
|
|
// Outputs of state machine, pure combinatorial
|
591 |
|
|
always @ (module_state or module_next_state or module_select_i or update_dr_i or capture_dr_i or shift_dr_i or operation_in[2]
|
592 |
|
|
or word_count_zero or bit_count_max or data_register_i[52] or biu_ready or intreg_instruction or module_cmd
|
593 |
|
|
or intreg_write or decremented_word_count)
|
594 |
|
|
begin
|
595 |
|
|
// Default everything to 0, keeps the case statement simple
|
596 |
|
|
addr_sel = 1'b1; // Selects data for address_counter. 0 = data_register_i, 1 = incremented address count
|
597 |
|
|
addr_ct_en = 1'b0; // Enable signal for address counter register
|
598 |
|
|
op_reg_en = 1'b0; // Enable signal for 'operation' register
|
599 |
|
|
bit_ct_en = 1'b0; // enable bit counter
|
600 |
|
|
bit_ct_rst = 1'b0; // reset (zero) bit count register
|
601 |
|
|
word_ct_sel = 1'b1; // Selects data for byte counter. 0 = data_register_i, 1 = decremented byte count
|
602 |
|
|
word_ct_en = 1'b0; // Enable byte counter register
|
603 |
|
|
out_reg_ld_en = 1'b0; // Enable parallel load of data_out_shift_reg
|
604 |
|
|
out_reg_shift_en = 1'b0; // Enable shift of data_out_shift_reg
|
605 |
|
|
tdo_output_sel = 2'b1; // 1 = data reg, 0 = biu_ready, 2 = crc_match, 3 = CRC data
|
606 |
|
|
biu_strobe = 1'b0;
|
607 |
|
|
crc_clr = 1'b0;
|
608 |
|
|
crc_en = 1'b0; // add the input bit to the CRC calculation
|
609 |
|
|
crc_in_sel = 1'b0; // 0 = tdo, 1 = tdi
|
610 |
|
|
crc_shift_en = 1'b0;
|
611 |
|
|
out_reg_data_sel = 1'b1; // 0 = BIU data, 1 = internal register data
|
612 |
|
|
regsel_ld_en = 1'b0;
|
613 |
|
|
intreg_ld_en = 1'b0;
|
614 |
|
|
error_reg_en = 1'b0;
|
615 |
|
|
biu_clr_err = 1'b0; // Set this to reset the BIU, clearing the biu_err bit
|
616 |
|
|
top_inhibit_o = 1'b0; // Don't disable the top-level module in the default case
|
617 |
|
|
|
618 |
|
|
case(module_state)
|
619 |
|
|
`STATE_idle:
|
620 |
|
|
begin
|
621 |
|
|
addr_sel = 1'b0;
|
622 |
|
|
word_ct_sel = 1'b0;
|
623 |
|
|
|
624 |
|
|
// Operations for internal registers - stay in idle state
|
625 |
|
|
if(module_select_i & shift_dr_i) out_reg_shift_en = 1'b1; // For module regs
|
626 |
|
|
if(module_select_i & capture_dr_i)
|
627 |
|
|
begin
|
628 |
|
|
out_reg_data_sel = 1'b1; // select internal register data
|
629 |
|
|
out_reg_ld_en = 1'b1; // For module regs
|
630 |
|
|
end
|
631 |
|
|
if(module_select_i & module_cmd & update_dr_i) begin
|
632 |
|
|
if(intreg_instruction) regsel_ld_en = 1'b1; // For module regs
|
633 |
|
|
if(intreg_write) intreg_ld_en = 1'b1; // For module regs
|
634 |
|
|
end
|
635 |
|
|
|
636 |
|
|
// Burst operations
|
637 |
|
|
if(module_next_state != `STATE_idle) begin // Do the same to receive read or write opcode
|
638 |
|
|
addr_ct_en = 1'b1;
|
639 |
|
|
op_reg_en = 1'b1;
|
640 |
|
|
bit_ct_rst = 1'b1;
|
641 |
|
|
word_ct_en = 1'b1;
|
642 |
|
|
crc_clr = 1'b1;
|
643 |
|
|
end
|
644 |
|
|
end
|
645 |
|
|
|
646 |
|
|
`STATE_Rbegin:
|
647 |
|
|
begin
|
648 |
|
|
if(!word_count_zero) begin // Start a biu read transaction
|
649 |
|
|
biu_strobe = 1'b1;
|
650 |
|
|
addr_sel = 1'b1;
|
651 |
|
|
addr_ct_en = 1'b1;
|
652 |
|
|
end
|
653 |
|
|
end
|
654 |
|
|
|
655 |
|
|
`STATE_Rready:
|
656 |
|
|
; // Just a wait state
|
657 |
|
|
|
658 |
|
|
`STATE_Rstatus:
|
659 |
|
|
begin
|
660 |
|
|
tdo_output_sel = 2'h0;
|
661 |
|
|
top_inhibit_o = 1'b1; // in case of early termination
|
662 |
|
|
|
663 |
|
|
if (module_next_state == `STATE_Rburst) begin
|
664 |
|
|
error_reg_en = 1'b1; // Check the wb_error bit
|
665 |
|
|
out_reg_data_sel = 1'b0; // select BIU data
|
666 |
|
|
out_reg_ld_en = 1'b1;
|
667 |
|
|
bit_ct_rst = 1'b1;
|
668 |
|
|
word_ct_sel = 1'b1;
|
669 |
|
|
word_ct_en = 1'b1;
|
670 |
|
|
if(!(decremented_word_count == 0) && !word_count_zero) begin // Start a biu read transaction
|
671 |
|
|
biu_strobe = 1'b1;
|
672 |
|
|
addr_sel = 1'b1;
|
673 |
|
|
addr_ct_en = 1'b1;
|
674 |
|
|
end
|
675 |
|
|
end
|
676 |
|
|
end
|
677 |
|
|
|
678 |
|
|
`STATE_Rburst:
|
679 |
|
|
begin
|
680 |
|
|
tdo_output_sel = 2'h1;
|
681 |
|
|
out_reg_shift_en = 1'b1;
|
682 |
|
|
bit_ct_en = 1'b1;
|
683 |
|
|
crc_en = 1'b1;
|
684 |
|
|
crc_in_sel = 1'b0; // read data in output shift register LSB (tdo)
|
685 |
|
|
top_inhibit_o = 1'b1; // in case of early termination
|
686 |
|
|
|
687 |
|
|
`ifdef ADBG_USE_HISPEED
|
688 |
|
|
if(bit_count_max)
|
689 |
|
|
begin
|
690 |
|
|
error_reg_en = 1'b1; // Check the wb_error bit
|
691 |
|
|
out_reg_data_sel = 1'b0; // select BIU data
|
692 |
|
|
out_reg_ld_en = 1'b1;
|
693 |
|
|
bit_ct_rst = 1'b1;
|
694 |
|
|
word_ct_sel = 1'b1;
|
695 |
|
|
word_ct_en = 1'b1;
|
696 |
|
|
if(!(decremented_word_count == 0) && !word_count_zero) // Start a biu read transaction
|
697 |
|
|
begin
|
698 |
|
|
biu_strobe = 1'b1;
|
699 |
|
|
addr_sel = 1'b1;
|
700 |
|
|
addr_ct_en = 1'b1;
|
701 |
|
|
end
|
702 |
|
|
end
|
703 |
|
|
`endif
|
704 |
|
|
end
|
705 |
|
|
|
706 |
|
|
`STATE_Rcrc:
|
707 |
|
|
begin
|
708 |
|
|
// Just shift out the data, don't bother counting, we don't move on until update_dr_i
|
709 |
|
|
tdo_output_sel = 2'h3;
|
710 |
|
|
crc_shift_en = 1'b1;
|
711 |
|
|
top_inhibit_o = 1'b1;
|
712 |
|
|
end
|
713 |
|
|
|
714 |
|
|
`STATE_Wready:
|
715 |
|
|
; // Just a wait state
|
716 |
|
|
|
717 |
|
|
`STATE_Wwait:
|
718 |
|
|
begin
|
719 |
|
|
tdo_output_sel = 2'h1;
|
720 |
|
|
top_inhibit_o = 1'b1; // in case of early termination
|
721 |
|
|
if(module_next_state == `STATE_Wburst) begin
|
722 |
|
|
biu_clr_err = 1'b1; // If error occurred on last transaction of last burst, biu_err is still set. Clear it.
|
723 |
|
|
bit_ct_en = 1'b1;
|
724 |
|
|
word_ct_sel = 1'b1; // Pre-decrement the byte count
|
725 |
|
|
word_ct_en = 1'b1;
|
726 |
|
|
crc_en = 1'b1; // CRC gets tdi_i, which is 1 cycle ahead of data_register_i, so we need the bit there now in the CRC
|
727 |
|
|
crc_in_sel = 1'b1; // read data from tdi_i
|
728 |
|
|
end
|
729 |
|
|
end
|
730 |
|
|
|
731 |
|
|
`STATE_Wburst:
|
732 |
|
|
begin
|
733 |
|
|
bit_ct_en = 1'b1;
|
734 |
|
|
tdo_output_sel = 2'h1;
|
735 |
|
|
crc_en = 1'b1;
|
736 |
|
|
crc_in_sel = 1'b1; // read data from tdi_i
|
737 |
|
|
top_inhibit_o = 1'b1; // in case of early termination
|
738 |
|
|
|
739 |
|
|
`ifdef ADBG_USE_HISPEED
|
740 |
|
|
// It would be better to do this in STATE_Wstatus, but we don't use that state
|
741 |
|
|
// if ADBG_USE_HISPEED is defined.
|
742 |
|
|
if(bit_count_max)
|
743 |
|
|
begin
|
744 |
|
|
error_reg_en = 1'b1; // Check the wb_error bit
|
745 |
|
|
bit_ct_rst = 1'b1; // Zero the bit count
|
746 |
|
|
// start transaction. Can't do this here if not hispeed, biu_ready
|
747 |
|
|
// is the status bit, and it's 0 if we start a transaction here.
|
748 |
|
|
biu_strobe = 1'b1; // Start a BIU transaction
|
749 |
|
|
addr_ct_en = 1'b1; // Increment thte address counter
|
750 |
|
|
// Also can't dec the byte count yet unless hispeed,
|
751 |
|
|
// that would skip the last word.
|
752 |
|
|
word_ct_sel = 1'b1; // Decrement the byte count
|
753 |
|
|
word_ct_en = 1'b1;
|
754 |
|
|
end
|
755 |
|
|
`endif
|
756 |
|
|
end
|
757 |
|
|
|
758 |
|
|
`STATE_Wstatus:
|
759 |
|
|
begin
|
760 |
|
|
tdo_output_sel = 2'h0; // Send the status bit to TDO
|
761 |
|
|
error_reg_en = 1'b1; // Check the wb_error bit
|
762 |
|
|
// start transaction
|
763 |
|
|
biu_strobe = 1'b1; // Start a BIU transaction
|
764 |
|
|
word_ct_sel = 1'b1; // Decrement the byte count
|
765 |
|
|
word_ct_en = 1'b1;
|
766 |
|
|
bit_ct_rst = 1'b1; // Zero the bit count
|
767 |
|
|
addr_ct_en = 1'b1; // Increment thte address counter
|
768 |
|
|
top_inhibit_o = 1'b1; // in case of early termination
|
769 |
|
|
end
|
770 |
|
|
|
771 |
|
|
`STATE_Wcrc:
|
772 |
|
|
begin
|
773 |
|
|
bit_ct_en = 1'b1;
|
774 |
|
|
top_inhibit_o = 1'b1; // in case of early termination
|
775 |
|
|
if(module_next_state == `STATE_Wmatch) tdo_output_sel = 2'h2; // This is when the 'match' bit is actually read
|
776 |
|
|
end
|
777 |
|
|
|
778 |
|
|
`STATE_Wmatch:
|
779 |
|
|
begin
|
780 |
|
|
tdo_output_sel = 2'h2;
|
781 |
|
|
top_inhibit_o = 1'b1;
|
782 |
|
|
// Bit of a hack here...an error on the final write won't be detected in STATE_Wstatus like the rest,
|
783 |
|
|
// so we assume the bus transaction is done and check it / latch it into the error register here.
|
784 |
|
|
if(module_next_state == `STATE_idle) error_reg_en = 1'b1;
|
785 |
|
|
end
|
786 |
|
|
|
787 |
|
|
default: ;
|
788 |
|
|
endcase
|
789 |
|
|
end
|
790 |
|
|
|
791 |
|
|
|
792 |
|
|
endmodule
|
793 |
|
|
|