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 92

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

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

powered by: WebSVN 2.1.0

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