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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [ethmac/] [eth_wishbone.v] - Blame information for rev 78

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

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

powered by: WebSVN 2.1.0

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