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 99

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

powered by: WebSVN 2.1.0

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