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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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