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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_4/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 338

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

powered by: WebSVN 2.1.0

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