OpenCores
URL https://opencores.org/ocsvn/dbg_interface/dbg_interface/trunk

Subversion Repositories dbg_interface

[/] [dbg_interface/] [trunk/] [rtl/] [verilog/] [dbg_wb.v] - Blame information for rev 141

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 82 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  dbg_wb.v                                                    ////
4
////                                                              ////
5
////                                                              ////
6 139 igorm
////  This file is part of the SoC Debug Interface.               ////
7 82 mohor
////  http://www.opencores.org/projects/DebugInterface/           ////
8
////                                                              ////
9
////  Author(s):                                                  ////
10
////       Igor Mohor (igorm@opencores.org)                       ////
11
////                                                              ////
12
////                                                              ////
13
////  All additional information is avaliable in the README.txt   ////
14
////  file.                                                       ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18 138 igorm
//// Copyright (C) 2000 - 2004 Authors                            ////
19 82 mohor
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
//
43
// CVS Revision History
44
//
45
// $Log: not supported by cvs2svn $
46 141 igorm
// Revision 1.20  2004/03/28 20:27:02  igorm
47
// New release of the debug interface (3rd. release).
48
//
49 139 igorm
// Revision 1.19  2004/03/22 16:35:46  igorm
50
// Temp version before changing dbg interface.
51
//
52 138 igorm
// Revision 1.18  2004/01/25 14:04:18  mohor
53
// All flipflops are reset.
54
//
55 123 mohor
// Revision 1.17  2004/01/22 13:58:53  mohor
56
// Port signals are all set to zero after reset.
57
//
58 121 mohor
// Revision 1.16  2004/01/19 07:32:41  simons
59
// Reset values width added because of FV, a good sentence changed because some tools can not handle it.
60
//
61 108 simons
// Revision 1.15  2004/01/17 18:01:24  mohor
62
// New version.
63
//
64 102 mohor
// Revision 1.14  2004/01/16 14:51:33  mohor
65
// cpu registers added.
66
//
67 99 mohor
// Revision 1.13  2004/01/15 12:09:43  mohor
68
// Working.
69
//
70 97 mohor
// Revision 1.12  2004/01/14 22:59:18  mohor
71
// Temp version.
72
//
73 95 mohor
// Revision 1.11  2004/01/14 12:29:40  mohor
74
// temp version. Resets will be changed in next version.
75
//
76 94 mohor
// Revision 1.10  2004/01/13 11:28:14  mohor
77
// tmp version.
78
//
79 93 mohor
// Revision 1.9  2004/01/10 07:50:24  mohor
80
// temp version.
81
//
82 92 mohor
// Revision 1.8  2004/01/09 12:48:44  mohor
83
// tmp version.
84
//
85 91 mohor
// Revision 1.7  2004/01/08 17:53:36  mohor
86
// tmp version.
87
//
88 90 mohor
// Revision 1.6  2004/01/07 11:58:56  mohor
89
// temp4 version.
90
//
91 89 mohor
// Revision 1.5  2004/01/06 17:15:19  mohor
92
// temp3 version.
93
//
94 88 mohor
// Revision 1.4  2004/01/05 12:16:00  mohor
95
// tmp2 version.
96
//
97 87 mohor
// Revision 1.3  2003/12/23 16:22:46  mohor
98
// Tmp version.
99
//
100 86 mohor
// Revision 1.2  2003/12/23 15:26:26  mohor
101
// Small fix.
102
//
103 83 mohor
// Revision 1.1  2003/12/23 15:09:04  mohor
104
// New directory structure. New version of the debug interface.
105 82 mohor
//
106
//
107 83 mohor
//
108 82 mohor
 
109
// synopsys translate_off
110
`include "timescale.v"
111
// synopsys translate_on
112
`include "dbg_wb_defines.v"
113
 
114
// Top module
115
module dbg_wb(
116
                // JTAG signals
117
                tck_i,
118
                tdi_i,
119
                tdo_o,
120
 
121
                // TAP states
122
                shift_dr_i,
123
                pause_dr_i,
124
                update_dr_i,
125
 
126
                wishbone_ce_i,
127
                crc_match_i,
128
                crc_en_o,
129
                shift_crc_o,
130 95 mohor
                rst_i,
131 82 mohor
 
132
                // WISHBONE common signals
133 95 mohor
                wb_clk_i,
134 82 mohor
 
135
                // WISHBONE master interface
136
                wb_adr_o, wb_dat_o, wb_dat_i, wb_cyc_o, wb_stb_o, wb_sel_o,
137
                wb_we_o, wb_ack_i, wb_cab_o, wb_err_i, wb_cti_o, wb_bte_o
138
 
139
              );
140
 
141
// JTAG signals
142 97 mohor
input         tck_i;
143
input         tdi_i;
144
output        tdo_o;
145 82 mohor
 
146
// TAP states
147 97 mohor
input         shift_dr_i;
148
input         pause_dr_i;
149
input         update_dr_i;
150 82 mohor
 
151 97 mohor
input         wishbone_ce_i;
152
input         crc_match_i;
153
output        crc_en_o;
154
output        shift_crc_o;
155
input         rst_i;
156 82 mohor
// WISHBONE common signals
157 97 mohor
input         wb_clk_i;
158 82 mohor
 
159
// WISHBONE master interface
160
output [31:0] wb_adr_o;
161
output [31:0] wb_dat_o;
162
input  [31:0] wb_dat_i;
163
output        wb_cyc_o;
164
output        wb_stb_o;
165
output  [3:0] wb_sel_o;
166
output        wb_we_o;
167
input         wb_ack_i;
168
output        wb_cab_o;
169
input         wb_err_i;
170
output  [2:0] wb_cti_o;
171
output  [1:0] wb_bte_o;
172
 
173
reg           wb_cyc_o;
174
 
175
reg           tdo_o;
176
 
177 139 igorm
reg    [31:0] wb_dat_tmp, wb_dat_dsff;
178
reg    [31:0] wb_adr_dsff;
179
reg     [3:0] wb_sel_dsff;
180
reg           wb_we_dsff;
181
reg    [`DBG_WB_DR_LEN -1 :0] dr;
182 88 mohor
wire          enable;
183 90 mohor
wire          cmd_cnt_en;
184 138 igorm
reg     [`DBG_WB_CMD_CNT_WIDTH -1:0] cmd_cnt;
185 88 mohor
wire          cmd_cnt_end;
186
reg           cmd_cnt_end_q;
187 139 igorm
reg           addr_len_cnt_en;
188 88 mohor
reg     [5:0] addr_len_cnt;
189
wire          addr_len_cnt_end;
190 139 igorm
reg           addr_len_cnt_end_q;
191
reg           crc_cnt_en;
192
reg     [`DBG_WB_CRC_CNT_WIDTH -1:0] crc_cnt;
193 88 mohor
wire          crc_cnt_end;
194
reg           crc_cnt_end_q;
195 139 igorm
reg           data_cnt_en;
196
reg    [`DBG_WB_DATA_CNT_WIDTH:0] data_cnt;
197 141 igorm
reg    [`DBG_WB_DATA_CNT_LIM_WIDTH:0] data_cnt_limit;
198 88 mohor
wire          data_cnt_end;
199 90 mohor
reg           data_cnt_end_q;
200 82 mohor
 
201 90 mohor
reg           crc_match_reg;
202 82 mohor
 
203 139 igorm
reg    [`DBG_WB_ACC_TYPE_LEN -1:0] acc_type;
204
reg    [`DBG_WB_ADR_LEN -1:0] adr;
205
reg    [`DBG_WB_LEN_LEN -1:0] len;
206
reg    [`DBG_WB_LEN_LEN:0]    len_var;
207 92 mohor
reg           start_rd_tck;
208 97 mohor
reg           rd_tck_started;
209 139 igorm
reg           start_rd_csff;
210 92 mohor
reg           start_wb_rd;
211
reg           start_wb_rd_q;
212
reg           start_wr_tck;
213 139 igorm
reg           start_wr_csff;
214 92 mohor
reg           start_wb_wr;
215
reg           start_wb_wr_q;
216 88 mohor
 
217 139 igorm
reg           status_cnt_en;
218 92 mohor
wire          status_cnt_end;
219 89 mohor
 
220 92 mohor
wire          byte, half, long;
221
reg           byte_q, half_q, long_q;
222 90 mohor
 
223 139 igorm
reg [`DBG_WB_STATUS_CNT_WIDTH -1:0] status_cnt;
224 90 mohor
 
225 138 igorm
reg [`DBG_WB_STATUS_LEN -1:0] status;
226 92 mohor
 
227 139 igorm
reg           wb_error, wb_error_csff, wb_error_tck;
228
reg           wb_overrun, wb_overrun_csff, wb_overrun_tck;
229 97 mohor
reg           underrun_tck;
230 92 mohor
 
231 97 mohor
reg           busy_wb;
232
reg           busy_tck;
233
reg           wb_end;
234
reg           wb_end_rst;
235 139 igorm
reg           wb_end_rst_csff;
236
reg           wb_end_csff;
237 97 mohor
reg           wb_end_tck, wb_end_tck_q;
238 139 igorm
reg           busy_csff;
239 97 mohor
reg           latch_data;
240 139 igorm
reg           update_dr_csff, update_dr_wb;
241 92 mohor
 
242 139 igorm
reg           set_addr, set_addr_csff, set_addr_wb, set_addr_wb_q;
243 97 mohor
wire   [31:0] input_data;
244 92 mohor
 
245 97 mohor
wire          len_eq_0;
246
wire          crc_cnt_31;
247 93 mohor
 
248 97 mohor
reg     [1:0] ptr;
249
reg     [2:0] fifo_cnt;
250
wire          fifo_full;
251
wire          fifo_empty;
252
reg     [7:0] mem [0:3];
253 139 igorm
reg     [2:0] mem_ptr_dsff;
254
reg           wishbone_ce_csff;
255
reg           mem_ptr_init;
256
reg [`DBG_WB_CMD_LEN -1: 0] curr_cmd;
257
wire          curr_cmd_go;
258
reg           curr_cmd_go_q;
259
wire          curr_cmd_wr_comm;
260
wire          curr_cmd_rd_comm;
261
wire          acc_type_read;
262
wire          acc_type_write;
263
wire          acc_type_8bit;
264
wire          acc_type_16bit;
265
wire          acc_type_32bit;
266 97 mohor
 
267
 
268 82 mohor
assign enable = wishbone_ce_i & shift_dr_i;
269 90 mohor
assign crc_en_o = enable & crc_cnt_end & (~status_cnt_end);
270 89 mohor
assign shift_crc_o = enable & status_cnt_end;  // Signals dbg module to shift out the CRC
271 82 mohor
 
272 139 igorm
assign curr_cmd_go      = (curr_cmd == `DBG_WB_GO) && cmd_cnt_end;
273
assign curr_cmd_wr_comm = (curr_cmd == `DBG_WB_WR_COMM) && cmd_cnt_end;
274
assign curr_cmd_rd_comm = (curr_cmd == `DBG_WB_RD_COMM) && cmd_cnt_end;
275 82 mohor
 
276 139 igorm
assign acc_type_read    = (acc_type == `DBG_WB_READ8  || acc_type == `DBG_WB_READ16  || acc_type == `DBG_WB_READ32);
277
assign acc_type_write   = (acc_type == `DBG_WB_WRITE8 || acc_type == `DBG_WB_WRITE16 || acc_type == `DBG_WB_WRITE32);
278
 
279
assign acc_type_8bit    = (acc_type == `DBG_WB_READ8  || acc_type == `DBG_WB_WRITE8);
280
assign acc_type_16bit   = (acc_type == `DBG_WB_READ16 || acc_type == `DBG_WB_WRITE16);
281
assign acc_type_32bit   = (acc_type == `DBG_WB_READ32 || acc_type == `DBG_WB_WRITE32);
282
 
283
 
284
// Selecting where to take the data from
285 123 mohor
always @ (posedge tck_i or posedge rst_i)
286 82 mohor
begin
287 123 mohor
  if (rst_i)
288 93 mohor
    ptr <= #1 2'h0;
289 123 mohor
  else if (update_dr_i)
290
    ptr <= #1 2'h0;
291 139 igorm
  else if (curr_cmd_go && acc_type_read && crc_cnt_31) // first latch
292 93 mohor
    ptr <= #1 ptr + 1'b1;
293 139 igorm
  else if (curr_cmd_go && acc_type_read && byte && (!byte_q))
294 93 mohor
    ptr <= ptr + 1'd1;
295
end
296 139 igorm
 
297 93 mohor
 
298 139 igorm
reg [799:0] dr_text;
299 97 mohor
// Shift register for shifting in and out the data
300 121 mohor
always @ (posedge tck_i or posedge rst_i)
301 93 mohor
begin
302 121 mohor
  if (rst_i)
303 90 mohor
    begin
304 121 mohor
      latch_data <= #1 1'b0;
305 139 igorm
      dr <= #1 {`DBG_WB_DR_LEN{1'b0}};
306
      dr_text = "reset";
307 121 mohor
    end
308 139 igorm
  else if (curr_cmd_rd_comm && crc_cnt_31)  // Latching data (from iternal regs)
309 121 mohor
    begin
310 139 igorm
      dr[`DBG_WB_ACC_TYPE_LEN + `DBG_WB_ADR_LEN + `DBG_WB_LEN_LEN -1:0] <= #1 {acc_type, adr, len};
311
      dr_text = "latch reg data";
312
    end
313
  else if (acc_type_read && curr_cmd_go && crc_cnt_31)  // Latchind first data (from WB)
314
    begin
315 93 mohor
      dr[31:0] <= #1 input_data[31:0];
316 97 mohor
      latch_data <= #1 1'b1;
317 139 igorm
      dr_text = "latch first data";
318 93 mohor
    end
319 139 igorm
  else if (acc_type_read && curr_cmd_go && crc_cnt_end) // Latching data (from WB)
320 93 mohor
    begin
321 139 igorm
      case (acc_type)  // synthesis parallel_case full_case
322
        `DBG_WB_READ8 : begin
323 90 mohor
                      if(byte & (~byte_q))
324 92 mohor
                        begin
325 93 mohor
                          case (ptr)    // synthesis parallel_case
326
                            2'b00 : dr[31:24] <= #1 input_data[31:24];
327
                            2'b01 : dr[31:24] <= #1 input_data[23:16];
328
                            2'b10 : dr[31:24] <= #1 input_data[15:8];
329
                            2'b11 : dr[31:24] <= #1 input_data[7:0];
330
                          endcase
331 97 mohor
                          latch_data <= #1 1'b1;
332 139 igorm
                          dr_text = "latch_data byte";
333 92 mohor
                        end
334 90 mohor
                      else
335 92 mohor
                        begin
336 93 mohor
                          dr[31:24] <= #1 {dr[30:24], 1'b0};
337 97 mohor
                          latch_data <= #1 1'b0;
338 139 igorm
                          dr_text = "shift byte";
339 92 mohor
                        end
340 90 mohor
                    end
341 139 igorm
        `DBG_WB_READ16: begin
342 90 mohor
                      if(half & (~half_q))
343 92 mohor
                        begin
344 93 mohor
                          if (ptr[1])
345 97 mohor
                            dr[31:16] <= #1 input_data[15:0];
346
                          else
347 93 mohor
                            dr[31:16] <= #1 input_data[31:16];
348 97 mohor
                          latch_data <= #1 1'b1;
349 139 igorm
                          dr_text = "latch_data_half";
350 92 mohor
                        end
351 90 mohor
                      else
352 92 mohor
                        begin
353 93 mohor
                          dr[31:16] <= #1 {dr[30:16], 1'b0};
354 97 mohor
                          latch_data <= #1 1'b0;
355 139 igorm
                          dr_text = "shift half";
356 92 mohor
                        end
357 90 mohor
                    end
358 139 igorm
        `DBG_WB_READ32: begin
359 90 mohor
                      if(long & (~long_q))
360 92 mohor
                        begin
361 93 mohor
                          dr[31:0] <= #1 input_data[31:0];
362 97 mohor
                          latch_data <= #1 1'b1;
363 139 igorm
                          dr_text = "latch_data word";
364 92 mohor
                        end
365 90 mohor
                      else
366 92 mohor
                        begin
367 93 mohor
                          dr[31:0] <= #1 {dr[30:0], 1'b0};
368 97 mohor
                          latch_data <= #1 1'b0;
369 139 igorm
                          dr_text = "shift word";
370 92 mohor
                        end
371 90 mohor
                    end
372
      endcase
373
    end
374 139 igorm
  else if (enable && (!addr_len_cnt_end))
375 92 mohor
    begin
376 139 igorm
      dr <= #1 {dr[`DBG_WB_DR_LEN -2:0], tdi_i};
377
      dr_text = "shift dr";
378 92 mohor
    end
379 82 mohor
end
380
 
381
 
382 139 igorm
 
383 90 mohor
assign cmd_cnt_en = enable & (~cmd_cnt_end);
384 88 mohor
 
385 97 mohor
 
386
// Command counter
387 95 mohor
always @ (posedge tck_i or posedge rst_i)
388 82 mohor
begin
389 95 mohor
  if (rst_i)
390 138 igorm
    cmd_cnt <= #1 {`DBG_WB_CMD_CNT_WIDTH{1'b0}};
391 82 mohor
  else if (update_dr_i)
392 138 igorm
    cmd_cnt <= #1 {`DBG_WB_CMD_CNT_WIDTH{1'b0}};
393 90 mohor
  else if (cmd_cnt_en)
394 87 mohor
    cmd_cnt <= #1 cmd_cnt + 1'b1;
395 82 mohor
end
396
 
397
 
398 139 igorm
// Assigning current command
399 95 mohor
always @ (posedge tck_i or posedge rst_i)
400 87 mohor
begin
401 95 mohor
  if (rst_i)
402 139 igorm
    curr_cmd <= #1 {`DBG_WB_CMD_LEN{1'b0}};
403 88 mohor
  else if (update_dr_i)
404 139 igorm
    curr_cmd <= #1 {`DBG_WB_CMD_LEN{1'b0}};
405
  else if (cmd_cnt == (`DBG_WB_CMD_LEN -1))
406
    curr_cmd <= #1 {dr[`DBG_WB_CMD_LEN-2 :0], tdi_i};
407 88 mohor
end
408
 
409
 
410 139 igorm
// Assigning current command
411 95 mohor
always @ (posedge tck_i or posedge rst_i)
412 88 mohor
begin
413 95 mohor
  if (rst_i)
414 139 igorm
    curr_cmd_go_q <= #1 1'b0;
415
  else
416
    curr_cmd_go_q <= #1 curr_cmd_go;
417 87 mohor
end
418 82 mohor
 
419 87 mohor
 
420 139 igorm
always @ (enable or cmd_cnt_end or addr_len_cnt_end or curr_cmd_wr_comm or curr_cmd_rd_comm or crc_cnt_end)
421 88 mohor
begin
422 139 igorm
  if (enable && (!addr_len_cnt_end))
423 123 mohor
    begin
424 139 igorm
      if (cmd_cnt_end && curr_cmd_wr_comm)
425
        addr_len_cnt_en = 1'b1;
426
      else if (crc_cnt_end && curr_cmd_rd_comm)
427
        addr_len_cnt_en = 1'b1;
428
      else
429
        addr_len_cnt_en = 1'b0;
430 123 mohor
    end
431
  else
432 139 igorm
    addr_len_cnt_en = 1'b0;
433 88 mohor
end
434
 
435
 
436 139 igorm
// Address/length counter
437 123 mohor
always @ (posedge tck_i or posedge rst_i)
438 88 mohor
begin
439 123 mohor
  if (rst_i)
440 139 igorm
    addr_len_cnt <= #1 6'h0;
441 123 mohor
  else if (update_dr_i)
442 139 igorm
    addr_len_cnt <= #1 6'h0;
443
  else if (addr_len_cnt_en)
444
    addr_len_cnt <= #1 addr_len_cnt + 1'b1;
445
end
446
 
447
 
448
always @ (enable or data_cnt_end or cmd_cnt_end or curr_cmd_go or acc_type_write or acc_type_read or crc_cnt_end)
449
begin
450
  if (enable && (!data_cnt_end))
451 123 mohor
    begin
452 139 igorm
      if (cmd_cnt_end && curr_cmd_go && acc_type_write)
453
        data_cnt_en = 1'b1;
454
      else if (crc_cnt_end && curr_cmd_go && acc_type_read)
455
        data_cnt_en = 1'b1;
456
      else
457
        data_cnt_en = 1'b0;
458 123 mohor
    end
459 139 igorm
  else
460
    data_cnt_en = 1'b0;
461 88 mohor
end
462
 
463
 
464 139 igorm
// Data counter
465 123 mohor
always @ (posedge tck_i or posedge rst_i)
466 88 mohor
begin
467 123 mohor
  if (rst_i)
468 139 igorm
    data_cnt <= #1 {`DBG_WB_DATA_CNT_WIDTH{1'b0}};
469
  else if (update_dr_i)
470
    data_cnt <= #1 {`DBG_WB_DATA_CNT_WIDTH{1'b0}};
471
  else if (data_cnt_en)
472
    data_cnt <= #1 data_cnt + 1'b1;
473 88 mohor
end
474
 
475 94 mohor
 
476 88 mohor
 
477 97 mohor
// Upper limit. Data counter counts until this value is reached.
478 123 mohor
always @ (posedge tck_i or posedge rst_i)
479 94 mohor
begin
480 123 mohor
  if (rst_i)
481 141 igorm
    data_cnt_limit <= #1 {`DBG_WB_DATA_CNT_LIM_WIDTH{1'b0}};
482 123 mohor
  else if (update_dr_i)
483 141 igorm
    data_cnt_limit <= #1 len + 1'b1;
484 94 mohor
end
485 88 mohor
 
486 90 mohor
 
487 139 igorm
always @ (enable or crc_cnt_end or curr_cmd_rd_comm or curr_cmd_wr_comm or curr_cmd_go or addr_len_cnt_end or data_cnt_end or acc_type_write or acc_type_read or cmd_cnt_end)
488
begin
489
  if (enable && (!crc_cnt_end) && cmd_cnt_end)
490
    begin
491
      if (addr_len_cnt_end && curr_cmd_wr_comm)
492
        crc_cnt_en = 1'b1;
493
      else if (data_cnt_end && curr_cmd_go && acc_type_write)
494
        crc_cnt_en = 1'b1;
495
      else if (cmd_cnt_end && (curr_cmd_go && acc_type_read || curr_cmd_rd_comm))
496
        crc_cnt_en = 1'b1;
497
      else
498
        crc_cnt_en = 1'b0;
499
    end
500
  else
501
    crc_cnt_en = 1'b0;
502
end
503 94 mohor
 
504 97 mohor
 
505 82 mohor
// crc counter
506 95 mohor
always @ (posedge tck_i or posedge rst_i)
507 82 mohor
begin
508 95 mohor
  if (rst_i)
509 139 igorm
    crc_cnt <= #1 {`DBG_WB_CRC_CNT_WIDTH{1'b0}};
510 90 mohor
  else if(crc_cnt_en)
511 82 mohor
    crc_cnt <= #1 crc_cnt + 1'b1;
512
  else if (update_dr_i)
513 139 igorm
    crc_cnt <= #1 {`DBG_WB_CRC_CNT_WIDTH{1'b0}};
514 82 mohor
end
515
 
516 139 igorm
assign cmd_cnt_end      = cmd_cnt      == `DBG_WB_CMD_LEN;
517
assign addr_len_cnt_end = addr_len_cnt == `DBG_WB_DR_LEN;
518
assign crc_cnt_end      = crc_cnt      == `DBG_WB_CRC_CNT_WIDTH'd32;
519
assign crc_cnt_31       = crc_cnt      == `DBG_WB_CRC_CNT_WIDTH'd31;
520 141 igorm
assign data_cnt_end     = (data_cnt    == {data_cnt_limit, 3'b000});
521 82 mohor
 
522 123 mohor
always @ (posedge tck_i or posedge rst_i)
523 82 mohor
begin
524 123 mohor
  if (rst_i)
525
    begin
526 139 igorm
      crc_cnt_end_q       <= #1 1'b0;
527
      cmd_cnt_end_q       <= #1 1'b0;
528
      data_cnt_end_q      <= #1 1'b0;
529
      addr_len_cnt_end_q  <= #1 1'b0;
530 123 mohor
    end
531
  else
532
    begin
533 139 igorm
      crc_cnt_end_q       <= #1 crc_cnt_end;
534
      cmd_cnt_end_q       <= #1 cmd_cnt_end;
535
      data_cnt_end_q      <= #1 data_cnt_end;
536
      addr_len_cnt_end_q  <= #1 addr_len_cnt_end;
537 123 mohor
    end
538 82 mohor
end
539
 
540 90 mohor
 
541 97 mohor
// Status counter is made of 4 serialy connected registers
542 95 mohor
always @ (posedge tck_i or posedge rst_i)
543 82 mohor
begin
544 95 mohor
  if (rst_i)
545 139 igorm
    status_cnt <= #1 {`DBG_WB_STATUS_CNT_WIDTH{1'b0}};
546 82 mohor
  else if (update_dr_i)
547 139 igorm
    status_cnt <= #1 {`DBG_WB_STATUS_CNT_WIDTH{1'b0}};
548
  else if (status_cnt_en)
549
    status_cnt <= #1 status_cnt + 1'b1;
550 82 mohor
end
551
 
552 90 mohor
 
553 141 igorm
always @ (enable or status_cnt_end or crc_cnt_end or curr_cmd_rd_comm or curr_cmd_wr_comm or curr_cmd_go or acc_type_write or acc_type_read or data_cnt_end or addr_len_cnt_end)
554 90 mohor
begin
555 139 igorm
  if (enable && (!status_cnt_end))
556 90 mohor
    begin
557 139 igorm
      if (crc_cnt_end && curr_cmd_wr_comm)
558
        status_cnt_en = 1'b1;
559
      else if (crc_cnt_end && curr_cmd_go && acc_type_write)
560
        status_cnt_en = 1'b1;
561
      else if (data_cnt_end && curr_cmd_go && acc_type_read)
562
        status_cnt_en = 1'b1;
563
      else if (addr_len_cnt_end && curr_cmd_rd_comm)
564
        status_cnt_en = 1'b1;
565
      else
566
        status_cnt_en = 1'b0;
567 90 mohor
    end
568
  else
569 139 igorm
    status_cnt_en = 1'b0;
570 90 mohor
end
571
 
572
 
573 139 igorm
assign status_cnt_end = status_cnt == `DBG_WB_STATUS_LEN;
574 82 mohor
 
575 97 mohor
 
576 139 igorm
// Latching acc_type, address and length
577 95 mohor
always @ (posedge tck_i or posedge rst_i)
578 82 mohor
begin
579 95 mohor
  if (rst_i)
580 92 mohor
    begin
581 139 igorm
      acc_type  <= #1 {`DBG_WB_ACC_TYPE_LEN{1'b0}};
582
      adr       <= #1 {`DBG_WB_ADR_LEN{1'b0}};
583
      len       <= #1 {`DBG_WB_LEN_LEN{1'b0}};
584
      set_addr  <= #1 1'b0;
585 92 mohor
    end
586 139 igorm
  else if(crc_cnt_end && (!crc_cnt_end_q) && crc_match_i && curr_cmd_wr_comm)
587 92 mohor
    begin
588 139 igorm
      acc_type  <= #1 dr[`DBG_WB_ACC_TYPE_LEN + `DBG_WB_ADR_LEN + `DBG_WB_LEN_LEN -1 : `DBG_WB_ADR_LEN + `DBG_WB_LEN_LEN];
589
      adr       <= #1 dr[`DBG_WB_ADR_LEN + `DBG_WB_LEN_LEN -1 : `DBG_WB_LEN_LEN];
590
      len       <= #1 dr[`DBG_WB_LEN_LEN -1:0];
591
      set_addr  <= #1 1'b1;
592 92 mohor
    end
593 139 igorm
  else if(wb_end_tck)               // Writing back the address
594 92 mohor
    begin
595 139 igorm
      adr  <= #1 wb_adr_dsff;
596 92 mohor
    end
597 82 mohor
  else
598 139 igorm
    set_addr <= #1 1'b0;
599 82 mohor
end
600
 
601
 
602 123 mohor
always @ (posedge tck_i or posedge rst_i)
603 82 mohor
begin
604 123 mohor
  if (rst_i)
605
    crc_match_reg <= #1 1'b0;
606
  else if(crc_cnt_end & (~crc_cnt_end_q))
607 90 mohor
    crc_match_reg <= #1 crc_match_i;
608
end
609
 
610
 
611 97 mohor
// Length counter
612 123 mohor
always @ (posedge tck_i or posedge rst_i)
613 93 mohor
begin
614 123 mohor
  if (rst_i)
615 139 igorm
    len_var <= #1 {1'b0, {`DBG_WB_LEN_LEN{1'b0}}};
616
  else if(update_dr_i)
617
    len_var <= #1 len + 1'b1;
618 95 mohor
  else if (start_rd_tck)
619 93 mohor
    begin
620 139 igorm
      case (acc_type)  // synthesis parallel_case full_case
621
        `DBG_WB_READ8 :
622
                    if (len_var > 'd1)
623
                      len_var <= #1 len_var - 1'd1;
624
                    else
625
                      len_var <= #1 {1'b0, {`DBG_WB_LEN_LEN{1'b0}}};
626
        `DBG_WB_READ16:
627
                    if (len_var > 'd2)
628
                      len_var <= #1 len_var - 2'd2;
629
                    else
630
                      len_var <= #1 {1'b0, {`DBG_WB_LEN_LEN{1'b0}}};
631
        `DBG_WB_READ32:
632
                    if (len_var > 'd4)
633
                      len_var <= #1 len_var - 3'd4;
634
                    else
635
                      len_var <= #1 {1'b0, {`DBG_WB_LEN_LEN{1'b0}}};
636 93 mohor
      endcase
637
    end
638
end
639
 
640
 
641 139 igorm
assign len_eq_0 = len_var == 'h0;
642 93 mohor
 
643
 
644 139 igorm
assign byte = data_cnt[2:0] == 3'd7;
645
assign half = data_cnt[3:0] == 4'd15;
646
assign long = data_cnt[4:0] == 5'd31;
647 89 mohor
 
648
 
649 123 mohor
always @ (posedge tck_i or posedge rst_i)
650 92 mohor
begin
651 123 mohor
  if (rst_i)
652 139 igorm
    begin
653
      byte_q <= #1  1'b0;
654
      half_q <= #1  1'b0;
655
      long_q <= #1  1'b0;
656
    end
657
  else
658
    begin
659
      byte_q <= #1 byte;
660
      half_q <= #1 half;
661
      long_q <= #1 long;
662
    end
663 97 mohor
end
664
 
665
 
666 89 mohor
// Start wishbone write cycle
667 121 mohor
always @ (posedge tck_i or posedge rst_i)
668 89 mohor
begin
669 121 mohor
  if (rst_i)
670 88 mohor
    begin
671 121 mohor
      start_wr_tck <= #1 1'b0;
672 139 igorm
      wb_dat_tmp <= #1 32'h0;
673 121 mohor
    end
674 139 igorm
  else if (curr_cmd_go && acc_type_write)
675 121 mohor
    begin
676 139 igorm
      case (acc_type)  // synthesis parallel_case full_case
677
        `DBG_WB_WRITE8  : begin
678
                        if (byte_q)
679 88 mohor
                          begin
680 89 mohor
                            start_wr_tck <= #1 1'b1;
681 139 igorm
                            wb_dat_tmp <= #1 {4{dr[7:0]}};
682 88 mohor
                          end
683
                        else
684
                          begin
685 89 mohor
                            start_wr_tck <= #1 1'b0;
686 88 mohor
                          end
687
                      end
688 139 igorm
        `DBG_WB_WRITE16 : begin
689
                        if (half_q)
690 88 mohor
                          begin
691 89 mohor
                            start_wr_tck <= #1 1'b1;
692 139 igorm
                            wb_dat_tmp <= #1 {2{dr[15:0]}};
693 88 mohor
                          end
694
                        else
695
                          begin
696 89 mohor
                            start_wr_tck <= #1 1'b0;
697 88 mohor
                          end
698
                      end
699 139 igorm
        `DBG_WB_WRITE32 : begin
700
                        if (long_q)
701 88 mohor
                          begin
702 89 mohor
                            start_wr_tck <= #1 1'b1;
703 139 igorm
                            wb_dat_tmp <= #1 dr[31:0];
704 88 mohor
                          end
705
                        else
706
                          begin
707 89 mohor
                            start_wr_tck <= #1 1'b0;
708 88 mohor
                          end
709
                      end
710
      endcase
711
    end
712
  else
713 89 mohor
    start_wr_tck <= #1 1'b0;
714 82 mohor
end
715
 
716
 
717 139 igorm
// wb_dat_o in WB clk domain
718
always @ (posedge wb_clk_i)
719
begin
720
  wb_dat_dsff <= #1 wb_dat_tmp;
721
end
722
 
723
assign wb_dat_o = wb_dat_dsff;
724
 
725
 
726
// Start wishbone read cycle
727
always @ (posedge tck_i or posedge rst_i)
728
begin
729
  if (rst_i)
730
    start_rd_tck <= #1 1'b0;
731
  else if (curr_cmd_go && (!curr_cmd_go_q) && acc_type_read)              // First read after cmd is entered
732
    start_rd_tck <= #1 1'b1;
733
  else if ((!start_rd_tck) && curr_cmd_go && acc_type_read  && (!len_eq_0) && (!fifo_full) && (!rd_tck_started))
734
    start_rd_tck <= #1 1'b1;
735
  else
736
    start_rd_tck <= #1 1'b0;
737
end
738
 
739
 
740
always @ (posedge tck_i or posedge rst_i)
741
begin
742
  if (rst_i)
743
    rd_tck_started <= #1 1'b0;
744
  else if (update_dr_i || wb_end_tck && (!wb_end_tck_q))
745
    rd_tck_started <= #1 1'b0;
746
  else if (start_rd_tck)
747
    rd_tck_started <= #1 1'b1;
748
end
749
 
750
 
751
 
752 123 mohor
always @ (posedge wb_clk_i or posedge rst_i)
753 82 mohor
begin
754 123 mohor
  if (rst_i)
755
    begin
756 139 igorm
      start_rd_csff   <= #1 1'b0;
757
      start_wb_rd     <= #1 1'b0;
758
      start_wb_rd_q   <= #1 1'b0;
759
 
760
      start_wr_csff   <= #1 1'b0;
761
      start_wb_wr     <= #1 1'b0;
762
      start_wb_wr_q   <= #1 1'b0;
763
 
764
      set_addr_csff   <= #1 1'b0;
765
      set_addr_wb     <= #1 1'b0;
766
      set_addr_wb_q   <= #1 1'b0;
767 123 mohor
    end
768
  else
769
    begin
770 139 igorm
      start_rd_csff   <= #1 start_rd_tck;
771
      start_wb_rd     <= #1 start_rd_csff;
772 123 mohor
      start_wb_rd_q   <= #1 start_wb_rd;
773 139 igorm
 
774
      start_wr_csff   <= #1 start_wr_tck;
775
      start_wb_wr     <= #1 start_wr_csff;
776 123 mohor
      start_wb_wr_q   <= #1 start_wb_wr;
777 139 igorm
 
778
      set_addr_csff   <= #1 set_addr;
779
      set_addr_wb     <= #1 set_addr_csff;
780 123 mohor
      set_addr_wb_q   <= #1 set_addr_wb;
781
    end
782 82 mohor
end
783
 
784
 
785 97 mohor
// wb_cyc_o
786 95 mohor
always @ (posedge wb_clk_i or posedge rst_i)
787 82 mohor
begin
788 95 mohor
  if (rst_i)
789 82 mohor
    wb_cyc_o <= #1 1'b0;
790 139 igorm
  else if ((start_wb_wr && (!start_wb_wr_q)) || (start_wb_rd && (!start_wb_rd_q)))
791 82 mohor
    wb_cyc_o <= #1 1'b1;
792 139 igorm
  else if (wb_ack_i || wb_err_i)
793 82 mohor
    wb_cyc_o <= #1 1'b0;
794
end
795
 
796
 
797 97 mohor
// wb_adr_o logic
798 121 mohor
always @ (posedge wb_clk_i or posedge rst_i)
799 82 mohor
begin
800 121 mohor
  if (rst_i)
801 139 igorm
    wb_adr_dsff <= #1 32'h0;
802
  else if (set_addr_wb && (!set_addr_wb_q)) // Setting starting address
803
    wb_adr_dsff <= #1 adr;
804 82 mohor
  else if (wb_ack_i)
805
    begin
806 139 igorm
      if ((acc_type == `DBG_WB_WRITE8) || (acc_type == `DBG_WB_READ8))
807
        wb_adr_dsff <= #1 wb_adr_dsff + 1'd1;
808
      else if ((acc_type == `DBG_WB_WRITE16) || (acc_type == `DBG_WB_READ16))
809
        wb_adr_dsff <= #1 wb_adr_dsff + 2'd2;
810 82 mohor
      else
811 139 igorm
        wb_adr_dsff <= #1 wb_adr_dsff + 3'd4;
812 82 mohor
    end
813
end
814
 
815
 
816 139 igorm
assign wb_adr_o = wb_adr_dsff;
817 89 mohor
 
818 139 igorm
 
819 88 mohor
//    adr   byte  |  short  |  long
820
//     0    1000     1100      1111
821
//     1    0100     err       err
822
//     2    0010     0011      err
823
//     3    0001     err       err
824 97 mohor
// wb_sel_o logic
825 139 igorm
 
826 95 mohor
always @ (posedge wb_clk_i or posedge rst_i)
827 82 mohor
begin
828 95 mohor
  if (rst_i)
829 139 igorm
    wb_sel_dsff[3:0] <= #1 4'h0;
830 95 mohor
  else
831 88 mohor
    begin
832 139 igorm
      case ({wb_adr_dsff[1:0], acc_type_8bit, acc_type_16bit, acc_type_32bit}) // synthesis parallel_case full_case
833
        {2'd0, 3'b100} : wb_sel_dsff[3:0] <= #1 4'h8;
834
        {2'd0, 3'b010} : wb_sel_dsff[3:0] <= #1 4'hC;
835
        {2'd0, 3'b001} : wb_sel_dsff[3:0] <= #1 4'hF;
836
        {2'd1, 3'b100} : wb_sel_dsff[3:0] <= #1 4'h4;
837
        {2'd2, 3'b100} : wb_sel_dsff[3:0] <= #1 4'h2;
838
        {2'd2, 3'b010} : wb_sel_dsff[3:0] <= #1 4'h3;
839
        {2'd3, 3'b100} : wb_sel_dsff[3:0] <= #1 4'h1;
840
      endcase
841 88 mohor
    end
842 82 mohor
end
843
 
844
 
845 139 igorm
assign wb_sel_o = wb_sel_dsff;
846
 
847
 
848
always @ (posedge wb_clk_i)
849
begin
850
  wb_we_dsff <= #1 curr_cmd_go && acc_type_write;
851
end
852
 
853
 
854
assign wb_we_o = wb_we_dsff;
855 82 mohor
assign wb_cab_o = 1'b0;
856
assign wb_stb_o = wb_cyc_o;
857
assign wb_cti_o = 3'h0;     // always performing single access
858
assign wb_bte_o = 2'h0;     // always performing single access
859 139 igorm
 
860
 
861
 
862 97 mohor
// Logic for detecting end of transaction
863 95 mohor
always @ (posedge wb_clk_i or posedge rst_i)
864 82 mohor
begin
865 95 mohor
  if (rst_i)
866 86 mohor
    wb_end <= #1 1'b0;
867 139 igorm
  else if (wb_ack_i || wb_err_i)
868 86 mohor
    wb_end <= #1 1'b1;
869
  else if (wb_end_rst)
870
    wb_end <= #1 1'b0;
871 82 mohor
end
872 139 igorm
 
873
 
874
always @ (posedge tck_i or posedge rst_i)
875
begin
876
  if (rst_i)
877
    begin
878
      wb_end_csff  <= #1 1'b0;
879
      wb_end_tck   <= #1 1'b0;
880
      wb_end_tck_q <= #1 1'b0;
881
    end
882
  else
883
    begin
884
      wb_end_csff  <= #1 wb_end;
885
      wb_end_tck   <= #1 wb_end_csff;
886
      wb_end_tck_q <= #1 wb_end_tck;
887
    end
888
end
889 82 mohor
 
890
 
891 139 igorm
always @ (posedge wb_clk_i or posedge rst_i)
892 82 mohor
begin
893 95 mohor
  if (rst_i)
894 82 mohor
    begin
895 139 igorm
      wb_end_rst_csff <= #1 1'b0;
896
      wb_end_rst      <= #1 1'b0;
897 82 mohor
    end
898
  else
899
    begin
900 139 igorm
      wb_end_rst_csff <= #1 wb_end_tck;
901
      wb_end_rst      <= #1 wb_end_rst_csff;
902 82 mohor
    end
903
end
904
 
905
 
906 95 mohor
always @ (posedge wb_clk_i or posedge rst_i)
907 82 mohor
begin
908 95 mohor
  if (rst_i)
909 82 mohor
    busy_wb <= #1 1'b0;
910 86 mohor
  else if (wb_end_rst)
911 82 mohor
    busy_wb <= #1 1'b0;
912 139 igorm
  else if (wb_cyc_o)
913 82 mohor
    busy_wb <= #1 1'b1;
914
end
915
 
916
 
917 95 mohor
always @ (posedge tck_i or posedge rst_i)
918 82 mohor
begin
919 95 mohor
  if (rst_i)
920 82 mohor
    begin
921 139 igorm
      busy_csff       <= #1 1'b0;
922
      busy_tck        <= #1 1'b0;
923
 
924
      update_dr_csff  <= #1 1'b0;
925
      update_dr_wb    <= #1 1'b0;
926 82 mohor
    end
927
  else
928
    begin
929 139 igorm
      busy_csff       <= #1 busy_wb;
930
      busy_tck        <= #1 busy_csff;
931 82 mohor
 
932 139 igorm
      update_dr_csff  <= #1 update_dr_i;
933
      update_dr_wb    <= #1 update_dr_csff;
934 123 mohor
    end
935 82 mohor
end
936
 
937
 
938 97 mohor
// Detecting WB error
939 95 mohor
always @ (posedge wb_clk_i or posedge rst_i)
940 82 mohor
begin
941 95 mohor
  if (rst_i)
942 82 mohor
    wb_error <= #1 1'b0;
943
  else if(wb_err_i)
944
    wb_error <= #1 1'b1;
945 139 igorm
  else if(update_dr_wb) // error remains active until update_dr arrives
946 82 mohor
    wb_error <= #1 1'b0;
947
end
948 97 mohor
 
949
 
950
// Detecting overrun when write operation.
951 95 mohor
always @ (posedge wb_clk_i or posedge rst_i)
952 82 mohor
begin
953 95 mohor
  if (rst_i)
954 88 mohor
    wb_overrun <= #1 1'b0;
955 139 igorm
  else if(start_wb_wr && (!start_wb_wr_q) && wb_cyc_o)
956 88 mohor
    wb_overrun <= #1 1'b1;
957 139 igorm
  else if(update_dr_wb) // error remains active until update_dr arrives
958 88 mohor
    wb_overrun <= #1 1'b0;
959 82 mohor
end
960
 
961
 
962 97 mohor
// Detecting underrun when read operation
963
always @ (posedge tck_i or posedge rst_i)
964
begin
965
  if (rst_i)
966
    underrun_tck <= #1 1'b0;
967 139 igorm
  else if(latch_data && fifo_empty && (!data_cnt_end))
968 97 mohor
    underrun_tck <= #1 1'b1;
969 139 igorm
  else if(update_dr_i) // error remains active until update_dr arrives
970 97 mohor
    underrun_tck <= #1 1'b0;
971
end
972 87 mohor
 
973 88 mohor
 
974 95 mohor
always @ (posedge tck_i or posedge rst_i)
975 87 mohor
begin
976 95 mohor
  if (rst_i)
977 139 igorm
    begin
978
      wb_error_csff   <= #1 1'b0;
979
      wb_error_tck    <= #1 1'b0;
980
 
981
      wb_overrun_csff <= #1 1'b0;
982
      wb_overrun_tck  <= #1 1'b0;
983
    end
984 87 mohor
  else
985 139 igorm
    begin
986
      wb_error_csff   <= #1 wb_error;
987
      wb_error_tck    <= #1 wb_error_csff;
988
 
989
      wb_overrun_csff <= #1 wb_overrun;
990
      wb_overrun_tck  <= #1 wb_overrun_csff;
991
    end
992 87 mohor
end
993 88 mohor
 
994 95 mohor
 
995 139 igorm
 
996 123 mohor
always @ (posedge wb_clk_i or posedge rst_i)
997 92 mohor
begin
998 123 mohor
  if (rst_i)
999
    begin
1000 139 igorm
      wishbone_ce_csff  <= #1 1'b0;
1001
      mem_ptr_init      <= #1 1'b0;
1002 123 mohor
    end
1003
  else
1004
    begin
1005 139 igorm
      wishbone_ce_csff  <= #1  wishbone_ce_i;
1006
      mem_ptr_init      <= #1 ~wishbone_ce_csff;
1007 123 mohor
    end
1008 92 mohor
end
1009 88 mohor
 
1010
 
1011 97 mohor
// Logic for latching data that is read from wishbone
1012 123 mohor
always @ (posedge wb_clk_i or posedge rst_i)
1013 92 mohor
begin
1014 123 mohor
  if (rst_i)
1015 139 igorm
    mem_ptr_dsff <= #1 3'h0;
1016
  else if(mem_ptr_init)
1017
    mem_ptr_dsff <= #1 3'h0;
1018 92 mohor
  else if (wb_ack_i)
1019
    begin
1020 139 igorm
      if (acc_type == `DBG_WB_READ8)
1021
        mem_ptr_dsff <= #1 mem_ptr_dsff + 1'd1;
1022
      else if (acc_type == `DBG_WB_READ16)
1023
        mem_ptr_dsff <= #1 mem_ptr_dsff + 2'd2;
1024 92 mohor
    end
1025
end
1026 88 mohor
 
1027
 
1028 97 mohor
// Logic for latching data that is read from wishbone
1029 92 mohor
always @ (posedge wb_clk_i)
1030
begin
1031
  if (wb_ack_i)
1032
    begin
1033 139 igorm
      case (wb_sel_dsff)    // synthesis parallel_case full_case
1034
        4'b1000  :  mem[mem_ptr_dsff[1:0]] <= #1 wb_dat_i[31:24];            // byte
1035
        4'b0100  :  mem[mem_ptr_dsff[1:0]] <= #1 wb_dat_i[23:16];            // byte
1036
        4'b0010  :  mem[mem_ptr_dsff[1:0]] <= #1 wb_dat_i[15:08];            // byte
1037
        4'b0001  :  mem[mem_ptr_dsff[1:0]] <= #1 wb_dat_i[07:00];            // byte
1038
 
1039 92 mohor
        4'b1100  :                                                      // half
1040
                    begin
1041 139 igorm
                      mem[mem_ptr_dsff[1:0]]      <= #1 wb_dat_i[31:24];
1042
                      mem[mem_ptr_dsff[1:0]+1'b1] <= #1 wb_dat_i[23:16];
1043 92 mohor
                    end
1044
        4'b0011  :                                                      // half
1045
                    begin
1046 139 igorm
                      mem[mem_ptr_dsff[1:0]]      <= #1 wb_dat_i[15:08];
1047
                      mem[mem_ptr_dsff[1:0]+1'b1] <= #1 wb_dat_i[07:00];
1048 92 mohor
                    end
1049
        4'b1111  :                                                      // long
1050
                    begin
1051
                      mem[0] <= #1 wb_dat_i[31:24];
1052
                      mem[1] <= #1 wb_dat_i[23:16];
1053
                      mem[2] <= #1 wb_dat_i[15:08];
1054 93 mohor
                      mem[3] <= #1 wb_dat_i[07:00];
1055 92 mohor
                    end
1056
      endcase
1057
    end
1058
end
1059 88 mohor
 
1060 97 mohor
 
1061 92 mohor
assign input_data = {mem[0], mem[1], mem[2], mem[3]};
1062 88 mohor
 
1063 92 mohor
 
1064 97 mohor
// Fifo counter and empty/full detection
1065 123 mohor
always @ (posedge tck_i or posedge rst_i)
1066 97 mohor
begin
1067 123 mohor
  if (rst_i)
1068 108 simons
    fifo_cnt <= #1 3'h0;
1069 123 mohor
  else if (update_dr_i)
1070
    fifo_cnt <= #1 3'h0;
1071 139 igorm
  else if (wb_end_tck && (!wb_end_tck_q) && (!latch_data) && (!fifo_full))  // incrementing
1072 97 mohor
    begin
1073 139 igorm
      case (acc_type)  // synthesis parallel_case full_case
1074
        `DBG_WB_READ8 : fifo_cnt <= #1 fifo_cnt + 1'd1;
1075
        `DBG_WB_READ16: fifo_cnt <= #1 fifo_cnt + 2'd2;
1076
        `DBG_WB_READ32: fifo_cnt <= #1 fifo_cnt + 3'd4;
1077 97 mohor
      endcase
1078
    end
1079 139 igorm
  else if (!(wb_end_tck && (!wb_end_tck_q)) && latch_data && (!fifo_empty))  // decrementing
1080 97 mohor
    begin
1081 139 igorm
      case (acc_type)  // synthesis parallel_case full_case
1082
        `DBG_WB_READ8 : fifo_cnt <= #1 fifo_cnt - 1'd1;
1083
        `DBG_WB_READ16: fifo_cnt <= #1 fifo_cnt - 2'd2;
1084
        `DBG_WB_READ32: fifo_cnt <= #1 fifo_cnt - 3'd4;
1085 97 mohor
      endcase
1086
    end
1087
end
1088 92 mohor
 
1089
 
1090 139 igorm
assign fifo_full  = fifo_cnt == 3'h4;
1091 97 mohor
assign fifo_empty = fifo_cnt == 3'h0;
1092 92 mohor
 
1093 139 igorm
reg [799:0] tdo_text;
1094 92 mohor
 
1095 139 igorm
// TDO multiplexer
1096 141 igorm
always @ (pause_dr_i or busy_tck or crc_cnt_end or crc_cnt_end_q or curr_cmd_wr_comm or
1097
          curr_cmd_rd_comm or curr_cmd_go or acc_type_write or acc_type_read or crc_match_i
1098
          or data_cnt_end or dr or data_cnt_end_q or crc_match_reg or status_cnt_en or status
1099
          or addr_len_cnt_end or addr_len_cnt_end_q)
1100 139 igorm
begin
1101
  if (pause_dr_i)
1102
    begin
1103
    tdo_o = busy_tck;
1104
    tdo_text = "busy_tck";
1105
    end
1106
  else if (crc_cnt_end && (!crc_cnt_end_q) && (curr_cmd_wr_comm || curr_cmd_go && acc_type_write ))
1107
    begin
1108
      tdo_o = ~crc_match_i;
1109
      tdo_text = "crc_match_i";
1110
    end
1111
  else if (curr_cmd_go && acc_type_read && crc_cnt_end && (!data_cnt_end))
1112
    begin
1113
      tdo_o = dr[31];
1114
      tdo_text = "dr[31]";
1115
    end
1116
  else if (curr_cmd_go && acc_type_read && data_cnt_end && (!data_cnt_end_q))
1117
    begin
1118
      tdo_o = ~crc_match_reg;
1119
      tdo_text = "crc_match_reg";
1120
    end
1121
  else if (curr_cmd_rd_comm && addr_len_cnt_end && (!addr_len_cnt_end_q))
1122
    begin
1123
      tdo_o = ~crc_match_reg;
1124
      tdo_text = "crc_match_reg_rd_comm";
1125
    end
1126
  else if (curr_cmd_rd_comm && crc_cnt_end && (!addr_len_cnt_end))
1127
    begin
1128
      tdo_o = dr[`DBG_WB_ACC_TYPE_LEN + `DBG_WB_ADR_LEN + `DBG_WB_LEN_LEN -1];
1129
      tdo_text = "rd_comm data";
1130
    end
1131
  else if (status_cnt_en)
1132
    begin
1133
      tdo_o = status[3];
1134
      tdo_text = "status";
1135
    end
1136
  else
1137
    begin
1138
      tdo_o = 1'b0;
1139
      tdo_text = "zero";
1140
    end
1141
end
1142 92 mohor
 
1143 139 igorm
reg [799:0] status_text;
1144
// Status register
1145
always @ (posedge tck_i or posedge rst_i)
1146
begin
1147
  if (rst_i)
1148
    begin
1149
    status <= #1 {`DBG_WB_STATUS_LEN{1'b0}};
1150
    status_text = "reset";
1151
    end
1152
  else if(crc_cnt_end && (!crc_cnt_end_q) && (!(curr_cmd_go && acc_type_read)))
1153
    begin
1154
    status <= #1 {1'b0, wb_error_tck, wb_overrun_tck, crc_match_i};
1155
    status_text = "latch ni read";
1156
    end
1157
  else if (data_cnt_end && (!data_cnt_end_q) && curr_cmd_go && acc_type_read)
1158
    begin
1159
    status <= #1 {1'b0, wb_error_tck, underrun_tck, crc_match_reg};
1160
    status_text = "latch read";
1161
    end
1162
  else if (addr_len_cnt_end && (!addr_len_cnt_end) && curr_cmd_rd_comm)
1163
    begin
1164
    status <= #1 {1'b0, 1'b0, 1'b0, crc_match_reg};
1165
    status_text = "rd_comm";
1166
    end
1167
  else if (shift_dr_i && (!status_cnt_end))
1168
    begin
1169
    status <= #1 {status[`DBG_WB_STATUS_LEN -2:0], status[`DBG_WB_STATUS_LEN -1]};
1170
    status_text = "shifting";
1171
    end
1172
end
1173
// Following status is shifted out (MSB first):
1174
// 3. bit:          1 if crc is OK, else 0
1175
// 2. bit:          1'b0
1176
// 1. bit:          1 if WB error occured, else 0
1177
// 0. bit:          1 if overrun occured during write (data couldn't be written fast enough)
1178
//                    or underrun occured during read (data couldn't be read fast enough)
1179 97 mohor
 
1180 139 igorm
 
1181 82 mohor
endmodule
1182
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.