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 139

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

powered by: WebSVN 2.1.0

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