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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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