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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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