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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [dbg_if/] [dbg_wb.v] - Blame information for rev 363

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

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

powered by: WebSVN 2.1.0

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