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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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