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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_7/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 164

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

powered by: WebSVN 2.1.0

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