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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_7/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 113

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

powered by: WebSVN 2.1.0

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