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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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