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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [trunk/] [rtl/] [verilog/] [dbg_wb.v] - Blame information for rev 121

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

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

powered by: WebSVN 2.1.0

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