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 159

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

powered by: WebSVN 2.1.0

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