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

Subversion Repositories ethmac

[/] [ethmac/] [branches/] [unneback/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 302

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

Line No. Rev Author Line
1 38 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth_wishbone.v                                              ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6
////  http://www.opencores.org/projects/ethmac/                   ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Igor Mohor (igorM@opencores.org)                      ////
10
////                                                              ////
11 166 mohor
////  All additional information is available in the Readme.txt   ////
12 38 mohor
////  file.                                                       ////
13
////                                                              ////
14
//////////////////////////////////////////////////////////////////////
15
////                                                              ////
16 118 mohor
//// Copyright (C) 2001, 2002 Authors                             ////
17 38 mohor
////                                                              ////
18
//// This source file may be used and distributed without         ////
19
//// restriction provided that this copyright statement is not    ////
20
//// removed from the file and that any derivative work contains  ////
21
//// the original copyright notice and the associated disclaimer. ////
22
////                                                              ////
23
//// This source file is free software; you can redistribute it   ////
24
//// and/or modify it under the terms of the GNU Lesser General   ////
25
//// Public License as published by the Free Software Foundation; ////
26
//// either version 2.1 of the License, or (at your option) any   ////
27
//// later version.                                               ////
28
////                                                              ////
29
//// This source is distributed in the hope that it will be       ////
30
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
31
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
32
//// PURPOSE.  See the GNU Lesser General Public License for more ////
33
//// details.                                                     ////
34
////                                                              ////
35
//// You should have received a copy of the GNU Lesser General    ////
36
//// Public License along with this source; if not, download it   ////
37
//// from http://www.opencores.org/lgpl.shtml                     ////
38
////                                                              ////
39
//////////////////////////////////////////////////////////////////////
40
//
41
// CVS Revision History
42
//
43
// $Log: not supported by cvs2svn $
44 302 markom
// Revision 1.52  2003/01/30 14:51:31  mohor
45
// Reset has priority in some flipflops.
46
//
47 280 mohor
// Revision 1.51  2003/01/30 13:36:22  mohor
48
// A new bug (entered with previous update) fixed. When abort occured sometimes
49
// data transmission was blocked.
50
//
51 278 mohor
// Revision 1.50  2003/01/22 13:49:26  tadejm
52
// When control packets were received, they were ignored in some cases.
53
//
54 272 tadejm
// Revision 1.49  2003/01/21 12:09:40  mohor
55
// When receiving normal data frame and RxFlow control was switched on, RXB
56
// interrupt was not set.
57
//
58 270 mohor
// Revision 1.48  2003/01/20 12:05:26  mohor
59
// When in full duplex, transmit was sometimes blocked. Fixed.
60
//
61 269 mohor
// Revision 1.47  2002/11/22 13:26:21  mohor
62
// Registers RxStatusWrite_rck and RxStatusWriteLatched were not used
63
// anywhere. Removed.
64
//
65 264 mohor
// Revision 1.46  2002/11/22 01:57:06  mohor
66
// Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
67
// synchronized.
68
//
69 261 mohor
// Revision 1.45  2002/11/19 17:33:34  mohor
70
// AddressMiss status is connecting to the Rx BD. AddressMiss is identifying
71
// that a frame was received because of the promiscous mode.
72
//
73 250 mohor
// Revision 1.44  2002/11/13 22:21:40  tadejm
74
// RxError is not generated when small frame reception is enabled and small
75
// frames are received.
76
//
77 239 tadejm
// Revision 1.43  2002/10/18 20:53:34  mohor
78
// case changed to casex.
79
//
80 229 mohor
// Revision 1.42  2002/10/18 17:04:20  tadejm
81
// Changed BIST scan signals.
82
//
83 227 tadejm
// Revision 1.41  2002/10/18 15:42:09  tadejm
84
// Igor added WB burst support and repaired BUG when handling TX under-run and retry.
85
//
86 226 tadejm
// Revision 1.40  2002/10/14 16:07:02  mohor
87
// TxStatus is written after last access to the TX fifo is finished (in case of abort
88
// or retry). TxDone is fixed.
89
//
90 221 mohor
// Revision 1.39  2002/10/11 15:35:20  mohor
91
// txfifo_cnt and rxfifo_cnt counters width is defined in the eth_define.v file,
92
// TxDone and TxRetry are generated after the current WISHBONE access is
93
// finished.
94
//
95 219 mohor
// Revision 1.38  2002/10/10 16:29:30  mohor
96
// BIST added.
97
//
98 210 mohor
// Revision 1.37  2002/09/11 14:18:46  mohor
99
// Sometimes both RxB_IRQ and RxE_IRQ were activated. Bug fixed.
100
//
101 167 mohor
// Revision 1.36  2002/09/10 13:48:46  mohor
102
// Reception is possible after RxPointer is read and not after BD is read. For
103
// that reason RxBDReady is changed to RxReady.
104
// Busy_IRQ interrupt connected. When there is no RxBD ready and frame
105
// comes, interrupt is generated.
106
//
107 166 mohor
// Revision 1.35  2002/09/10 10:35:23  mohor
108
// Ethernet debug registers removed.
109
//
110 164 mohor
// Revision 1.34  2002/09/08 16:31:49  mohor
111
// Async reset for WB_ACK_O removed (when core was in reset, it was
112
// impossible to access BDs).
113
// RxPointers and TxPointers names changed to be more descriptive.
114
// TxUnderRun synchronized.
115
//
116 159 mohor
// Revision 1.33  2002/09/04 18:47:57  mohor
117
// Debug registers reg1, 2, 3, 4 connected. Synchronization of many signals
118
// changed (bugs fixed). Access to un-alligned buffers fixed. RxAbort signal
119
// was not used OK.
120
//
121 150 mohor
// Revision 1.32  2002/08/14 19:31:48  mohor
122
// Register TX_BD_NUM is changed so it contains value of the Tx buffer descriptors. No
123
// need to multiply or devide any more.
124
//
125 134 mohor
// Revision 1.31  2002/07/25 18:29:01  mohor
126
// WriteRxDataToMemory signal changed so end of frame (when last word is
127
// written to fifo) is changed.
128
//
129 127 mohor
// Revision 1.30  2002/07/23 15:28:31  mohor
130
// Ram , used for BDs changed from generic_spram to eth_spram_256x32.
131
//
132 119 mohor
// Revision 1.29  2002/07/20 00:41:32  mohor
133
// ShiftEnded synchronization changed.
134
//
135 118 mohor
// Revision 1.28  2002/07/18 16:11:46  mohor
136
// RxBDAddress takes `ETH_TX_BD_NUM_DEF value after reset.
137
//
138 115 mohor
// Revision 1.27  2002/07/11 02:53:20  mohor
139
// RxPointer bug fixed.
140
//
141 113 mohor
// Revision 1.26  2002/07/10 13:12:38  mohor
142
// Previous bug wasn't succesfully removed. Now fixed.
143
//
144 112 mohor
// Revision 1.25  2002/07/09 23:53:24  mohor
145
// Master state machine had a bug when switching from master write to
146
// master read.
147
//
148 111 mohor
// Revision 1.24  2002/07/09 20:44:41  mohor
149
// m_wb_cyc_o signal released after every single transfer.
150
//
151 110 mohor
// Revision 1.23  2002/05/03 10:15:50  mohor
152
// Outputs registered. Reset changed for eth_wishbone module.
153
//
154 106 mohor
// Revision 1.22  2002/04/24 08:52:19  mohor
155
// Compiler directives added. Tx and Rx fifo size incremented. A "late collision"
156
// bug fixed.
157
//
158 105 mohor
// Revision 1.21  2002/03/29 16:18:11  lampret
159
// Small typo fixed.
160
//
161 97 lampret
// Revision 1.20  2002/03/25 16:19:12  mohor
162
// Any address can be used for Tx and Rx BD pointers. Address does not need
163
// to be aligned.
164
//
165 96 mohor
// Revision 1.19  2002/03/19 12:51:50  mohor
166
// Comments in Slovene language removed.
167
//
168 91 mohor
// Revision 1.18  2002/03/19 12:46:52  mohor
169
// casex changed with case, fifo reset changed.
170
//
171 90 mohor
// Revision 1.17  2002/03/09 16:08:45  mohor
172
// rx_fifo was not always cleared ok. Fixed.
173
//
174 88 mohor
// Revision 1.16  2002/03/09 13:51:20  mohor
175
// Status was not latched correctly sometimes. Fixed.
176
//
177 87 mohor
// Revision 1.15  2002/03/08 06:56:46  mohor
178
// Big Endian problem when sending frames fixed.
179
//
180 86 mohor
// Revision 1.14  2002/03/02 19:12:40  mohor
181
// Byte ordering changed (Big Endian used). casex changed with case because
182
// Xilinx Foundation had problems. Tested in HW. It WORKS.
183
//
184 82 mohor
// Revision 1.13  2002/02/26 16:59:55  mohor
185
// Small fixes for external/internal DMA missmatches.
186
//
187 80 mohor
// Revision 1.12  2002/02/26 16:22:07  mohor
188
// Interrupts changed
189
//
190 77 mohor
// Revision 1.11  2002/02/15 17:07:39  mohor
191
// Status was not written correctly when frames were discarted because of
192
// address mismatch.
193
//
194 64 mohor
// Revision 1.10  2002/02/15 12:17:39  mohor
195
// RxStartFrm cleared when abort or retry comes.
196
//
197 61 mohor
// Revision 1.9  2002/02/15 11:59:10  mohor
198
// Changes that were lost when updating from 1.5 to 1.8 fixed.
199
//
200 60 mohor
// Revision 1.8  2002/02/14 20:54:33  billditt
201
// Addition  of new module eth_addrcheck.v
202
//
203
// Revision 1.7  2002/02/12 17:03:47  mohor
204
// RxOverRun added to statuses.
205
//
206
// Revision 1.6  2002/02/11 09:18:22  mohor
207
// Tx status is written back to the BD.
208
//
209 43 mohor
// Revision 1.5  2002/02/08 16:21:54  mohor
210
// Rx status is written back to the BD.
211
//
212 42 mohor
// Revision 1.4  2002/02/06 14:10:21  mohor
213
// non-DMA host interface added. Select the right configutation in eth_defines.
214
//
215 41 mohor
// Revision 1.3  2002/02/05 16:44:39  mohor
216
// Both rx and tx part are finished. Tested with wb_clk_i between 10 and 200
217
// MHz. Statuses, overrun, control frame transmission and reception still  need
218
// to be fixed.
219
//
220 40 mohor
// Revision 1.2  2002/02/01 12:46:51  mohor
221
// Tx part finished. TxStatus needs to be fixed. Pause request needs to be
222
// added.
223
//
224 39 mohor
// Revision 1.1  2002/01/23 10:47:59  mohor
225
// Initial version. Equals to eth_wishbonedma.v at this moment.
226 38 mohor
//
227
//
228
//
229
 
230
`include "eth_defines.v"
231
`include "timescale.v"
232
 
233
 
234
module eth_wishbone
235
   (
236
 
237
    // WISHBONE common
238 40 mohor
    WB_CLK_I, WB_DAT_I, WB_DAT_O,
239 38 mohor
 
240
    // WISHBONE slave
241 77 mohor
                WB_ADR_I, WB_WE_I, WB_ACK_O,
242 40 mohor
    BDCs,
243 38 mohor
 
244 40 mohor
    Reset,
245
 
246 39 mohor
    // WISHBONE master
247
    m_wb_adr_o, m_wb_sel_o, m_wb_we_o,
248
    m_wb_dat_o, m_wb_dat_i, m_wb_cyc_o,
249
    m_wb_stb_o, m_wb_ack_i, m_wb_err_i,
250
 
251 219 mohor
`ifdef ETH_WISHBONE_B3
252
    m_wb_cti_o, m_wb_bte_o,
253
`endif
254
 
255 38 mohor
    //TX
256 60 mohor
    MTxClk, TxStartFrm, TxEndFrm, TxUsedData, TxData,
257 150 mohor
    TxRetry, TxAbort, TxUnderRun, TxDone, PerPacketCrcEn,
258 38 mohor
    PerPacketPad,
259
 
260
    //RX
261 272 tadejm
    MRxClk, RxData, RxValid, RxStartFrm, RxEndFrm, RxAbort, RxStatusWriteLatched_sync2,
262 38 mohor
 
263
    // Register
264 270 mohor
    r_TxEn, r_RxEn, r_TxBDNum, TX_BD_NUM_Wr, r_RxFlow, r_PassAll,
265 38 mohor
 
266
    // Interrupts
267 150 mohor
    TxB_IRQ, TxE_IRQ, RxB_IRQ, RxE_IRQ, Busy_IRQ,
268 42 mohor
 
269 60 mohor
    // Rx Status
270 42 mohor
    InvalidSymbol, LatchedCrcError, RxLateCollision, ShortFrame, DribbleNibble,
271 250 mohor
    ReceivedPacketTooBig, RxLength, LoadRxStatus, ReceivedPacketGood, AddressMiss,
272 261 mohor
    ReceivedPauseFrm,
273 60 mohor
 
274
    // Tx Status
275 164 mohor
    RetryCntLatched, RetryLimit, LateCollLatched, DeferLatched, CarrierSenseLost
276
 
277 210 mohor
    // Bist
278
`ifdef ETH_BIST
279 227 tadejm
    ,
280
    // debug chain signals
281 302 markom
    mbist_si_i,       // bist scan serial in
282
    mbist_so_o,       // bist scan serial out
283
    mbist_ctrl_i        // bist chain shift control
284 210 mohor
`endif
285
 
286
 
287
 
288 38 mohor
                );
289
 
290
 
291
parameter Tp = 1;
292
 
293 150 mohor
 
294 38 mohor
// WISHBONE common
295
input           WB_CLK_I;       // WISHBONE clock
296
input  [31:0]   WB_DAT_I;       // WISHBONE data input
297
output [31:0]   WB_DAT_O;       // WISHBONE data output
298
 
299
// WISHBONE slave
300
input   [9:2]   WB_ADR_I;       // WISHBONE address input
301
input           WB_WE_I;        // WISHBONE write enable input
302
input           BDCs;           // Buffer descriptors are selected
303
output          WB_ACK_O;       // WISHBONE acknowledge output
304
 
305 39 mohor
// WISHBONE master
306
output  [31:0]  m_wb_adr_o;     // 
307
output   [3:0]  m_wb_sel_o;     // 
308
output          m_wb_we_o;      // 
309
output  [31:0]  m_wb_dat_o;     // 
310
output          m_wb_cyc_o;     // 
311
output          m_wb_stb_o;     // 
312
input   [31:0]  m_wb_dat_i;     // 
313
input           m_wb_ack_i;     // 
314
input           m_wb_err_i;     // 
315
 
316 219 mohor
`ifdef ETH_WISHBONE_B3
317
output   [2:0]  m_wb_cti_o;     // Cycle Type Identifier
318
output   [1:0]  m_wb_bte_o;     // Burst Type Extension
319
reg      [2:0]  m_wb_cti_o;     // Cycle Type Identifier
320
`endif
321
 
322 40 mohor
input           Reset;       // Reset signal
323 39 mohor
 
324 60 mohor
// Rx Status signals
325 42 mohor
input           InvalidSymbol;    // Invalid symbol was received during reception in 100 Mbps mode
326
input           LatchedCrcError;  // CRC error
327
input           RxLateCollision;  // Late collision occured while receiving frame
328
input           ShortFrame;       // Frame shorter then the minimum size (r_MinFL) was received while small packets are enabled (r_RecSmall)
329
input           DribbleNibble;    // Extra nibble received
330
input           ReceivedPacketTooBig;// Received packet is bigger than r_MaxFL
331
input    [15:0] RxLength;         // Length of the incoming frame
332
input           LoadRxStatus;     // Rx status was loaded
333 77 mohor
input           ReceivedPacketGood;// Received packet's length and CRC are good
334 250 mohor
input           AddressMiss;      // When a packet is received AddressMiss status is written to the Rx BD
335 261 mohor
input           r_RxFlow;
336 270 mohor
input           r_PassAll;
337 261 mohor
input           ReceivedPauseFrm;
338 39 mohor
 
339 60 mohor
// Tx Status signals
340
input     [3:0] RetryCntLatched;  // Latched Retry Counter
341
input           RetryLimit;       // Retry limit reached (Retry Max value + 1 attempts were made)
342
input           LateCollLatched;  // Late collision occured
343
input           DeferLatched;     // Defer indication (Frame was defered before sucessfully sent)
344
input           CarrierSenseLost; // Carrier Sense was lost during the frame transmission
345
 
346 38 mohor
// Tx
347
input           MTxClk;         // Transmit clock (from PHY)
348
input           TxUsedData;     // Transmit packet used data
349
input           TxRetry;        // Transmit packet retry
350
input           TxAbort;        // Transmit packet abort
351
input           TxDone;         // Transmission ended
352
output          TxStartFrm;     // Transmit packet start frame
353
output          TxEndFrm;       // Transmit packet end frame
354
output  [7:0]   TxData;         // Transmit packet data byte
355
output          TxUnderRun;     // Transmit packet under-run
356
output          PerPacketCrcEn; // Per packet crc enable
357
output          PerPacketPad;   // Per packet pading
358
 
359
// Rx
360
input           MRxClk;         // Receive clock (from PHY)
361
input   [7:0]   RxData;         // Received data byte (from PHY)
362
input           RxValid;        // 
363
input           RxStartFrm;     // 
364
input           RxEndFrm;       // 
365 40 mohor
input           RxAbort;        // This signal is set when address doesn't match.
366 272 tadejm
output          RxStatusWriteLatched_sync2;
367 38 mohor
 
368
//Register
369
input           r_TxEn;         // Transmit enable
370
input           r_RxEn;         // Receive enable
371
input   [7:0]   r_TxBDNum;      // Receive buffer descriptor number
372
input           TX_BD_NUM_Wr;   // RxBDNumber written
373
 
374
// Interrupts
375
output TxB_IRQ;
376
output TxE_IRQ;
377
output RxB_IRQ;
378 77 mohor
output RxE_IRQ;
379 38 mohor
output Busy_IRQ;
380
 
381 77 mohor
 
382 210 mohor
// Bist
383
`ifdef ETH_BIST
384 302 markom
input   mbist_si_i;       // bist scan serial in
385
output  mbist_so_o;       // bist scan serial out
386
input [`ETH_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;       // bist chain shift control
387 210 mohor
`endif
388
 
389 77 mohor
reg TxB_IRQ;
390
reg TxE_IRQ;
391
reg RxB_IRQ;
392
reg RxE_IRQ;
393
 
394 38 mohor
reg             TxStartFrm;
395
reg             TxEndFrm;
396
reg     [7:0]   TxData;
397
 
398
reg             TxUnderRun;
399 60 mohor
reg             TxUnderRun_wb;
400 38 mohor
 
401
reg             TxBDRead;
402 39 mohor
wire            TxStatusWrite;
403 38 mohor
 
404
reg     [1:0]   TxValidBytesLatched;
405
 
406
reg    [15:0]   TxLength;
407 60 mohor
reg    [15:0]   LatchedTxLength;
408
reg   [14:11]   TxStatus;
409 38 mohor
 
410 60 mohor
reg   [14:13]   RxStatus;
411 38 mohor
 
412
reg             TxStartFrm_wb;
413
reg             TxRetry_wb;
414 39 mohor
reg             TxAbort_wb;
415 38 mohor
reg             TxDone_wb;
416
 
417
reg             TxDone_wb_q;
418
reg             TxAbort_wb_q;
419 39 mohor
reg             TxRetry_wb_q;
420 219 mohor
reg             TxRetryPacket;
421 221 mohor
reg             TxRetryPacket_NotCleared;
422
reg             TxDonePacket;
423
reg             TxDonePacket_NotCleared;
424 219 mohor
reg             TxAbortPacket;
425 221 mohor
reg             TxAbortPacket_NotCleared;
426 38 mohor
reg             RxBDReady;
427 166 mohor
reg             RxReady;
428 38 mohor
reg             TxBDReady;
429
 
430
reg             RxBDRead;
431
 
432
reg    [31:0]   TxDataLatched;
433
reg     [1:0]   TxByteCnt;
434
reg             LastWord;
435 39 mohor
reg             ReadTxDataFromFifo_tck;
436 38 mohor
 
437
reg             BlockingTxStatusWrite;
438
reg             BlockingTxBDRead;
439
 
440 40 mohor
reg             Flop;
441 38 mohor
 
442
reg     [7:0]   TxBDAddress;
443
reg     [7:0]   RxBDAddress;
444
 
445
reg             TxRetrySync1;
446
reg             TxAbortSync1;
447 39 mohor
reg             TxDoneSync1;
448 38 mohor
 
449
reg             TxAbort_q;
450
reg             TxRetry_q;
451
reg             TxUsedData_q;
452
 
453
reg    [31:0]   RxDataLatched2;
454 82 mohor
 
455
reg    [31:8]   RxDataLatched1;     // Big Endian Byte Ordering
456
 
457 38 mohor
reg     [1:0]   RxValidBytes;
458
reg     [1:0]   RxByteCnt;
459
reg             LastByteIn;
460
reg             ShiftWillEnd;
461
 
462 40 mohor
reg             WriteRxDataToFifo;
463 42 mohor
reg    [15:0]   LatchedRxLength;
464 64 mohor
reg             RxAbortLatched;
465 38 mohor
 
466 40 mohor
reg             ShiftEnded;
467 60 mohor
reg             RxOverrun;
468 38 mohor
 
469 40 mohor
reg             BDWrite;                    // BD Write Enable for access from WISHBONE side
470
reg             BDRead;                     // BD Read access from WISHBONE side
471 39 mohor
wire   [31:0]   RxBDDataIn;                 // Rx BD data in
472
wire   [31:0]   TxBDDataIn;                 // Tx BD data in
473 38 mohor
 
474 39 mohor
reg             TxEndFrm_wb;
475 38 mohor
 
476 39 mohor
wire            TxRetryPulse;
477 38 mohor
wire            TxDonePulse;
478
wire            TxAbortPulse;
479
 
480
wire            StartRxBDRead;
481
 
482
wire            StartTxBDRead;
483
 
484
wire            TxIRQEn;
485
wire            WrapTxStatusBit;
486
 
487 77 mohor
wire            RxIRQEn;
488 38 mohor
wire            WrapRxStatusBit;
489
 
490
wire    [1:0]   TxValidBytes;
491
 
492
wire    [7:0]   TempTxBDAddress;
493
wire    [7:0]   TempRxBDAddress;
494
 
495 272 tadejm
wire            RxStatusWrite;
496
 
497 106 mohor
reg             WB_ACK_O;
498 38 mohor
 
499 261 mohor
wire    [8:0]   RxStatusIn;
500
reg     [8:0]   RxStatusInLatched;
501 42 mohor
 
502 39 mohor
reg WbEn, WbEn_q;
503
reg RxEn, RxEn_q;
504
reg TxEn, TxEn_q;
505 38 mohor
 
506 39 mohor
wire ram_ce;
507
wire ram_we;
508
wire ram_oe;
509
reg [7:0]   ram_addr;
510
reg [31:0]  ram_di;
511
wire [31:0] ram_do;
512 38 mohor
 
513 39 mohor
wire StartTxPointerRead;
514
reg  TxPointerRead;
515
reg TxEn_needed;
516 40 mohor
reg RxEn_needed;
517 38 mohor
 
518 40 mohor
wire StartRxPointerRead;
519
reg RxPointerRead;
520 38 mohor
 
521 219 mohor
`ifdef ETH_WISHBONE_B3
522
assign m_wb_bte_o = 2'b00;    // Linear burst
523
`endif
524 39 mohor
 
525 219 mohor
 
526 159 mohor
always @ (posedge WB_CLK_I)
527 40 mohor
begin
528 159 mohor
  WB_ACK_O <=#Tp BDWrite & WbEn & WbEn_q | BDRead & WbEn & ~WbEn_q;
529 40 mohor
end
530 39 mohor
 
531 106 mohor
assign WB_DAT_O = ram_do;
532 39 mohor
 
533 41 mohor
// Generic synchronous single-port RAM interface
534 119 mohor
eth_spram_256x32 bd_ram (
535 226 tadejm
        .clk(WB_CLK_I), .rst(Reset), .ce(ram_ce), .we(ram_we), .oe(ram_oe), .addr(ram_addr), .di(ram_di), .do(ram_do)
536 210 mohor
`ifdef ETH_BIST
537 227 tadejm
  ,
538 302 markom
  .mbist_si_i       (mbist_si_i),
539
  .mbist_so_o       (mbist_so_o),
540
  .mbist_ctrl_i       (mbist_ctrl_i)
541 210 mohor
`endif
542 39 mohor
);
543 41 mohor
 
544 39 mohor
assign ram_ce = 1'b1;
545 40 mohor
assign ram_we = BDWrite & WbEn & WbEn_q | TxStatusWrite | RxStatusWrite;
546 61 mohor
assign ram_oe = BDRead & WbEn & WbEn_q | TxEn & TxEn_q & (TxBDRead | TxPointerRead) | RxEn & RxEn_q & (RxBDRead | RxPointerRead);
547 39 mohor
 
548
 
549 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
550 38 mohor
begin
551 40 mohor
  if(Reset)
552 39 mohor
    TxEn_needed <=#Tp 1'b0;
553 38 mohor
  else
554 40 mohor
  if(~TxBDReady & r_TxEn & WbEn & ~WbEn_q)
555 39 mohor
    TxEn_needed <=#Tp 1'b1;
556
  else
557
  if(TxPointerRead & TxEn & TxEn_q)
558
    TxEn_needed <=#Tp 1'b0;
559 38 mohor
end
560
 
561 39 mohor
// Enabling access to the RAM for three devices.
562 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
563 39 mohor
begin
564 40 mohor
  if(Reset)
565 39 mohor
    begin
566
      WbEn <=#Tp 1'b1;
567
      RxEn <=#Tp 1'b0;
568
      TxEn <=#Tp 1'b0;
569
      ram_addr <=#Tp 8'h0;
570
      ram_di <=#Tp 32'h0;
571 77 mohor
      BDRead <=#Tp 1'b0;
572
      BDWrite <=#Tp 1'b0;
573 39 mohor
    end
574
  else
575
    begin
576
      // Switching between three stages depends on enable signals
577 90 mohor
      case ({WbEn_q, RxEn_q, TxEn_q, RxEn_needed, TxEn_needed})  // synopsys parallel_case
578
        5'b100_10, 5'b100_11 :
579 39 mohor
          begin
580
            WbEn <=#Tp 1'b0;
581
            RxEn <=#Tp 1'b1;  // wb access stage and r_RxEn is enabled
582
            TxEn <=#Tp 1'b0;
583 40 mohor
            ram_addr <=#Tp RxBDAddress + RxPointerRead;
584 39 mohor
            ram_di <=#Tp RxBDDataIn;
585
          end
586
        5'b100_01 :
587
          begin
588
            WbEn <=#Tp 1'b0;
589
            RxEn <=#Tp 1'b0;
590
            TxEn <=#Tp 1'b1;  // wb access stage, r_RxEn is disabled but r_TxEn is enabled
591
            ram_addr <=#Tp TxBDAddress + TxPointerRead;
592
            ram_di <=#Tp TxBDDataIn;
593
          end
594 90 mohor
        5'b010_00, 5'b010_10 :
595 39 mohor
          begin
596
            WbEn <=#Tp 1'b1;  // RxEn access stage and r_TxEn is disabled
597
            RxEn <=#Tp 1'b0;
598
            TxEn <=#Tp 1'b0;
599
            ram_addr <=#Tp WB_ADR_I[9:2];
600
            ram_di <=#Tp WB_DAT_I;
601 40 mohor
            BDWrite <=#Tp BDCs & WB_WE_I;
602
            BDRead <=#Tp BDCs & ~WB_WE_I;
603 39 mohor
          end
604 90 mohor
        5'b010_01, 5'b010_11 :
605 39 mohor
          begin
606
            WbEn <=#Tp 1'b0;
607
            RxEn <=#Tp 1'b0;
608
            TxEn <=#Tp 1'b1;  // RxEn access stage and r_TxEn is enabled
609
            ram_addr <=#Tp TxBDAddress + TxPointerRead;
610
            ram_di <=#Tp TxBDDataIn;
611
          end
612 90 mohor
        5'b001_00, 5'b001_01, 5'b001_10, 5'b001_11 :
613 39 mohor
          begin
614
            WbEn <=#Tp 1'b1;  // TxEn access stage (we always go to wb access stage)
615
            RxEn <=#Tp 1'b0;
616
            TxEn <=#Tp 1'b0;
617
            ram_addr <=#Tp WB_ADR_I[9:2];
618
            ram_di <=#Tp WB_DAT_I;
619 40 mohor
            BDWrite <=#Tp BDCs & WB_WE_I;
620
            BDRead <=#Tp BDCs & ~WB_WE_I;
621 39 mohor
          end
622
        5'b100_00 :
623
          begin
624
            WbEn <=#Tp 1'b0;  // WbEn access stage and there is no need for other stages. WbEn needs to be switched off for a bit
625
          end
626
        5'b000_00 :
627
          begin
628
            WbEn <=#Tp 1'b1;  // Idle state. We go to WbEn access stage.
629
            RxEn <=#Tp 1'b0;
630
            TxEn <=#Tp 1'b0;
631
            ram_addr <=#Tp WB_ADR_I[9:2];
632
            ram_di <=#Tp WB_DAT_I;
633 40 mohor
            BDWrite <=#Tp BDCs & WB_WE_I;
634
            BDRead <=#Tp BDCs & ~WB_WE_I;
635 39 mohor
          end
636
      endcase
637
    end
638
end
639
 
640
 
641
// Delayed stage signals
642 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
643 39 mohor
begin
644 40 mohor
  if(Reset)
645 39 mohor
    begin
646
      WbEn_q <=#Tp 1'b0;
647
      RxEn_q <=#Tp 1'b0;
648
      TxEn_q <=#Tp 1'b0;
649
    end
650
  else
651
    begin
652
      WbEn_q <=#Tp WbEn;
653
      RxEn_q <=#Tp RxEn;
654
      TxEn_q <=#Tp TxEn;
655
    end
656
end
657
 
658 38 mohor
// Changes for tx occur every second clock. Flop is used for this manner.
659 40 mohor
always @ (posedge MTxClk or posedge Reset)
660 38 mohor
begin
661 40 mohor
  if(Reset)
662 38 mohor
    Flop <=#Tp 1'b0;
663
  else
664
  if(TxDone | TxAbort | TxRetry_q)
665
    Flop <=#Tp 1'b0;
666
  else
667
  if(TxUsedData)
668
    Flop <=#Tp ~Flop;
669
end
670
 
671 39 mohor
wire ResetTxBDReady;
672
assign ResetTxBDReady = TxDonePulse | TxAbortPulse | TxRetryPulse;
673 38 mohor
 
674
// Latching READY status of the Tx buffer descriptor
675 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
676 38 mohor
begin
677 40 mohor
  if(Reset)
678 38 mohor
    TxBDReady <=#Tp 1'b0;
679
  else
680 40 mohor
  if(TxEn & TxEn_q & TxBDRead)
681
    TxBDReady <=#Tp ram_do[15] & (ram_do[31:16] > 4); // TxBDReady is sampled only once at the beginning.
682
  else                                                // Only packets larger then 4 bytes are transmitted.
683 39 mohor
  if(ResetTxBDReady)
684 38 mohor
    TxBDReady <=#Tp 1'b0;
685
end
686
 
687
 
688 39 mohor
// Reading the Tx buffer descriptor
689 221 mohor
assign StartTxBDRead = (TxRetryPacket_NotCleared | TxStatusWrite) & ~BlockingTxBDRead & ~TxBDReady;
690 39 mohor
 
691 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
692 38 mohor
begin
693 40 mohor
  if(Reset)
694 39 mohor
    TxBDRead <=#Tp 1'b1;
695 38 mohor
  else
696 110 mohor
  if(StartTxBDRead)
697 39 mohor
    TxBDRead <=#Tp 1'b1;
698 38 mohor
  else
699 39 mohor
  if(TxBDReady)
700
    TxBDRead <=#Tp 1'b0;
701 38 mohor
end
702
 
703
 
704 39 mohor
// Reading Tx BD pointer
705
assign StartTxPointerRead = TxBDRead & TxBDReady;
706 38 mohor
 
707 39 mohor
// Reading Tx BD Pointer
708 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
709 38 mohor
begin
710 40 mohor
  if(Reset)
711 39 mohor
    TxPointerRead <=#Tp 1'b0;
712 38 mohor
  else
713 39 mohor
  if(StartTxPointerRead)
714
    TxPointerRead <=#Tp 1'b1;
715 38 mohor
  else
716 39 mohor
  if(TxEn_q)
717
    TxPointerRead <=#Tp 1'b0;
718 38 mohor
end
719
 
720
 
721 39 mohor
// Writing status back to the Tx buffer descriptor
722 221 mohor
assign TxStatusWrite = (TxDonePacket_NotCleared | TxAbortPacket_NotCleared) & TxEn & TxEn_q & ~BlockingTxStatusWrite;
723 38 mohor
 
724
 
725
 
726 39 mohor
// Status writing must occur only once. Meanwhile it is blocked.
727 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
728 38 mohor
begin
729 40 mohor
  if(Reset)
730 39 mohor
    BlockingTxStatusWrite <=#Tp 1'b0;
731 38 mohor
  else
732 272 tadejm
  if(~TxDone_wb & ~TxAbort_wb)
733
    BlockingTxStatusWrite <=#Tp 1'b0;
734
  else
735 39 mohor
  if(TxStatusWrite)
736
    BlockingTxStatusWrite <=#Tp 1'b1;
737 38 mohor
end
738
 
739
 
740 159 mohor
reg BlockingTxStatusWrite_sync1;
741
reg BlockingTxStatusWrite_sync2;
742
 
743
// Synchronizing BlockingTxStatusWrite to MTxClk
744
always @ (posedge MTxClk or posedge Reset)
745
begin
746
  if(Reset)
747
    BlockingTxStatusWrite_sync1 <=#Tp 1'b0;
748
  else
749
    BlockingTxStatusWrite_sync1 <=#Tp BlockingTxStatusWrite;
750
end
751
 
752
// Synchronizing BlockingTxStatusWrite to MTxClk
753
always @ (posedge MTxClk or posedge Reset)
754
begin
755
  if(Reset)
756
    BlockingTxStatusWrite_sync2 <=#Tp 1'b0;
757
  else
758
    BlockingTxStatusWrite_sync2 <=#Tp BlockingTxStatusWrite_sync1;
759
end
760
 
761
 
762 39 mohor
// TxBDRead state is activated only once. 
763 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
764 39 mohor
begin
765 40 mohor
  if(Reset)
766 39 mohor
    BlockingTxBDRead <=#Tp 1'b0;
767
  else
768 110 mohor
  if(StartTxBDRead)
769 39 mohor
    BlockingTxBDRead <=#Tp 1'b1;
770
  else
771 110 mohor
  if(~StartTxBDRead & ~TxBDReady)
772 39 mohor
    BlockingTxBDRead <=#Tp 1'b0;
773
end
774 38 mohor
 
775
 
776 39 mohor
// Latching status from the tx buffer descriptor
777
// Data is avaliable one cycle after the access is started (at that time signal TxEn is not active)
778 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
779 38 mohor
begin
780 40 mohor
  if(Reset)
781 60 mohor
    TxStatus <=#Tp 4'h0;
782 38 mohor
  else
783 40 mohor
  if(TxEn & TxEn_q & TxBDRead)
784 60 mohor
    TxStatus <=#Tp ram_do[14:11];
785 38 mohor
end
786
 
787 40 mohor
reg ReadTxDataFromMemory;
788
wire WriteRxDataToMemory;
789 38 mohor
 
790 39 mohor
reg MasterWbTX;
791
reg MasterWbRX;
792
 
793
reg [31:0] m_wb_adr_o;
794
reg        m_wb_cyc_o;
795
reg        m_wb_stb_o;
796 96 mohor
reg  [3:0] m_wb_sel_o;
797 39 mohor
reg        m_wb_we_o;
798 40 mohor
 
799 39 mohor
wire TxLengthEq0;
800
wire TxLengthLt4;
801
 
802 150 mohor
reg BlockingIncrementTxPointer;
803 159 mohor
reg [31:2] TxPointerMSB;
804
reg [1:0]  TxPointerLSB;
805
reg [1:0]  TxPointerLSB_rst;
806
reg [31:2] RxPointerMSB;
807
reg [1:0]  RxPointerLSB_rst;
808 39 mohor
 
809 150 mohor
wire RxBurstAcc;
810
wire RxWordAcc;
811
wire RxHalfAcc;
812
wire RxByteAcc;
813
 
814 39 mohor
//Latching length from the buffer descriptor;
815 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
816 38 mohor
begin
817 40 mohor
  if(Reset)
818 39 mohor
    TxLength <=#Tp 16'h0;
819 38 mohor
  else
820 39 mohor
  if(TxEn & TxEn_q & TxBDRead)
821
    TxLength <=#Tp ram_do[31:16];
822 38 mohor
  else
823 39 mohor
  if(MasterWbTX & m_wb_ack_i)
824
    begin
825
      if(TxLengthLt4)
826
        TxLength <=#Tp 16'h0;
827 150 mohor
      else
828 159 mohor
      if(TxPointerLSB_rst==2'h0)
829 96 mohor
        TxLength <=#Tp TxLength - 3'h4;    // Length is subtracted at the data request
830 39 mohor
      else
831 159 mohor
      if(TxPointerLSB_rst==2'h1)
832 150 mohor
        TxLength <=#Tp TxLength - 3'h3;    // Length is subtracted at the data request
833
      else
834 159 mohor
      if(TxPointerLSB_rst==2'h2)
835 150 mohor
        TxLength <=#Tp TxLength - 3'h2;    // Length is subtracted at the data request
836
      else
837 159 mohor
      if(TxPointerLSB_rst==2'h3)
838 150 mohor
        TxLength <=#Tp TxLength - 3'h1;    // Length is subtracted at the data request
839 39 mohor
    end
840 38 mohor
end
841
 
842 96 mohor
 
843
 
844 60 mohor
//Latching length from the buffer descriptor;
845
always @ (posedge WB_CLK_I or posedge Reset)
846
begin
847
  if(Reset)
848
    LatchedTxLength <=#Tp 16'h0;
849
  else
850
  if(TxEn & TxEn_q & TxBDRead)
851
    LatchedTxLength <=#Tp ram_do[31:16];
852
end
853
 
854 39 mohor
assign TxLengthEq0 = TxLength == 0;
855
assign TxLengthLt4 = TxLength < 4;
856 38 mohor
 
857 150 mohor
reg cyc_cleared;
858
reg IncrTxPointer;
859 39 mohor
 
860
 
861 159 mohor
// Latching Tx buffer pointer from buffer descriptor. Only 30 MSB bits are latched
862
// because TxPointerMSB is only used for word-aligned accesses.
863 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
864 38 mohor
begin
865 40 mohor
  if(Reset)
866 159 mohor
    TxPointerMSB <=#Tp 30'h0;
867 38 mohor
  else
868 39 mohor
  if(TxEn & TxEn_q & TxPointerRead)
869 159 mohor
    TxPointerMSB <=#Tp ram_do[31:2];
870 38 mohor
  else
871 150 mohor
  if(IncrTxPointer & ~BlockingIncrementTxPointer)
872 159 mohor
    TxPointerMSB <=#Tp TxPointerMSB + 1'b1;     // TxPointer is word-aligned
873 38 mohor
end
874
 
875 96 mohor
 
876 159 mohor
// Latching 2 MSB bits of the buffer descriptor. Since word accesses are performed,
877
// valid data does not necesserly start at byte 0 (could be byte 0, 1, 2 or 3). This
878
// signals are used for proper selection of the start byte (TxData and TxByteCnt) are
879
// set by this two bits.
880 96 mohor
always @ (posedge WB_CLK_I or posedge Reset)
881
begin
882
  if(Reset)
883 159 mohor
    TxPointerLSB[1:0] <=#Tp 0;
884 96 mohor
  else
885
  if(TxEn & TxEn_q & TxPointerRead)
886 159 mohor
    TxPointerLSB[1:0] <=#Tp ram_do[1:0];
887 96 mohor
end
888
 
889
 
890 159 mohor
// Latching 2 MSB bits of the buffer descriptor. 
891
// After the read access, TxLength needs to be decremented for the number of the valid
892
// bytes (1 to 4 bytes are valid in the first word). After the first read all bytes are 
893
// valid so this two bits are reset to zero. 
894 150 mohor
always @ (posedge WB_CLK_I or posedge Reset)
895
begin
896
  if(Reset)
897 159 mohor
    TxPointerLSB_rst[1:0] <=#Tp 0;
898 150 mohor
  else
899
  if(TxEn & TxEn_q & TxPointerRead)
900 159 mohor
    TxPointerLSB_rst[1:0] <=#Tp ram_do[1:0];
901 150 mohor
  else
902
  if(MasterWbTX & m_wb_ack_i)                 // After first access pointer is word alligned
903 159 mohor
    TxPointerLSB_rst[1:0] <=#Tp 0;
904 150 mohor
end
905 96 mohor
 
906 150 mohor
 
907 159 mohor
reg  [3:0] RxByteSel;
908 39 mohor
wire MasterAccessFinished;
909 38 mohor
 
910 39 mohor
 
911 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
912 38 mohor
begin
913 40 mohor
  if(Reset)
914 39 mohor
    BlockingIncrementTxPointer <=#Tp 0;
915 38 mohor
  else
916 39 mohor
  if(MasterAccessFinished)
917
    BlockingIncrementTxPointer <=#Tp 0;
918 38 mohor
  else
919 150 mohor
  if(IncrTxPointer)
920 39 mohor
    BlockingIncrementTxPointer <=#Tp 1'b1;
921 38 mohor
end
922
 
923
 
924 39 mohor
wire TxBufferAlmostFull;
925
wire TxBufferFull;
926
wire TxBufferEmpty;
927
wire TxBufferAlmostEmpty;
928 40 mohor
wire SetReadTxDataFromMemory;
929 39 mohor
 
930 40 mohor
reg BlockReadTxDataFromMemory;
931 39 mohor
 
932 40 mohor
assign SetReadTxDataFromMemory = TxEn & TxEn_q & TxPointerRead;
933 39 mohor
 
934 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
935 38 mohor
begin
936 40 mohor
  if(Reset)
937
    ReadTxDataFromMemory <=#Tp 1'b0;
938 38 mohor
  else
939 278 mohor
  if(TxLengthEq0 | TxAbortPulse | TxRetryPulse)
940 40 mohor
    ReadTxDataFromMemory <=#Tp 1'b0;
941 39 mohor
  else
942 40 mohor
  if(SetReadTxDataFromMemory)
943
    ReadTxDataFromMemory <=#Tp 1'b1;
944 38 mohor
end
945
 
946 226 tadejm
reg tx_burst_en;
947
reg rx_burst_en;
948 221 mohor
 
949 278 mohor
wire ReadTxDataFromMemory_2 = ReadTxDataFromMemory & ~BlockReadTxDataFromMemory;
950 226 tadejm
wire tx_burst = ReadTxDataFromMemory_2 & tx_burst_en;
951 221 mohor
 
952 39 mohor
wire [31:0] TxData_wb;
953
wire ReadTxDataFromFifo_wb;
954 38 mohor
 
955 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
956 38 mohor
begin
957 40 mohor
  if(Reset)
958
    BlockReadTxDataFromMemory <=#Tp 1'b0;
959 38 mohor
  else
960 278 mohor
  if((TxBufferAlmostFull | TxLength <= 4)& MasterWbTX & (~cyc_cleared) & (!(TxAbortPacket_NotCleared | TxRetryPacket_NotCleared)))
961 40 mohor
    BlockReadTxDataFromMemory <=#Tp 1'b1;
962 219 mohor
  else
963 221 mohor
  if(ReadTxDataFromFifo_wb | TxDonePacket | TxAbortPacket | TxRetryPacket)
964 219 mohor
    BlockReadTxDataFromMemory <=#Tp 1'b0;
965 39 mohor
end
966
 
967
 
968
assign MasterAccessFinished = m_wb_ack_i | m_wb_err_i;
969 219 mohor
wire [`ETH_TX_FIFO_CNT_WIDTH-1:0] txfifo_cnt;
970
wire [`ETH_RX_FIFO_CNT_WIDTH-1:0] rxfifo_cnt;
971 226 tadejm
reg  [`ETH_BURST_CNT_WIDTH-1:0] tx_burst_cnt;
972
reg  [`ETH_BURST_CNT_WIDTH-1:0] rx_burst_cnt;
973 159 mohor
 
974 226 tadejm
wire rx_burst;
975
wire enough_data_in_rxfifo_for_burst;
976
wire enough_data_in_rxfifo_for_burst_plus1;
977 229 mohor
 
978 39 mohor
// Enabling master wishbone access to the memory for two devices TX and RX.
979 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
980 39 mohor
begin
981 40 mohor
  if(Reset)
982 38 mohor
    begin
983 39 mohor
      MasterWbTX <=#Tp 1'b0;
984
      MasterWbRX <=#Tp 1'b0;
985
      m_wb_adr_o <=#Tp 32'h0;
986
      m_wb_cyc_o <=#Tp 1'b0;
987
      m_wb_stb_o <=#Tp 1'b0;
988
      m_wb_we_o  <=#Tp 1'b0;
989 96 mohor
      m_wb_sel_o <=#Tp 4'h0;
990 110 mohor
      cyc_cleared<=#Tp 1'b0;
991 226 tadejm
      tx_burst_cnt<=#Tp 0;
992
      rx_burst_cnt<=#Tp 0;
993 150 mohor
      IncrTxPointer<=#Tp 1'b0;
994 226 tadejm
      tx_burst_en<=#Tp 1'b1;
995
      rx_burst_en<=#Tp 1'b0;
996
      `ifdef ETH_WISHBONE_B3
997
        m_wb_cti_o <=#Tp 3'b0;
998
      `endif
999 38 mohor
    end
1000 39 mohor
  else
1001
    begin
1002
      // Switching between two stages depends on enable signals
1003 229 mohor
      casex ({MasterWbTX, MasterWbRX, ReadTxDataFromMemory_2, WriteRxDataToMemory, MasterAccessFinished, cyc_cleared, tx_burst, rx_burst})  // synopsys parallel_case
1004 226 tadejm
        8'b00_10_00_10,             // Idle and MRB needed
1005 229 mohor
        8'b10_1x_10_1x,             // MRB continues
1006 226 tadejm
        8'b10_10_01_10,             // Clear (previously MR) and MRB needed
1007 229 mohor
        8'b01_1x_01_1x :            // Clear (previously MW) and MRB needed
1008 39 mohor
          begin
1009 226 tadejm
            MasterWbTX <=#Tp 1'b1;  // tx burst
1010
            MasterWbRX <=#Tp 1'b0;
1011
            m_wb_cyc_o <=#Tp 1'b1;
1012
            m_wb_stb_o <=#Tp 1'b1;
1013
            m_wb_we_o  <=#Tp 1'b0;
1014
            m_wb_sel_o <=#Tp 4'hf;
1015
            cyc_cleared<=#Tp 1'b0;
1016
            IncrTxPointer<=#Tp 1'b1;
1017
            tx_burst_cnt <=#Tp tx_burst_cnt+1;
1018
            if(tx_burst_cnt==0)
1019
              m_wb_adr_o <=#Tp {TxPointerMSB, 2'h0};
1020
            else
1021
              m_wb_adr_o <=#Tp m_wb_adr_o+3'h4;
1022
 
1023
            if(tx_burst_cnt==(`ETH_BURST_LENGTH-1))
1024
              begin
1025
                tx_burst_en<=#Tp 1'b0;
1026
              `ifdef ETH_WISHBONE_B3
1027
                m_wb_cti_o <=#Tp 3'b111;
1028
              `endif
1029
              end
1030
            else
1031
              begin
1032
              `ifdef ETH_WISHBONE_B3
1033
                m_wb_cti_o <=#Tp 3'b010;
1034
              `endif
1035
              end
1036
          end
1037 229 mohor
        8'b00_x1_00_x1,             // Idle and MWB needed
1038
        8'b01_x1_10_x1,             // MWB continues
1039 226 tadejm
        8'b01_01_01_01,             // Clear (previously MW) and MWB needed
1040 229 mohor
        8'b10_x1_01_x1 :            // Clear (previously MR) and MWB needed
1041 226 tadejm
          begin
1042
            MasterWbTX <=#Tp 1'b0;  // rx burst
1043 39 mohor
            MasterWbRX <=#Tp 1'b1;
1044 226 tadejm
            m_wb_cyc_o <=#Tp 1'b1;
1045
            m_wb_stb_o <=#Tp 1'b1;
1046
            m_wb_we_o  <=#Tp 1'b1;
1047
            m_wb_sel_o <=#Tp RxByteSel;
1048
            IncrTxPointer<=#Tp 1'b0;
1049
            cyc_cleared<=#Tp 1'b0;
1050
            rx_burst_cnt <=#Tp rx_burst_cnt+1;
1051
 
1052
            if(rx_burst_cnt==0)
1053
              m_wb_adr_o <=#Tp {RxPointerMSB, 2'h0};
1054
            else
1055
              m_wb_adr_o <=#Tp m_wb_adr_o+3'h4;
1056
 
1057
            if(rx_burst_cnt==(`ETH_BURST_LENGTH-1))
1058
              begin
1059
                rx_burst_en<=#Tp 1'b0;
1060
              `ifdef ETH_WISHBONE_B3
1061
                m_wb_cti_o <=#Tp 3'b111;
1062
              `endif
1063
              end
1064
            else
1065
              begin
1066
              `ifdef ETH_WISHBONE_B3
1067
                m_wb_cti_o <=#Tp 3'b010;
1068
              `endif
1069
              end
1070
          end
1071 229 mohor
        8'b00_x1_00_x0 :            // idle and MW is needed (data write to rx buffer)
1072 226 tadejm
          begin
1073
            MasterWbTX <=#Tp 1'b0;
1074
            MasterWbRX <=#Tp 1'b1;
1075 159 mohor
            m_wb_adr_o <=#Tp {RxPointerMSB, 2'h0};
1076 39 mohor
            m_wb_cyc_o <=#Tp 1'b1;
1077
            m_wb_stb_o <=#Tp 1'b1;
1078
            m_wb_we_o  <=#Tp 1'b1;
1079 159 mohor
            m_wb_sel_o <=#Tp RxByteSel;
1080 150 mohor
            IncrTxPointer<=#Tp 1'b0;
1081 39 mohor
          end
1082 226 tadejm
        8'b00_10_00_00 :            // idle and MR is needed (data read from tx buffer)
1083 39 mohor
          begin
1084 226 tadejm
            MasterWbTX <=#Tp 1'b1;
1085 39 mohor
            MasterWbRX <=#Tp 1'b0;
1086 159 mohor
            m_wb_adr_o <=#Tp {TxPointerMSB, 2'h0};
1087 39 mohor
            m_wb_cyc_o <=#Tp 1'b1;
1088
            m_wb_stb_o <=#Tp 1'b1;
1089
            m_wb_we_o  <=#Tp 1'b0;
1090 150 mohor
            m_wb_sel_o <=#Tp 4'hf;
1091
            IncrTxPointer<=#Tp 1'b1;
1092 39 mohor
          end
1093 226 tadejm
        8'b10_10_01_00,             // MR and MR is needed (data read from tx buffer)
1094 229 mohor
        8'b01_1x_01_0x  :           // MW and MR is needed (data read from tx buffer)
1095 39 mohor
          begin
1096 226 tadejm
            MasterWbTX <=#Tp 1'b1;
1097 39 mohor
            MasterWbRX <=#Tp 1'b0;
1098 159 mohor
            m_wb_adr_o <=#Tp {TxPointerMSB, 2'h0};
1099 39 mohor
            m_wb_cyc_o <=#Tp 1'b1;
1100
            m_wb_stb_o <=#Tp 1'b1;
1101
            m_wb_we_o  <=#Tp 1'b0;
1102 150 mohor
            m_wb_sel_o <=#Tp 4'hf;
1103 110 mohor
            cyc_cleared<=#Tp 1'b0;
1104 150 mohor
            IncrTxPointer<=#Tp 1'b1;
1105 39 mohor
          end
1106 226 tadejm
        8'b01_01_01_00,             // MW and MW needed (data write to rx buffer)
1107 229 mohor
        8'b10_x1_01_x0  :           // MR and MW is needed (data write to rx buffer)
1108 39 mohor
          begin
1109 226 tadejm
            MasterWbTX <=#Tp 1'b0;
1110 39 mohor
            MasterWbRX <=#Tp 1'b1;
1111 159 mohor
            m_wb_adr_o <=#Tp {RxPointerMSB, 2'h0};
1112 112 mohor
            m_wb_cyc_o <=#Tp 1'b1;
1113
            m_wb_stb_o <=#Tp 1'b1;
1114 39 mohor
            m_wb_we_o  <=#Tp 1'b1;
1115 159 mohor
            m_wb_sel_o <=#Tp RxByteSel;
1116 110 mohor
            cyc_cleared<=#Tp 1'b0;
1117 150 mohor
            IncrTxPointer<=#Tp 1'b0;
1118 39 mohor
          end
1119 226 tadejm
        8'b01_01_10_00,             // MW and MW needed (cycle is cleared between previous and next access)
1120 229 mohor
        8'b01_1x_10_x0,             // MW and MW or MR or MRB needed (cycle is cleared between previous and next access)
1121 226 tadejm
        8'b10_10_10_00,             // MR and MR needed (cycle is cleared between previous and next access)
1122 229 mohor
        8'b10_x1_10_0x :            // MR and MR or MW or MWB (cycle is cleared between previous and next access)
1123 39 mohor
          begin
1124 110 mohor
            m_wb_cyc_o <=#Tp 1'b0;  // whatever and master read or write is needed. We need to clear m_wb_cyc_o before next access is started
1125
            m_wb_stb_o <=#Tp 1'b0;
1126
            cyc_cleared<=#Tp 1'b1;
1127 150 mohor
            IncrTxPointer<=#Tp 1'b0;
1128 226 tadejm
            tx_burst_cnt<=#Tp 0;
1129
            tx_burst_en<=#Tp txfifo_cnt<(`ETH_TX_FIFO_DEPTH-`ETH_BURST_LENGTH) & (TxLength>(`ETH_BURST_LENGTH*4+4));
1130
            rx_burst_cnt<=#Tp 0;
1131
            rx_burst_en<=#Tp MasterWbRX ? enough_data_in_rxfifo_for_burst_plus1 : enough_data_in_rxfifo_for_burst;  // Counter is not decremented, yet, so plus1 is used.
1132
            `ifdef ETH_WISHBONE_B3
1133
              m_wb_cti_o <=#Tp 3'b0;
1134
            `endif
1135 110 mohor
          end
1136 229 mohor
        8'bxx_00_10_00,             // whatever and no master read or write is needed (ack or err comes finishing previous access)
1137
        8'bxx_00_01_00 :            // Between cyc_cleared request was cleared
1138 110 mohor
          begin
1139 226 tadejm
            MasterWbTX <=#Tp 1'b0;
1140 39 mohor
            MasterWbRX <=#Tp 1'b0;
1141
            m_wb_cyc_o <=#Tp 1'b0;
1142
            m_wb_stb_o <=#Tp 1'b0;
1143 226 tadejm
            cyc_cleared<=#Tp 1'b0;
1144 150 mohor
            IncrTxPointer<=#Tp 1'b0;
1145 226 tadejm
            rx_burst_cnt<=#Tp 0;
1146
            rx_burst_en<=#Tp MasterWbRX ? enough_data_in_rxfifo_for_burst_plus1 : enough_data_in_rxfifo_for_burst;  // Counter is not decremented, yet, so plus1 is used.
1147
            `ifdef ETH_WISHBONE_B3
1148
              m_wb_cti_o <=#Tp 3'b0;
1149
            `endif
1150 39 mohor
          end
1151 226 tadejm
        8'b00_00_00_00:             // whatever and no master read or write is needed (ack or err comes finishing previous access)
1152 127 mohor
          begin
1153 226 tadejm
            tx_burst_cnt<=#Tp 0;
1154
            tx_burst_en<=#Tp txfifo_cnt<(`ETH_TX_FIFO_DEPTH-`ETH_BURST_LENGTH) & (TxLength>(`ETH_BURST_LENGTH*4+4));
1155 127 mohor
          end
1156 226 tadejm
        default:                    // Don't touch
1157 82 mohor
          begin
1158
            MasterWbTX <=#Tp MasterWbTX;
1159
            MasterWbRX <=#Tp MasterWbRX;
1160
            m_wb_cyc_o <=#Tp m_wb_cyc_o;
1161
            m_wb_stb_o <=#Tp m_wb_stb_o;
1162 96 mohor
            m_wb_sel_o <=#Tp m_wb_sel_o;
1163 150 mohor
            IncrTxPointer<=#Tp IncrTxPointer;
1164 82 mohor
          end
1165 39 mohor
      endcase
1166
    end
1167 38 mohor
end
1168
 
1169 110 mohor
 
1170 39 mohor
wire TxFifoClear;
1171 96 mohor
 
1172 219 mohor
assign TxFifoClear = (TxAbortPacket | TxRetryPacket);
1173 38 mohor
 
1174 219 mohor
eth_fifo #(`ETH_TX_FIFO_DATA_WIDTH, `ETH_TX_FIFO_DEPTH, `ETH_TX_FIFO_CNT_WIDTH)
1175 150 mohor
tx_fifo ( .data_in(m_wb_dat_i),                             .data_out(TxData_wb),
1176 96 mohor
          .clk(WB_CLK_I),                                   .reset(Reset),
1177 226 tadejm
          .write(MasterWbTX & m_wb_ack_i),                  .read(ReadTxDataFromFifo_wb & ~TxBufferEmpty),
1178 96 mohor
          .clear(TxFifoClear),                              .full(TxBufferFull),
1179
          .almost_full(TxBufferAlmostFull),                 .almost_empty(TxBufferAlmostEmpty),
1180 150 mohor
          .empty(TxBufferEmpty),                            .cnt(txfifo_cnt)
1181 96 mohor
        );
1182 39 mohor
 
1183
 
1184
reg StartOccured;
1185
reg TxStartFrm_sync1;
1186
reg TxStartFrm_sync2;
1187
reg TxStartFrm_syncb1;
1188
reg TxStartFrm_syncb2;
1189
 
1190
 
1191
 
1192
// Start: Generation of the TxStartFrm_wb which is then synchronized to the MTxClk
1193 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1194 38 mohor
begin
1195 40 mohor
  if(Reset)
1196 39 mohor
    TxStartFrm_wb <=#Tp 1'b0;
1197 38 mohor
  else
1198 39 mohor
  if(TxBDReady & ~StartOccured & (TxBufferFull | TxLengthEq0))
1199
    TxStartFrm_wb <=#Tp 1'b1;
1200 38 mohor
  else
1201 39 mohor
  if(TxStartFrm_syncb2)
1202
    TxStartFrm_wb <=#Tp 1'b0;
1203 38 mohor
end
1204
 
1205 39 mohor
// StartOccured: TxStartFrm_wb occurs only ones at the beginning. Then it's blocked.
1206 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1207 38 mohor
begin
1208 40 mohor
  if(Reset)
1209 39 mohor
    StartOccured <=#Tp 1'b0;
1210 38 mohor
  else
1211 39 mohor
  if(TxStartFrm_wb)
1212
    StartOccured <=#Tp 1'b1;
1213 38 mohor
  else
1214 39 mohor
  if(ResetTxBDReady)
1215
    StartOccured <=#Tp 1'b0;
1216 38 mohor
end
1217
 
1218 39 mohor
// Synchronizing TxStartFrm_wb to MTxClk
1219 40 mohor
always @ (posedge MTxClk or posedge Reset)
1220 39 mohor
begin
1221 40 mohor
  if(Reset)
1222 39 mohor
    TxStartFrm_sync1 <=#Tp 1'b0;
1223
  else
1224
    TxStartFrm_sync1 <=#Tp TxStartFrm_wb;
1225
end
1226 38 mohor
 
1227 40 mohor
always @ (posedge MTxClk or posedge Reset)
1228 39 mohor
begin
1229 40 mohor
  if(Reset)
1230 39 mohor
    TxStartFrm_sync2 <=#Tp 1'b0;
1231
  else
1232
    TxStartFrm_sync2 <=#Tp TxStartFrm_sync1;
1233
end
1234
 
1235 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1236 38 mohor
begin
1237 40 mohor
  if(Reset)
1238 39 mohor
    TxStartFrm_syncb1 <=#Tp 1'b0;
1239 38 mohor
  else
1240 39 mohor
    TxStartFrm_syncb1 <=#Tp TxStartFrm_sync2;
1241 38 mohor
end
1242
 
1243 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1244 38 mohor
begin
1245 40 mohor
  if(Reset)
1246 39 mohor
    TxStartFrm_syncb2 <=#Tp 1'b0;
1247 38 mohor
  else
1248 39 mohor
    TxStartFrm_syncb2 <=#Tp TxStartFrm_syncb1;
1249
end
1250
 
1251 40 mohor
always @ (posedge MTxClk or posedge Reset)
1252 39 mohor
begin
1253 40 mohor
  if(Reset)
1254 39 mohor
    TxStartFrm <=#Tp 1'b0;
1255 38 mohor
  else
1256 39 mohor
  if(TxStartFrm_sync2)
1257 61 mohor
    TxStartFrm <=#Tp 1'b1;
1258 39 mohor
  else
1259 278 mohor
  if(TxUsedData_q | ~TxStartFrm_sync2 & (TxRetry & (~TxRetry_q) | TxAbort & (~TxAbort_q)))
1260 39 mohor
    TxStartFrm <=#Tp 1'b0;
1261 38 mohor
end
1262 39 mohor
// End: Generation of the TxStartFrm_wb which is then synchronized to the MTxClk
1263 38 mohor
 
1264
 
1265 39 mohor
// TxEndFrm_wb: indicator of the end of frame
1266 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1267 38 mohor
begin
1268 40 mohor
  if(Reset)
1269 39 mohor
    TxEndFrm_wb <=#Tp 1'b0;
1270 38 mohor
  else
1271 221 mohor
  if(TxLengthEq0 & TxBufferAlmostEmpty & TxUsedData)
1272 39 mohor
    TxEndFrm_wb <=#Tp 1'b1;
1273 38 mohor
  else
1274 39 mohor
  if(TxRetryPulse | TxDonePulse | TxAbortPulse)
1275
    TxEndFrm_wb <=#Tp 1'b0;
1276 38 mohor
end
1277
 
1278
 
1279
// Marks which bytes are valid within the word.
1280 39 mohor
assign TxValidBytes = TxLengthLt4 ? TxLength[1:0] : 2'b0;
1281 38 mohor
 
1282 39 mohor
reg LatchValidBytes;
1283
reg LatchValidBytes_q;
1284 38 mohor
 
1285 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1286 38 mohor
begin
1287 40 mohor
  if(Reset)
1288 39 mohor
    LatchValidBytes <=#Tp 1'b0;
1289 38 mohor
  else
1290 39 mohor
  if(TxLengthLt4 & TxBDReady)
1291
    LatchValidBytes <=#Tp 1'b1;
1292 38 mohor
  else
1293 39 mohor
    LatchValidBytes <=#Tp 1'b0;
1294 38 mohor
end
1295
 
1296 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1297 38 mohor
begin
1298 40 mohor
  if(Reset)
1299 39 mohor
    LatchValidBytes_q <=#Tp 1'b0;
1300 38 mohor
  else
1301 39 mohor
    LatchValidBytes_q <=#Tp LatchValidBytes;
1302 38 mohor
end
1303
 
1304
 
1305 39 mohor
// Latching valid bytes
1306 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1307 38 mohor
begin
1308 40 mohor
  if(Reset)
1309 39 mohor
    TxValidBytesLatched <=#Tp 2'h0;
1310 38 mohor
  else
1311 39 mohor
  if(LatchValidBytes & ~LatchValidBytes_q)
1312
    TxValidBytesLatched <=#Tp TxValidBytes;
1313
  else
1314
  if(TxRetryPulse | TxDonePulse | TxAbortPulse)
1315
    TxValidBytesLatched <=#Tp 2'h0;
1316 38 mohor
end
1317
 
1318
 
1319
assign TxIRQEn          = TxStatus[14];
1320 60 mohor
assign WrapTxStatusBit  = TxStatus[13];
1321
assign PerPacketPad     = TxStatus[12];
1322
assign PerPacketCrcEn   = TxStatus[11];
1323 38 mohor
 
1324
 
1325 77 mohor
assign RxIRQEn         = RxStatus[14];
1326 60 mohor
assign WrapRxStatusBit = RxStatus[13];
1327 38 mohor
 
1328
 
1329
// Temporary Tx and Rx buffer descriptor address 
1330 39 mohor
assign TempTxBDAddress[7:0] = {8{ TxStatusWrite     & ~WrapTxStatusBit}} & (TxBDAddress + 2'h2) ; // Tx BD increment or wrap (last BD)
1331 134 mohor
assign TempRxBDAddress[7:0] = {8{ WrapRxStatusBit}} & (r_TxBDNum<<1)     | // Using first Rx BD
1332 39 mohor
                              {8{~WrapRxStatusBit}} & (RxBDAddress + 2'h2) ; // Using next Rx BD (incremenrement address)
1333 38 mohor
 
1334
 
1335
// Latching Tx buffer descriptor address
1336 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1337 38 mohor
begin
1338 40 mohor
  if(Reset)
1339 38 mohor
    TxBDAddress <=#Tp 8'h0;
1340
  else
1341
  if(TxStatusWrite)
1342
    TxBDAddress <=#Tp TempTxBDAddress;
1343
end
1344
 
1345
 
1346
// Latching Rx buffer descriptor address
1347 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1348 38 mohor
begin
1349 40 mohor
  if(Reset)
1350 134 mohor
    RxBDAddress <=#Tp `ETH_TX_BD_NUM_DEF<<1;
1351 38 mohor
  else
1352 77 mohor
  if(TX_BD_NUM_Wr)                        // When r_TxBDNum is updated, RxBDAddress is also
1353 134 mohor
    RxBDAddress <=#Tp WB_DAT_I[7:0]<<1;
1354 38 mohor
  else
1355
  if(RxStatusWrite)
1356
    RxBDAddress <=#Tp TempRxBDAddress;
1357
end
1358
 
1359 60 mohor
wire [8:0] TxStatusInLatched = {TxUnderRun, RetryCntLatched[3:0], RetryLimit, LateCollLatched, DeferLatched, CarrierSenseLost};
1360 38 mohor
 
1361 261 mohor
assign RxBDDataIn = {LatchedRxLength, 1'b0, RxStatus, 4'h0, RxStatusInLatched};
1362 60 mohor
assign TxBDDataIn = {LatchedTxLength, 1'b0, TxStatus, 2'h0, TxStatusInLatched};
1363 38 mohor
 
1364 60 mohor
 
1365 38 mohor
// Signals used for various purposes
1366 39 mohor
assign TxRetryPulse   = TxRetry_wb   & ~TxRetry_wb_q;
1367 38 mohor
assign TxDonePulse    = TxDone_wb    & ~TxDone_wb_q;
1368
assign TxAbortPulse   = TxAbort_wb   & ~TxAbort_wb_q;
1369
 
1370
 
1371
 
1372 39 mohor
// Generating delayed signals
1373 40 mohor
always @ (posedge MTxClk or posedge Reset)
1374 38 mohor
begin
1375 40 mohor
  if(Reset)
1376 39 mohor
    begin
1377
      TxAbort_q      <=#Tp 1'b0;
1378
      TxRetry_q      <=#Tp 1'b0;
1379
      TxUsedData_q   <=#Tp 1'b0;
1380
    end
1381 38 mohor
  else
1382 39 mohor
    begin
1383
      TxAbort_q      <=#Tp TxAbort;
1384
      TxRetry_q      <=#Tp TxRetry;
1385
      TxUsedData_q   <=#Tp TxUsedData;
1386
    end
1387 38 mohor
end
1388
 
1389
// Generating delayed signals
1390 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1391 38 mohor
begin
1392 40 mohor
  if(Reset)
1393 38 mohor
    begin
1394 39 mohor
      TxDone_wb_q   <=#Tp 1'b0;
1395
      TxAbort_wb_q  <=#Tp 1'b0;
1396 40 mohor
      TxRetry_wb_q  <=#Tp 1'b0;
1397 38 mohor
    end
1398
  else
1399
    begin
1400 39 mohor
      TxDone_wb_q   <=#Tp TxDone_wb;
1401
      TxAbort_wb_q  <=#Tp TxAbort_wb;
1402 40 mohor
      TxRetry_wb_q  <=#Tp TxRetry_wb;
1403 38 mohor
    end
1404
end
1405
 
1406
 
1407 219 mohor
reg TxAbortPacketBlocked;
1408
always @ (posedge WB_CLK_I or posedge Reset)
1409
begin
1410
  if(Reset)
1411
    TxAbortPacket <=#Tp 1'b0;
1412
  else
1413 278 mohor
  if(TxAbort_wb & (~tx_burst_en) & MasterWbTX & MasterAccessFinished & (~TxAbortPacketBlocked) |
1414
     TxAbort_wb & (~MasterWbTX) & (~TxAbortPacketBlocked))
1415 219 mohor
    TxAbortPacket <=#Tp 1'b1;
1416
  else
1417
    TxAbortPacket <=#Tp 1'b0;
1418
end
1419
 
1420
 
1421
always @ (posedge WB_CLK_I or posedge Reset)
1422
begin
1423
  if(Reset)
1424 221 mohor
    TxAbortPacket_NotCleared <=#Tp 1'b0;
1425
  else
1426 272 tadejm
  if(TxEn & TxEn_q & TxAbortPacket_NotCleared)
1427
    TxAbortPacket_NotCleared <=#Tp 1'b0;
1428
  else
1429 278 mohor
  if(TxAbort_wb & (~tx_burst_en) & MasterWbTX & MasterAccessFinished & (~TxAbortPacketBlocked) |
1430
     TxAbort_wb & (~MasterWbTX) & (~TxAbortPacketBlocked))
1431 221 mohor
    TxAbortPacket_NotCleared <=#Tp 1'b1;
1432
end
1433
 
1434
 
1435
always @ (posedge WB_CLK_I or posedge Reset)
1436
begin
1437
  if(Reset)
1438 219 mohor
    TxAbortPacketBlocked <=#Tp 1'b0;
1439
  else
1440 280 mohor
  if(!TxAbort_wb & TxAbort_wb_q)
1441
    TxAbortPacketBlocked <=#Tp 1'b0;
1442
  else
1443 219 mohor
  if(TxAbortPacket)
1444
    TxAbortPacketBlocked <=#Tp 1'b1;
1445
end
1446
 
1447
 
1448
reg TxRetryPacketBlocked;
1449
always @ (posedge WB_CLK_I or posedge Reset)
1450
begin
1451
  if(Reset)
1452
    TxRetryPacket <=#Tp 1'b0;
1453
  else
1454 226 tadejm
  if(TxRetry_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished & !TxRetryPacketBlocked |
1455
     TxRetry_wb & !MasterWbTX & !TxRetryPacketBlocked)
1456 219 mohor
    TxRetryPacket <=#Tp 1'b1;
1457
  else
1458
    TxRetryPacket <=#Tp 1'b0;
1459
end
1460
 
1461
 
1462
always @ (posedge WB_CLK_I or posedge Reset)
1463
begin
1464
  if(Reset)
1465 221 mohor
    TxRetryPacket_NotCleared <=#Tp 1'b0;
1466
  else
1467 272 tadejm
  if(StartTxBDRead)
1468
    TxRetryPacket_NotCleared <=#Tp 1'b0;
1469
  else
1470 278 mohor
  if(TxRetry_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished & !TxRetryPacketBlocked |
1471
     TxRetry_wb & !MasterWbTX & !TxRetryPacketBlocked)
1472 221 mohor
    TxRetryPacket_NotCleared <=#Tp 1'b1;
1473
end
1474
 
1475
 
1476
always @ (posedge WB_CLK_I or posedge Reset)
1477
begin
1478
  if(Reset)
1479 219 mohor
    TxRetryPacketBlocked <=#Tp 1'b0;
1480
  else
1481 280 mohor
  if(!TxRetry_wb & TxRetry_wb_q)
1482
    TxRetryPacketBlocked <=#Tp 1'b0;
1483
  else
1484 219 mohor
  if(TxRetryPacket)
1485
    TxRetryPacketBlocked <=#Tp 1'b1;
1486
end
1487
 
1488
 
1489 221 mohor
reg TxDonePacketBlocked;
1490
always @ (posedge WB_CLK_I or posedge Reset)
1491
begin
1492
  if(Reset)
1493
    TxDonePacket <=#Tp 1'b0;
1494
  else
1495 226 tadejm
  if(TxDone_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished & !TxDonePacketBlocked |
1496
     TxDone_wb & !MasterWbTX & !TxDonePacketBlocked)
1497 221 mohor
    TxDonePacket <=#Tp 1'b1;
1498
  else
1499
    TxDonePacket <=#Tp 1'b0;
1500
end
1501
 
1502
 
1503
always @ (posedge WB_CLK_I or posedge Reset)
1504
begin
1505
  if(Reset)
1506
    TxDonePacket_NotCleared <=#Tp 1'b0;
1507
  else
1508 272 tadejm
  if(TxEn & TxEn_q & TxDonePacket_NotCleared)
1509
    TxDonePacket_NotCleared <=#Tp 1'b0;
1510
  else
1511 278 mohor
  if(TxDone_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished & (~TxDonePacketBlocked) |
1512
     TxDone_wb & !MasterWbTX & (~TxDonePacketBlocked))
1513 221 mohor
    TxDonePacket_NotCleared <=#Tp 1'b1;
1514
end
1515
 
1516
 
1517
always @ (posedge WB_CLK_I or posedge Reset)
1518
begin
1519
  if(Reset)
1520
    TxDonePacketBlocked <=#Tp 1'b0;
1521
  else
1522 280 mohor
  if(!TxDone_wb & TxDone_wb_q)
1523
    TxDonePacketBlocked <=#Tp 1'b0;
1524
  else
1525 221 mohor
  if(TxDonePacket)
1526
    TxDonePacketBlocked <=#Tp 1'b1;
1527
end
1528
 
1529
 
1530 38 mohor
// Indication of the last word
1531 40 mohor
always @ (posedge MTxClk or posedge Reset)
1532 38 mohor
begin
1533 40 mohor
  if(Reset)
1534 38 mohor
    LastWord <=#Tp 1'b0;
1535
  else
1536
  if((TxEndFrm | TxAbort | TxRetry) & Flop)
1537
    LastWord <=#Tp 1'b0;
1538
  else
1539
  if(TxUsedData & Flop & TxByteCnt == 2'h3)
1540 39 mohor
    LastWord <=#Tp TxEndFrm_wb;
1541 38 mohor
end
1542
 
1543
 
1544
// Tx end frame generation
1545 40 mohor
always @ (posedge MTxClk or posedge Reset)
1546 38 mohor
begin
1547 40 mohor
  if(Reset)
1548 38 mohor
    TxEndFrm <=#Tp 1'b0;
1549
  else
1550 91 mohor
  if(Flop & TxEndFrm | TxAbort | TxRetry_q)
1551 38 mohor
    TxEndFrm <=#Tp 1'b0;
1552
  else
1553
  if(Flop & LastWord)
1554
    begin
1555 105 mohor
      case (TxValidBytesLatched)  // synopsys parallel_case
1556 38 mohor
        1 : TxEndFrm <=#Tp TxByteCnt == 2'h0;
1557
        2 : TxEndFrm <=#Tp TxByteCnt == 2'h1;
1558
        3 : TxEndFrm <=#Tp TxByteCnt == 2'h2;
1559
 
1560
        default : TxEndFrm <=#Tp 1'b0;
1561
      endcase
1562
    end
1563
end
1564
 
1565
 
1566
// Tx data selection (latching)
1567 40 mohor
always @ (posedge MTxClk or posedge Reset)
1568 38 mohor
begin
1569 40 mohor
  if(Reset)
1570 96 mohor
    TxData <=#Tp 0;
1571 38 mohor
  else
1572 39 mohor
  if(TxStartFrm_sync2 & ~TxStartFrm)
1573 159 mohor
    case(TxPointerLSB)  // synopsys parallel_case
1574 96 mohor
      2'h0 : TxData <=#Tp TxData_wb[31:24];                  // Big Endian Byte Ordering
1575
      2'h1 : TxData <=#Tp TxData_wb[23:16];                  // Big Endian Byte Ordering
1576
      2'h2 : TxData <=#Tp TxData_wb[15:08];                  // Big Endian Byte Ordering
1577
      2'h3 : TxData <=#Tp TxData_wb[07:00];                  // Big Endian Byte Ordering
1578
    endcase
1579 38 mohor
  else
1580 159 mohor
  if(TxStartFrm & TxUsedData & TxPointerLSB==2'h3)
1581 96 mohor
    TxData <=#Tp TxData_wb[31:24];                           // Big Endian Byte Ordering
1582
  else
1583 38 mohor
  if(TxUsedData & Flop)
1584
    begin
1585 105 mohor
      case(TxByteCnt)  // synopsys parallel_case
1586 226 tadejm
 
1587 82 mohor
        1 : TxData <=#Tp TxDataLatched[23:16];
1588
        2 : TxData <=#Tp TxDataLatched[15:8];
1589
        3 : TxData <=#Tp TxDataLatched[7:0];
1590 38 mohor
      endcase
1591
    end
1592
end
1593
 
1594
 
1595
// Latching tx data
1596 40 mohor
always @ (posedge MTxClk or posedge Reset)
1597 38 mohor
begin
1598 40 mohor
  if(Reset)
1599 38 mohor
    TxDataLatched[31:0] <=#Tp 32'h0;
1600
  else
1601 96 mohor
 if(TxStartFrm_sync2 & ~TxStartFrm | TxUsedData & Flop & TxByteCnt == 2'h3 | TxStartFrm & TxUsedData & Flop & TxByteCnt == 2'h0)
1602 39 mohor
    TxDataLatched[31:0] <=#Tp TxData_wb[31:0];
1603 38 mohor
end
1604
 
1605
 
1606
// Tx under run
1607 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1608 38 mohor
begin
1609 40 mohor
  if(Reset)
1610 60 mohor
    TxUnderRun_wb <=#Tp 1'b0;
1611 38 mohor
  else
1612 39 mohor
  if(TxAbortPulse)
1613 60 mohor
    TxUnderRun_wb <=#Tp 1'b0;
1614
  else
1615
  if(TxBufferEmpty & ReadTxDataFromFifo_wb)
1616
    TxUnderRun_wb <=#Tp 1'b1;
1617
end
1618
 
1619
 
1620 159 mohor
reg TxUnderRun_sync1;
1621
 
1622 60 mohor
// Tx under run
1623
always @ (posedge MTxClk or posedge Reset)
1624
begin
1625
  if(Reset)
1626 159 mohor
    TxUnderRun_sync1 <=#Tp 1'b0;
1627 43 mohor
  else
1628 60 mohor
  if(TxUnderRun_wb)
1629 159 mohor
    TxUnderRun_sync1 <=#Tp 1'b1;
1630 60 mohor
  else
1631 159 mohor
  if(BlockingTxStatusWrite_sync2)
1632
    TxUnderRun_sync1 <=#Tp 1'b0;
1633
end
1634
 
1635
// Tx under run
1636
always @ (posedge MTxClk or posedge Reset)
1637
begin
1638
  if(Reset)
1639 60 mohor
    TxUnderRun <=#Tp 1'b0;
1640 159 mohor
  else
1641
  if(BlockingTxStatusWrite_sync2)
1642
    TxUnderRun <=#Tp 1'b0;
1643
  else
1644
  if(TxUnderRun_sync1)
1645
    TxUnderRun <=#Tp 1'b1;
1646 38 mohor
end
1647
 
1648
 
1649
// Tx Byte counter
1650 40 mohor
always @ (posedge MTxClk or posedge Reset)
1651 38 mohor
begin
1652 40 mohor
  if(Reset)
1653 38 mohor
    TxByteCnt <=#Tp 2'h0;
1654
  else
1655
  if(TxAbort_q | TxRetry_q)
1656
    TxByteCnt <=#Tp 2'h0;
1657
  else
1658
  if(TxStartFrm & ~TxUsedData)
1659 159 mohor
    case(TxPointerLSB)  // synopsys parallel_case
1660 96 mohor
      2'h0 : TxByteCnt <=#Tp 2'h1;
1661
      2'h1 : TxByteCnt <=#Tp 2'h2;
1662
      2'h2 : TxByteCnt <=#Tp 2'h3;
1663
      2'h3 : TxByteCnt <=#Tp 2'h0;
1664
    endcase
1665 38 mohor
  else
1666
  if(TxUsedData & Flop)
1667 96 mohor
    TxByteCnt <=#Tp TxByteCnt + 1'b1;
1668 38 mohor
end
1669
 
1670 39 mohor
 
1671 150 mohor
// Start: Generation of the ReadTxDataFromFifo_tck signal and synchronization to the WB_CLK_I
1672
reg ReadTxDataFromFifo_sync1;
1673
reg ReadTxDataFromFifo_sync2;
1674
reg ReadTxDataFromFifo_sync3;
1675
reg ReadTxDataFromFifo_syncb1;
1676
reg ReadTxDataFromFifo_syncb2;
1677
reg ReadTxDataFromFifo_syncb3;
1678
 
1679
 
1680
always @ (posedge MTxClk or posedge Reset)
1681
begin
1682
  if(Reset)
1683
    ReadTxDataFromFifo_tck <=#Tp 1'b0;
1684
  else
1685 96 mohor
  if(TxStartFrm_sync2 & ~TxStartFrm | TxUsedData & Flop & TxByteCnt == 2'h3 & ~LastWord | TxStartFrm & TxUsedData & Flop & TxByteCnt == 2'h0)
1686 39 mohor
     ReadTxDataFromFifo_tck <=#Tp 1'b1;
1687 150 mohor
  else
1688
  if(ReadTxDataFromFifo_syncb2 & ~ReadTxDataFromFifo_syncb3)
1689
    ReadTxDataFromFifo_tck <=#Tp 1'b0;
1690 38 mohor
end
1691
 
1692 39 mohor
// Synchronizing TxStartFrm_wb to MTxClk
1693 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1694 38 mohor
begin
1695 40 mohor
  if(Reset)
1696 39 mohor
    ReadTxDataFromFifo_sync1 <=#Tp 1'b0;
1697 38 mohor
  else
1698 39 mohor
    ReadTxDataFromFifo_sync1 <=#Tp ReadTxDataFromFifo_tck;
1699
end
1700 38 mohor
 
1701 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1702 38 mohor
begin
1703 40 mohor
  if(Reset)
1704 39 mohor
    ReadTxDataFromFifo_sync2 <=#Tp 1'b0;
1705 38 mohor
  else
1706 39 mohor
    ReadTxDataFromFifo_sync2 <=#Tp ReadTxDataFromFifo_sync1;
1707 38 mohor
end
1708
 
1709 40 mohor
always @ (posedge MTxClk or posedge Reset)
1710 38 mohor
begin
1711 40 mohor
  if(Reset)
1712 39 mohor
    ReadTxDataFromFifo_syncb1 <=#Tp 1'b0;
1713 38 mohor
  else
1714 39 mohor
    ReadTxDataFromFifo_syncb1 <=#Tp ReadTxDataFromFifo_sync2;
1715 38 mohor
end
1716
 
1717 40 mohor
always @ (posedge MTxClk or posedge Reset)
1718 38 mohor
begin
1719 40 mohor
  if(Reset)
1720 39 mohor
    ReadTxDataFromFifo_syncb2 <=#Tp 1'b0;
1721 38 mohor
  else
1722 39 mohor
    ReadTxDataFromFifo_syncb2 <=#Tp ReadTxDataFromFifo_syncb1;
1723 38 mohor
end
1724
 
1725 150 mohor
always @ (posedge MTxClk or posedge Reset)
1726
begin
1727
  if(Reset)
1728
    ReadTxDataFromFifo_syncb3 <=#Tp 1'b0;
1729
  else
1730
    ReadTxDataFromFifo_syncb3 <=#Tp ReadTxDataFromFifo_syncb2;
1731
end
1732
 
1733 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1734 38 mohor
begin
1735 40 mohor
  if(Reset)
1736 39 mohor
    ReadTxDataFromFifo_sync3 <=#Tp 1'b0;
1737 38 mohor
  else
1738 39 mohor
    ReadTxDataFromFifo_sync3 <=#Tp ReadTxDataFromFifo_sync2;
1739 38 mohor
end
1740
 
1741 39 mohor
assign ReadTxDataFromFifo_wb = ReadTxDataFromFifo_sync2 & ~ReadTxDataFromFifo_sync3;
1742
// End: Generation of the ReadTxDataFromFifo_tck signal and synchronization to the WB_CLK_I
1743 38 mohor
 
1744
 
1745 39 mohor
// Synchronizing TxRetry signal (synchronized to WISHBONE clock)
1746 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1747 38 mohor
begin
1748 40 mohor
  if(Reset)
1749 39 mohor
    TxRetrySync1 <=#Tp 1'b0;
1750 38 mohor
  else
1751 39 mohor
    TxRetrySync1 <=#Tp TxRetry;
1752 38 mohor
end
1753
 
1754 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1755 38 mohor
begin
1756 40 mohor
  if(Reset)
1757 39 mohor
    TxRetry_wb <=#Tp 1'b0;
1758 38 mohor
  else
1759 39 mohor
    TxRetry_wb <=#Tp TxRetrySync1;
1760 38 mohor
end
1761
 
1762
 
1763 39 mohor
// Synchronized TxDone_wb signal (synchronized to WISHBONE clock)
1764 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1765 38 mohor
begin
1766 40 mohor
  if(Reset)
1767 39 mohor
    TxDoneSync1 <=#Tp 1'b0;
1768 38 mohor
  else
1769 39 mohor
    TxDoneSync1 <=#Tp TxDone;
1770 38 mohor
end
1771
 
1772 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1773 38 mohor
begin
1774 40 mohor
  if(Reset)
1775 39 mohor
    TxDone_wb <=#Tp 1'b0;
1776 38 mohor
  else
1777 39 mohor
    TxDone_wb <=#Tp TxDoneSync1;
1778 38 mohor
end
1779
 
1780 39 mohor
// Synchronizing TxAbort signal (synchronized to WISHBONE clock)
1781 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1782 38 mohor
begin
1783 40 mohor
  if(Reset)
1784 39 mohor
    TxAbortSync1 <=#Tp 1'b0;
1785 38 mohor
  else
1786 39 mohor
    TxAbortSync1 <=#Tp TxAbort;
1787 38 mohor
end
1788
 
1789 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1790 38 mohor
begin
1791 40 mohor
  if(Reset)
1792 38 mohor
    TxAbort_wb <=#Tp 1'b0;
1793
  else
1794 39 mohor
    TxAbort_wb <=#Tp TxAbortSync1;
1795 38 mohor
end
1796
 
1797
 
1798 150 mohor
reg RxAbortSync1;
1799
reg RxAbortSync2;
1800
reg RxAbortSync3;
1801
reg RxAbortSync4;
1802
reg RxAbortSyncb1;
1803
reg RxAbortSyncb2;
1804 39 mohor
 
1805 150 mohor
assign StartRxBDRead = RxStatusWrite | RxAbortSync3 & ~RxAbortSync4;
1806
 
1807 40 mohor
// Reading the Rx buffer descriptor
1808
always @ (posedge WB_CLK_I or posedge Reset)
1809
begin
1810
  if(Reset)
1811
    RxBDRead <=#Tp 1'b1;
1812
  else
1813 166 mohor
  if(StartRxBDRead & ~RxReady)
1814 40 mohor
    RxBDRead <=#Tp 1'b1;
1815
  else
1816
  if(RxBDReady)
1817
    RxBDRead <=#Tp 1'b0;
1818
end
1819 39 mohor
 
1820
 
1821 38 mohor
// Reading of the next receive buffer descriptor starts after reception status is
1822
// written to the previous one.
1823
 
1824
// Latching READY status of the Rx buffer descriptor
1825 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1826 38 mohor
begin
1827 40 mohor
  if(Reset)
1828 38 mohor
    RxBDReady <=#Tp 1'b0;
1829
  else
1830 166 mohor
  if(RxPointerRead)
1831 150 mohor
    RxBDReady <=#Tp 1'b0;
1832
  else
1833 40 mohor
  if(RxEn & RxEn_q & RxBDRead)
1834
    RxBDReady <=#Tp ram_do[15]; // RxBDReady is sampled only once at the beginning
1835 38 mohor
end
1836
 
1837 40 mohor
// Latching Rx buffer descriptor status
1838
// Data is avaliable one cycle after the access is started (at that time signal RxEn is not active)
1839
always @ (posedge WB_CLK_I or posedge Reset)
1840 38 mohor
begin
1841 40 mohor
  if(Reset)
1842 60 mohor
    RxStatus <=#Tp 2'h0;
1843 38 mohor
  else
1844 40 mohor
  if(RxEn & RxEn_q & RxBDRead)
1845 60 mohor
    RxStatus <=#Tp ram_do[14:13];
1846 38 mohor
end
1847
 
1848
 
1849 166 mohor
// RxReady generation
1850
always @ (posedge WB_CLK_I or posedge Reset)
1851
begin
1852
  if(Reset)
1853
    RxReady <=#Tp 1'b0;
1854
  else
1855
  if(ShiftEnded | RxAbortSync2 & ~RxAbortSync3)
1856
    RxReady <=#Tp 1'b0;
1857
  else
1858
  if(RxEn & RxEn_q & RxPointerRead)
1859
    RxReady <=#Tp 1'b1;
1860
end
1861 38 mohor
 
1862
 
1863 40 mohor
// Reading Rx BD pointer
1864
 
1865
 
1866
assign StartRxPointerRead = RxBDRead & RxBDReady;
1867
 
1868
// Reading Tx BD Pointer
1869
always @ (posedge WB_CLK_I or posedge Reset)
1870 38 mohor
begin
1871 40 mohor
  if(Reset)
1872
    RxPointerRead <=#Tp 1'b0;
1873 38 mohor
  else
1874 40 mohor
  if(StartRxPointerRead)
1875
    RxPointerRead <=#Tp 1'b1;
1876 38 mohor
  else
1877 166 mohor
  if(RxEn & RxEn_q)
1878 40 mohor
    RxPointerRead <=#Tp 1'b0;
1879 38 mohor
end
1880
 
1881 113 mohor
 
1882 40 mohor
//Latching Rx buffer pointer from buffer descriptor;
1883
always @ (posedge WB_CLK_I or posedge Reset)
1884
begin
1885
  if(Reset)
1886 159 mohor
    RxPointerMSB <=#Tp 30'h0;
1887 40 mohor
  else
1888
  if(RxEn & RxEn_q & RxPointerRead)
1889 159 mohor
    RxPointerMSB <=#Tp ram_do[31:2];
1890 40 mohor
  else
1891 113 mohor
  if(MasterWbRX & m_wb_ack_i)
1892 159 mohor
      RxPointerMSB <=#Tp RxPointerMSB + 1; // Word access  (always word access. m_wb_sel_o are used for selecting bytes)
1893 40 mohor
end
1894 38 mohor
 
1895
 
1896 96 mohor
//Latching last addresses from buffer descriptor (used as byte-half-word indicator);
1897 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
1898
begin
1899
  if(Reset)
1900 159 mohor
    RxPointerLSB_rst[1:0] <=#Tp 0;
1901 96 mohor
  else
1902 159 mohor
  if(MasterWbRX & m_wb_ack_i)                 // After first write all RxByteSel are active
1903
    RxPointerLSB_rst[1:0] <=#Tp 0;
1904 96 mohor
  else
1905
  if(RxEn & RxEn_q & RxPointerRead)
1906 159 mohor
    RxPointerLSB_rst[1:0] <=#Tp ram_do[1:0];
1907 96 mohor
end
1908
 
1909
 
1910 159 mohor
always @ (RxPointerLSB_rst)
1911 96 mohor
begin
1912 159 mohor
  case(RxPointerLSB_rst[1:0])  // synopsys parallel_case
1913
    2'h0 : RxByteSel[3:0] = 4'hf;
1914
    2'h1 : RxByteSel[3:0] = 4'h7;
1915
    2'h2 : RxByteSel[3:0] = 4'h3;
1916
    2'h3 : RxByteSel[3:0] = 4'h1;
1917 96 mohor
  endcase
1918
end
1919
 
1920
 
1921
always @ (posedge WB_CLK_I or posedge Reset)
1922
begin
1923
  if(Reset)
1924 40 mohor
    RxEn_needed <=#Tp 1'b0;
1925 38 mohor
  else
1926 166 mohor
  if(~RxReady & r_RxEn & WbEn & ~WbEn_q)
1927 40 mohor
    RxEn_needed <=#Tp 1'b1;
1928 38 mohor
  else
1929 40 mohor
  if(RxPointerRead & RxEn & RxEn_q)
1930
    RxEn_needed <=#Tp 1'b0;
1931 38 mohor
end
1932
 
1933
 
1934 40 mohor
// Reception status is written back to the buffer descriptor after the end of frame is detected.
1935
assign RxStatusWrite = ShiftEnded & RxEn & RxEn_q;
1936 38 mohor
 
1937 40 mohor
reg RxEnableWindow;
1938 38 mohor
 
1939
// Indicating that last byte is being reveived
1940 40 mohor
always @ (posedge MRxClk or posedge Reset)
1941 38 mohor
begin
1942 40 mohor
  if(Reset)
1943 38 mohor
    LastByteIn <=#Tp 1'b0;
1944
  else
1945 40 mohor
  if(ShiftWillEnd & (&RxByteCnt) | RxAbort)
1946 38 mohor
    LastByteIn <=#Tp 1'b0;
1947
  else
1948 166 mohor
  if(RxValid & RxReady & RxEndFrm & ~(&RxByteCnt) & RxEnableWindow)
1949 38 mohor
    LastByteIn <=#Tp 1'b1;
1950
end
1951
 
1952 159 mohor
reg ShiftEnded_rck;
1953 40 mohor
reg ShiftEndedSync1;
1954
reg ShiftEndedSync2;
1955 118 mohor
reg ShiftEndedSync3;
1956
reg ShiftEndedSync_c1;
1957
reg ShiftEndedSync_c2;
1958
 
1959 40 mohor
wire StartShiftWillEnd;
1960 96 mohor
assign StartShiftWillEnd = LastByteIn  | RxValid & RxEndFrm & (&RxByteCnt) & RxEnableWindow;
1961 38 mohor
 
1962
// Indicating that data reception will end
1963 40 mohor
always @ (posedge MRxClk or posedge Reset)
1964 38 mohor
begin
1965 40 mohor
  if(Reset)
1966 38 mohor
    ShiftWillEnd <=#Tp 1'b0;
1967
  else
1968 159 mohor
  if(ShiftEnded_rck | RxAbort)
1969 38 mohor
    ShiftWillEnd <=#Tp 1'b0;
1970
  else
1971 40 mohor
  if(StartShiftWillEnd)
1972 38 mohor
    ShiftWillEnd <=#Tp 1'b1;
1973
end
1974
 
1975
 
1976 40 mohor
 
1977 38 mohor
// Receive byte counter
1978 40 mohor
always @ (posedge MRxClk or posedge Reset)
1979 38 mohor
begin
1980 40 mohor
  if(Reset)
1981 38 mohor
    RxByteCnt <=#Tp 2'h0;
1982
  else
1983 159 mohor
  if(ShiftEnded_rck | RxAbort)
1984 38 mohor
    RxByteCnt <=#Tp 2'h0;
1985 97 lampret
  else
1986 166 mohor
  if(RxValid & RxStartFrm & RxReady)
1987 159 mohor
    case(RxPointerLSB_rst)  // synopsys parallel_case
1988 96 mohor
      2'h0 : RxByteCnt <=#Tp 2'h1;
1989
      2'h1 : RxByteCnt <=#Tp 2'h2;
1990
      2'h2 : RxByteCnt <=#Tp 2'h3;
1991
      2'h3 : RxByteCnt <=#Tp 2'h0;
1992
    endcase
1993 38 mohor
  else
1994 166 mohor
  if(RxValid & RxEnableWindow & RxReady | LastByteIn)
1995 40 mohor
    RxByteCnt <=#Tp RxByteCnt + 1'b1;
1996 38 mohor
end
1997
 
1998
 
1999
// Indicates how many bytes are valid within the last word
2000 40 mohor
always @ (posedge MRxClk or posedge Reset)
2001 38 mohor
begin
2002 40 mohor
  if(Reset)
2003 38 mohor
    RxValidBytes <=#Tp 2'h1;
2004
  else
2005 96 mohor
  if(RxValid & RxStartFrm)
2006 159 mohor
    case(RxPointerLSB_rst)  // synopsys parallel_case
2007 96 mohor
      2'h0 : RxValidBytes <=#Tp 2'h1;
2008
      2'h1 : RxValidBytes <=#Tp 2'h2;
2009
      2'h2 : RxValidBytes <=#Tp 2'h3;
2010
      2'h3 : RxValidBytes <=#Tp 2'h0;
2011
    endcase
2012 38 mohor
  else
2013 40 mohor
  if(RxValid & ~LastByteIn & ~RxStartFrm & RxEnableWindow)
2014 38 mohor
    RxValidBytes <=#Tp RxValidBytes + 1;
2015
end
2016
 
2017
 
2018 40 mohor
always @ (posedge MRxClk or posedge Reset)
2019 38 mohor
begin
2020 40 mohor
  if(Reset)
2021
    RxDataLatched1       <=#Tp 24'h0;
2022 38 mohor
  else
2023 166 mohor
  if(RxValid & RxReady & ~LastByteIn)
2024 96 mohor
    if(RxStartFrm)
2025 40 mohor
    begin
2026 159 mohor
      case(RxPointerLSB_rst)     // synopsys parallel_case
2027 96 mohor
        2'h0:        RxDataLatched1[31:24] <=#Tp RxData;            // Big Endian Byte Ordering
2028
        2'h1:        RxDataLatched1[23:16] <=#Tp RxData;
2029
        2'h2:        RxDataLatched1[15:8]  <=#Tp RxData;
2030
        2'h3:        RxDataLatched1        <=#Tp RxDataLatched1;
2031
      endcase
2032
    end
2033
    else if (RxEnableWindow)
2034
    begin
2035 40 mohor
      case(RxByteCnt)     // synopsys parallel_case
2036 82 mohor
        2'h0:        RxDataLatched1[31:24] <=#Tp RxData;            // Big Endian Byte Ordering
2037
        2'h1:        RxDataLatched1[23:16] <=#Tp RxData;
2038
        2'h2:        RxDataLatched1[15:8]  <=#Tp RxData;
2039 40 mohor
        2'h3:        RxDataLatched1        <=#Tp RxDataLatched1;
2040
      endcase
2041
    end
2042 38 mohor
end
2043
 
2044 40 mohor
wire SetWriteRxDataToFifo;
2045 38 mohor
 
2046 40 mohor
// Assembling data that will be written to the rx_fifo
2047
always @ (posedge MRxClk or posedge Reset)
2048 38 mohor
begin
2049 40 mohor
  if(Reset)
2050
    RxDataLatched2 <=#Tp 32'h0;
2051 38 mohor
  else
2052 40 mohor
  if(SetWriteRxDataToFifo & ~ShiftWillEnd)
2053 82 mohor
    RxDataLatched2 <=#Tp {RxDataLatched1[31:8], RxData};              // Big Endian Byte Ordering
2054 38 mohor
  else
2055 40 mohor
  if(SetWriteRxDataToFifo & ShiftWillEnd)
2056 105 mohor
    case(RxValidBytes)  // synopsys parallel_case
2057 82 mohor
 
2058
      1 : RxDataLatched2 <=#Tp {RxDataLatched1[31:24], 24'h0};
2059
      2 : RxDataLatched2 <=#Tp {RxDataLatched1[31:16], 16'h0};
2060
      3 : RxDataLatched2 <=#Tp {RxDataLatched1[31:8],   8'h0};
2061 40 mohor
    endcase
2062 38 mohor
end
2063
 
2064
 
2065 40 mohor
reg WriteRxDataToFifoSync1;
2066
reg WriteRxDataToFifoSync2;
2067 150 mohor
reg WriteRxDataToFifoSync3;
2068 38 mohor
 
2069
 
2070 40 mohor
// Indicating start of the reception process
2071 166 mohor
assign SetWriteRxDataToFifo = (RxValid & RxReady & ~RxStartFrm & RxEnableWindow & (&RxByteCnt)) |
2072
                              (RxValid & RxReady &  RxStartFrm & (&RxPointerLSB_rst))           |
2073
                              (ShiftWillEnd & LastByteIn & (&RxByteCnt));
2074 38 mohor
 
2075 150 mohor
always @ (posedge MRxClk or posedge Reset)
2076
begin
2077
  if(Reset)
2078
    WriteRxDataToFifo <=#Tp 1'b0;
2079
  else
2080
  if(SetWriteRxDataToFifo & ~RxAbort)
2081
    WriteRxDataToFifo <=#Tp 1'b1;
2082
  else
2083
  if(WriteRxDataToFifoSync2 | RxAbort)
2084
    WriteRxDataToFifo <=#Tp 1'b0;
2085
end
2086 40 mohor
 
2087 150 mohor
 
2088
 
2089
always @ (posedge WB_CLK_I or posedge Reset)
2090
begin
2091
  if(Reset)
2092
    WriteRxDataToFifoSync1 <=#Tp 1'b0;
2093
  else
2094
  if(WriteRxDataToFifo)
2095
    WriteRxDataToFifoSync1 <=#Tp 1'b1;
2096
  else
2097
    WriteRxDataToFifoSync1 <=#Tp 1'b0;
2098
end
2099
 
2100
always @ (posedge WB_CLK_I or posedge Reset)
2101
begin
2102
  if(Reset)
2103
    WriteRxDataToFifoSync2 <=#Tp 1'b0;
2104
  else
2105
    WriteRxDataToFifoSync2 <=#Tp WriteRxDataToFifoSync1;
2106
end
2107
 
2108
always @ (posedge WB_CLK_I or posedge Reset)
2109
begin
2110
  if(Reset)
2111
    WriteRxDataToFifoSync3 <=#Tp 1'b0;
2112
  else
2113
    WriteRxDataToFifoSync3 <=#Tp WriteRxDataToFifoSync2;
2114
end
2115
 
2116
wire WriteRxDataToFifo_wb;
2117
assign WriteRxDataToFifo_wb = WriteRxDataToFifoSync2 & ~WriteRxDataToFifoSync3;
2118
 
2119
 
2120 90 mohor
reg LatchedRxStartFrm;
2121
reg SyncRxStartFrm;
2122
reg SyncRxStartFrm_q;
2123 150 mohor
reg SyncRxStartFrm_q2;
2124 90 mohor
wire RxFifoReset;
2125 40 mohor
 
2126 90 mohor
always @ (posedge MRxClk or posedge Reset)
2127
begin
2128
  if(Reset)
2129
    LatchedRxStartFrm <=#Tp 0;
2130
  else
2131 150 mohor
  if(RxStartFrm & ~SyncRxStartFrm_q)
2132 90 mohor
    LatchedRxStartFrm <=#Tp 1;
2133
  else
2134 150 mohor
  if(SyncRxStartFrm_q)
2135 90 mohor
    LatchedRxStartFrm <=#Tp 0;
2136
end
2137
 
2138
 
2139
always @ (posedge WB_CLK_I or posedge Reset)
2140
begin
2141
  if(Reset)
2142
    SyncRxStartFrm <=#Tp 0;
2143
  else
2144
  if(LatchedRxStartFrm)
2145
    SyncRxStartFrm <=#Tp 1;
2146
  else
2147
    SyncRxStartFrm <=#Tp 0;
2148
end
2149
 
2150
 
2151
always @ (posedge WB_CLK_I or posedge Reset)
2152
begin
2153
  if(Reset)
2154
    SyncRxStartFrm_q <=#Tp 0;
2155
  else
2156
    SyncRxStartFrm_q <=#Tp SyncRxStartFrm;
2157
end
2158
 
2159 150 mohor
always @ (posedge WB_CLK_I or posedge Reset)
2160
begin
2161
  if(Reset)
2162
    SyncRxStartFrm_q2 <=#Tp 0;
2163
  else
2164
    SyncRxStartFrm_q2 <=#Tp SyncRxStartFrm_q;
2165
end
2166 90 mohor
 
2167
 
2168 150 mohor
assign RxFifoReset = SyncRxStartFrm_q & ~SyncRxStartFrm_q2;
2169 90 mohor
 
2170 150 mohor
 
2171 219 mohor
eth_fifo #(`ETH_RX_FIFO_DATA_WIDTH, `ETH_RX_FIFO_DEPTH, `ETH_RX_FIFO_CNT_WIDTH)
2172 88 mohor
rx_fifo (.data_in(RxDataLatched2),                      .data_out(m_wb_dat_o),
2173
         .clk(WB_CLK_I),                                .reset(Reset),
2174 219 mohor
         .write(WriteRxDataToFifo_wb & ~RxBufferFull),  .read(MasterWbRX & m_wb_ack_i),
2175 90 mohor
         .clear(RxFifoReset),                           .full(RxBufferFull),
2176 118 mohor
         .almost_full(),                                .almost_empty(RxBufferAlmostEmpty),
2177 150 mohor
         .empty(RxBufferEmpty),                         .cnt(rxfifo_cnt)
2178 88 mohor
        );
2179 40 mohor
 
2180 226 tadejm
assign enough_data_in_rxfifo_for_burst = rxfifo_cnt>=`ETH_BURST_LENGTH;
2181
assign enough_data_in_rxfifo_for_burst_plus1 = rxfifo_cnt>`ETH_BURST_LENGTH;
2182 219 mohor
assign WriteRxDataToMemory = ~RxBufferEmpty;
2183 226 tadejm
assign rx_burst = rx_burst_en & WriteRxDataToMemory;
2184 40 mohor
 
2185
 
2186
// Generation of the end-of-frame signal
2187
always @ (posedge MRxClk or posedge Reset)
2188 38 mohor
begin
2189 40 mohor
  if(Reset)
2190 159 mohor
    ShiftEnded_rck <=#Tp 1'b0;
2191 38 mohor
  else
2192 118 mohor
  if(~RxAbort & SetWriteRxDataToFifo & StartShiftWillEnd)
2193 159 mohor
    ShiftEnded_rck <=#Tp 1'b1;
2194 38 mohor
  else
2195 118 mohor
  if(RxAbort | ShiftEndedSync_c1 & ShiftEndedSync_c2)
2196 159 mohor
    ShiftEnded_rck <=#Tp 1'b0;
2197 38 mohor
end
2198
 
2199 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
2200
begin
2201
  if(Reset)
2202
    ShiftEndedSync1 <=#Tp 1'b0;
2203
  else
2204 159 mohor
    ShiftEndedSync1 <=#Tp ShiftEnded_rck;
2205 40 mohor
end
2206 38 mohor
 
2207 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
2208 38 mohor
begin
2209 40 mohor
  if(Reset)
2210
    ShiftEndedSync2 <=#Tp 1'b0;
2211 38 mohor
  else
2212 90 mohor
    ShiftEndedSync2 <=#Tp ShiftEndedSync1;
2213 40 mohor
end
2214 38 mohor
 
2215 118 mohor
always @ (posedge WB_CLK_I or posedge Reset)
2216
begin
2217
  if(Reset)
2218
    ShiftEndedSync3 <=#Tp 1'b0;
2219
  else
2220
  if(ShiftEndedSync1 & ~ShiftEndedSync2)
2221
    ShiftEndedSync3 <=#Tp 1'b1;
2222
  else
2223
  if(ShiftEnded)
2224
    ShiftEndedSync3 <=#Tp 1'b0;
2225
end
2226 38 mohor
 
2227 40 mohor
// Generation of the end-of-frame signal
2228
always @ (posedge WB_CLK_I or posedge Reset)
2229 38 mohor
begin
2230 40 mohor
  if(Reset)
2231
    ShiftEnded <=#Tp 1'b0;
2232 38 mohor
  else
2233 118 mohor
  if(ShiftEndedSync3 & MasterWbRX & m_wb_ack_i & RxBufferAlmostEmpty & ~ShiftEnded)
2234 40 mohor
    ShiftEnded <=#Tp 1'b1;
2235 38 mohor
  else
2236 40 mohor
  if(RxStatusWrite)
2237
    ShiftEnded <=#Tp 1'b0;
2238 38 mohor
end
2239
 
2240 118 mohor
always @ (posedge MRxClk or posedge Reset)
2241
begin
2242
  if(Reset)
2243
    ShiftEndedSync_c1 <=#Tp 1'b0;
2244
  else
2245
    ShiftEndedSync_c1 <=#Tp ShiftEndedSync2;
2246
end
2247 38 mohor
 
2248 118 mohor
always @ (posedge MRxClk or posedge Reset)
2249
begin
2250
  if(Reset)
2251
    ShiftEndedSync_c2 <=#Tp 1'b0;
2252
  else
2253
    ShiftEndedSync_c2 <=#Tp ShiftEndedSync_c1;
2254
end
2255
 
2256 40 mohor
// Generation of the end-of-frame signal
2257
always @ (posedge MRxClk or posedge Reset)
2258 38 mohor
begin
2259 40 mohor
  if(Reset)
2260
    RxEnableWindow <=#Tp 1'b0;
2261 38 mohor
  else
2262 40 mohor
  if(RxStartFrm)
2263
    RxEnableWindow <=#Tp 1'b1;
2264 38 mohor
  else
2265 40 mohor
  if(RxEndFrm | RxAbort)
2266
    RxEnableWindow <=#Tp 1'b0;
2267 38 mohor
end
2268
 
2269
 
2270 40 mohor
always @ (posedge WB_CLK_I or posedge Reset)
2271 38 mohor
begin
2272 40 mohor
  if(Reset)
2273
    RxAbortSync1 <=#Tp 1'b0;
2274 38 mohor
  else
2275 150 mohor
    RxAbortSync1 <=#Tp RxAbortLatched;
2276 40 mohor
end
2277
 
2278
always @ (posedge WB_CLK_I or posedge Reset)
2279
begin
2280
  if(Reset)
2281
    RxAbortSync2 <=#Tp 1'b0;
2282 38 mohor
  else
2283 40 mohor
    RxAbortSync2 <=#Tp RxAbortSync1;
2284 38 mohor
end
2285
 
2286 150 mohor
always @ (posedge WB_CLK_I or posedge Reset)
2287
begin
2288
  if(Reset)
2289
    RxAbortSync3 <=#Tp 1'b0;
2290
  else
2291
    RxAbortSync3 <=#Tp RxAbortSync2;
2292
end
2293
 
2294
always @ (posedge WB_CLK_I or posedge Reset)
2295
begin
2296
  if(Reset)
2297
    RxAbortSync4 <=#Tp 1'b0;
2298
  else
2299
    RxAbortSync4 <=#Tp RxAbortSync3;
2300
end
2301
 
2302 40 mohor
always @ (posedge MRxClk or posedge Reset)
2303
begin
2304
  if(Reset)
2305
    RxAbortSyncb1 <=#Tp 1'b0;
2306
  else
2307
    RxAbortSyncb1 <=#Tp RxAbortSync2;
2308
end
2309 38 mohor
 
2310 40 mohor
always @ (posedge MRxClk or posedge Reset)
2311 38 mohor
begin
2312 40 mohor
  if(Reset)
2313
    RxAbortSyncb2 <=#Tp 1'b0;
2314 38 mohor
  else
2315 40 mohor
    RxAbortSyncb2 <=#Tp RxAbortSyncb1;
2316 38 mohor
end
2317
 
2318
 
2319 64 mohor
always @ (posedge MRxClk or posedge Reset)
2320
begin
2321
  if(Reset)
2322
    RxAbortLatched <=#Tp 1'b0;
2323
  else
2324 150 mohor
  if(RxAbortSyncb2)
2325
    RxAbortLatched <=#Tp 1'b0;
2326
  else
2327 64 mohor
  if(RxAbort)
2328
    RxAbortLatched <=#Tp 1'b1;
2329
end
2330 40 mohor
 
2331 64 mohor
 
2332 42 mohor
always @ (posedge MRxClk or posedge Reset)
2333
begin
2334
  if(Reset)
2335
    LatchedRxLength[15:0] <=#Tp 16'h0;
2336
  else
2337 150 mohor
  if(LoadRxStatus)
2338 42 mohor
    LatchedRxLength[15:0] <=#Tp RxLength[15:0];
2339
end
2340
 
2341
 
2342 261 mohor
assign RxStatusIn = {ReceivedPauseFrm, AddressMiss, RxOverrun, InvalidSymbol, DribbleNibble, ReceivedPacketTooBig, ShortFrame, LatchedCrcError, RxLateCollision};
2343 42 mohor
 
2344
always @ (posedge MRxClk or posedge Reset)
2345
begin
2346
  if(Reset)
2347
    RxStatusInLatched <=#Tp 'h0;
2348
  else
2349 150 mohor
  if(LoadRxStatus)
2350 42 mohor
    RxStatusInLatched <=#Tp RxStatusIn;
2351
end
2352
 
2353
 
2354 60 mohor
// Rx overrun
2355
always @ (posedge WB_CLK_I or posedge Reset)
2356
begin
2357
  if(Reset)
2358
    RxOverrun <=#Tp 1'b0;
2359
  else
2360
  if(RxStatusWrite)
2361
    RxOverrun <=#Tp 1'b0;
2362
  else
2363
  if(RxBufferFull & WriteRxDataToFifo_wb)
2364
    RxOverrun <=#Tp 1'b1;
2365
end
2366 48 mohor
 
2367 77 mohor
 
2368
 
2369
wire TxError;
2370
assign TxError = TxUnderRun | RetryLimit | LateCollLatched | CarrierSenseLost;
2371
 
2372
wire RxError;
2373
 
2374 239 tadejm
// ShortFrame (RxStatusInLatched[2]) can not set an error because short frames
2375 250 mohor
// are aborted when signal r_RecSmall is set to 0 in MODER register. 
2376
// AddressMiss is identifying that a frame was received because of the promiscous
2377
// mode and is not an error
2378 239 tadejm
assign RxError = (|RxStatusInLatched[6:3]) | (|RxStatusInLatched[1:0]);
2379
 
2380 272 tadejm
 
2381
 
2382
reg RxStatusWriteLatched;
2383
reg RxStatusWriteLatched_sync1;
2384
reg RxStatusWriteLatched_sync2;
2385
reg RxStatusWriteLatched_syncb1;
2386
reg RxStatusWriteLatched_syncb2;
2387
 
2388
 
2389
// Latching and synchronizing RxStatusWrite signal. This signal is used for clearing the ReceivedPauseFrm signal
2390
always @ (posedge WB_CLK_I or posedge Reset)
2391
begin
2392
  if(Reset)
2393
    RxStatusWriteLatched <=#Tp 1'b0;
2394
  else
2395
  if(RxStatusWriteLatched_syncb2)
2396
    RxStatusWriteLatched <=#Tp 1'b0;
2397
  else
2398
  if(RxStatusWrite)
2399
    RxStatusWriteLatched <=#Tp 1'b1;
2400
end
2401
 
2402
 
2403
always @ (posedge MRxClk or posedge Reset)
2404
begin
2405
  if(Reset)
2406
    begin
2407
      RxStatusWriteLatched_sync1 <=#Tp 1'b0;
2408
      RxStatusWriteLatched_sync2 <=#Tp 1'b0;
2409
    end
2410
  else
2411
    begin
2412
      RxStatusWriteLatched_sync1 <=#Tp RxStatusWriteLatched;
2413
      RxStatusWriteLatched_sync2 <=#Tp RxStatusWriteLatched_sync1;
2414
    end
2415
end
2416
 
2417
 
2418
always @ (posedge WB_CLK_I or posedge Reset)
2419
begin
2420
  if(Reset)
2421
    begin
2422
      RxStatusWriteLatched_syncb1 <=#Tp 1'b0;
2423
      RxStatusWriteLatched_syncb2 <=#Tp 1'b0;
2424
    end
2425
  else
2426
    begin
2427
      RxStatusWriteLatched_syncb1 <=#Tp RxStatusWriteLatched_sync2;
2428
      RxStatusWriteLatched_syncb2 <=#Tp RxStatusWriteLatched_syncb1;
2429
    end
2430
end
2431
 
2432
 
2433
 
2434 77 mohor
// Tx Done Interrupt
2435
always @ (posedge WB_CLK_I or posedge Reset)
2436
begin
2437
  if(Reset)
2438
    TxB_IRQ <=#Tp 1'b0;
2439
  else
2440
  if(TxStatusWrite & TxIRQEn)
2441
    TxB_IRQ <=#Tp ~TxError;
2442
  else
2443
    TxB_IRQ <=#Tp 1'b0;
2444
end
2445
 
2446
 
2447
// Tx Error Interrupt
2448
always @ (posedge WB_CLK_I or posedge Reset)
2449
begin
2450
  if(Reset)
2451
    TxE_IRQ <=#Tp 1'b0;
2452
  else
2453
  if(TxStatusWrite & TxIRQEn)
2454
    TxE_IRQ <=#Tp TxError;
2455
  else
2456
    TxE_IRQ <=#Tp 1'b0;
2457
end
2458
 
2459
 
2460
// Rx Done Interrupt
2461
always @ (posedge WB_CLK_I or posedge Reset)
2462
begin
2463
  if(Reset)
2464
    RxB_IRQ <=#Tp 1'b0;
2465
  else
2466 270 mohor
  if(RxStatusWrite & RxIRQEn & ReceivedPacketGood & (~ReceivedPauseFrm | ReceivedPauseFrm & r_PassAll & (~r_RxFlow)))
2467
    RxB_IRQ <=#Tp (~RxError);
2468 77 mohor
  else
2469
    RxB_IRQ <=#Tp 1'b0;
2470
end
2471
 
2472
 
2473
// Rx Error Interrupt
2474
always @ (posedge WB_CLK_I or posedge Reset)
2475
begin
2476
  if(Reset)
2477
    RxE_IRQ <=#Tp 1'b0;
2478
  else
2479 270 mohor
  if(RxStatusWrite & RxIRQEn & (~ReceivedPauseFrm | ReceivedPauseFrm & r_PassAll & (~r_RxFlow)))
2480 77 mohor
    RxE_IRQ <=#Tp RxError;
2481
  else
2482
    RxE_IRQ <=#Tp 1'b0;
2483
end
2484
 
2485
 
2486 166 mohor
// Busy Interrupt
2487 77 mohor
 
2488 166 mohor
reg Busy_IRQ_rck;
2489
reg Busy_IRQ_sync1;
2490
reg Busy_IRQ_sync2;
2491
reg Busy_IRQ_sync3;
2492
reg Busy_IRQ_syncb1;
2493
reg Busy_IRQ_syncb2;
2494 77 mohor
 
2495
 
2496 166 mohor
always @ (posedge MRxClk or posedge Reset)
2497
begin
2498
  if(Reset)
2499
    Busy_IRQ_rck <=#Tp 1'b0;
2500
  else
2501
  if(RxValid & RxStartFrm & ~RxReady)
2502
    Busy_IRQ_rck <=#Tp 1'b1;
2503
  else
2504
  if(Busy_IRQ_syncb2)
2505
    Busy_IRQ_rck <=#Tp 1'b0;
2506
end
2507 77 mohor
 
2508 166 mohor
always @ (posedge WB_CLK_I)
2509
begin
2510
    Busy_IRQ_sync1 <=#Tp Busy_IRQ_rck;
2511
    Busy_IRQ_sync2 <=#Tp Busy_IRQ_sync1;
2512
    Busy_IRQ_sync3 <=#Tp Busy_IRQ_sync2;
2513
end
2514
 
2515
always @ (posedge MRxClk)
2516
begin
2517
    Busy_IRQ_syncb1 <=#Tp Busy_IRQ_sync2;
2518
    Busy_IRQ_syncb2 <=#Tp Busy_IRQ_syncb1;
2519
end
2520
 
2521
assign Busy_IRQ = Busy_IRQ_sync2 & ~Busy_IRQ_sync3;
2522
 
2523
 
2524 60 mohor
 
2525
 
2526
 
2527 38 mohor
endmodule

powered by: WebSVN 2.1.0

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