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

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [rtl/] [dbg_interface/] [rtl/] [verilog/] [dbg_wb.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 xianfeng
//////////////////////////////////////////////////////////////////////
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.22  2004/04/01 11:56:59  igorm
47
// Port names and defines for the supported CPUs changed.
48
//
49
// Revision 1.21  2004/03/31 14:34:09  igorm
50
// data_cnt_lim length changed to reduce number of warnings.
51
//
52
// Revision 1.20  2004/03/28 20:27:02  igorm
53
// New release of the debug interface (3rd. release).
54
//
55
// Revision 1.19  2004/03/22 16:35:46  igorm
56
// Temp version before changing dbg interface.
57
//
58
// Revision 1.18  2004/01/25 14:04:18  mohor
59
// All flipflops are reset.
60
//
61
// Revision 1.17  2004/01/22 13:58:53  mohor
62
// Port signals are all set to zero after reset.
63
//
64
// 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
// Revision 1.15  2004/01/17 18:01:24  mohor
68
// New version.
69
//
70
// Revision 1.14  2004/01/16 14:51:33  mohor
71
// cpu registers added.
72
//
73
// Revision 1.13  2004/01/15 12:09:43  mohor
74
// Working.
75
//
76
// Revision 1.12  2004/01/14 22:59:18  mohor
77
// Temp version.
78
//
79
// Revision 1.11  2004/01/14 12:29:40  mohor
80
// temp version. Resets will be changed in next version.
81
//
82
// Revision 1.10  2004/01/13 11:28:14  mohor
83
// tmp version.
84
//
85
// Revision 1.9  2004/01/10 07:50:24  mohor
86
// temp version.
87
//
88
// Revision 1.8  2004/01/09 12:48:44  mohor
89
// tmp version.
90
//
91
// Revision 1.7  2004/01/08 17:53:36  mohor
92
// tmp version.
93
//
94
// Revision 1.6  2004/01/07 11:58:56  mohor
95
// temp4 version.
96
//
97
// Revision 1.5  2004/01/06 17:15:19  mohor
98
// temp3 version.
99
//
100
// Revision 1.4  2004/01/05 12:16:00  mohor
101
// tmp2 version.
102
//
103
// Revision 1.3  2003/12/23 16:22:46  mohor
104
// Tmp version.
105
//
106
// Revision 1.2  2003/12/23 15:26:26  mohor
107
// Small fix.
108
//
109
// Revision 1.1  2003/12/23 15:09:04  mohor
110
// New directory structure. New version of the debug interface.
111
//
112
//
113
//
114
 
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
                rst_i,
137
 
138
                // WISHBONE common signals
139
                wb_clk_i,
140
 
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
input         tck_i;
149
input         tdi_i;
150
output        tdo_o;
151
 
152
// TAP states
153
input         shift_dr_i;
154
input         pause_dr_i;
155
input         update_dr_i;
156
 
157
input         wishbone_ce_i;
158
input         crc_match_i;
159
output        crc_en_o;
160
output        shift_crc_o;
161
input         rst_i;
162
// WISHBONE common signals
163
input         wb_clk_i;
164
 
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
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
wire          enable;
189
wire          cmd_cnt_en;
190
reg     [`DBG_WB_CMD_CNT_WIDTH -1:0] cmd_cnt;
191
wire          cmd_cnt_end;
192
reg           cmd_cnt_end_q;
193
reg           addr_len_cnt_en;
194
reg     [5:0] addr_len_cnt;
195
wire          addr_len_cnt_end;
196
reg           addr_len_cnt_end_q;
197
reg           crc_cnt_en;
198
reg     [`DBG_WB_CRC_CNT_WIDTH -1:0] crc_cnt;
199
wire          crc_cnt_end;
200
reg           crc_cnt_end_q;
201
reg           data_cnt_en;
202
reg    [`DBG_WB_DATA_CNT_WIDTH:0] data_cnt;
203
reg    [`DBG_WB_DATA_CNT_LIM_WIDTH:0] data_cnt_limit;
204
wire          data_cnt_end;
205
reg           data_cnt_end_q;
206
 
207
reg           crc_match_reg;
208
 
209
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
reg           start_rd_tck;
214
reg           rd_tck_started;
215
reg           start_rd_csff;
216
reg           start_wb_rd;
217
reg           start_wb_rd_q;
218
reg           start_wr_tck;
219
reg           start_wr_csff;
220
reg           start_wb_wr;
221
reg           start_wb_wr_q;
222
 
223
reg           status_cnt_en;
224
wire          status_cnt_end;
225
 
226
wire          byte, half, long;
227
reg           byte_q, half_q, long_q;
228
 
229
reg [`DBG_WB_STATUS_CNT_WIDTH -1:0] status_cnt;
230
 
231
reg [`DBG_WB_STATUS_LEN -1:0] status;
232
 
233
reg           wb_error, wb_error_csff, wb_error_tck;
234
reg           wb_overrun, wb_overrun_csff, wb_overrun_tck;
235
reg           underrun_tck;
236
 
237
reg           busy_wb;
238
reg           busy_tck;
239
reg           wb_end;
240
reg           wb_end_rst;
241
reg           wb_end_rst_csff;
242
reg           wb_end_csff;
243
reg           wb_end_tck, wb_end_tck_q;
244
reg           busy_csff;
245
reg           latch_data;
246
reg           update_dr_csff, update_dr_wb;
247
 
248
reg           set_addr, set_addr_csff, set_addr_wb, set_addr_wb_q;
249
wire   [31:0] input_data;
250
 
251
wire          len_eq_0;
252
wire          crc_cnt_31;
253
 
254
reg     [1:0] ptr;
255
reg     [2:0] fifo_cnt;
256
wire          fifo_full;
257
wire          fifo_empty;
258
reg     [7:0] mem [0:3];
259
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
 
273
 
274
assign enable = wishbone_ce_i & shift_dr_i;
275
assign crc_en_o = enable & crc_cnt_end & (~status_cnt_end);
276
assign shift_crc_o = enable & status_cnt_end;  // Signals dbg module to shift out the CRC
277
 
278
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
 
282
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
always @ (posedge tck_i or posedge rst_i)
292
begin
293
  if (rst_i)
294
    ptr <= #1 2'h0;
295
  else if (update_dr_i)
296
    ptr <= #1 2'h0;
297
  else if (curr_cmd_go && acc_type_read && crc_cnt_31) // first latch
298
    ptr <= #1 ptr + 1'b1;
299
  else if (curr_cmd_go && acc_type_read && byte && (!byte_q))
300
    ptr <= ptr + 1'd1;
301
end
302
 
303
 
304
// Shift register for shifting in and out the data
305
always @ (posedge tck_i or posedge rst_i)
306
begin
307
  if (rst_i)
308
    begin
309
      latch_data <= #1 1'b0;
310
      dr <= #1 {`DBG_WB_DR_LEN{1'b0}};
311
    end
312
  else if (curr_cmd_rd_comm && crc_cnt_31)  // Latching data (from iternal regs)
313
    begin
314
      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
      dr[31:0] <= #1 input_data[31:0];
319
      latch_data <= #1 1'b1;
320
    end
321
  else if (acc_type_read && curr_cmd_go && crc_cnt_end) // Latching data (from WB)
322
    begin
323
      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
    end
371
  else if (enable && (!addr_len_cnt_end))
372
    begin
373
      dr <= #1 {dr[`DBG_WB_DR_LEN -2:0], tdi_i};
374
    end
375
end
376
 
377
 
378
 
379
assign cmd_cnt_en = enable & (~cmd_cnt_end);
380
 
381
 
382
// Command counter
383
always @ (posedge tck_i or posedge rst_i)
384
begin
385
  if (rst_i)
386
    cmd_cnt <= #1 {`DBG_WB_CMD_CNT_WIDTH{1'b0}};
387
  else if (update_dr_i)
388
    cmd_cnt <= #1 {`DBG_WB_CMD_CNT_WIDTH{1'b0}};
389
  else if (cmd_cnt_en)
390
    cmd_cnt <= #1 cmd_cnt + 1'b1;
391
end
392
 
393
 
394
// Assigning current command
395
always @ (posedge tck_i or posedge rst_i)
396
begin
397
  if (rst_i)
398
    curr_cmd <= #1 {`DBG_WB_CMD_LEN{1'b0}};
399
  else if (update_dr_i)
400
    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
end
404
 
405
 
406
// Assigning current command
407
always @ (posedge tck_i or posedge rst_i)
408
begin
409
  if (rst_i)
410
    curr_cmd_go_q <= #1 1'b0;
411
  else
412
    curr_cmd_go_q <= #1 curr_cmd_go;
413
end
414
 
415
 
416
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
begin
418
  if (enable && (!addr_len_cnt_end))
419
    begin
420
      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
    end
427
  else
428
    addr_len_cnt_en = 1'b0;
429
end
430
 
431
 
432
// Address/length counter
433
always @ (posedge tck_i or posedge rst_i)
434
begin
435
  if (rst_i)
436
    addr_len_cnt <= #1 6'h0;
437
  else if (update_dr_i)
438
    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
    begin
448
      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
    end
455
  else
456
    data_cnt_en = 1'b0;
457
end
458
 
459
 
460
// Data counter
461
always @ (posedge tck_i or posedge rst_i)
462
begin
463
  if (rst_i)
464
    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
end
470
 
471
 
472
 
473
// Upper limit. Data counter counts until this value is reached.
474
always @ (posedge tck_i or posedge rst_i)
475
begin
476
  if (rst_i)
477
    data_cnt_limit <= #1 {`DBG_WB_DATA_CNT_LIM_WIDTH{1'b0}};
478
  else if (update_dr_i)
479
    data_cnt_limit <= #1 len + 1'b1;
480
end
481
 
482
 
483
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
 
500
 
501
// crc counter
502
always @ (posedge tck_i or posedge rst_i)
503
begin
504
  if (rst_i)
505
    crc_cnt <= #1 {`DBG_WB_CRC_CNT_WIDTH{1'b0}};
506
  else if(crc_cnt_en)
507
    crc_cnt <= #1 crc_cnt + 1'b1;
508
  else if (update_dr_i)
509
    crc_cnt <= #1 {`DBG_WB_CRC_CNT_WIDTH{1'b0}};
510
end
511
 
512
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
assign data_cnt_end     = (data_cnt    == {data_cnt_limit, 3'b000});
517
 
518
always @ (posedge tck_i or posedge rst_i)
519
begin
520
  if (rst_i)
521
    begin
522
      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
    end
527
  else
528
    begin
529
      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
    end
534
end
535
 
536
 
537
// Status counter is made of 4 serialy connected registers
538
always @ (posedge tck_i or posedge rst_i)
539
begin
540
  if (rst_i)
541
    status_cnt <= #1 {`DBG_WB_STATUS_CNT_WIDTH{1'b0}};
542
  else if (update_dr_i)
543
    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
end
547
 
548
 
549
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
begin
551
  if (enable && (!status_cnt_end))
552
    begin
553
      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
    end
564
  else
565
    status_cnt_en = 1'b0;
566
end
567
 
568
 
569
assign status_cnt_end = status_cnt == `DBG_WB_STATUS_LEN;
570
 
571
 
572
// Latching acc_type, address and length
573
always @ (posedge tck_i or posedge rst_i)
574
begin
575
  if (rst_i)
576
    begin
577
      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
    end
582
  else if(crc_cnt_end && (!crc_cnt_end_q) && crc_match_i && curr_cmd_wr_comm)
583
    begin
584
      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
    end
589
  else if(wb_end_tck)               // Writing back the address
590
    begin
591
      adr  <= #1 wb_adr_dsff;
592
    end
593
  else
594
    set_addr <= #1 1'b0;
595
end
596
 
597
 
598
always @ (posedge tck_i or posedge rst_i)
599
begin
600
  if (rst_i)
601
    crc_match_reg <= #1 1'b0;
602
  else if(crc_cnt_end & (~crc_cnt_end_q))
603
    crc_match_reg <= #1 crc_match_i;
604
end
605
 
606
 
607
// Length counter
608
always @ (posedge tck_i or posedge rst_i)
609
begin
610
  if (rst_i)
611
    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
  else if (start_rd_tck)
615
    begin
616
      case (acc_type)  // synthesis parallel_case
617
        `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
        default:      len_var <= #1 {1'bx, {`DBG_WB_LEN_LEN{1'bx}}};
633
      endcase
634
    end
635
end
636
 
637
 
638
assign len_eq_0 = len_var == 'h0;
639
 
640
 
641
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
 
645
 
646
always @ (posedge tck_i or posedge rst_i)
647
begin
648
  if (rst_i)
649
    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
end
661
 
662
 
663
// Start wishbone write cycle
664
always @ (posedge tck_i or posedge rst_i)
665
begin
666
  if (rst_i)
667
    begin
668
      start_wr_tck <= #1 1'b0;
669
      wb_dat_tmp <= #1 32'h0;
670
    end
671
  else if (curr_cmd_go && acc_type_write)
672
    begin
673
      case (acc_type)  // synthesis parallel_case full_case
674
        `DBG_WB_WRITE8  : begin
675
                        if (byte_q)
676
                          begin
677
                            start_wr_tck <= #1 1'b1;
678
                            wb_dat_tmp <= #1 {4{dr[7:0]}};
679
                          end
680
                        else
681
                          begin
682
                            start_wr_tck <= #1 1'b0;
683
                          end
684
                      end
685
        `DBG_WB_WRITE16 : begin
686
                        if (half_q)
687
                          begin
688
                            start_wr_tck <= #1 1'b1;
689
                            wb_dat_tmp <= #1 {2{dr[15:0]}};
690
                          end
691
                        else
692
                          begin
693
                            start_wr_tck <= #1 1'b0;
694
                          end
695
                      end
696
        `DBG_WB_WRITE32 : begin
697
                        if (long_q)
698
                          begin
699
                            start_wr_tck <= #1 1'b1;
700
                            wb_dat_tmp <= #1 dr[31:0];
701
                          end
702
                        else
703
                          begin
704
                            start_wr_tck <= #1 1'b0;
705
                          end
706
                      end
707
      endcase
708
    end
709
  else
710
    start_wr_tck <= #1 1'b0;
711
end
712
 
713
 
714
// 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
always @ (posedge wb_clk_i or posedge rst_i)
750
begin
751
  if (rst_i)
752
    begin
753
      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
    end
765
  else
766
    begin
767
      start_rd_csff   <= #1 start_rd_tck;
768
      start_wb_rd     <= #1 start_rd_csff;
769
      start_wb_rd_q   <= #1 start_wb_rd;
770
 
771
      start_wr_csff   <= #1 start_wr_tck;
772
      start_wb_wr     <= #1 start_wr_csff;
773
      start_wb_wr_q   <= #1 start_wb_wr;
774
 
775
      set_addr_csff   <= #1 set_addr;
776
      set_addr_wb     <= #1 set_addr_csff;
777
      set_addr_wb_q   <= #1 set_addr_wb;
778
    end
779
end
780
 
781
 
782
// wb_cyc_o
783
always @ (posedge wb_clk_i or posedge rst_i)
784
begin
785
  if (rst_i)
786
    wb_cyc_o <= #1 1'b0;
787
  else if ((start_wb_wr && (!start_wb_wr_q)) || (start_wb_rd && (!start_wb_rd_q)))
788
    wb_cyc_o <= #1 1'b1;
789
  else if (wb_ack_i || wb_err_i)
790
    wb_cyc_o <= #1 1'b0;
791
end
792
 
793
 
794
// wb_adr_o logic
795
always @ (posedge wb_clk_i or posedge rst_i)
796
begin
797
  if (rst_i)
798
    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
  else if (wb_ack_i)
802
    begin
803
      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
      else
808
        wb_adr_dsff <= #1 wb_adr_dsff + 3'd4;
809
    end
810
end
811
 
812
 
813
assign wb_adr_o = wb_adr_dsff;
814
 
815
 
816
//    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
// wb_sel_o logic
822
 
823
always @ (posedge wb_clk_i or posedge rst_i)
824
begin
825
  if (rst_i)
826
    wb_sel_dsff[3:0] <= #1 4'h0;
827
  else
828
    begin
829
      case ({wb_adr_dsff[1:0], acc_type_8bit, acc_type_16bit, acc_type_32bit}) // synthesis parallel_case
830
        {2'd0, 3'b100} : wb_sel_dsff[3:0] <= #1 4'h8;
831
        {2'd0, 3'b010} : wb_sel_dsff[3:0] <= #1 4'hC;
832
        {2'd0, 3'b001} : wb_sel_dsff[3:0] <= #1 4'hF;
833
        {2'd1, 3'b100} : wb_sel_dsff[3:0] <= #1 4'h4;
834
        {2'd2, 3'b100} : wb_sel_dsff[3:0] <= #1 4'h2;
835
        {2'd2, 3'b010} : wb_sel_dsff[3:0] <= #1 4'h3;
836
        {2'd3, 3'b100} : wb_sel_dsff[3:0] <= #1 4'h1;
837
        default:         wb_sel_dsff[3:0] <= #1 4'hx;
838
      endcase
839
    end
840
end
841
 
842
 
843
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
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
 
858
 
859
 
860
// Logic for detecting end of transaction
861
always @ (posedge wb_clk_i or posedge rst_i)
862
begin
863
  if (rst_i)
864
    wb_end <= #1 1'b0;
865
  else if (wb_ack_i || wb_err_i)
866
    wb_end <= #1 1'b1;
867
  else if (wb_end_rst)
868
    wb_end <= #1 1'b0;
869
end
870
 
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
 
888
 
889
always @ (posedge wb_clk_i or posedge rst_i)
890
begin
891
  if (rst_i)
892
    begin
893
      wb_end_rst_csff <= #1 1'b0;
894
      wb_end_rst      <= #1 1'b0;
895
    end
896
  else
897
    begin
898
      wb_end_rst_csff <= #1 wb_end_tck;
899
      wb_end_rst      <= #1 wb_end_rst_csff;
900
    end
901
end
902
 
903
 
904
always @ (posedge wb_clk_i or posedge rst_i)
905
begin
906
  if (rst_i)
907
    busy_wb <= #1 1'b0;
908
  else if (wb_end_rst)
909
    busy_wb <= #1 1'b0;
910
  else if (wb_cyc_o)
911
    busy_wb <= #1 1'b1;
912
end
913
 
914
 
915
always @ (posedge tck_i or posedge rst_i)
916
begin
917
  if (rst_i)
918
    begin
919
      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
    end
925
  else
926
    begin
927
      busy_csff       <= #1 busy_wb;
928
      busy_tck        <= #1 busy_csff;
929
 
930
      update_dr_csff  <= #1 update_dr_i;
931
      update_dr_wb    <= #1 update_dr_csff;
932
    end
933
end
934
 
935
 
936
// Detecting WB error
937
always @ (posedge wb_clk_i or posedge rst_i)
938
begin
939
  if (rst_i)
940
    wb_error <= #1 1'b0;
941
  else if(wb_err_i)
942
    wb_error <= #1 1'b1;
943
  else if(update_dr_wb) // error remains active until update_dr arrives
944
    wb_error <= #1 1'b0;
945
end
946
 
947
 
948
// Detecting overrun when write operation.
949
always @ (posedge wb_clk_i or posedge rst_i)
950
begin
951
  if (rst_i)
952
    wb_overrun <= #1 1'b0;
953
  else if(start_wb_wr && (!start_wb_wr_q) && wb_cyc_o)
954
    wb_overrun <= #1 1'b1;
955
  else if(update_dr_wb) // error remains active until update_dr arrives
956
    wb_overrun <= #1 1'b0;
957
end
958
 
959
 
960
// 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
  else if(latch_data && fifo_empty && (!data_cnt_end))
966
    underrun_tck <= #1 1'b1;
967
  else if(update_dr_i) // error remains active until update_dr arrives
968
    underrun_tck <= #1 1'b0;
969
end
970
 
971
 
972
always @ (posedge tck_i or posedge rst_i)
973
begin
974
  if (rst_i)
975
    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
  else
983
    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
end
991
 
992
 
993
 
994
always @ (posedge wb_clk_i or posedge rst_i)
995
begin
996
  if (rst_i)
997
    begin
998
      wishbone_ce_csff  <= #1 1'b0;
999
      mem_ptr_init      <= #1 1'b0;
1000
    end
1001
  else
1002
    begin
1003
      wishbone_ce_csff  <= #1  wishbone_ce_i;
1004
      mem_ptr_init      <= #1 ~wishbone_ce_csff;
1005
    end
1006
end
1007
 
1008
 
1009
// Logic for latching data that is read from wishbone
1010
always @ (posedge wb_clk_i or posedge rst_i)
1011
begin
1012
  if (rst_i)
1013
    mem_ptr_dsff <= #1 3'h0;
1014
  else if(mem_ptr_init)
1015
    mem_ptr_dsff <= #1 3'h0;
1016
  else if (wb_ack_i)
1017
    begin
1018
      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
    end
1023
end
1024
 
1025
 
1026
// Logic for latching data that is read from wishbone
1027
always @ (posedge wb_clk_i)
1028
begin
1029
  if (wb_ack_i)
1030
    begin
1031
      case (wb_sel_dsff)    // synthesis parallel_case
1032
        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
        4'b1100  :                                                      // half
1038
                    begin
1039
                      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
                    end
1042
        4'b0011  :                                                      // half
1043
                    begin
1044
                      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
                    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
                      mem[3] <= #1 wb_dat_i[07:00];
1053
                    end
1054
        default  :                                                      // long
1055
                    begin
1056
                      mem[0] <= #1 8'hxx;
1057
                      mem[1] <= #1 8'hxx;
1058
                      mem[2] <= #1 8'hxx;
1059
                      mem[3] <= #1 8'hxx;
1060
                    end
1061
      endcase
1062
    end
1063
end
1064
 
1065
 
1066
 
1067
assign input_data = {mem[0], mem[1], mem[2], mem[3]};
1068
 
1069
 
1070
// Fifo counter and empty/full detection
1071
always @ (posedge tck_i or posedge rst_i)
1072
begin
1073
  if (rst_i)
1074
    fifo_cnt <= #1 3'h0;
1075
  else if (update_dr_i)
1076
    fifo_cnt <= #1 3'h0;
1077
  else if (wb_end_tck && (!wb_end_tck_q) && (!latch_data) && (!fifo_full))  // incrementing
1078
    begin
1079
      case (acc_type)  // synthesis parallel_case
1080
        `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
        default:        fifo_cnt <= #1 3'bxxx;
1084
      endcase
1085
    end
1086
  else if (!(wb_end_tck && (!wb_end_tck_q)) && latch_data && (!fifo_empty))  // decrementing
1087
    begin
1088
      case (acc_type)  // synthesis parallel_case
1089
        `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
        default:        fifo_cnt <= #1 3'bxxx;
1093
      endcase
1094
    end
1095
end
1096
 
1097
 
1098
assign fifo_full  = fifo_cnt == 3'h4;
1099
assign fifo_empty = fifo_cnt == 3'h0;
1100
 
1101
 
1102
// TDO multiplexer
1103
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
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
 
1142
// 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
 
1173
 
1174
endmodule
1175
 

powered by: WebSVN 2.1.0

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