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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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