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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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