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 146

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

powered by: WebSVN 2.1.0

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