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

Subversion Repositories ethmac

[/] [ethmac/] [trunk/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 166

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

powered by: WebSVN 2.1.0

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