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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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