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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [rtl/] [verilog/] [dbg_interface/] [rtl/] [verilog/] [dbg_wb.v] - Blame information for rev 1771

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

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

powered by: WebSVN 2.1.0

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