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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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