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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_14/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 134

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

powered by: WebSVN 2.1.0

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