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

Subversion Repositories ethmac

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

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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