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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [ethmac/] [eth_wishbone.v] - Blame information for rev 854

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

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

powered by: WebSVN 2.1.0

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