OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [rtl/] [src_peripheral/] [ethmac/] [rtl/] [eth_wishbone.v] - Blame information for rev 48

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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