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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_14/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 77

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

powered by: WebSVN 2.1.0

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