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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_6/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 111

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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