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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_14/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 226

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

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

powered by: WebSVN 2.1.0

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