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 167

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

powered by: WebSVN 2.1.0

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