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 144

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

powered by: WebSVN 2.1.0

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