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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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