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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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