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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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