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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [ethmac/] [eth_wishbone.v] - Blame information for rev 409

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth_wishbone.v                                              ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6 409 julius
////  http://www.opencores.org/project,ethmac                   ////
7 6 julius
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Igor Mohor (igorM@opencores.org)                      ////
10
////                                                              ////
11
////  All additional information is available in the Readme.txt   ////
12
////  file.                                                       ////
13
////                                                              ////
14
//////////////////////////////////////////////////////////////////////
15
////                                                              ////
16
//// Copyright (C) 2001, 2002 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 409 julius
`include "ethmac_defines.v"
42 6 julius
`include "timescale.v"
43
 
44
 
45
module eth_wishbone
46 403 julius
  (
47 6 julius
 
48 403 julius
   // WISHBONE common
49
   WB_CLK_I, WB_DAT_I, WB_DAT_O,
50 6 julius
 
51 403 julius
   // WISHBONE slave
52
   WB_ADR_I, WB_WE_I, WB_ACK_O,
53
   BDCs,
54 6 julius
 
55 403 julius
   Reset,
56 6 julius
 
57 403 julius
   // WISHBONE master
58
   m_wb_adr_o, m_wb_sel_o, m_wb_we_o,
59
   m_wb_dat_o, m_wb_dat_i, m_wb_cyc_o,
60
   m_wb_stb_o, m_wb_ack_i, m_wb_err_i,
61 6 julius
 
62
`ifdef ETH_WISHBONE_B3
63 403 julius
   m_wb_cti_o, m_wb_bte_o,
64 6 julius
`endif
65
 
66 403 julius
   //TX
67
   MTxClk, TxStartFrm, TxEndFrm, TxUsedData, TxData,
68
   TxRetry, TxAbort, TxUnderRun, TxDone, PerPacketCrcEn,
69
   PerPacketPad,
70 6 julius
 
71 403 julius
   //RX
72
   MRxClk, RxData, RxValid, RxStartFrm, RxEndFrm, RxAbort, RxStatusWriteLatched_sync2,
73
 
74
   // Register
75
   r_TxEn, r_RxEn, r_TxBDNum, r_RxFlow, r_PassAll,
76 6 julius
 
77 403 julius
   // Interrupts
78
   TxB_IRQ, TxE_IRQ, RxB_IRQ, RxE_IRQ, Busy_IRQ,
79
 
80
   // Rx Status
81
   InvalidSymbol, LatchedCrcError, RxLateCollision, ShortFrame, DribbleNibble,
82
   ReceivedPacketTooBig, RxLength, LoadRxStatus, ReceivedPacketGood, AddressMiss,
83
   ReceivedPauseFrm,
84
 
85
   // Tx Status
86
   RetryCntLatched, RetryLimit, LateCollLatched, DeferLatched, RstDeferLatched, CarrierSenseLost
87 6 julius
 
88 403 julius
   // Bist
89 6 julius
`ifdef ETH_BIST
90 403 julius
   ,
91
   // debug chain signals
92
   mbist_si_i,       // bist scan serial in
93
   mbist_so_o,       // bist scan serial out
94
   mbist_ctrl_i        // bist chain shift control
95 6 julius
`endif
96
 
97 403 julius
`ifdef WISHBONE_DEBUG
98
   ,
99
   dbg_dat0
100
`endif
101 6 julius
 
102
 
103 403 julius
   );
104 6 julius
 
105
 
106 403 julius
   //parameter Tp = 1;
107
   parameter Tp = 0;
108 6 julius
 
109
 
110 403 julius
   // WISHBONE common
111
   input           WB_CLK_I;       // WISHBONE clock
112
   input [31:0]    WB_DAT_I;       // WISHBONE data input
113
   output [31:0]   WB_DAT_O;       // WISHBONE data output
114 6 julius
 
115 403 julius
   // WISHBONE slave
116
   input [9:2]     WB_ADR_I;       // WISHBONE address input
117
   input           WB_WE_I;        // WISHBONE write enable input
118
   input [3:0]      BDCs;           // Buffer descriptors are selected
119
   output          WB_ACK_O;       // WISHBONE acknowledge output
120 6 julius
 
121 403 julius
   // WISHBONE master
122
   output [29:0]   m_wb_adr_o;     // 
123
   output [3:0]    m_wb_sel_o;     // 
124
   output          m_wb_we_o;      // 
125
   output [31:0]   m_wb_dat_o;     // 
126
   output          m_wb_cyc_o;     // 
127
   output          m_wb_stb_o;     // 
128
   input [31:0]    m_wb_dat_i;     // 
129
   input           m_wb_ack_i;     // 
130
   input           m_wb_err_i;     // 
131 69 julius
 
132 6 julius
`ifdef ETH_WISHBONE_B3
133 403 julius
   output [2:0]    m_wb_cti_o;     // Cycle Type Identifier
134
 `ifdef BURST_4BEAT
135
   output reg [1:0] m_wb_bte_o;     // Burst Type Extension
136
 `else
137
   output [1:0]     m_wb_bte_o;     // Burst Type Extension
138
 `endif
139
   reg [2:0]         m_wb_cti_o;     // Cycle Type Identifier
140 6 julius
`endif
141
 
142 403 julius
   input            Reset;       // Reset signal
143 6 julius
 
144 403 julius
   // Rx Status signals
145
   input            InvalidSymbol;    // Invalid symbol was received during 
146
                                      // reception in 100 Mbps mode
147
   input            LatchedCrcError;  // CRC error
148
   input            RxLateCollision;  // Late collision occured while receiving
149
                                      // frame
150
   input            ShortFrame;       // Frame shorter then the minimum size 
151
                                      // (r_MinFL) was received while small 
152
                                      // packets are enabled (r_RecSmall)
153
   input            DribbleNibble;    // Extra nibble received
154
   input            ReceivedPacketTooBig;// Received packet is bigger than 
155
                                         // r_MaxFL
156
   input [15:0]     RxLength;         // Length of the incoming frame
157
   input            LoadRxStatus;     // Rx status was loaded
158
   input            ReceivedPacketGood;// Received packet's length and CRC are 
159
                                       // good
160
   input            AddressMiss;      // When a packet is received AddressMiss 
161
                                      // status is written to the Rx BD
162
   input            r_RxFlow;
163
   input            r_PassAll;
164
   input            ReceivedPauseFrm;
165 6 julius
 
166 403 julius
   // Tx Status signals
167
   input [3:0]       RetryCntLatched;  // Latched Retry Counter
168
   input            RetryLimit;       // Retry limit reached (Retry Max value +
169
                                      //  1 attempts were made)
170
   input            LateCollLatched;  // Late collision occured
171
   input            DeferLatched;     // Defer indication (Frame was defered 
172
                                      // before sucessfully sent)
173
   output           RstDeferLatched;
174
   input            CarrierSenseLost; // Carrier Sense was lost during the 
175
                                      // frame transmission
176 6 julius
 
177 403 julius
   // Tx
178
   input            MTxClk;         // Transmit clock (from PHY)
179
   input            TxUsedData;     // Transmit packet used data
180
   input            TxRetry;        // Transmit packet retry
181
   input            TxAbort;        // Transmit packet abort
182
   input            TxDone;         // Transmission ended
183
   output           TxStartFrm;     // Transmit packet start frame
184
   output           TxEndFrm;       // Transmit packet end frame
185
   output [7:0]     TxData;         // Transmit packet data byte
186
   output           TxUnderRun;     // Transmit packet under-run
187
   output           PerPacketCrcEn; // Per packet crc enable
188
   output           PerPacketPad;   // Per packet pading
189 6 julius
 
190 403 julius
   // Rx
191
   input            MRxClk;         // Receive clock (from PHY)
192
   input [7:0]       RxData;         // Received data byte (from PHY)
193
   input            RxValid;        // 
194
   input            RxStartFrm;     // 
195
   input            RxEndFrm;       // 
196
   input            RxAbort;        // This signal is set when address doesn't
197
                                    // match.
198
   output           RxStatusWriteLatched_sync2;
199 6 julius
 
200 403 julius
   //Register
201
   input            r_TxEn;         // Transmit enable
202
   input            r_RxEn;         // Receive enable
203
   input [7:0]       r_TxBDNum;      // Receive buffer descriptor number
204 6 julius
 
205 403 julius
   // Interrupts
206
   output           TxB_IRQ;
207
   output           TxE_IRQ;
208
   output           RxB_IRQ;
209
   output           RxE_IRQ;
210
   output           Busy_IRQ;
211 6 julius
 
212
 
213 403 julius
   // Bist
214 6 julius
`ifdef ETH_BIST
215 403 julius
   input            mbist_si_i;       // bist scan serial in
216
   output           mbist_so_o;       // bist scan serial out
217
   input [`ETH_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i; // bist chain shift control
218 6 julius
`endif
219
 
220 403 julius
`ifdef WISHBONE_DEBUG
221
   output [31:0]                        dbg_dat0;
222
`endif
223 6 julius
 
224
 
225
 
226 403 julius
   reg                                 TxB_IRQ;
227
   reg                                 TxE_IRQ;
228
   reg                                 RxB_IRQ;
229
   reg                                 RxE_IRQ;
230 6 julius
 
231 403 julius
   reg                                 TxStartFrm;
232
   reg                                 TxEndFrm;
233
   reg [7:0]                            TxData;
234 6 julius
 
235 403 julius
   reg                                 TxUnderRun;
236
   reg                                 TxUnderRun_wb;
237 6 julius
 
238 403 julius
   reg                                 TxBDRead;
239
   wire                                TxStatusWrite;
240 6 julius
 
241 403 julius
   reg [1:0]                            TxValidBytesLatched;
242 6 julius
 
243 403 julius
   reg [15:0]                           TxLength;
244
   reg [15:0]                           LatchedTxLength;
245
   reg [14:11]                         TxStatus;
246 6 julius
 
247 403 julius
   reg [14:13]                         RxStatus;
248 6 julius
 
249 403 julius
   reg                                 TxStartFrm_wb;
250
   reg                                 TxRetry_wb;
251
   reg                                 TxAbort_wb;
252
   reg                                 TxDone_wb;
253 6 julius
 
254 403 julius
   reg                                 TxDone_wb_q;
255
   reg                                 TxAbort_wb_q;
256
   reg                                 TxRetry_wb_q;
257
   reg                                 TxRetryPacket;
258
   reg                                 TxRetryPacket_NotCleared;
259
   reg                                 TxDonePacket;
260
   reg                                 TxDonePacket_NotCleared;
261
   reg                                 TxAbortPacket;
262
   reg                                 TxAbortPacket_NotCleared;
263
   reg                                 RxBDReady;
264
   reg                                 RxBDOK;
265
   reg                                 TxBDReady;
266 6 julius
 
267 403 julius
   reg                                 RxBDRead;
268 6 julius
 
269 403 julius
   reg [31:0]                           TxDataLatched;
270
   reg [1:0]                            TxByteCnt;
271
   reg                                 LastWord;
272
   reg                                 ReadTxDataFromFifo_tck;
273 6 julius
 
274 403 julius
   reg                                 BlockingTxStatusWrite;
275
   reg                                 BlockingTxBDRead;
276 6 julius
 
277 403 julius
   reg                                 Flop;
278 6 julius
 
279 403 julius
   reg [7:1]                           TxBDAddress;
280
   reg [7:1]                           RxBDAddress;
281 6 julius
 
282 403 julius
   reg                                 TxRetrySync1;
283
   reg                                 TxAbortSync1;
284
   reg                                 TxDoneSync1;
285 6 julius
 
286 403 julius
   reg                                 TxAbort_q;
287
   reg                                 TxRetry_q;
288
   reg                                 TxUsedData_q;
289 6 julius
 
290 403 julius
   reg [31:0]                           RxDataLatched2;
291 6 julius
 
292 403 julius
   reg [31:8]                          RxDataLatched1;     // Big Endian Byte Ordering
293 6 julius
 
294 403 julius
   reg [1:0]                            RxValidBytes;
295
   reg [1:0]                            RxByteCnt;
296
   reg                                 LastByteIn;
297
   reg                                 ShiftWillEnd;
298 6 julius
 
299 403 julius
   reg                                 WriteRxDataToFifo;
300
   reg [15:0]                           LatchedRxLength;
301
   reg                                 RxAbortLatched;
302 6 julius
 
303 403 julius
   reg                                 ShiftEnded;
304
   reg                                 RxOverrun;
305 6 julius
 
306 403 julius
   reg [3:0]                            BDWrite;                    // BD Write Enable for access from WISHBONE side
307
   reg                                 BDRead;                     // BD Read access from WISHBONE side
308
   wire [31:0]                          RxBDDataIn;                 // Rx BD data in
309
   wire [31:0]                          TxBDDataIn;                 // Tx BD data in
310 6 julius
 
311 403 julius
   reg                                 TxEndFrm_wb;
312 6 julius
 
313 403 julius
   wire                                TxRetryPulse;
314
   wire                                TxDonePulse;
315
   wire                                TxAbortPulse;
316 6 julius
 
317 403 julius
   wire                                StartRxBDRead;
318 6 julius
 
319 403 julius
   wire                                StartTxBDRead;
320 6 julius
 
321 403 julius
   wire                                TxIRQEn;
322
   wire                                WrapTxStatusBit;
323 6 julius
 
324 403 julius
   wire                                RxIRQEn;
325
   wire                                WrapRxStatusBit;
326 6 julius
 
327 403 julius
   wire [1:0]                           TxValidBytes;
328 6 julius
 
329 403 julius
   wire [7:1]                          TempTxBDAddress;
330
   wire [7:1]                          TempRxBDAddress;
331 6 julius
 
332 403 julius
   wire                                RxStatusWrite;
333
   wire                                RxBufferFull;
334
   wire                                RxBufferAlmostEmpty;
335
   wire                                RxBufferEmpty;
336 6 julius
 
337 403 julius
   reg                                 WB_ACK_O;
338 6 julius
 
339 403 julius
   wire [8:0]                           RxStatusIn;
340
   reg [8:0]                            RxStatusInLatched;
341 6 julius
 
342 403 julius
   reg                                 WbEn, WbEn_q;
343
   reg                                 RxEn, RxEn_q;
344
   reg                                 TxEn, TxEn_q;
345
   reg                                 r_TxEn_q;
346
   reg                                 r_RxEn_q;
347 6 julius
 
348 403 julius
   wire                                ram_ce;
349
   wire [3:0]                           ram_we;
350
   wire                                ram_oe;
351
   reg [7:0]                            ram_addr;
352
   reg [31:0]                           ram_di;
353
   wire [31:0]                          ram_do;
354
 
355
   wire                                StartTxPointerRead;
356
   reg                                 TxPointerRead;
357
   reg                                 TxEn_needed;
358
   reg                                 RxEn_needed;
359
 
360
   wire                                StartRxPointerRead;
361
   reg                                 RxPointerRead;
362
 
363
   // RX shift ending signals
364
   reg ShiftEnded_rck;
365
   reg ShiftEndedSync1;
366
   reg ShiftEndedSync2;
367
   reg ShiftEndedSync3;
368
   reg ShiftEndedSync_c1;
369
   reg ShiftEndedSync_c2;
370
 
371
   wire StartShiftWillEnd;
372
 
373
   // Pulse for wishbone side having finished writing back
374
   reg  rx_wb_writeback_finished;
375
   // Indicator of last set of writes from the Wishbone master coming up
376
   reg  rx_wb_last_writes;
377
 
378
 
379
`ifdef TXBD_POLL
380
   reg [31:0]                           TxBDReadySamples; // -- jb
381
   wire                                TxBDNotReady; // -- jb
382
`endif
383
 
384 6 julius
`ifdef ETH_WISHBONE_B3
385 403 julius
 `ifndef BURST_4BEAT
386
   assign m_wb_bte_o = 2'b00;    // Linear burst
387
 `endif
388 6 julius
`endif
389
 
390 403 julius
   assign m_wb_stb_o = m_wb_cyc_o;
391 6 julius
 
392 403 julius
   always @ (posedge WB_CLK_I)
393
     begin
394
        WB_ACK_O <= (|BDWrite) & WbEn & WbEn_q | BDRead & WbEn & ~WbEn_q;
395
     end
396 6 julius
 
397 403 julius
   assign WB_DAT_O = ram_do;
398 6 julius
 
399 403 julius
   // Generic synchronous single-port RAM interface
400
   eth_spram_256x32
401
     #(1) // Write enable width
402
     bd_ram
403
     (
404
      .clk     (WB_CLK_I),
405
      .rst     (Reset),
406
      .ce      (ram_ce),
407
      .we      (ram_we[0]),
408
      .oe      (ram_oe),
409
      .addr    (ram_addr),
410
      .di      (ram_di),
411
      .do      (ram_do)
412 6 julius
`ifdef ETH_BIST
413 403 julius
      ,
414
      .mbist_si_i       (mbist_si_i),
415
      .mbist_so_o       (mbist_so_o),
416
      .mbist_ctrl_i       (mbist_ctrl_i)
417 6 julius
`endif
418 403 julius
      );
419 6 julius
 
420 403 julius
   assign ram_ce = 1'b1;
421
   assign ram_we = (BDWrite & {4{(WbEn & WbEn_q)}}) |
422
                   {4{(TxStatusWrite | RxStatusWrite)}};
423
   assign ram_oe = BDRead & WbEn & WbEn_q | TxEn & TxEn_q &
424
                   (TxBDRead | TxPointerRead) | RxEn & RxEn_q &
425
                   (RxBDRead | RxPointerRead);
426 6 julius
 
427
 
428 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
429
     begin
430
        if(Reset)
431
          TxEn_needed <= 1'b0;
432
        else
433
          if(~TxBDReady & r_TxEn & WbEn & ~WbEn_q)
434
            TxEn_needed <= 1'b1;
435
          else
436
            if(TxPointerRead & TxEn & TxEn_q)
437
              TxEn_needed <= 1'b0;
438
     end
439 6 julius
 
440 403 julius
   // Enabling access to the RAM for three devices.
441
   always @ (posedge WB_CLK_I or posedge Reset)
442
     begin
443
        if(Reset)
444
          begin
445
             WbEn <= 1'b1;
446
             RxEn <= 1'b0;
447
             TxEn <= 1'b0;
448
             ram_addr <= 8'h0;
449
             ram_di <= 32'h0;
450
             BDRead <= 1'b0;
451
             BDWrite <= 1'b0;
452
          end
453
        else
454
          begin
455
             // Switching between three stages depends on enable signals
456
             case ({WbEn_q, RxEn_q, TxEn_q, RxEn_needed, TxEn_needed})  // synopsys parallel_case
457
               5'b100_10, 5'b100_11 :
458
                 begin
459
                    WbEn <= 1'b0;
460
                    RxEn <= 1'b1;  // wb access stage and r_RxEn is enabled
461
                    TxEn <= 1'b0;
462
                    ram_addr <= {RxBDAddress, RxPointerRead};
463
                    ram_di <= RxBDDataIn;
464
                 end
465
               5'b100_01 :
466
                 begin
467
                    WbEn <= 1'b0;
468
                    RxEn <= 1'b0;
469
                    TxEn <= 1'b1;  // wb access stage, r_RxEn is disabled but 
470
                                   // r_TxEn is enabled
471
                    ram_addr <= {TxBDAddress, TxPointerRead};
472
                    ram_di <= TxBDDataIn;
473
                 end
474
               5'b010_00, 5'b010_10 :
475
                 begin
476
                    WbEn <= 1'b1;  // RxEn access stage and r_TxEn is disabled
477
                    RxEn <= 1'b0;
478
                    TxEn <= 1'b0;
479
                    ram_addr <= WB_ADR_I[9:2];
480
                    ram_di <= WB_DAT_I;
481
                    BDWrite <= BDCs[3:0] & {4{WB_WE_I}};
482
                    BDRead <= (|BDCs) & ~WB_WE_I;
483
                 end
484
               5'b010_01, 5'b010_11 :
485
                 begin
486
                    WbEn <= 1'b0;
487
                    RxEn <= 1'b0;
488
                    TxEn <= 1'b1;  // RxEn access stage and r_TxEn is enabled
489
                    ram_addr <= {TxBDAddress, TxPointerRead};
490
                    ram_di <= TxBDDataIn;
491
                 end
492
               5'b001_00, 5'b001_01, 5'b001_10, 5'b001_11 :
493
                 begin
494
                    WbEn <= 1'b1;  // TxEn access stage (we always go to wb 
495
                                   // access stage)
496
                    RxEn <= 1'b0;
497
                    TxEn <= 1'b0;
498
                    ram_addr <= WB_ADR_I[9:2];
499
                    ram_di <= WB_DAT_I;
500
                    BDWrite <= BDCs[3:0] & {4{WB_WE_I}};
501
                    BDRead <= (|BDCs) & ~WB_WE_I;
502
                 end
503
               5'b100_00 :
504
                 begin
505
                    WbEn <= 1'b0;  // WbEn access stage and there is no need 
506
                                   // for other stages. WbEn needs to be 
507
                                   // switched off for a bit
508
                 end
509
               5'b000_00 :
510
                 begin
511
                    WbEn <= 1'b1;  // Idle state. We go to WbEn access stage.
512
                    RxEn <= 1'b0;
513
                    TxEn <= 1'b0;
514
                    ram_addr <= WB_ADR_I[9:2];
515
                    ram_di <= WB_DAT_I;
516
                    BDWrite <= BDCs[3:0] & {4{WB_WE_I}};
517
                    BDRead <= (|BDCs) & ~WB_WE_I;
518
                 end
519
             endcase
520
          end
521
     end
522 6 julius
 
523
 
524 403 julius
   // Delayed stage signals
525
   always @ (posedge WB_CLK_I or posedge Reset)
526
     begin
527
        if(Reset)
528
          begin
529
             WbEn_q <= 1'b0;
530
             RxEn_q <= 1'b0;
531
             TxEn_q <= 1'b0;
532
             r_TxEn_q <= 1'b0;
533
             r_RxEn_q <= 1'b0;
534
          end
535
        else
536
          begin
537
             WbEn_q <= WbEn;
538
             RxEn_q <= RxEn;
539
             TxEn_q <= TxEn;
540
             r_TxEn_q <= r_TxEn;
541
             r_RxEn_q <= r_RxEn;
542
          end
543
     end
544 6 julius
 
545 403 julius
   // Changes for tx occur every second clock. Flop is used for this manner.
546
   always @ (posedge MTxClk or posedge Reset)
547
     begin
548
        if(Reset)
549
          Flop <= 1'b0;
550
        else
551
          if(TxDone | TxAbort | TxRetry_q)
552
            Flop <= 1'b0;
553
          else
554
            if(TxUsedData)
555
              Flop <= ~Flop;
556
     end
557 6 julius
 
558 403 julius
   wire ResetTxBDReady;
559
   assign ResetTxBDReady = TxDonePulse | TxAbortPulse | TxRetryPulse;
560 6 julius
 
561 403 julius
   // Latching READY status of the Tx buffer descriptor
562
   always @ (posedge WB_CLK_I or posedge Reset)
563
     begin
564
        if(Reset)
565
          TxBDReady <= 1'b0;
566
        else
567
          if(TxEn & TxEn_q & TxBDRead)
568
            // TxBDReady is sampled only once at the beginning.
569
            TxBDReady <= ram_do[15] & (ram_do[31:16] > 4);
570
          else
571
            // Only packets larger then 4 bytes are transmitted.
572
            if(ResetTxBDReady)
573
              TxBDReady <= 1'b0;
574
     end
575 6 julius
 
576 403 julius
`ifdef TXBD_POLL
577
   // Register TxBDReady 4 times, when all are low we know this one is not 
578
   // good to transmit
579 69 julius
   always @(posedge WB_CLK_I or posedge Reset) // -- jb
580
     begin
581
        if (Reset) TxBDReadySamples <= 32'hffffffff;
582
        else begin
583
           if (r_TxEn)
584
             begin
585
                if (TxBDNotReady)
586 403 julius
                  TxBDReadySamples <= 32'hffffffff;
587 69 julius
                else
588
                  TxBDReadySamples[31:0] <= {TxBDReadySamples[30:0],TxBDReady};
589
             end
590 403 julius
           else
591
             TxBDReadySamples <= 32'hffffffff;
592 69 julius
        end // else: !if(Reset)
593
     end // always @ (posedge WB_CLK_I or posedge Reset)
594 403 julius
   // When all low, this goes high -- jb
595
   assign TxBDNotReady = ~(|TxBDReadySamples);
596
 
597 69 julius
 
598 403 julius
`endif
599 6 julius
 
600 403 julius
   // Reading the Tx buffer descriptor
601
   assign StartTxBDRead = (TxRetryPacket_NotCleared | TxStatusWrite) &
602
                          ~BlockingTxBDRead & ~TxBDReady;
603 69 julius
 
604 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
605
     begin
606
        if(Reset)
607
          TxBDRead <= 1'b1;
608
        else
609
          if(StartTxBDRead)
610
            TxBDRead <= 1'b1;
611
          else
612
            if(TxBDReady)
613
              TxBDRead <= 1'b0;
614
     end
615 6 julius
 
616
 
617 403 julius
   // Reading Tx BD pointer
618
   assign StartTxPointerRead = TxBDRead & TxBDReady;
619 6 julius
 
620 403 julius
   // Reading Tx BD Pointer
621
   always @ (posedge WB_CLK_I or posedge Reset)
622
     begin
623
        if(Reset)
624
          TxPointerRead <= 1'b0;
625
        else
626
          if(StartTxPointerRead)
627
            TxPointerRead <= 1'b1;
628
          else
629
            if(TxEn_q)
630
              TxPointerRead <= 1'b0;
631
     end
632 6 julius
 
633
 
634 403 julius
   // Writing status back to the Tx buffer descriptor
635
   assign TxStatusWrite = (TxDonePacket_NotCleared | TxAbortPacket_NotCleared)&
636
                          TxEn & TxEn_q & ~BlockingTxStatusWrite;
637 6 julius
 
638
 
639
 
640 403 julius
   // Status writing must occur only once. Meanwhile it is blocked.
641
   always @ (posedge WB_CLK_I or posedge Reset)
642
     begin
643
        if(Reset)
644
          BlockingTxStatusWrite <= 1'b0;
645
        else
646
          if(~TxDone_wb & ~TxAbort_wb)
647
            BlockingTxStatusWrite <= 1'b0;
648
          else
649
            if(TxStatusWrite)
650
              BlockingTxStatusWrite <= 1'b1;
651
     end
652 6 julius
 
653
 
654 403 julius
   reg BlockingTxStatusWrite_sync1;
655
   reg BlockingTxStatusWrite_sync2;
656
   reg BlockingTxStatusWrite_sync3;
657 6 julius
 
658 403 julius
   // Synchronizing BlockingTxStatusWrite to MTxClk
659
   always @ (posedge MTxClk or posedge Reset)
660
     begin
661
        if(Reset)
662
          BlockingTxStatusWrite_sync1 <= 1'b0;
663
        else
664
          BlockingTxStatusWrite_sync1 <= BlockingTxStatusWrite;
665
     end
666 6 julius
 
667 403 julius
   // Synchronizing BlockingTxStatusWrite to MTxClk
668
   always @ (posedge MTxClk or posedge Reset)
669
     begin
670
        if(Reset)
671
          BlockingTxStatusWrite_sync2 <= 1'b0;
672
        else
673
          BlockingTxStatusWrite_sync2 <= BlockingTxStatusWrite_sync1;
674
     end
675 6 julius
 
676 403 julius
   // Synchronizing BlockingTxStatusWrite to MTxClk
677
   always @ (posedge MTxClk or posedge Reset)
678
     begin
679
        if(Reset)
680
          BlockingTxStatusWrite_sync3 <= 1'b0;
681
        else
682
          BlockingTxStatusWrite_sync3 <= BlockingTxStatusWrite_sync2;
683
     end
684 6 julius
 
685 403 julius
   assign RstDeferLatched = BlockingTxStatusWrite_sync2 &
686
                            ~BlockingTxStatusWrite_sync3;
687 6 julius
 
688 403 julius
   // TxBDRead state is activated only once. 
689
   always @ (posedge WB_CLK_I or posedge Reset)
690
     begin
691
        if(Reset)
692
          BlockingTxBDRead <= 1'b0;
693
        else
694
          if(StartTxBDRead)
695
            BlockingTxBDRead <= 1'b1;
696
          else
697
            if(~StartTxBDRead & ~TxBDReady)
698
              BlockingTxBDRead <= 1'b0;
699
     end
700 6 julius
 
701
 
702 403 julius
   // Latching status from the tx buffer descriptor
703
   // Data is avaliable one cycle after the access is started (at that time 
704
   // signal TxEn is not active)
705
   always @ (posedge WB_CLK_I or posedge Reset)
706
     begin
707
        if(Reset)
708
          TxStatus <= 4'h0;
709
        else
710
          if(TxEn & TxEn_q & TxBDRead)
711
            TxStatus <= ram_do[14:11];
712
     end
713 6 julius
 
714 403 julius
   reg ReadTxDataFromMemory;
715
   wire WriteRxDataToMemory;
716
   reg WriteRxDataToMemory_r;
717 6 julius
 
718 403 julius
   // Register WriteRxDataToMemory in Wishbone clock domain
719
   // so it doesn't get out of sync with burst capability indication signals
720
   always @(posedge WB_CLK_I or posedge Reset)
721
     if (Reset)
722
       WriteRxDataToMemory_r <= 0;
723
     else
724
       WriteRxDataToMemory_r <= WriteRxDataToMemory;
725
 
726
   reg  MasterWbTX;
727
   reg  MasterWbRX;
728 6 julius
 
729 403 julius
   reg [29:0] m_wb_adr_o;
730
   reg        m_wb_cyc_o;
731
   reg [3:0]  m_wb_sel_o;
732
   reg        m_wb_we_o;
733 6 julius
 
734 403 julius
   wire       TxLengthEq0;
735
   wire       TxLengthLt4;
736 6 julius
 
737 403 julius
   reg        BlockingIncrementTxPointer;
738
   reg [31:2] TxPointerMSB;
739
   reg [1:0]  TxPointerLSB;
740
   reg [1:0]  TxPointerLSB_rst;
741
   reg [31:2] RxPointerMSB;
742
   reg [1:0]  RxPointerLSB_rst;
743 6 julius
 
744 403 julius
   wire       RxBurstAcc;
745
   wire       RxWordAcc;
746
   wire       RxHalfAcc;
747
   wire       RxByteAcc;
748 6 julius
 
749 403 julius
   //Latching length from the buffer descriptor;
750
   always @ (posedge WB_CLK_I or posedge Reset)
751
     begin
752
        if(Reset)
753
          TxLength <= 16'h0;
754
        else
755
          if(TxEn & TxEn_q & TxBDRead)
756
            TxLength <= ram_do[31:16];
757
          else
758
            if(MasterWbTX & m_wb_ack_i)
759
              begin
760
                 if(TxLengthLt4)
761
                   TxLength <= 16'h0;
762
                 else
763
                   if(TxPointerLSB_rst==2'h0)
764
                     TxLength <= TxLength - 3'h4;    // Length is subtracted at
765
                                                     // the data request
766
                   else
767
                     if(TxPointerLSB_rst==2'h1)
768
                       TxLength <= TxLength - 3'h3;    // Length is subtracted 
769
                                                       // at the data request
770
                     else
771
                       if(TxPointerLSB_rst==2'h2)
772
                         TxLength <= TxLength - 3'h2;    // Length is subtracted
773
                                                         // at the data request
774
                       else
775
                         if(TxPointerLSB_rst==2'h3)
776
                           TxLength <= TxLength - 3'h1;  // Length is subtracted
777
                                                         // at the data request
778
              end
779
     end
780 6 julius
 
781
 
782
 
783 403 julius
   //Latching length from the buffer descriptor;
784
   always @ (posedge WB_CLK_I or posedge Reset)
785
     begin
786
        if(Reset)
787
          LatchedTxLength <= 16'h0;
788
        else
789
          if(TxEn & TxEn_q & TxBDRead)
790
            LatchedTxLength <= ram_do[31:16];
791
     end
792 6 julius
 
793 403 julius
   assign TxLengthEq0 = TxLength == 0;
794
   assign TxLengthLt4 = TxLength < 4;
795 6 julius
 
796 403 julius
   reg cyc_cleared;
797
   reg IncrTxPointer;
798 6 julius
 
799
 
800 403 julius
   // Latching Tx buffer pointer from buffer descriptor. Only 30 MSB bits are 
801
   // latched because TxPointerMSB is only used for word-aligned accesses.
802
   always @ (posedge WB_CLK_I or posedge Reset)
803
     begin
804
        if(Reset)
805
          TxPointerMSB <= 30'h0;
806
        else
807
          if(TxEn & TxEn_q & TxPointerRead)
808
            TxPointerMSB <= ram_do[31:2];
809
          else
810
            if(IncrTxPointer & ~BlockingIncrementTxPointer)
811
              // TxPointer is word-aligned
812
              TxPointerMSB <= TxPointerMSB + 1'b1;
813
     end
814 6 julius
 
815
 
816 403 julius
   // Latching 2 MSB bits of the buffer descriptor. Since word accesses are 
817
   // performed, valid data does not necesserly start at byte 0 (could be byte 
818
   // 0, 1, 2 or 3). This signals are used for proper selection of the start 
819
   // byte (TxData and TxByteCnt) are set by this two bits.
820
   always @ (posedge WB_CLK_I or posedge Reset)
821
     begin
822
        if(Reset)
823
          TxPointerLSB[1:0] <= 0;
824
        else
825
          if(TxEn & TxEn_q & TxPointerRead)
826
            TxPointerLSB[1:0] <= ram_do[1:0];
827
     end
828 6 julius
 
829
 
830 403 julius
   // Latching 2 MSB bits of the buffer descriptor. 
831
   // After the read access, TxLength needs to be decremented for the number of
832
   // the valid bytes (1 to 4 bytes are valid in the first word). After the 
833
   // first read all bytes are valid so this two bits are reset to zero. 
834
   always @ (posedge WB_CLK_I or posedge Reset)
835
     begin
836
        if(Reset)
837
          TxPointerLSB_rst[1:0] <= 0;
838
        else
839
          if(TxEn & TxEn_q & TxPointerRead)
840
            TxPointerLSB_rst[1:0] <= ram_do[1:0];
841
          else
842
            // After first access pointer is word alligned
843
            if(MasterWbTX & m_wb_ack_i)
844
              TxPointerLSB_rst[1:0] <= 0;
845
     end
846 6 julius
 
847
 
848 403 julius
   reg  [3:0] RxByteSel;
849
   wire       MasterAccessFinished;
850 6 julius
 
851
 
852 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
853
     begin
854
        if(Reset)
855
          BlockingIncrementTxPointer <= 0;
856
        else
857
          if(MasterAccessFinished)
858
            BlockingIncrementTxPointer <= 0;
859
          else
860
            if(IncrTxPointer)
861
              BlockingIncrementTxPointer <= 1'b1;
862
     end
863 6 julius
 
864
 
865 403 julius
   wire TxBufferAlmostFull;
866
   wire TxBufferFull;
867
   wire TxBufferEmpty;
868
   wire TxBufferAlmostEmpty;
869
   wire SetReadTxDataFromMemory;
870 6 julius
 
871 403 julius
   reg  BlockReadTxDataFromMemory;
872 6 julius
 
873 403 julius
   assign SetReadTxDataFromMemory = TxEn & TxEn_q & TxPointerRead;
874 6 julius
 
875 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
876
     begin
877
        if(Reset)
878
          ReadTxDataFromMemory <= 1'b0;
879
        else
880
          if(TxLengthEq0 | TxAbortPulse | TxRetryPulse)
881
            ReadTxDataFromMemory <= 1'b0;
882
          else
883
            if(SetReadTxDataFromMemory)
884
              ReadTxDataFromMemory <= 1'b1;
885
     end
886 6 julius
 
887 403 julius
   reg tx_burst_en;
888
   reg rx_burst_en;
889
   reg [`ETH_BURST_CNT_WIDTH-1:0] tx_burst_cnt;
890
 
891
   wire                           ReadTxDataFromMemory_2;
892
   wire                           tx_burst;
893
 
894 6 julius
 
895 403 julius
   wire [31:0]                     TxData_wb;
896
   wire                           ReadTxDataFromFifo_wb;
897 6 julius
 
898 403 julius
   assign ReadTxDataFromMemory_2 = ReadTxDataFromMemory &
899
                                   ~BlockReadTxDataFromMemory | (|tx_burst_cnt);
900
 
901
   assign tx_burst = ReadTxDataFromMemory_2 & tx_burst_en;
902 6 julius
 
903 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
904
     begin
905
        if(Reset)
906
          BlockReadTxDataFromMemory <= 1'b0;
907
        else
908
          if((TxBufferAlmostFull | TxLength <= 4)& MasterWbTX &
909
             (~cyc_cleared) & (!(TxAbortPacket_NotCleared |
910
                                 TxRetryPacket_NotCleared)))
911
            BlockReadTxDataFromMemory <= 1'b1;
912
          else
913
            if(ReadTxDataFromFifo_wb | TxDonePacket | TxAbortPacket |
914
               TxRetryPacket)
915
              BlockReadTxDataFromMemory <= 1'b0;
916
     end
917 6 julius
 
918 403 julius
`define TX_BURST_EN_CONDITION (txfifo_cnt<(`ETH_TX_FIFO_DEPTH-`ETH_BURST_LENGTH) & (TxLength>(`ETH_BURST_LENGTH*4+4)))
919
 
920
   assign MasterAccessFinished = m_wb_ack_i | m_wb_err_i;
921
   wire [`ETH_TX_FIFO_CNT_WIDTH-1:0] txfifo_cnt;
922
   wire [`ETH_RX_FIFO_CNT_WIDTH-1:0] rxfifo_cnt;
923 6 julius
 
924 403 julius
   reg [`ETH_BURST_CNT_WIDTH-1:0]    rx_burst_cnt;
925 6 julius
 
926 403 julius
   wire                              rx_burst;
927
   wire                              enough_data_in_rxfifo_for_burst;
928
   wire                              enough_data_in_rxfifo_for_burst_plus1;
929 6 julius
 
930 403 julius
   // Enabling master wishbone access to the memory for two devices TX and RX.
931
   always @ (posedge WB_CLK_I or posedge Reset)
932
     begin
933
        if(Reset)
934
          begin
935
             MasterWbTX <= 1'b0;
936
             MasterWbRX <= 1'b0;
937
             m_wb_adr_o <= 30'h0;
938
             m_wb_cyc_o <= 1'b0;
939
             m_wb_we_o  <= 1'b0;
940
             m_wb_sel_o <= 4'h0;
941
             cyc_cleared<= 1'b0;
942
             tx_burst_cnt<= 0;
943
             rx_burst_cnt<= 0;
944
             IncrTxPointer<= 1'b0;
945
             tx_burst_en<= 1'b1;
946
             rx_burst_en<= 1'b0;
947
`ifdef ETH_WISHBONE_B3
948
             m_wb_cti_o <= 3'b0;
949
 `ifdef BURST_4BEAT
950
             m_wb_bte_o <= 2'b00;
951
 `endif
952
`endif
953
          end
954
        else
955
          begin
956
             // Switching between two stages depends on enable signals
957
             casex ({MasterWbTX,
958
                     MasterWbRX,
959
                     ReadTxDataFromMemory_2,
960
                     WriteRxDataToMemory_r,
961
                     MasterAccessFinished,
962
                     cyc_cleared,
963
                     tx_burst,
964
                     rx_burst})  // synopsys parallel_case
965
 
966
               8'b00_10_00_10, // Idle and MRB needed
967
               8'b10_1x_10_1x, // MRB continues
968
               8'b10_10_01_10, // Clear (previously MR) and MRB needed
969
               8'b01_1x_01_1x: // Clear (previously MW) and MRB needed
970
                   begin
971
                      MasterWbTX <= 1'b1;  // tx burst
972
                      MasterWbRX <= 1'b0;
973
                      m_wb_cyc_o <= 1'b1;
974
                      m_wb_we_o  <= 1'b0;
975
                      m_wb_sel_o <= 4'hf;
976
                      cyc_cleared<= 1'b0;
977
                      IncrTxPointer<= 1'b1;
978
                      tx_burst_cnt <= tx_burst_cnt+3'h1;
979
                      if(tx_burst_cnt==0)
980
                        m_wb_adr_o <= TxPointerMSB;
981
                      else
982
                        m_wb_adr_o <= m_wb_adr_o+1'b1;
983 6 julius
 
984 403 julius
                      if(tx_burst_cnt==(`ETH_BURST_LENGTH-1))
985
                        begin
986
                           tx_burst_en<= 1'b0;
987
`ifdef ETH_WISHBONE_B3
988
                           m_wb_cti_o <= 3'b111;
989
`endif
990
                        end
991
                      else
992
                        begin
993
`ifdef ETH_WISHBONE_B3
994
                           m_wb_cti_o <= 3'b010;
995
 `ifdef BURST_4BEAT
996
                           m_wb_bte_o <= 2'b01;
997
 `endif
998
`endif
999
                        end
1000
                   end // case: 8'b00_10_00_10,...
1001
`ifdef ETH_RX_BURST_EN
1002
         8'b00_x1_00_x1,             // Idle and MWB needed
1003
         8'b01_x1_10_x1,             // MWB continues
1004
         8'b01_01_01_01,             // Clear (previously MW) and MWB needed
1005
         8'b10_x1_01_x1 :            // Clear (previously MR) and MWB needed
1006
           begin
1007
              MasterWbTX <= 1'b0;  // rx burst
1008
              MasterWbRX <= 1'b1;
1009
              m_wb_cyc_o <= 1'b1;
1010
              m_wb_we_o  <= 1'b1;
1011
              m_wb_sel_o <= RxByteSel;
1012
              IncrTxPointer<= 1'b0;
1013
              cyc_cleared<= 1'b0;
1014
              rx_burst_cnt <= rx_burst_cnt+3'h1;
1015 6 julius
 
1016 403 julius
              if(rx_burst_cnt==0)
1017
                m_wb_adr_o <= RxPointerMSB;
1018
              else
1019
                m_wb_adr_o <= m_wb_adr_o+1'b1;
1020 6 julius
 
1021 403 julius
              if(rx_burst_cnt==(`ETH_BURST_LENGTH-1))
1022
                begin
1023
                   rx_burst_en<= 1'b0;
1024
 `ifdef ETH_WISHBONE_B3
1025
                   m_wb_cti_o <= 3'b111;
1026
 `endif
1027
                end
1028
              else
1029
                begin
1030
 `ifdef ETH_WISHBONE_B3
1031
  `ifdef BURST_4BEAT
1032
                   m_wb_cti_o <= 3'b010;
1033
                   m_wb_bte_o <= 2'b01;
1034
  `endif
1035
 `endif
1036
                end
1037
           end // case: 8'b00_x1_00_x1,...
1038
`endif //  `ifdef ETH_RX_BURST_EN
1039
               8'b00_x1_00_x0 ,//idle and MW is needed (data write to rx buffer)
1040
               8'b01_x1_00_x0 :// Sometimes gets caught changing states - JB
1041
                   begin
1042
                      MasterWbTX <= 1'b0;
1043
                      MasterWbRX <= !RxBufferEmpty;
1044
                      m_wb_adr_o <= RxPointerMSB;
1045
                      m_wb_cyc_o <= !RxBufferEmpty;
1046
                      m_wb_we_o  <= !RxBufferEmpty;
1047
                      m_wb_sel_o <= RxByteSel;
1048
                      IncrTxPointer<= 1'b0;
1049
`ifdef ETH_WISHBONE_B3
1050
 `ifdef ETH_RX_BURST_EN
1051
  `ifdef BURST_4BEAT
1052
                      if ((RxPointerMSB[3:2]==2'b00) & !RxBufferEmpty &
1053
                          enough_data_in_rxfifo_for_burst & !m_wb_cyc_o)
1054
                        // Added "& !_m_wb_cyc_o" here to stop burst signals
1055
                        // going high during a transfer
1056
                        begin
1057
                           rx_burst_en<= 1'b1;
1058
                           m_wb_cti_o <= 3'b010;
1059
                           m_wb_bte_o <= 2'b01;
1060
                           rx_burst_cnt<= 1;
1061
                        end
1062
  `endif
1063
 `endif
1064
`endif //  `ifdef ETH_WISHBONE_B3
1065
 
1066
                   end
1067
               8'b00_10_00_00 : // idle and MR is needed (data read from tx 
1068
                                // buffer)
1069
                 begin
1070
                    MasterWbTX <= 1'b1;
1071
                    MasterWbRX <= 1'b0;
1072
                    m_wb_adr_o <= TxPointerMSB;
1073
                    m_wb_cyc_o <= 1'b1;
1074
                    m_wb_we_o  <= 1'b0;
1075
                    m_wb_sel_o <= 4'hf;
1076
                    IncrTxPointer<= 1'b1;
1077
`ifdef BURST_4BEAT
1078 6 julius
 
1079 403 julius
                    // Attempt ethernet bugfix, start bursts later
1080
                    if ((TxPointerMSB[3:2]==2'b00) && `TX_BURST_EN_CONDITION)
1081
                      begin
1082
 `ifdef TX_BURST_EN_VERBOSE
1083
                         $display("(%t)(%m): %b enabling tx_burst_en",$time,
1084
                                  {MasterWbTX,MasterWbRX,ReadTxDataFromMemory_2,
1085
                                   WriteRxDataToMemory,MasterAccessFinished,
1086
                                   cyc_cleared,tx_burst,rx_burst});
1087
 `endif
1088
                         tx_burst_en<= 1'b1;
1089
                         tx_burst_cnt <= 3'h1;
1090 6 julius
 
1091 403 julius
 `ifdef ETH_WISHBONE_B3
1092
                         m_wb_cti_o <= 3'b010;
1093
                         m_wb_bte_o <= 2'b01;
1094
 `endif
1095
                      end
1096
`endif
1097
                 end
1098
               8'b10_10_01_00,// MR and MR is needed (data read from tx buffer)
1099
               8'b01_1x_01_0x  :// MW and MR is needed (data read from tx 
1100
                                  // buffer)
1101
                   begin
1102
                      MasterWbTX <= 1'b1; // Only switch to TX here
1103
                                          // when not end of RX
1104
                      MasterWbRX <= 1'b0;
1105
                      m_wb_adr_o <= TxPointerMSB;
1106
                      m_wb_cyc_o <= 1'b1;
1107
                      m_wb_we_o  <= 1'b0;
1108
                      m_wb_sel_o <= 4'hf;
1109
                      cyc_cleared<= 1'b0;
1110
                      IncrTxPointer<= 1'b1;
1111
`ifdef BURST_4BEAT
1112
                      if ((TxPointerMSB[3:2]==2'b00) & `TX_BURST_EN_CONDITION)
1113
                        begin
1114
 `ifdef TX_BURST_EN_VERBOSE
1115
                           $display("(%t)(%m): %b enabling tx_burst_en",$time,
1116
                                    {MasterWbTX,MasterWbRX,
1117
                                     ReadTxDataFromMemory_2,
1118
                                     WriteRxDataToMemory,
1119
                                     MasterAccessFinished,
1120
                                     cyc_cleared,
1121
                                     tx_burst,
1122
                                     rx_burst});
1123
 `endif
1124
                           tx_burst_en<= 1'b1;
1125
                           tx_burst_cnt <= 3'h1;
1126
 `ifdef ETH_WISHBONE_B3
1127
                           m_wb_cti_o <= 3'b010;
1128
                           m_wb_bte_o <= 2'b01;
1129
 `endif
1130
                        end
1131
`endif
1132
 
1133
                   end
1134
               8'b01_01_01_00,// MW and MW needed (data write to rx buffer)
1135
               8'b10_x1_01_x0 ://MR and MW is needed (data write to rx buffer)
1136
                   begin
1137
                      MasterWbTX <= 1'b0;
1138
                      MasterWbRX <= !RxBufferEmpty;
1139
                      rx_burst_cnt<= 0;
1140
                      m_wb_adr_o <= RxPointerMSB;
1141
                      m_wb_cyc_o <= !RxBufferEmpty;
1142
                      m_wb_we_o  <= !RxBufferEmpty;
1143
                      m_wb_sel_o <= RxByteSel;
1144
`ifdef ETH_WISHBONE_B3
1145
 `ifdef ETH_RX_BURST_EN
1146
  `ifdef BURST_4BEAT
1147
                      if ((RxPointerMSB[3:2]==2'b00) &
1148
                          enough_data_in_rxfifo_for_burst & !RxBufferEmpty)
1149
                          //enough_data_in_rxfifo_for_burst_plus1)
1150 6 julius
 
1151 403 julius
 
1152
                        begin
1153
                           rx_burst_en<= 1'b1;
1154
                           m_wb_cti_o <= 3'b010;
1155
                           m_wb_bte_o <= 2'b01;
1156
                           rx_burst_cnt<= 1;
1157
                        end
1158
  `endif
1159
 `endif //  `ifdef ETH_RX_BURST_EN           
1160
`endif //  `ifdef ETH_WISHBONE_B3            
1161
                      cyc_cleared<= 1'b0;
1162
                      IncrTxPointer<= 1'b0;
1163
                   end
1164
               8'b01_01_10_00,// MW and MW needed (cycle is cleared between 
1165
                              // previous and next access)
1166
               8'b01_1x_10_x0,// MW and MW or MR or MRB needed (cycle is 
1167
                              // cleared between previous and next access)
1168
               8'b10_10_10_00,// MR and MR needed (cycle is cleared between 
1169
                              // previous  and next access)
1170
               8'b10_x1_10_0x :// MR and MR or MW or MWB (cycle is cleared 
1171
                               // between previous and next access)
1172
                   begin
1173
                      m_wb_cyc_o <= 1'b0;// whatever and master read or write is
1174
                                         // needed. We need to clear m_wb_cyc_o
1175
                                         //  before next access is started
1176
                      cyc_cleared<= 1'b1;
1177
                      IncrTxPointer<= 1'b0;
1178
                      tx_burst_cnt<= 0;
1179
`ifdef BURST_4BEAT
1180
                      // Caused a bug!
1181
                      // if (TxPointerMSB[3:2]==2'b00)       
1182
                      //tx_burst_en<= `TX_BURST_EN_CONDITION;        
1183
                      // Set this to 0 here
1184
                      tx_burst_en<= 0;
1185
 
1186
`endif
1187
                      rx_burst_cnt<= 0;
1188
`ifdef ETH_WISHBONE_B3
1189
                      m_wb_bte_o <= 2'b00;
1190
                      m_wb_cti_o <= 3'b0;
1191
`endif
1192
                   end
1193
               8'bxx_00_10_00,// whatever and no master read or write is needed
1194
                              // (ack or err comes finishing previous access)
1195
                 8'bxx_00_01_00 : // Between cyc_cleared request was cleared
1196
                   begin
1197
                      MasterWbTX <= 1'b0;
1198
                      MasterWbRX <= 1'b0;
1199
                      m_wb_cyc_o <= 1'b0;
1200
                      cyc_cleared<= 1'b0;
1201
                      IncrTxPointer<= 1'b0;
1202
                      rx_burst_cnt<= 0;
1203
                      m_wb_bte_o <= 2'b00;
1204
                      m_wb_cti_o <= 3'b0;
1205
                   end
1206
               8'b00_00_00_00:  // whatever and no master read or write is 
1207
                                // needed (ack or err comes finishing previous 
1208
                                // access)
1209
                 begin
1210
                    tx_burst_cnt<= 0;
1211
`ifdef BURST_4BEAT
1212 6 julius
 
1213 403 julius
                    // This caused tx_burst to remain set between
1214
                    // transmits, and sometimes we would burst immediately
1215
                    // and maybe get the wrong data because the offset of
1216
                    // the buffer pointer wasn't 16-byte aligned.
1217
                    //if (TxPointerMSB[3:2]==2'b00)
1218
                    //  tx_burst_en<= `TX_BURST_EN_CONDITION;
1219 6 julius
 
1220 403 julius
                    // Fix for transmit problems... maybe - jb
1221
                    if(TxEn & TxEn_q & TxPointerRead & (ram_do[3:0]===4'h0))
1222
                      begin
1223
 `ifdef TX_BURST_EN_VERBOSE
1224
                         $display("(%t)(%m): %b enabling tx_burst_en",$time,
1225
                                  {MasterWbTX,MasterWbRX,ReadTxDataFromMemory_2,
1226
                                   WriteRxDataToMemory,MasterAccessFinished,
1227
                                   cyc_cleared,tx_burst,rx_burst});
1228
 `endif
1229
                         tx_burst_en<= `TX_BURST_EN_CONDITION;
1230
                      end
1231
                    else
1232
                      tx_burst_en<= 0;
1233
`endif
1234
                 end
1235
               default:                    // Don't touch
1236
                 begin
1237
                    MasterWbTX <= MasterWbTX;
1238
                    MasterWbRX <= MasterWbRX;
1239
                    m_wb_cyc_o <= m_wb_cyc_o;
1240
                    m_wb_sel_o <= m_wb_sel_o;
1241
                    IncrTxPointer<= IncrTxPointer;
1242
                 end
1243
             endcase
1244
          end
1245
     end
1246 6 julius
 
1247
 
1248 403 julius
   wire TxFifoClear;
1249 6 julius
 
1250 403 julius
   assign TxFifoClear = (TxAbortPacket | TxRetryPacket | StartTxPointerRead);
1251
 
1252
   eth_fifo
1253
     #(
1254
       `ETH_TX_FIFO_DATA_WIDTH,
1255
       `ETH_TX_FIFO_DEPTH,
1256
       `ETH_TX_FIFO_CNT_WIDTH
1257
       )
1258
   tx_fifo
1259
     (
1260
       .data_in(m_wb_dat_i),
1261
       .data_out(TxData_wb),
1262
       .clk(WB_CLK_I),
1263
       .reset(Reset),
1264
       .write(MasterWbTX & m_wb_ack_i),
1265
       .read(ReadTxDataFromFifo_wb & ~TxBufferEmpty),
1266
       .clear(TxFifoClear),
1267
       .full(TxBufferFull),
1268
       .almost_full(TxBufferAlmostFull),
1269
       .almost_empty(TxBufferAlmostEmpty),
1270
       .empty(TxBufferEmpty),
1271
       .cnt(txfifo_cnt)
1272
       );
1273 6 julius
 
1274
 
1275 403 julius
   reg  StartOccured;
1276
   reg  TxStartFrm_sync1;
1277
   reg  TxStartFrm_sync2;
1278
   reg  TxStartFrm_syncb1;
1279
   reg  TxStartFrm_syncb2;
1280 6 julius
 
1281
 
1282
 
1283 403 julius
   // Start: Generation of the TxStartFrm_wb which is then synchronized to the MTxClk
1284
   always @ (posedge WB_CLK_I or posedge Reset)
1285
     begin
1286
        if(Reset)
1287
          TxStartFrm_wb <= 1'b0;
1288
        else
1289
          if(TxBDReady & ~StartOccured & (TxBufferFull | TxLengthEq0))
1290
            TxStartFrm_wb <= 1'b1;
1291
          else
1292
            if(TxStartFrm_syncb2)
1293
              TxStartFrm_wb <= 1'b0;
1294
     end
1295 6 julius
 
1296 403 julius
   // StartOccured: TxStartFrm_wb occurs only ones at the beginning. Then it's 
1297
   // blocked.
1298
   always @ (posedge WB_CLK_I or posedge Reset)
1299
     begin
1300
        if(Reset)
1301
          StartOccured <= 1'b0;
1302
        else
1303
          if(TxStartFrm_wb)
1304
            StartOccured <= 1'b1;
1305
          else
1306
            if(ResetTxBDReady)
1307
              StartOccured <= 1'b0;
1308
     end
1309 6 julius
 
1310 403 julius
   // Synchronizing TxStartFrm_wb to MTxClk
1311
   always @ (posedge MTxClk or posedge Reset)
1312
     begin
1313
        if(Reset)
1314
          TxStartFrm_sync1 <= 1'b0;
1315
        else
1316
          TxStartFrm_sync1 <= TxStartFrm_wb;
1317
     end
1318 6 julius
 
1319 403 julius
   always @ (posedge MTxClk or posedge Reset)
1320
     begin
1321
        if(Reset)
1322
          TxStartFrm_sync2 <= 1'b0;
1323
        else
1324
          TxStartFrm_sync2 <= TxStartFrm_sync1;
1325
     end
1326 6 julius
 
1327 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1328
     begin
1329
        if(Reset)
1330
          TxStartFrm_syncb1 <= 1'b0;
1331
        else
1332
          TxStartFrm_syncb1 <= TxStartFrm_sync2;
1333
     end
1334 6 julius
 
1335 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1336
     begin
1337
        if(Reset)
1338
          TxStartFrm_syncb2 <= 1'b0;
1339
        else
1340
          TxStartFrm_syncb2 <= TxStartFrm_syncb1;
1341
     end
1342 6 julius
 
1343 403 julius
   always @ (posedge MTxClk or posedge Reset)
1344
     begin
1345
        if(Reset)
1346
          TxStartFrm <= 1'b0;
1347
        else
1348
          if(TxStartFrm_sync2)
1349
            TxStartFrm <= 1'b1;
1350
          else
1351
            if(TxUsedData_q | ~TxStartFrm_sync2 &
1352
               (TxRetry & (~TxRetry_q) | TxAbort & (~TxAbort_q)))
1353
              TxStartFrm <= 1'b0;
1354
     end
1355
   // End: Generation of the TxStartFrm_wb which is then synchronized to the 
1356
   // MTxClk
1357 6 julius
 
1358
 
1359 403 julius
   // TxEndFrm_wb: indicator of the end of frame
1360
   always @ (posedge WB_CLK_I or posedge Reset)
1361
     begin
1362
        if(Reset)
1363
          TxEndFrm_wb <= 1'b0;
1364
        else
1365
          if(TxLengthEq0 & TxBufferAlmostEmpty & TxUsedData)
1366
            TxEndFrm_wb <= 1'b1;
1367
          else
1368
            if(TxRetryPulse | TxDonePulse | TxAbortPulse)
1369
              TxEndFrm_wb <= 1'b0;
1370
     end
1371 6 julius
 
1372
 
1373 403 julius
   // Marks which bytes are valid within the word.
1374
   assign TxValidBytes = TxLengthLt4 ? TxLength[1:0] : 2'b0;
1375 6 julius
 
1376 403 julius
   reg LatchValidBytes;
1377
   reg LatchValidBytes_q;
1378 6 julius
 
1379 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1380
     begin
1381
        if(Reset)
1382
          LatchValidBytes <= 1'b0;
1383
        else
1384
          if(TxLengthLt4 & TxBDReady)
1385
            LatchValidBytes <= 1'b1;
1386
          else
1387
            LatchValidBytes <= 1'b0;
1388
     end
1389 6 julius
 
1390 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1391
     begin
1392
        if(Reset)
1393
          LatchValidBytes_q <= 1'b0;
1394
        else
1395
          LatchValidBytes_q <= LatchValidBytes;
1396
     end
1397 6 julius
 
1398
 
1399 403 julius
   // Latching valid bytes
1400
   always @ (posedge WB_CLK_I or posedge Reset)
1401
     begin
1402
        if(Reset)
1403
          TxValidBytesLatched <= 2'h0;
1404
        else
1405
          if(LatchValidBytes & ~LatchValidBytes_q)
1406
            TxValidBytesLatched <= TxValidBytes;
1407
          else
1408
            if(TxRetryPulse | TxDonePulse | TxAbortPulse)
1409
              TxValidBytesLatched <= 2'h0;
1410
     end
1411 6 julius
 
1412
 
1413 403 julius
   assign TxIRQEn          = TxStatus[14];
1414
   assign WrapTxStatusBit  = TxStatus[13];
1415
   assign PerPacketPad     = TxStatus[12];
1416
   assign PerPacketCrcEn   = TxStatus[11];
1417 6 julius
 
1418
 
1419 403 julius
   assign RxIRQEn         = RxStatus[14];
1420
   assign WrapRxStatusBit = RxStatus[13];
1421 6 julius
 
1422 403 julius
 
1423
   // Temporary Tx and Rx buffer descriptor address
1424
`ifdef TXBD_POLL
1425
   assign TempTxBDAddress[7:1] = {7{ (TxStatusWrite|TxBDNotReady)     & ~WrapTxStatusBit}}   & (TxBDAddress + 1'b1) ; // Tx BD increment or wrap (last BD) -- jb
1426
`else
1427
   assign TempTxBDAddress[7:1] = {7{ TxStatusWrite     & ~WrapTxStatusBit}}   & (TxBDAddress + 1'b1) ; // Tx BD increment or wrap (last BD)
1428 69 julius
`endif
1429 403 julius
   assign TempRxBDAddress[7:1] = {7{ WrapRxStatusBit}} & (r_TxBDNum[6:0])     | // Using first Rx BD
1430
                                 {7{~WrapRxStatusBit}} & (RxBDAddress + 1'b1) ; // Using next Rx BD (incremenrement address)
1431 6 julius
 
1432
 
1433 403 julius
   // Latching Tx buffer descriptor address
1434
   always @ (posedge WB_CLK_I or posedge Reset)
1435
     begin
1436
        if(Reset)
1437
          TxBDAddress <= 7'h0;
1438
        else if (r_TxEn & (~r_TxEn_q))
1439
          TxBDAddress <= 7'h0;
1440
`ifdef TXBD_POLL
1441
        else if (TxStatusWrite | TxBDNotReady)  // -- jb
1442
`else
1443
          else if (TxStatusWrite)
1444
`endif
1445
            TxBDAddress <= TempTxBDAddress;
1446
     end
1447 6 julius
 
1448
 
1449 403 julius
   // Latching Rx buffer descriptor address
1450
   always @ (posedge WB_CLK_I or posedge Reset)
1451
     begin
1452
        if(Reset)
1453
          RxBDAddress <= 7'h0;
1454
        else if(r_RxEn & (~r_RxEn_q))
1455
          RxBDAddress <= r_TxBDNum[6:0];
1456
        else if(RxStatusWrite)
1457
          RxBDAddress <= TempRxBDAddress;
1458
     end
1459 6 julius
 
1460 403 julius
   wire [8:0] TxStatusInLatched = {TxUnderRun, RetryCntLatched[3:0],
1461
                                   RetryLimit, LateCollLatched, DeferLatched,
1462
                                   CarrierSenseLost};
1463 6 julius
 
1464 403 julius
   assign RxBDDataIn = {LatchedRxLength, 1'b0, RxStatus, 4'h0,
1465
                        RxStatusInLatched};
1466
   assign TxBDDataIn = {LatchedTxLength, 1'b0, TxStatus, 2'h0,
1467
                        TxStatusInLatched};
1468 6 julius
 
1469
 
1470 403 julius
   // Signals used for various purposes
1471
   assign TxRetryPulse   = TxRetry_wb   & ~TxRetry_wb_q;
1472
   assign TxDonePulse    = TxDone_wb    & ~TxDone_wb_q;
1473
   assign TxAbortPulse   = TxAbort_wb   & ~TxAbort_wb_q;
1474 6 julius
 
1475
 
1476
 
1477 403 julius
   // Generating delayed signals
1478
   always @ (posedge MTxClk or posedge Reset)
1479
     begin
1480
        if(Reset)
1481
          begin
1482
             TxAbort_q      <= 1'b0;
1483
             TxRetry_q      <= 1'b0;
1484
             TxUsedData_q   <= 1'b0;
1485
          end
1486
        else
1487
          begin
1488
             TxAbort_q      <= TxAbort;
1489
             TxRetry_q      <= TxRetry;
1490
             TxUsedData_q   <= TxUsedData;
1491
          end
1492
     end
1493 6 julius
 
1494 403 julius
   // Generating delayed signals
1495
   always @ (posedge WB_CLK_I or posedge Reset)
1496
     begin
1497
        if(Reset)
1498
          begin
1499
             TxDone_wb_q   <= 1'b0;
1500
             TxAbort_wb_q  <= 1'b0;
1501
             TxRetry_wb_q  <= 1'b0;
1502
          end
1503
        else
1504
          begin
1505
             TxDone_wb_q   <= TxDone_wb;
1506
             TxAbort_wb_q  <= TxAbort_wb;
1507
             TxRetry_wb_q  <= TxRetry_wb;
1508
          end
1509
     end
1510 6 julius
 
1511
 
1512 403 julius
   reg TxAbortPacketBlocked;
1513
   always @ (posedge WB_CLK_I or posedge Reset)
1514
     begin
1515
        if(Reset)
1516
          TxAbortPacket <= 1'b0;
1517
        else
1518
          if(TxAbort_wb & (~tx_burst_en) & MasterWbTX & MasterAccessFinished &
1519
             (~TxAbortPacketBlocked) | TxAbort_wb & (~MasterWbTX) &
1520
             (~TxAbortPacketBlocked))
1521
            TxAbortPacket <= 1'b1;
1522
          else
1523
            TxAbortPacket <= 1'b0;
1524
     end
1525 6 julius
 
1526
 
1527 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1528
     begin
1529
        if(Reset)
1530
          TxAbortPacket_NotCleared <= 1'b0;
1531
        else
1532
          if(TxEn & TxEn_q & TxAbortPacket_NotCleared)
1533
            TxAbortPacket_NotCleared <= 1'b0;
1534
          else
1535
            if(TxAbort_wb & (~tx_burst_en) & MasterWbTX &
1536
               MasterAccessFinished & (~TxAbortPacketBlocked) | TxAbort_wb &
1537
               (~MasterWbTX) & (~TxAbortPacketBlocked))
1538
              TxAbortPacket_NotCleared <= 1'b1;
1539
     end
1540 6 julius
 
1541
 
1542 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1543
     begin
1544
        if(Reset)
1545
          TxAbortPacketBlocked <= 1'b0;
1546
        else
1547
          if(!TxAbort_wb & TxAbort_wb_q)
1548
            TxAbortPacketBlocked <= 1'b0;
1549
          else
1550
            if(TxAbortPacket)
1551
              TxAbortPacketBlocked <= 1'b1;
1552
     end
1553 6 julius
 
1554
 
1555 403 julius
   reg TxRetryPacketBlocked;
1556
   always @ (posedge WB_CLK_I or posedge Reset)
1557
     begin
1558
        if(Reset)
1559
          TxRetryPacket <= 1'b0;
1560
        else
1561
          if(TxRetry_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished &
1562
             !TxRetryPacketBlocked | TxRetry_wb & !MasterWbTX &
1563
             !TxRetryPacketBlocked)
1564
            TxRetryPacket <= 1'b1;
1565
          else
1566
            TxRetryPacket <= 1'b0;
1567
     end
1568 6 julius
 
1569
 
1570 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1571
     begin
1572
        if(Reset)
1573
          TxRetryPacket_NotCleared <= 1'b0;
1574
        else
1575
          if(StartTxBDRead)
1576
            TxRetryPacket_NotCleared <= 1'b0;
1577
          else
1578
            if(TxRetry_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished &
1579
               !TxRetryPacketBlocked | TxRetry_wb & !MasterWbTX &
1580
               !TxRetryPacketBlocked)
1581
              TxRetryPacket_NotCleared <= 1'b1;
1582
     end
1583 6 julius
 
1584
 
1585 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1586
     begin
1587
        if(Reset)
1588
          TxRetryPacketBlocked <= 1'b0;
1589
        else
1590
          if(!TxRetry_wb & TxRetry_wb_q)
1591
            TxRetryPacketBlocked <= 1'b0;
1592
          else
1593
            if(TxRetryPacket)
1594
              TxRetryPacketBlocked <= 1'b1;
1595
     end
1596 6 julius
 
1597
 
1598 403 julius
   reg TxDonePacketBlocked;
1599
   always @ (posedge WB_CLK_I or posedge Reset)
1600
     begin
1601
        if(Reset)
1602
          TxDonePacket <= 1'b0;
1603
        else
1604
          if(TxDone_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished &
1605
             !TxDonePacketBlocked | TxDone_wb & !MasterWbTX &
1606
             !TxDonePacketBlocked)
1607
            TxDonePacket <= 1'b1;
1608
          else
1609
            TxDonePacket <= 1'b0;
1610
     end
1611 6 julius
 
1612
 
1613 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1614
     begin
1615
        if(Reset)
1616
          TxDonePacket_NotCleared <= 1'b0;
1617
        else
1618
          if(TxEn & TxEn_q & TxDonePacket_NotCleared)
1619
            TxDonePacket_NotCleared <= 1'b0;
1620
          else
1621
            if(TxDone_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished
1622
               & (~TxDonePacketBlocked) | TxDone_wb & !MasterWbTX
1623
               & (~TxDonePacketBlocked))
1624
              TxDonePacket_NotCleared <= 1'b1;
1625
     end
1626 6 julius
 
1627
 
1628 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1629
     begin
1630
        if(Reset)
1631
          TxDonePacketBlocked <= 1'b0;
1632
        else
1633
          if(!TxDone_wb & TxDone_wb_q)
1634
            TxDonePacketBlocked <= 1'b0;
1635
          else
1636
            if(TxDonePacket)
1637
              TxDonePacketBlocked <= 1'b1;
1638
     end
1639 6 julius
 
1640
 
1641 403 julius
   // Indication of the last word
1642
   always @ (posedge MTxClk or posedge Reset)
1643
     begin
1644
        if(Reset)
1645
          LastWord <= 1'b0;
1646
        else
1647
          if((TxEndFrm | TxAbort | TxRetry) & Flop)
1648
            LastWord <= 1'b0;
1649
          else
1650
            if(TxUsedData & Flop & TxByteCnt == 2'h3)
1651
              LastWord <= TxEndFrm_wb;
1652
     end
1653 6 julius
 
1654
 
1655 403 julius
   // Tx end frame generation
1656
   always @ (posedge MTxClk or posedge Reset)
1657
     begin
1658
        if(Reset)
1659
          TxEndFrm <= 1'b0;
1660
        else
1661
          if(Flop & TxEndFrm | TxAbort | TxRetry_q)
1662
            TxEndFrm <= 1'b0;
1663
          else
1664
            if(Flop & LastWord)
1665
              begin
1666
                 case (TxValidBytesLatched)  // synopsys parallel_case
1667
                   1 : TxEndFrm <= TxByteCnt == 2'h0;
1668
                   2 : TxEndFrm <= TxByteCnt == 2'h1;
1669
                   3 : TxEndFrm <= TxByteCnt == 2'h2;
1670
 
1671
                   default : TxEndFrm <= 1'b0;
1672
                 endcase
1673
              end
1674
     end
1675 6 julius
 
1676
 
1677 403 julius
   // Tx data selection (latching)
1678
   always @ (posedge MTxClk or posedge Reset)
1679
     begin
1680
        if(Reset)
1681
          TxData <= 0;
1682
        else
1683
          if(TxStartFrm_sync2 & ~TxStartFrm)
1684
            case(TxPointerLSB)  // synopsys parallel_case
1685
              2'h0 : TxData <= TxData_wb[31:24];// Big Endian Byte Ordering
1686
              2'h1 : TxData <= TxData_wb[23:16];// Big Endian Byte Ordering
1687
              2'h2 : TxData <= TxData_wb[15:08];// Big Endian Byte Ordering
1688
              2'h3 : TxData <= TxData_wb[07:00];// Big Endian Byte Ordering
1689
            endcase
1690
          else
1691
            if(TxStartFrm & TxUsedData & TxPointerLSB==2'h3)
1692
              TxData <= TxData_wb[31:24];// Big Endian Byte Ordering
1693
            else
1694
              if(TxUsedData & Flop)
1695
                begin
1696
                   case(TxByteCnt)  // synopsys parallel_case
1697
                     // Big Endian Byte Ordering
1698
 
1699
                     1 : TxData <= TxDataLatched[23:16];
1700
                     2 : TxData <= TxDataLatched[15:8];
1701
                     3 : TxData <= TxDataLatched[7:0];
1702
                   endcase
1703
                end
1704
     end
1705 6 julius
 
1706
 
1707 403 julius
   // Latching tx data
1708
   always @ (posedge MTxClk or posedge Reset)
1709
     begin
1710
        if(Reset)
1711
          TxDataLatched[31:0] <= 32'h0;
1712
        else
1713
          if(TxStartFrm_sync2 & ~TxStartFrm | TxUsedData & Flop &
1714
             TxByteCnt == 2'h3 | TxStartFrm & TxUsedData & Flop &
1715
             TxByteCnt == 2'h0)
1716
            TxDataLatched[31:0] <= TxData_wb[31:0];
1717
     end
1718 6 julius
 
1719
 
1720 403 julius
   // Tx under run
1721
   always @ (posedge WB_CLK_I or posedge Reset)
1722
     begin
1723
        if(Reset)
1724
          TxUnderRun_wb <= 1'b0;
1725
        else
1726
          if(TxAbortPulse)
1727
            TxUnderRun_wb <= 1'b0;
1728
          else
1729
            if(TxBufferEmpty & ReadTxDataFromFifo_wb)
1730
              TxUnderRun_wb <= 1'b1;
1731
     end
1732 6 julius
 
1733
 
1734 403 julius
   reg TxUnderRun_sync1;
1735 6 julius
 
1736 403 julius
   // Tx under run
1737
   always @ (posedge MTxClk or posedge Reset)
1738
     begin
1739
        if(Reset)
1740
          TxUnderRun_sync1 <= 1'b0;
1741
        else
1742
          if(TxUnderRun_wb)
1743
            TxUnderRun_sync1 <= 1'b1;
1744
          else
1745
            if(BlockingTxStatusWrite_sync2)
1746
              TxUnderRun_sync1 <= 1'b0;
1747
     end
1748 6 julius
 
1749 403 julius
   // Tx under run
1750
   always @ (posedge MTxClk or posedge Reset)
1751
     begin
1752
        if(Reset)
1753
          TxUnderRun <= 1'b0;
1754
        else
1755
          if(BlockingTxStatusWrite_sync2)
1756
            TxUnderRun <= 1'b0;
1757
          else
1758
            if(TxUnderRun_sync1)
1759
              TxUnderRun <= 1'b1;
1760
     end
1761 6 julius
 
1762
 
1763 403 julius
   // Tx Byte counter
1764
   always @ (posedge MTxClk or posedge Reset)
1765
     begin
1766
        if(Reset)
1767
          TxByteCnt <= 2'h0;
1768
        else
1769
          if(TxAbort_q | TxRetry_q)
1770
            TxByteCnt <= 2'h0;
1771
          else
1772
            if(TxStartFrm & ~TxUsedData)
1773
              case(TxPointerLSB)  // synopsys parallel_case
1774
                2'h0 : TxByteCnt <= 2'h1;
1775
                2'h1 : TxByteCnt <= 2'h2;
1776
                2'h2 : TxByteCnt <= 2'h3;
1777
                2'h3 : TxByteCnt <= 2'h0;
1778
              endcase
1779
            else
1780
              if(TxUsedData & Flop)
1781
                TxByteCnt <= TxByteCnt + 1'b1;
1782
     end
1783 6 julius
 
1784
 
1785 403 julius
   // Start: Generation of the ReadTxDataFromFifo_tck signal and synchronization to the WB_CLK_I
1786
   reg ReadTxDataFromFifo_sync1;
1787
   reg ReadTxDataFromFifo_sync2;
1788
   reg ReadTxDataFromFifo_sync3;
1789
   reg ReadTxDataFromFifo_syncb1;
1790
   reg ReadTxDataFromFifo_syncb2;
1791
   reg ReadTxDataFromFifo_syncb3;
1792 6 julius
 
1793
 
1794 403 julius
   always @ (posedge MTxClk or posedge Reset)
1795
     begin
1796
        if(Reset)
1797
          ReadTxDataFromFifo_tck <= 1'b0;
1798
        else
1799
          if(TxStartFrm_sync2 & ~TxStartFrm | TxUsedData & Flop &
1800
             TxByteCnt == 2'h3 & ~LastWord | TxStartFrm & TxUsedData & Flop &
1801
             TxByteCnt == 2'h0)
1802
            ReadTxDataFromFifo_tck <= 1'b1;
1803
          else
1804
            if(ReadTxDataFromFifo_syncb2 & ~ReadTxDataFromFifo_syncb3)
1805
              ReadTxDataFromFifo_tck <= 1'b0;
1806
     end
1807 6 julius
 
1808 403 julius
   // Synchronizing TxStartFrm_wb to MTxClk
1809
   always @ (posedge WB_CLK_I or posedge Reset)
1810
     begin
1811
        if(Reset)
1812
          ReadTxDataFromFifo_sync1 <= 1'b0;
1813
        else
1814
          ReadTxDataFromFifo_sync1 <= ReadTxDataFromFifo_tck;
1815
     end
1816 6 julius
 
1817 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1818
     begin
1819
        if(Reset)
1820
          ReadTxDataFromFifo_sync2 <= 1'b0;
1821
        else
1822
          ReadTxDataFromFifo_sync2 <= ReadTxDataFromFifo_sync1;
1823
     end
1824 6 julius
 
1825 403 julius
   always @ (posedge MTxClk or posedge Reset)
1826
     begin
1827
        if(Reset)
1828
          ReadTxDataFromFifo_syncb1 <= 1'b0;
1829
        else
1830
          ReadTxDataFromFifo_syncb1 <= ReadTxDataFromFifo_sync2;
1831
     end
1832 6 julius
 
1833 403 julius
   always @ (posedge MTxClk or posedge Reset)
1834
     begin
1835
        if(Reset)
1836
          ReadTxDataFromFifo_syncb2 <= 1'b0;
1837
        else
1838
          ReadTxDataFromFifo_syncb2 <= ReadTxDataFromFifo_syncb1;
1839
     end
1840 6 julius
 
1841 403 julius
   always @ (posedge MTxClk or posedge Reset)
1842
     begin
1843
        if(Reset)
1844
          ReadTxDataFromFifo_syncb3 <= 1'b0;
1845
        else
1846
          ReadTxDataFromFifo_syncb3 <= ReadTxDataFromFifo_syncb2;
1847
     end
1848 6 julius
 
1849 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1850
     begin
1851
        if(Reset)
1852
          ReadTxDataFromFifo_sync3 <= 1'b0;
1853
        else
1854
          ReadTxDataFromFifo_sync3 <= ReadTxDataFromFifo_sync2;
1855
     end
1856 6 julius
 
1857 403 julius
   assign ReadTxDataFromFifo_wb = ReadTxDataFromFifo_sync2 &
1858
                                  ~ReadTxDataFromFifo_sync3;
1859
   // End: Generation of the ReadTxDataFromFifo_tck signal and synchronization 
1860
   // to the WB_CLK_I
1861 6 julius
 
1862
 
1863 403 julius
   // Synchronizing TxRetry signal (synchronized to WISHBONE clock)
1864
   always @ (posedge WB_CLK_I or posedge Reset)
1865
     begin
1866
        if(Reset)
1867
          TxRetrySync1 <= 1'b0;
1868
        else
1869
          TxRetrySync1 <= TxRetry;
1870
     end
1871 6 julius
 
1872 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1873
     begin
1874
        if(Reset)
1875
          TxRetry_wb <= 1'b0;
1876
        else
1877
          TxRetry_wb <= TxRetrySync1;
1878
     end
1879 6 julius
 
1880
 
1881 403 julius
   // Synchronized TxDone_wb signal (synchronized to WISHBONE clock)
1882
   always @ (posedge WB_CLK_I or posedge Reset)
1883
     begin
1884
        if(Reset)
1885
          TxDoneSync1 <= 1'b0;
1886
        else
1887
          TxDoneSync1 <= TxDone;
1888
     end
1889 6 julius
 
1890 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1891
     begin
1892
        if(Reset)
1893
          TxDone_wb <= 1'b0;
1894
        else
1895
          TxDone_wb <= TxDoneSync1;
1896
     end
1897 6 julius
 
1898 403 julius
   // Synchronizing TxAbort signal (synchronized to WISHBONE clock)
1899
   always @ (posedge WB_CLK_I or posedge Reset)
1900
     begin
1901
        if(Reset)
1902
          TxAbortSync1 <= 1'b0;
1903
        else
1904
          TxAbortSync1 <= TxAbort;
1905
     end
1906 6 julius
 
1907 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
1908
     begin
1909
        if(Reset)
1910
          TxAbort_wb <= 1'b0;
1911
        else
1912
          TxAbort_wb <= TxAbortSync1;
1913
     end
1914 6 julius
 
1915
 
1916 403 julius
   reg RxAbortSync1;
1917
   reg RxAbortSync2;
1918
   reg RxAbortSync3;
1919
   reg RxAbortSync4;
1920
   reg RxAbortSyncb1;
1921
   reg RxAbortSyncb2;
1922 6 julius
 
1923 403 julius
   assign StartRxBDRead = RxStatusWrite | RxAbortSync3 & ~RxAbortSync4 |
1924
                          r_RxEn & ~r_RxEn_q;
1925 6 julius
 
1926 403 julius
   // Reading the Rx buffer descriptor
1927
   always @ (posedge WB_CLK_I or posedge Reset)
1928
     begin
1929
        if(Reset)
1930
          RxBDRead <= 1'b0;
1931
        else
1932
          if(StartRxBDRead)
1933
            RxBDRead <= 1'b1;
1934
          else
1935
            if(RxBDReady)
1936
              RxBDRead <= 1'b0;
1937
     end
1938 6 julius
 
1939
 
1940 403 julius
   // Reading of the next receive buffer descriptor starts after reception 
1941
   // status is written to the previous one.
1942 6 julius
 
1943 403 julius
   // Latching READY status of the Rx buffer descriptor
1944
   always @ (posedge WB_CLK_I or posedge Reset)
1945
     begin
1946
        if(Reset)
1947
          RxBDReady <= 1'b0;
1948
        else
1949
          if(RxPointerRead)
1950
            RxBDReady <= 1'b0;
1951
          else
1952
            if(RxEn & RxEn_q & RxBDRead)
1953
              // RxBDReady is sampled only once at the beginning
1954
              RxBDReady <= ram_do[15];
1955
     end // always @ (posedge WB_CLK_I or posedge Reset)
1956 6 julius
 
1957 403 julius
   // Indicate we just read the RX buffer descriptor and that RxBDReady is 
1958
   // valid.
1959
   reg rx_just_read_bd;
1960
   always @ (posedge WB_CLK_I or posedge Reset)
1961
     if(Reset)
1962
       rx_just_read_bd <= 0;
1963
     else if (rx_just_read_bd)
1964
       rx_just_read_bd <= 0;
1965
     else
1966
       rx_just_read_bd <= (RxEn & RxEn_q & RxBDRead);
1967 6 julius
 
1968 403 julius
   // Signal to indicate we've checked and the RxBD we want to use is not free
1969
   reg rx_waiting_for_bd_to_become_free;
1970
   always @ (posedge WB_CLK_I or posedge Reset)
1971
     if(Reset)
1972
       rx_waiting_for_bd_to_become_free <= 0;
1973
     else if (rx_just_read_bd & !RxBDReady)
1974
       // Assert if we read the BD and it's not cool
1975
       rx_waiting_for_bd_to_become_free <= 1;
1976
     else if (RxBDOK)
1977
       rx_waiting_for_bd_to_become_free <= 0;
1978
 
1979 6 julius
 
1980
 
1981 403 julius
   // Latching Rx buffer descriptor status
1982
   // Data is avaliable one cycle after the access is started (at that time 
1983
   // signal RxEn is not active)
1984
   always @ (posedge WB_CLK_I or posedge Reset)
1985
     begin
1986
        if(Reset)
1987
          RxStatus <= 2'h0;
1988
        else
1989
          if(RxEn & RxEn_q & RxBDRead)
1990
            RxStatus <= ram_do[14:13];
1991
     end
1992 6 julius
 
1993
 
1994 403 julius
   // RxBDOK generation
1995
   always @ (posedge WB_CLK_I or posedge Reset)
1996
     begin
1997
        if(Reset)
1998
          RxBDOK <= 1'b0;
1999
        else
2000
          if(rx_wb_writeback_finished | RxAbortSync2 & ~RxAbortSync3 |
2001
             ~r_RxEn & r_RxEn_q)
2002
            RxBDOK <= 1'b0;
2003
          else
2004
            if(RxBDReady)
2005
              RxBDOK <= 1'b1;
2006
     end
2007 6 julius
 
2008 403 julius
   // Reading Rx BD pointer
2009
   assign StartRxPointerRead = RxBDRead & RxBDReady;
2010 6 julius
 
2011 403 julius
   // Reading Tx BD Pointer
2012
   always @ (posedge WB_CLK_I or posedge Reset)
2013
     begin
2014
        if(Reset)
2015
          RxPointerRead <= 1'b0;
2016
        else
2017
          if(StartRxPointerRead)
2018
            RxPointerRead <= 1'b1;
2019
          else
2020
            if(RxEn & RxEn_q)
2021
              RxPointerRead <= 1'b0;
2022
     end
2023 6 julius
 
2024
 
2025 403 julius
   //Latching Rx buffer pointer from buffer descriptor;
2026
   always @ (posedge WB_CLK_I or posedge Reset)
2027
     begin
2028
        if(Reset)
2029
          RxPointerMSB <= 30'h0;
2030
        else
2031
          if(RxEn & RxEn_q & RxPointerRead)
2032
            RxPointerMSB <= ram_do[31:2];
2033
          else
2034
            if(MasterWbRX & m_wb_ack_i)
2035
              // Word access  (always word access. m_wb_sel_o are used for 
2036
              // selecting bytes)
2037
              RxPointerMSB <= RxPointerMSB + 1'b1;
2038
     end
2039 6 julius
 
2040
 
2041 403 julius
   //Latching last addresses from buffer descriptor (used as byte-half-word 
2042
   // indicator);
2043
   always @ (posedge WB_CLK_I or posedge Reset)
2044
     begin
2045
        if(Reset)
2046
          RxPointerLSB_rst[1:0] <= 0;
2047
        else
2048
          if(MasterWbRX & m_wb_ack_i)
2049
            // After first write all RxByteSel are active
2050
            RxPointerLSB_rst[1:0] <= 0;
2051
          else
2052
            if(RxEn & RxEn_q & RxPointerRead)
2053
              RxPointerLSB_rst[1:0] <= ram_do[1:0];
2054
     end
2055 6 julius
 
2056
 
2057 403 julius
   always @ (RxPointerLSB_rst)
2058
     begin
2059
        case(RxPointerLSB_rst[1:0])  // synopsys parallel_case
2060
          2'h0 : RxByteSel[3:0] = 4'hf;
2061
          2'h1 : RxByteSel[3:0] = 4'h7;
2062
          2'h2 : RxByteSel[3:0] = 4'h3;
2063
          2'h3 : RxByteSel[3:0] = 4'h1;
2064
        endcase
2065
     end
2066 6 julius
 
2067
 
2068 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2069
     begin
2070
        if(Reset)
2071
          RxEn_needed <= 1'b0;
2072
        else
2073
          if(/*~RxReady &*/ r_RxEn & WbEn & ~WbEn_q)
2074
            RxEn_needed <= 1'b1;
2075
          else
2076
            if(RxPointerRead & RxEn & RxEn_q)
2077
              RxEn_needed <= 1'b0;
2078
     end
2079 6 julius
 
2080
 
2081 403 julius
   // Reception status is written back to the buffer descriptor after the end 
2082
   // of frame is detected.
2083
   assign RxStatusWrite = rx_wb_writeback_finished & RxEn & RxEn_q;
2084 6 julius
 
2085 403 julius
   reg RxEnableWindow;
2086 6 julius
 
2087 403 julius
   // Indicating that last byte is being reveived
2088
   always @ (posedge MRxClk or posedge Reset)
2089
     begin
2090
        if(Reset)
2091
          LastByteIn <= 1'b0;
2092
        else
2093
          if(ShiftWillEnd & (&RxByteCnt) | RxAbort)
2094
            LastByteIn <= 1'b0;
2095
          else
2096
            if(RxValid /*& RxReady*/& RxEndFrm & ~(&RxByteCnt) & RxEnableWindow)
2097
              LastByteIn <= 1'b1;
2098
     end
2099 6 julius
 
2100 403 julius
   assign StartShiftWillEnd = LastByteIn  | RxValid & RxEndFrm & (&RxByteCnt) &
2101
                              RxEnableWindow;
2102 6 julius
 
2103 403 julius
   // Indicating that data reception will end
2104
   always @ (posedge MRxClk or posedge Reset)
2105
     begin
2106
        if(Reset)
2107
          ShiftWillEnd <= 1'b0;
2108
        else
2109
          if(ShiftEnded_rck | RxAbort)
2110
            ShiftWillEnd <= 1'b0;
2111
          else
2112
            if(StartShiftWillEnd)
2113
              ShiftWillEnd <= 1'b1;
2114
     end
2115 6 julius
 
2116 403 julius
   // Receive byte counter
2117
   always @ (posedge MRxClk or posedge Reset)
2118
     begin
2119
        if(Reset)
2120
          RxByteCnt <= 2'h0;
2121
        else
2122
          if(ShiftEnded_rck | RxAbort)
2123
            RxByteCnt <= 2'h0;
2124
          else
2125
            if(RxValid & RxStartFrm /*& RxReady*/)
2126
              case(RxPointerLSB_rst)  // synopsys parallel_case
2127
                2'h0 : RxByteCnt <= 2'h1;
2128
                2'h1 : RxByteCnt <= 2'h2;
2129
                2'h2 : RxByteCnt <= 2'h3;
2130
                2'h3 : RxByteCnt <= 2'h0;
2131
              endcase
2132
            else
2133
              if(RxValid & RxEnableWindow /*& RxReady*/ | LastByteIn)
2134
                RxByteCnt <= RxByteCnt + 1'b1;
2135
     end
2136 6 julius
 
2137
 
2138 403 julius
   // Indicates how many bytes are valid within the last word
2139
   always @ (posedge MRxClk or posedge Reset)
2140
     begin
2141
        if(Reset)
2142
          RxValidBytes <= 2'h1;
2143
        else
2144
          if(RxValid & RxStartFrm)
2145
            case(RxPointerLSB_rst)  // synopsys parallel_case
2146
              2'h0 : RxValidBytes <= 2'h1;
2147
              2'h1 : RxValidBytes <= 2'h2;
2148
              2'h2 : RxValidBytes <= 2'h3;
2149
              2'h3 : RxValidBytes <= 2'h0;
2150
            endcase
2151
          else
2152
            if(RxValid & ~LastByteIn & ~RxStartFrm & RxEnableWindow)
2153
              RxValidBytes <= RxValidBytes + 1'b1;
2154
     end
2155 6 julius
 
2156
 
2157 403 julius
   always @ (posedge MRxClk or posedge Reset)
2158
     begin
2159
        if(Reset)
2160
          RxDataLatched1       <= 24'h0;
2161
        else
2162
          if(RxValid /*& RxReady*/ & ~LastByteIn)
2163
            if(RxStartFrm)
2164
              begin
2165
                 case(RxPointerLSB_rst)     // synopsys parallel_case
2166
                   // Big Endian Byte Ordering
2167
                   2'h0:        RxDataLatched1[31:24] <= RxData;
2168
                   2'h1:        RxDataLatched1[23:16] <= RxData;
2169
                   2'h2:        RxDataLatched1[15:8]  <= RxData;
2170
                   2'h3:        RxDataLatched1        <= RxDataLatched1;
2171
                 endcase
2172
              end
2173
            else if (RxEnableWindow)
2174
              begin
2175
                 case(RxByteCnt)     // synopsys parallel_case
2176
                   // Big Endian Byte Ordering
2177
                   2'h0:        RxDataLatched1[31:24] <= RxData;
2178
                   2'h1:        RxDataLatched1[23:16] <= RxData;
2179
                   2'h2:        RxDataLatched1[15:8]  <= RxData;
2180
                   2'h3:        RxDataLatched1        <= RxDataLatched1;
2181
                 endcase
2182
              end
2183
     end
2184 6 julius
 
2185 403 julius
   wire SetWriteRxDataToFifo;
2186 6 julius
 
2187 403 julius
   // Assembling data that will be written to the rx_fifo
2188
   always @ (posedge MRxClk or posedge Reset)
2189
     begin
2190
        if(Reset)
2191
          RxDataLatched2 <= 32'h0;
2192
        else
2193
          if(SetWriteRxDataToFifo & ~ShiftWillEnd)
2194
            // Big Endian Byte Ordering
2195
            RxDataLatched2 <= {RxDataLatched1[31:8], RxData};
2196
          else
2197
            if(SetWriteRxDataToFifo & ShiftWillEnd)
2198
              case(RxValidBytes)  // synopsys parallel_case
2199
                // Big Endian Byte Ordering
2200
 
2201
                1 : RxDataLatched2 <= {RxDataLatched1[31:24], 24'h0};
2202
                2 : RxDataLatched2 <= {RxDataLatched1[31:16], 16'h0};
2203
                3 : RxDataLatched2 <= {RxDataLatched1[31:8],   8'h0};
2204
              endcase
2205
     end
2206 6 julius
 
2207
 
2208 403 julius
   reg WriteRxDataToFifoSync1;
2209
   reg WriteRxDataToFifoSync2;
2210
   reg WriteRxDataToFifoSync3;
2211 6 julius
 
2212
 
2213 403 julius
   // Indicating start of the reception process
2214
   assign SetWriteRxDataToFifo = (RxValid &/* RxReady &*/ ~RxStartFrm &
2215
                                  RxEnableWindow & (&RxByteCnt)) |
2216
                                 (RxValid &/* RxReady &*/  RxStartFrm &
2217
                                  (&RxPointerLSB_rst))           |
2218
                                 (ShiftWillEnd & LastByteIn & (&RxByteCnt));
2219 6 julius
 
2220 403 julius
   always @ (posedge MRxClk or posedge Reset)
2221
     begin
2222
        if(Reset)
2223
          WriteRxDataToFifo <= 1'b0;
2224
        else
2225
          if(SetWriteRxDataToFifo & ~RxAbort)
2226
            WriteRxDataToFifo <= 1'b1;
2227
          else
2228
            if(WriteRxDataToFifoSync2 | RxAbort)
2229
              WriteRxDataToFifo <= 1'b0;
2230
     end
2231 6 julius
 
2232
 
2233
 
2234 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2235
     begin
2236
        if(Reset)
2237
          WriteRxDataToFifoSync1 <= 1'b0;
2238
        else
2239
          if(WriteRxDataToFifo)
2240
            WriteRxDataToFifoSync1 <= 1'b1;
2241
          else
2242
            WriteRxDataToFifoSync1 <= 1'b0;
2243
     end
2244 6 julius
 
2245 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2246
     begin
2247
        if(Reset)
2248
          WriteRxDataToFifoSync2 <= 1'b0;
2249
        else
2250
          WriteRxDataToFifoSync2 <= WriteRxDataToFifoSync1;
2251
     end
2252 6 julius
 
2253 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2254
     begin
2255
        if(Reset)
2256
          WriteRxDataToFifoSync3 <= 1'b0;
2257
        else
2258
          WriteRxDataToFifoSync3 <= WriteRxDataToFifoSync2;
2259
     end
2260 6 julius
 
2261 403 julius
   wire WriteRxDataToFifo_wb;
2262
   assign WriteRxDataToFifo_wb = WriteRxDataToFifoSync2 &
2263
                                 ~WriteRxDataToFifoSync3;
2264
   // Receive fifo selection register - JB
2265
   reg [3:0] rx_shift_ended_wb_shr;
2266
   reg       rx_ethside_fifo_sel;
2267
   reg       rx_wbside_fifo_sel;
2268 6 julius
 
2269 403 julius
   // Shift in this - our detection of end of data RX
2270
   always @(posedge WB_CLK_I)
2271
     rx_shift_ended_wb_shr <= {rx_shift_ended_wb_shr[2:0],
2272
                               ShiftEndedSync1 & ~ShiftEndedSync2};
2273
 
2274
 
2275
   always @ (posedge WB_CLK_I or posedge Reset)
2276
     if(Reset)
2277
       rx_ethside_fifo_sel <= 0;
2278
     else
2279
       if(rx_shift_ended_wb_shr[3:2] == 2'b01)
2280
         // Switch over whenever we've finished receiving last frame's data
2281
         rx_ethside_fifo_sel <= ~rx_ethside_fifo_sel;
2282 6 julius
 
2283 403 julius
   // Wishbone side looks at other FIFO when we write back the status of this 
2284
   // received frame
2285
   always @ (posedge WB_CLK_I or posedge Reset)
2286
     if(Reset)
2287
       rx_wbside_fifo_sel <= 0;
2288
     else
2289
       if(rx_wb_writeback_finished & RxEn & RxEn_q)
2290
         // Switch over whenever we've finished receiving last frame's data
2291
         rx_wbside_fifo_sel <= ~rx_wbside_fifo_sel;
2292 6 julius
 
2293 403 julius
   reg  LatchedRxStartFrm;
2294
   reg  SyncRxStartFrm;
2295
   reg  SyncRxStartFrm_q;
2296
   reg  SyncRxStartFrm_q2;
2297
   wire RxFifoReset;
2298 6 julius
 
2299 403 julius
   always @ (posedge MRxClk or posedge Reset)
2300
     begin
2301
        if(Reset)
2302
          LatchedRxStartFrm <= 0;
2303
        else
2304
          if(RxStartFrm & ~SyncRxStartFrm_q)
2305
            LatchedRxStartFrm <= 1;
2306
          else
2307
            if(SyncRxStartFrm_q)
2308
              LatchedRxStartFrm <= 0;
2309
     end
2310 6 julius
 
2311
 
2312 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2313
     begin
2314
        if(Reset)
2315
          SyncRxStartFrm <= 0;
2316
        else
2317
          if(LatchedRxStartFrm)
2318
            SyncRxStartFrm <= 1;
2319
          else
2320
            SyncRxStartFrm <= 0;
2321
     end
2322 6 julius
 
2323
 
2324 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2325
     begin
2326
        if(Reset)
2327
          SyncRxStartFrm_q <= 0;
2328
        else
2329
          SyncRxStartFrm_q <= SyncRxStartFrm;
2330
     end
2331 6 julius
 
2332 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2333
     begin
2334
        if(Reset)
2335
          SyncRxStartFrm_q2 <= 0;
2336
        else
2337
          SyncRxStartFrm_q2 <= SyncRxStartFrm_q;
2338
     end
2339
   wire rx_startfrm_wb;
2340
   assign rx_startfrm_wb = SyncRxStartFrm_q & ~SyncRxStartFrm_q2;
2341
 
2342
 
2343
   assign RxFifoReset = rx_startfrm_wb;
2344
 
2345 6 julius
 
2346 403 julius
   wire [31:0] rx_fifo0_data_out;
2347
   wire        rx_fifo0_write;
2348
   wire        rx_fifo0_read;
2349
   wire        rx_fifo0_clear;
2350
   wire        rx_fifo0_full;
2351
   wire        rx_fifo0_afull;
2352
   wire        rx_fifo0_empty;
2353
   wire        rx_fifo0_aempty;
2354 6 julius
 
2355
 
2356 403 julius
   wire [31:0] rx_fifo1_data_out;
2357
   wire        rx_fifo1_write;
2358
   wire        rx_fifo1_read;
2359
   wire        rx_fifo1_clear;
2360
   wire        rx_fifo1_full;
2361
   wire        rx_fifo1_afull;
2362
   wire        rx_fifo1_empty;
2363
   wire        rx_fifo1_aempty;
2364 6 julius
 
2365 403 julius
   wire [`ETH_RX_FIFO_CNT_WIDTH-1:0] rx_fifo0_cnt;
2366
   wire [`ETH_RX_FIFO_CNT_WIDTH-1:0] rx_fifo1_cnt;
2367
 
2368
   // RX FIFO buffer 0 controls
2369
   assign rx_fifo0_write = (!rx_ethside_fifo_sel) & WriteRxDataToFifo_wb &
2370
                           ~rx_fifo0_full;
2371
 
2372
   assign rx_fifo0_read = (!rx_wbside_fifo_sel) & MasterWbRX & m_wb_ack_i &
2373
                          ~rx_fifo0_empty;
2374
 
2375
   assign rx_fifo0_clear = (!rx_ethside_fifo_sel) & RxFifoReset;
2376 6 julius
 
2377 403 julius
   // RX FIFO buffer 1 controls
2378
   assign rx_fifo1_write = (rx_ethside_fifo_sel) & WriteRxDataToFifo_wb &
2379
                           ~rx_fifo1_full;
2380
 
2381
   assign rx_fifo1_read = (rx_wbside_fifo_sel) & MasterWbRX & m_wb_ack_i &
2382
                           ~rx_fifo1_empty;
2383 6 julius
 
2384 403 julius
   assign rx_fifo1_clear = (rx_ethside_fifo_sel) & RxFifoReset;
2385
 
2386
   eth_fifo #(
2387
              `ETH_RX_FIFO_DATA_WIDTH,
2388
              `ETH_RX_FIFO_DEPTH,
2389
              `ETH_RX_FIFO_CNT_WIDTH
2390
              )
2391
   rx_fifo0 (
2392
             .clk            (WB_CLK_I         ),
2393
             .reset          (Reset            ),
2394
             // Inputs
2395
             .data_in        (RxDataLatched2   ),
2396
             .write          (rx_fifo0_write   ),
2397
             .read           (rx_fifo0_read    ),
2398
             .clear          (rx_fifo0_clear   ),
2399
             // Outputs
2400
             .data_out       (rx_fifo0_data_out),
2401
             .full           (rx_fifo0_full    ),
2402
             .almost_full    (),
2403
             .almost_empty   (rx_fifo0_aempty  ),
2404
             .empty          (rx_fifo0_empty   ),
2405
             .cnt            (rx_fifo0_cnt     )
2406
             );
2407 6 julius
 
2408 403 julius
   eth_fifo #(
2409
              `ETH_RX_FIFO_DATA_WIDTH,
2410
              `ETH_RX_FIFO_DEPTH,
2411
              `ETH_RX_FIFO_CNT_WIDTH
2412
              )
2413
   rx_fifo1 (
2414
             .clk            (WB_CLK_I         ),
2415
             .reset          (Reset            ),
2416
             // Inputs
2417
             .data_in        (RxDataLatched2   ),
2418
             .write          (rx_fifo1_write   ),
2419
             .read           (rx_fifo1_read    ),
2420
             .clear          (rx_fifo1_clear   ),
2421
             // Outputs
2422
             .data_out       (rx_fifo1_data_out),
2423
             .full           (rx_fifo1_full    ),
2424
             .almost_full    (),
2425
             .almost_empty   (rx_fifo1_aempty  ),
2426
             .empty          (rx_fifo1_empty   ),
2427
             .cnt            (rx_fifo1_cnt     )
2428
             );
2429 6 julius
 
2430 403 julius
   assign m_wb_dat_o = rx_wbside_fifo_sel ?
2431
                       rx_fifo1_data_out : rx_fifo0_data_out;
2432
   assign rxfifo_cnt = rx_wbside_fifo_sel ?
2433
                       rx_fifo1_cnt : rx_fifo0_cnt;
2434
 
2435
   assign RxBufferAlmostEmpty = rx_wbside_fifo_sel ?
2436
                                rx_fifo1_aempty : rx_fifo0_aempty;
2437 6 julius
 
2438 403 julius
   assign RxBufferEmpty = rx_wbside_fifo_sel ?
2439
                          rx_fifo1_empty : rx_fifo0_empty;
2440 6 julius
 
2441 403 julius
   assign RxBufferFull = rx_wbside_fifo_sel ?
2442
                         rx_fifo1_full : rx_fifo0_full;
2443
 
2444
 
2445
 
2446 6 julius
 
2447 403 julius
 
2448
   wire                              write_rx_data_to_memory_wait;
2449
   assign write_rx_data_to_memory_wait = !RxBDOK | RxPointerRead;
2450
   wire                              write_rx_data_to_memory_go;
2451
 
2452
`ifdef ETH_RX_BURST_EN
2453
   assign enough_data_in_rxfifo_for_burst = rxfifo_cnt>=(`ETH_BURST_LENGTH);
2454
   assign enough_data_in_rxfifo_for_burst_plus1 = rxfifo_cnt>(`ETH_BURST_LENGTH - 1);
2455
   // While receiving, don't flog the bus too hard, only write out when
2456
   // we can burst. But when finishing keep going until we've emptied the fifo
2457
   assign write_rx_data_to_memory_go =
2458
                                       RxEnableWindow & (rx_wbside_fifo_sel == rx_ethside_fifo_sel) ?
2459
                                       (rxfifo_cnt>(`ETH_BURST_LENGTH)+2) |
2460
                                       (|rx_burst_cnt) : ~RxBufferEmpty;
2461
 
2462
`else
2463
   assign enough_data_in_rxfifo_for_burst = rxfifo_cnt>=`ETH_BURST_LENGTH;
2464
   assign enough_data_in_rxfifo_for_burst_plus1 = rxfifo_cnt>`ETH_BURST_LENGTH;
2465
   assign write_rx_data_to_memory_go = ~RxBufferEmpty;
2466
`endif // !`ifdef ETH_RX_BURST_EN
2467
 
2468
   assign WriteRxDataToMemory = write_rx_data_to_memory_go & !write_rx_data_to_memory_wait;
2469
 
2470
   assign rx_burst = rx_burst_en & WriteRxDataToMemory;
2471 6 julius
 
2472
 
2473 403 julius
   // Generation of the end-of-frame signal
2474
   always @ (posedge MRxClk or posedge Reset)
2475
     begin
2476
        if(Reset)
2477
          ShiftEnded_rck <= 1'b0;
2478
        else
2479
          if(~RxAbort & SetWriteRxDataToFifo & StartShiftWillEnd)
2480
            ShiftEnded_rck <= 1'b1;
2481
          else
2482
            if(RxAbort | ShiftEndedSync_c1 & ShiftEndedSync_c2)
2483
              ShiftEnded_rck <= 1'b0;
2484
     end
2485 6 julius
 
2486 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2487
     begin
2488
        if(Reset)
2489
          ShiftEndedSync1 <= 1'b0;
2490
        else
2491
          ShiftEndedSync1 <= ShiftEnded_rck;
2492
     end
2493 6 julius
 
2494 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2495
     begin
2496
        if(Reset)
2497
          ShiftEndedSync2 <= 1'b0;
2498
        else
2499
          ShiftEndedSync2 <= ShiftEndedSync1;
2500
     end
2501 6 julius
 
2502 403 julius
   // indicate end of wishbone RX is coming up
2503
   always @ (posedge WB_CLK_I or posedge Reset)
2504
     if(Reset)
2505
       rx_wb_last_writes <= 1'b0;
2506
     else if (!rx_wb_last_writes)
2507
       rx_wb_last_writes <= ShiftEndedSync1 & ~ShiftEndedSync2;
2508
     else if (rx_wb_writeback_finished & RxEn & RxEn_q)
2509
       rx_wb_last_writes <= 0;
2510
 
2511
   // Pulse indicating last of RX data has been written out
2512
   always @ (posedge WB_CLK_I or posedge Reset)
2513
     if(Reset)
2514
       rx_wb_writeback_finished <= 0;
2515
     else if (rx_wb_writeback_finished & RxEn & RxEn_q)
2516
       rx_wb_writeback_finished <= 0;
2517
     else
2518
       rx_wb_writeback_finished <= rx_wb_last_writes & RxBufferEmpty &
2519
                                   !WriteRxDataToFifo_wb;
2520
 
2521 6 julius
 
2522 403 julius
   always @ (posedge MRxClk or posedge Reset)
2523
     begin
2524
        if(Reset)
2525
          ShiftEndedSync_c1 <= 1'b0;
2526
        else
2527
          ShiftEndedSync_c1 <= ShiftEndedSync2;
2528
     end
2529 6 julius
 
2530 403 julius
   always @ (posedge MRxClk or posedge Reset)
2531
     begin
2532
        if(Reset)
2533
          ShiftEndedSync_c2 <= 1'b0;
2534
        else
2535
          ShiftEndedSync_c2 <= ShiftEndedSync_c1;
2536
     end
2537 6 julius
 
2538 403 julius
   // Generation of the end-of-frame signal
2539
   always @ (posedge MRxClk or posedge Reset)
2540
     begin
2541
        if(Reset)
2542
          RxEnableWindow <= 1'b0;
2543
        else
2544
          if(RxStartFrm)
2545
            RxEnableWindow <= 1'b1;
2546
          else
2547
            if(RxEndFrm | RxAbort)
2548
              RxEnableWindow <= 1'b0;
2549
     end
2550 6 julius
 
2551
 
2552 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2553
     begin
2554
        if(Reset)
2555
          RxAbortSync1 <= 1'b0;
2556
        else
2557
          RxAbortSync1 <= RxAbortLatched;
2558
     end
2559 6 julius
 
2560 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2561
     begin
2562
        if(Reset)
2563
          RxAbortSync2 <= 1'b0;
2564
        else
2565
          RxAbortSync2 <= RxAbortSync1;
2566
     end
2567 6 julius
 
2568 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2569
     begin
2570
        if(Reset)
2571
          RxAbortSync3 <= 1'b0;
2572
        else
2573
          RxAbortSync3 <= RxAbortSync2;
2574
     end
2575 6 julius
 
2576 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2577
     begin
2578
        if(Reset)
2579
          RxAbortSync4 <= 1'b0;
2580
        else
2581
          RxAbortSync4 <= RxAbortSync3;
2582
     end
2583 6 julius
 
2584 403 julius
   always @ (posedge MRxClk or posedge Reset)
2585
     begin
2586
        if(Reset)
2587
          RxAbortSyncb1 <= 1'b0;
2588
        else
2589
          RxAbortSyncb1 <= RxAbortSync2;
2590
     end
2591 6 julius
 
2592 403 julius
   always @ (posedge MRxClk or posedge Reset)
2593
     begin
2594
        if(Reset)
2595
          RxAbortSyncb2 <= 1'b0;
2596
        else
2597
          RxAbortSyncb2 <= RxAbortSyncb1;
2598
     end
2599 6 julius
 
2600
 
2601 403 julius
   always @ (posedge MRxClk or posedge Reset)
2602
     begin
2603
        if(Reset)
2604
          RxAbortLatched <= 1'b0;
2605
        else
2606
          if(RxAbortSyncb2)
2607
            RxAbortLatched <= 1'b0;
2608
          else
2609
            if(RxAbort)
2610
              RxAbortLatched <= 1'b1;
2611
     end
2612 6 julius
 
2613
 
2614 403 julius
   always @ (posedge MRxClk or posedge Reset)
2615
     begin
2616
        if(Reset)
2617
          LatchedRxLength[15:0] <= 16'h0;
2618
        else
2619
          if(LoadRxStatus)
2620
            LatchedRxLength[15:0] <= RxLength[15:0];
2621
     end
2622 6 julius
 
2623
 
2624 403 julius
   assign RxStatusIn = {ReceivedPauseFrm, AddressMiss, RxOverrun, InvalidSymbol, DribbleNibble, ReceivedPacketTooBig, ShortFrame, LatchedCrcError, RxLateCollision};
2625 6 julius
 
2626 403 julius
   always @ (posedge MRxClk or posedge Reset)
2627
     begin
2628
        if(Reset)
2629
          RxStatusInLatched <= 'h0;
2630
        else
2631
          if(LoadRxStatus)
2632
            RxStatusInLatched <= RxStatusIn;
2633
     end
2634 6 julius
 
2635
 
2636 403 julius
   // Rx overrun
2637
   always @ (posedge WB_CLK_I or posedge Reset)
2638
     begin
2639
        if(Reset)
2640
          RxOverrun <= 1'b0;
2641
        else
2642
          if(RxStatusWrite)
2643
            RxOverrun <= 1'b0;
2644
          else
2645
            if(RxBufferFull & WriteRxDataToFifo_wb)
2646
              RxOverrun <= 1'b1;
2647
     end
2648 6 julius
 
2649
 
2650
 
2651 403 julius
   wire TxError;
2652
   assign TxError = TxUnderRun | RetryLimit | LateCollLatched | CarrierSenseLost;
2653 6 julius
 
2654 403 julius
   wire RxError;
2655 6 julius
 
2656 403 julius
   // ShortFrame (RxStatusInLatched[2]) can not set an error because short 
2657
   // frames are aborted when signal r_RecSmall is set to 0 in MODER register. 
2658
   // AddressMiss is identifying that a frame was received because of the 
2659
   // promiscous mode and is not an error
2660
   assign RxError = (|RxStatusInLatched[6:3]) | (|RxStatusInLatched[1:0]);
2661 6 julius
 
2662
 
2663
 
2664 403 julius
   reg  RxStatusWriteLatched;
2665
   reg  RxStatusWriteLatched_sync1;
2666
   reg  RxStatusWriteLatched_sync2;
2667
   reg  RxStatusWriteLatched_syncb1;
2668
   reg  RxStatusWriteLatched_syncb2;
2669 6 julius
 
2670
 
2671 403 julius
   // Latching and synchronizing RxStatusWrite signal. This signal is used for 
2672
   // clearing the ReceivedPauseFrm signal
2673
   always @ (posedge WB_CLK_I or posedge Reset)
2674
     begin
2675
        if(Reset)
2676
          RxStatusWriteLatched <= 1'b0;
2677
        else
2678
          if(RxStatusWriteLatched_syncb2)
2679
            RxStatusWriteLatched <= 1'b0;
2680
          else
2681
            if(RxStatusWrite)
2682
              RxStatusWriteLatched <= 1'b1;
2683
     end
2684 6 julius
 
2685
 
2686 403 julius
   always @ (posedge MRxClk or posedge Reset)
2687
     begin
2688
        if(Reset)
2689
          begin
2690
             RxStatusWriteLatched_sync1 <= 1'b0;
2691
             RxStatusWriteLatched_sync2 <= 1'b0;
2692
          end
2693
        else
2694
          begin
2695
             RxStatusWriteLatched_sync1 <= RxStatusWriteLatched;
2696
             RxStatusWriteLatched_sync2 <= RxStatusWriteLatched_sync1;
2697
          end
2698
     end
2699 6 julius
 
2700
 
2701 403 julius
   always @ (posedge WB_CLK_I or posedge Reset)
2702
     begin
2703
        if(Reset)
2704
          begin
2705
             RxStatusWriteLatched_syncb1 <= 1'b0;
2706
             RxStatusWriteLatched_syncb2 <= 1'b0;
2707
          end
2708
        else
2709
          begin
2710
             RxStatusWriteLatched_syncb1 <= RxStatusWriteLatched_sync2;
2711
             RxStatusWriteLatched_syncb2 <= RxStatusWriteLatched_syncb1;
2712
          end
2713
     end
2714 6 julius
 
2715
 
2716
 
2717 403 julius
   // Tx Done Interrupt
2718
   always @ (posedge WB_CLK_I or posedge Reset)
2719
     begin
2720
        if(Reset)
2721
          TxB_IRQ <= 1'b0;
2722
        else
2723
          if(TxStatusWrite & TxIRQEn)
2724
            TxB_IRQ <= ~TxError;
2725
          else
2726
            TxB_IRQ <= 1'b0;
2727
     end
2728 6 julius
 
2729
 
2730 403 julius
   // Tx Error Interrupt
2731
   always @ (posedge WB_CLK_I or posedge Reset)
2732
     begin
2733
        if(Reset)
2734
          TxE_IRQ <= 1'b0;
2735
        else
2736
          if(TxStatusWrite & TxIRQEn)
2737
            TxE_IRQ <= TxError;
2738
          else
2739
            TxE_IRQ <= 1'b0;
2740
     end
2741 6 julius
 
2742
 
2743 403 julius
   // Rx Done Interrupt
2744
   always @ (posedge WB_CLK_I or posedge Reset)
2745
     begin
2746
        if(Reset)
2747
          RxB_IRQ <= 1'b0;
2748
        else
2749
          if(RxStatusWrite & RxIRQEn & ReceivedPacketGood &
2750
             (~ReceivedPauseFrm | ReceivedPauseFrm & r_PassAll & (~r_RxFlow)))
2751
            RxB_IRQ <= (~RxError);
2752
          else
2753
            RxB_IRQ <= 1'b0;
2754
     end
2755 6 julius
 
2756
 
2757 403 julius
   // Rx Error Interrupt
2758
   always @ (posedge WB_CLK_I or posedge Reset)
2759
     begin
2760
        if(Reset)
2761
          RxE_IRQ <= 1'b0;
2762
        else
2763
          if(RxStatusWrite & RxIRQEn & (~ReceivedPauseFrm | ReceivedPauseFrm
2764
                                        & r_PassAll & (~r_RxFlow)))
2765
            RxE_IRQ <= RxError;
2766
          else
2767
            RxE_IRQ <= 1'b0;
2768
     end
2769 6 julius
 
2770 403 julius
   // Set this high when we started receiving another packet while the wishbone
2771
   // side was still writing out the last one. This makes sure we check at the
2772
   // right time if the next buffer descriptor is free.
2773
   reg rxstartfrm_occurred;
2774
   always @ (posedge WB_CLK_I)
2775
     if (Reset)
2776
       rxstartfrm_occurred <= 0;
2777
     else if (rx_just_read_bd)
2778
       rxstartfrm_occurred <= 0;
2779
     else if (((rx_ethside_fifo_sel != rx_wbside_fifo_sel) | StartRxBDRead |
2780
               RxBDRead) & rx_startfrm_wb)
2781
       rxstartfrm_occurred <= 1;
2782 6 julius
 
2783 403 julius
 
2784 6 julius
 
2785 403 julius
   reg busy_wb;
2786
   always @ (posedge WB_CLK_I or posedge Reset)
2787
     if(Reset)
2788
       busy_wb <= 0;
2789
     else if (busy_wb)
2790
       busy_wb <= 0;
2791
     else if
2792
       // Indicate busy if either:
2793
       // a) RX is idle and we get a start frame and current BD indicates not
2794
       //    ready.
2795
       // b) RX is already receiving another packet and we got a startframe,
2796
       //    indicated by rx_startfrm_occurred, and we then read the BD and
2797
       //    it says it's not ready.
2798
       // This actually may not work since it's in the MII RX clock domain.
2799
       ((rx_ethside_fifo_sel == rx_wbside_fifo_sel) &
2800
        ((rxstartfrm_occurred & rx_just_read_bd & ~RxBDReady) |
2801
         (!rxstartfrm_occurred & !StartRxBDRead & !RxBDRead & rx_startfrm_wb &
2802
          rx_waiting_for_bd_to_become_free))
2803
        )
2804
       busy_wb <= 1;
2805
 
2806 6 julius
 
2807 403 julius
   assign Busy_IRQ = busy_wb;
2808 6 julius
 
2809 403 julius
   always @(posedge Busy_IRQ)
2810
     $display("(%t)(%m) Ethernet MAC BUSY signal asserted", $time);
2811
 
2812
 
2813
   // Assign the debug output
2814
`ifdef WISHBONE_DEBUG
2815
   // Top byte, burst progress counters
2816
   assign dbg_dat0[31] = 0;
2817
   assign dbg_dat0[30] = 0;
2818
   assign dbg_dat0[29:28] = rx_burst_cnt;
2819
   assign dbg_dat0[27] = 0;
2820
   assign dbg_dat0[26] = 0;
2821
   assign dbg_dat0[25:24] = tx_burst_cnt;
2822
 
2823
   // Third byte
2824
   assign dbg_dat0[23] = 0;
2825
   assign dbg_dat0[22] = 0;
2826
   assign dbg_dat0[21] = rx_burst;
2827
   assign dbg_dat0[20] = rx_burst_en;
2828
   assign dbg_dat0[19] = 0;
2829
   assign dbg_dat0[18] = 0;
2830
   assign dbg_dat0[17] = tx_burst;
2831
   assign dbg_dat0[16] = tx_burst_en;
2832
   // Second byte - TxBDAddress - or TX BD address pointer
2833
   assign dbg_dat0[15:8] = { 1'b0, TxBDAddress};
2834
   // Bottom byte - FSM controlling vector
2835
   assign dbg_dat0[7:0] = {MasterWbTX,MasterWbRX,
2836
                           ReadTxDataFromMemory_2,WriteRxDataToMemory,
2837
                           MasterAccessFinished,cyc_cleared,
2838
                           tx_burst,rx_burst};
2839
 
2840
`endif
2841 6 julius
 
2842
 
2843
 
2844
endmodule

powered by: WebSVN 2.1.0

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