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 88

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

powered by: WebSVN 2.1.0

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