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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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