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 61

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

powered by: WebSVN 2.1.0

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