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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_14/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 110

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

powered by: WebSVN 2.1.0

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