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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [orp/] [orp_soc/] [rtl/] [verilog/] [ethernet.old/] [eth_wishbonedma.v] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 746 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth_wishbonedma.v                                           ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6
////  http://www.opencores.org/projects/ethmac/                   ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Igor Mohor (igorM@opencores.org)                      ////
10
////                                                              ////
11
////  All additional information is avaliable in the Readme.txt   ////
12
////  file.                                                       ////
13
////                                                              ////
14
//////////////////////////////////////////////////////////////////////
15
////                                                              ////
16
//// Copyright (C) 2001 Authors                                   ////
17
////                                                              ////
18
//// This source file may be used and distributed without         ////
19
//// restriction provided that this copyright statement is not    ////
20
//// removed from the file and that any derivative work contains  ////
21
//// the original copyright notice and the associated disclaimer. ////
22
////                                                              ////
23
//// This source file is free software; you can redistribute it   ////
24
//// and/or modify it under the terms of the GNU Lesser General   ////
25
//// Public License as published by the Free Software Foundation; ////
26
//// either version 2.1 of the License, or (at your option) any   ////
27
//// later version.                                               ////
28
////                                                              ////
29
//// This source is distributed in the hope that it will be       ////
30
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
31
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
32
//// PURPOSE.  See the GNU Lesser General Public License for more ////
33
//// details.                                                     ////
34
////                                                              ////
35
//// You should have received a copy of the GNU Lesser General    ////
36
//// Public License along with this source; if not, download it   ////
37
//// from http://www.opencores.org/lgpl.shtml                     ////
38
////                                                              ////
39
//////////////////////////////////////////////////////////////////////
40
//
41
// CVS Revision History
42
//
43
// $Log: not supported by cvs2svn $
44
// Revision 1.16  2002/02/26 16:59:55  mohor
45
// Small fixes for external/internal DMA missmatches.
46
//
47
// Revision 1.15  2002/02/26 16:23:05  mohor
48
//  WB_SEL_I was unused and removed from design
49
//
50
// Revision 1.14  2002/02/12 17:03:47  mohor
51
// RxOverRun added to statuses.
52
//
53
// Revision 1.13  2002/02/11 09:18:22  mohor
54
// Tx status is written back to the BD.
55
//
56
// Revision 1.12  2002/02/08 16:21:54  mohor
57
// Rx status is written back to the BD.
58
//
59
// Revision 1.11  2002/02/06 14:10:21  mohor
60
// non-DMA host interface added. Select the right configutation in eth_defines.
61
//
62
// Revision 1.10  2002/01/23 10:28:16  mohor
63
// Link in the header changed.
64
//
65
// Revision 1.9  2001/12/05 15:00:16  mohor
66
// RX_BD_NUM changed to TX_BD_NUM (holds number of TX descriptors
67
// instead of the number of RX descriptors).
68
//
69
// Revision 1.8  2001/12/05 10:45:59  mohor
70
// ETH_RX_BD_ADR register deleted. ETH_RX_BD_NUM is used instead.
71
//
72
// Revision 1.7  2001/11/13 14:23:56  mohor
73
// Generic memory model is used. Defines are changed for the same reason.
74
//
75
// Revision 1.6  2001/10/19 11:24:29  mohor
76
// Number of addresses (wb_adr_i) minimized.
77
//
78
// Revision 1.5  2001/10/19 08:43:51  mohor
79
// eth_timescale.v changed to timescale.v This is done because of the
80
// simulation of the few cores in a one joined project.
81
//
82
// Revision 1.4  2001/10/18 12:07:11  mohor
83
// Status signals changed, Adress decoding changed, interrupt controller
84
// added.
85
//
86
// Revision 1.3  2001/09/24 15:02:56  mohor
87
// Defines changed (All precede with ETH_). Small changes because some
88
// tools generate warnings when two operands are together. Synchronization
89
// between two clocks domains in eth_wishbonedma.v is changed (due to ASIC
90
// demands).
91
//
92
// Revision 1.2  2001/08/08 08:28:21  mohor
93
// "else" was missing within the always block in file eth_wishbonedma.v.
94
//
95
// Revision 1.1  2001/08/06 14:44:29  mohor
96
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
97
// Include files fixed to contain no path.
98
// File names and module names changed ta have a eth_ prologue in the name.
99
// File eth_timescale.v is used to define timescale
100
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
101
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
102
// and Mdo_OE. The bidirectional signal must be created on the top level. This
103
// is done due to the ASIC tools.
104
//
105
// Revision 1.1  2001/07/30 21:23:42  mohor
106
// Directory structure changed. Files checked and joind together.
107
//
108
//
109
//
110
//
111
//
112
 
113
 
114
`include "eth_defines.v"
115
`include "timescale.v"
116
 
117
 
118
module eth_wishbonedma
119
   (
120
 
121
    // WISHBONE common
122
    WB_CLK_I, Reset, WB_DAT_I, WB_DAT_O,
123
 
124
    // WISHBONE slave
125
                WB_ADR_I, WB_WE_I, WB_ACK_O,
126
                WB_REQ_O, WB_ACK_I, WB_ND_O, WB_RD_O, BDCs,
127
 
128
    //TX
129
    MTxClk, TxStartFrm, TxEndFrm, TxUsedData, TxData,
130
    TxRetry, TxAbort, TxUnderRun, TxDone, TPauseRq, TxPauseTV, PerPacketCrcEn,
131
    PerPacketPad,
132
 
133
    //RX
134
    MRxClk, RxData, RxValid, RxStartFrm, RxEndFrm,
135
 
136
    // Register
137
    r_TxEn, r_RxEn, r_TxBDNum, r_DmaEn, TX_BD_NUM_Wr, r_RecSmall,
138
 
139
    WillSendControlFrame, TxCtrlEndFrm,
140
 
141
    // Interrupts
142
    TxB_IRQ, TxE_IRQ, RxB_IRQ, RxE_IRQ, Busy_IRQ, TxC_IRQ, RxC_IRQ,
143
 
144
    RxAbort, ReceivedPacketGood,
145
 
146
    InvalidSymbol, LatchedCrcError, RxLateCollision, ShortFrame, DribbleNibble,
147
    ReceivedPacketTooBig, RxLength, LoadRxStatus, RetryCntLatched, RetryLimit,
148
    LateCollLatched, DeferLatched, CarrierSenseLost
149
 
150
 
151
                );
152
 
153
 
154
parameter Tp = 1;
155
 
156
// WISHBONE common
157
input           WB_CLK_I;       // WISHBONE clock
158
input           Reset;          // WISHBONE reset
159
input  [31:0]   WB_DAT_I;       // WISHBONE data input
160
output [31:0]   WB_DAT_O;       // WISHBONE data output
161
 
162
// WISHBONE slave
163
input   [9:2]   WB_ADR_I;       // WISHBONE address input
164
input           WB_WE_I;        // WISHBONE write enable input
165
input           BDCs;           // Buffer descriptors are selected
166
output          WB_ACK_O;       // WISHBONE acknowledge output
167
 
168
// DMA
169
input   [1:0]   WB_ACK_I;       // DMA acknowledge input
170
output  [1:0]   WB_REQ_O;       // DMA request output
171
output  [1:0]   WB_ND_O;        // DMA force new descriptor output
172
output          WB_RD_O;        // DMA restart descriptor output
173
 
174
// Rx Status
175
input           InvalidSymbol;
176
input           LatchedCrcError;
177
input           RxLateCollision;
178
input           ShortFrame;
179
input           DribbleNibble;
180
input           ReceivedPacketTooBig;
181
input   [15:0]  RxLength;
182
input           LoadRxStatus;
183
 
184
// Tx Status
185
input    [3:0]  RetryCntLatched;
186
input           RetryLimit;
187
input           LateCollLatched;
188
input           DeferLatched;
189
input           CarrierSenseLost;
190
 
191
 
192
// Tx
193
input           MTxClk;         // Transmit clock (from PHY)
194
input           TxUsedData;     // Transmit packet used data
195
input           TxRetry;        // Transmit packet retry
196
input           TxAbort;        // Transmit packet abort
197
input           TxDone;         // Transmission ended
198
output          TxStartFrm;     // Transmit packet start frame
199
output          TxEndFrm;       // Transmit packet end frame
200
output  [7:0]   TxData;         // Transmit packet data byte
201
output          TxUnderRun;     // Transmit packet under-run
202
output          PerPacketCrcEn; // Per packet crc enable
203
output          PerPacketPad;   // Per packet pading
204
output          TPauseRq;       // Tx PAUSE control frame
205
output [15:0]   TxPauseTV;      // PAUSE timer value
206
input           WillSendControlFrame;
207
input           TxCtrlEndFrm;
208
 
209
// Rx
210
input           MRxClk;         // Receive clock (from PHY)
211
input   [7:0]   RxData;         // Received data byte (from PHY)
212
input           RxValid;        // 
213
input           RxStartFrm;     // 
214
input           RxEndFrm;       // 
215
 
216
//Register
217
input           r_TxEn;         // Transmit enable
218
input           r_RxEn;         // Receive enable
219
input   [7:0]   r_TxBDNum;      // Receive buffer descriptor number
220
input           r_DmaEn;        // DMA enable
221
input           TX_BD_NUM_Wr;   // RxBDNumber written
222
input           r_RecSmall;     // Receive small frames
223
 
224
input           RxAbort;
225
input           ReceivedPacketGood;
226
 
227
// Interrupts
228
output TxB_IRQ;
229
output TxE_IRQ;
230
output RxB_IRQ;
231
output RxE_IRQ;
232
output Busy_IRQ;
233
output TxC_IRQ;
234
output RxC_IRQ;
235
 
236
reg             WB_REQ_O_RX;
237
reg             WB_ND_O_TX;     // New descriptor
238
reg             WB_RD_O;        // Restart descriptor
239
 
240
reg             TxStartFrm;
241
reg             TxEndFrm;
242
reg     [7:0]   TxData;
243
 
244
reg             TxUnderRun;
245
reg             TPauseRq;
246
reg             TxPauseRq;
247
 
248
reg             RxStartFrm_wb;
249
reg     [31:0]  RxData_wb;
250
reg             RxDataValid_wb;
251
reg             RxEndFrm_wb;
252
 
253
reg     [7:0]   BDAddress;    // BD address for access from MAC side
254
reg             BDRead_q;
255
 
256
reg             TxBDRead;
257
reg             TxDataRead;
258
reg             TxStatusWrite;
259
 
260
reg     [1:0]   TxValidBytesLatched;
261
reg             TxEndFrm_wbLatched;
262
 
263
reg    [15:0]   TxLength;
264
reg    [31:0]   TxStatus;
265
 
266
reg    [15:0]   RxStatus;
267
 
268
reg             TxStartFrm_wb;
269
reg             TxRetry_wb;
270
reg             GetNewTxData_wb;
271
reg             TxDone_wb;
272
reg             TxAbort_wb;
273
 
274
 
275
reg             TxStartFrmRequest;
276
reg    [31:0]   TxDataLatched_wb;
277
 
278
reg             RxStatusWriteOccured;
279
 
280
reg             TxRestart_wb_q;
281
reg             TxDone_wb_q;
282
reg             TxAbort_wb_q;
283
reg             RxBDReady;
284
reg             TxBDReady;
285
 
286
reg             RxBDRead;
287
reg             RxStatusWrite;
288
reg             WbWriteError;
289
 
290
reg    [31:0]   TxDataLatched;
291
reg     [1:0]   TxByteCnt;
292
reg             LastWord;
293
reg             GetNewTxData;
294
reg             TxRetryLatched;
295
 
296
reg             Div2;
297
reg             Flop;
298
 
299
reg             BlockingTxStatusWrite;
300
reg             TxStatusWriteOccured;
301
reg             BlockingTxBDRead;
302
 
303
reg             GetNewTxData_wb_latched;
304
 
305
reg             NewTxDataAvaliable_wb;
306
 
307
reg             TxBDAccessed;
308
 
309
reg     [7:0]   TxBDAddress;
310
reg     [7:0]   RxBDAddress;
311
 
312
reg             GotDataSync1;
313
reg             GotDataSync2;
314
wire            TPauseRqSync2;
315
wire            GotDataSync3;
316
reg             GotData;
317
reg             SyncGetNewTxData_wb1;
318
reg             SyncGetNewTxData_wb2;
319
reg             SyncGetNewTxData_wb3;
320
reg             TxDoneSync1;
321
reg             TxDoneSync2;
322
wire            TxDoneSync3;
323
reg             TxRetrySync1;
324
reg             TxRetrySync2;
325
wire            TxRetrySync3;
326
reg             TxAbortSync1;
327
reg             TxAbortSync2;
328
wire            TxAbortSync3;
329
 
330
reg             TxAbort_q;
331
reg             TxDone_q;
332
reg             TxRetry_q;
333
reg             TxUsedData_q;
334
 
335
reg    [31:0]   RxDataLatched2;
336
reg    [15:0]   RxDataLatched1;
337
reg     [1:0]   RxValidBytes;
338
reg     [1:0]   RxByteCnt;
339
reg             LastByteIn;
340
reg             ShiftWillEnd;
341
 
342
reg             StartShifting;
343
reg             Shifting_wb_Sync1;
344
reg             Shifting_wb_Sync2;
345
reg             LatchNow_wb;
346
 
347
reg             ShiftEndedSync1;
348
reg             ShiftEndedSync2;
349
reg             ShiftEndedSync3;
350
wire            ShiftEnded;
351
 
352
reg             RxStartFrmSync1;
353
reg             RxStartFrmSync2;
354
wire            RxStartFrmSync3;
355
 
356
reg             DMACycleFinishedTx_q;
357
reg             DataNotAvaliable;
358
 
359
reg             ClearTxBDReadySync1;
360
reg             ClearTxBDReadySync2;
361
reg             ClearTxBDReady;
362
 
363
reg             TxCtrlEndFrm_wbSync1;
364
reg             TxCtrlEndFrm_wbSync2;
365
wire            TxCtrlEndFrm_wbSync3;
366
reg             TxCtrlEndFrm_wb;
367
 
368
wire    [15:0]  TxPauseTV;
369
wire            ResetDataNotAvaliable;
370
wire            SetDataNotAvaliable;
371
wire            DWord;                      // Only 32-bit accesses are valid
372
wire            BDWe;                       // BD Write Enable for access from WISHBONE side
373
wire            BDRead;                     // BD Read access from WISHBONE side
374
wire   [31:0]   BDDataIn;                   // BD data in
375
wire   [31:0]   BDDataOut;                  // BD data out
376
 
377
wire            TxEndFrm_wb;
378
 
379
wire            DMACycleFinishedTx;
380
wire            BDStatusWrite;
381
 
382
wire            TxEn;
383
wire            RxEn;
384
wire            TxRestartPulse;
385
wire            TxDonePulse;
386
wire            TxAbortPulse;
387
 
388
wire            StartRxBDRead;
389
wire            ResetRxBDRead;
390
wire            StartRxStatusWrite;
391
 
392
wire            ResetShifting_wb;
393
wire            StartShifting_wb;
394
wire            DMACycleFinishedRx;
395
 
396
wire   [31:0]   WB_BDDataOut;
397
 
398
wire            StartTxBDRead;
399
wire            StartTxDataRead;
400
wire            ResetTxDataRead;
401
wire            StartTxStatusWrite;
402
wire            ResetTxStatusWrite;
403
 
404
wire            TxIRQEn;
405
wire            WrapTxStatusBit;
406
 
407
wire            WrapRxStatusBit;
408
 
409
wire    [1:0]   TxValidBytes;
410
 
411
wire    [7:0]   TempTxBDAddress;
412
wire    [7:0]   TempRxBDAddress;
413
 
414
wire   [15:0]   NewRxStatus;
415
 
416
wire            SetGotData;
417
wire            ResetGotData;
418
wire            GotDataEvaluate;
419
wire            ResetSyncGetNewTxData_wb;
420
wire            ResetTxDoneSync;
421
wire            ResetTxRetrySync;
422
wire            ResetTxAbortSync;
423
wire            SetSyncGetNewTxData_wb;
424
 
425
wire            SetTxAbortSync;
426
wire            ResetShiftEnded;
427
wire            ResetRxStartFrmSync1;
428
wire            StartShiftEnded;
429
wire            StartRxStartFrmSync1;
430
 
431
wire            SetClearTxBDReady;
432
wire            ResetClearTxBDReady;
433
 
434
wire            ResetTxCtrlEndFrm_wb;
435
wire            SetTxCtrlEndFrm_wb;
436
 
437
 
438
 
439
 
440
assign BDWe   = BDCs &  WB_WE_I;
441
assign BDRead = BDCs & ~WB_WE_I;
442
assign WB_ACK_O = BDWe | BDRead & BDRead_q;  // ACK is delayed one clock because of BLOCKRAM properties when performing read
443
 
444
 
445
 
446
reg EnableRAM;
447
always @ (posedge WB_CLK_I or posedge Reset)
448
begin
449
  if(Reset)
450
    EnableRAM   <=#Tp 1'b0;
451
  else
452
  if(BDWe)
453
    EnableRAM   <=#Tp 1'b1;
454
  else
455
    EnableRAM   <=#Tp EnableRAM;
456
end
457
 
458
 
459
// Generic synchronous two-port RAM interface
460
generic_tpram     #(8, 32)  i_generic_tpram
461
(
462
  .clk_a(WB_CLK_I),   .rst_a(Reset),            .ce_a(1'b1),        .we_a(BDWe),
463
  .oe_a(EnableRAM),   .addr_a(WB_ADR_I[9:2]),   .di_a(WB_DAT_I),    .do_a(WB_BDDataOut),
464
 
465
  .clk_b(WB_CLK_I),   .rst_b(Reset),            .ce_b(EnableRAM),   .we_b(BDStatusWrite),
466
  .oe_b(EnableRAM),   .addr_b(BDAddress[7:0]),  .di_b(BDDataIn),    .do_b(BDDataOut)
467
);
468
 
469
 
470
// WB_CLK_I is divided by 2. This signal is used for enabling tx and rx operations sequentially
471
always @ (posedge WB_CLK_I or posedge Reset)
472
begin
473
  if(Reset)
474
    Div2 <=#Tp 1'h0;
475
  else
476
    Div2 <=#Tp ~Div2;
477
end
478
 
479
 
480
// Tx_En and Rx_En select who can access the BD memory (Tx or Rx)
481
assign TxEn =  Div2 & r_TxEn;
482
assign RxEn = ~Div2 & r_RxEn;
483
 
484
 
485
// Changes for tx occur every second clock. Flop is used for this manner.
486
always @ (posedge MTxClk or posedge Reset)
487
begin
488
  if(Reset)
489
    Flop <=#Tp 1'b0;
490
  else
491
  if(TxDone | TxAbort | TxRetry_q)
492
    Flop <=#Tp 1'b0;
493
  else
494
  if(TxUsedData)
495
    Flop <=#Tp ~Flop;
496
end
497
 
498
 
499
// Latching READY status of the Tx buffer descriptor
500
always @ (posedge WB_CLK_I or posedge Reset)
501
begin
502
  if(Reset)
503
    TxBDReady <=#Tp 1'b0;
504
  else
505
  if(TxEn & TxBDRead)
506
    TxBDReady <=#Tp BDDataOut[15]; // TxBDReady=BDDataOut[15]   // TxBDReady is sampled only once at the beginning
507
  else
508
  if(TxDone & ~TxDone_q | TxAbort & ~TxAbort_q | TxRetry & ~TxRetry_q | ClearTxBDReady | TxPauseRq)
509
    TxBDReady <=#Tp 1'b0;
510
end
511
 
512
 
513
// Latching READY status of the Tx buffer descriptor
514
always @ (posedge WB_CLK_I or posedge Reset)
515
begin
516
  if(Reset)
517
    begin
518
      TxPauseRq <=#Tp 1'b0;
519
    end
520
  else
521
  if(TxEn & TxBDRead)
522
    begin
523
      TxPauseRq <=#Tp BDDataOut[9];    // Tx PAUSE request
524
    end
525
  else
526
      TxPauseRq <=#Tp 1'b0;
527
end
528
 
529
 
530
assign TxPauseTV[15:0] = TxLength[15:0];
531
 
532
// Reading the Tx buffer descriptor
533
assign StartTxBDRead = TxEn & ~BlockingTxBDRead & (TxRetry_wb | TxStatusWriteOccured);
534
 
535
always @ (posedge WB_CLK_I or posedge Reset)
536
begin
537
  if(Reset)
538
    TxBDRead <=#Tp 1'b1;
539
  else
540
  if(StartTxBDRead)
541
    TxBDRead <=#Tp 1'b1;
542
  else
543
  if(StartTxDataRead | TxPauseRq)
544
    TxBDRead <=#Tp 1'b0;
545
end
546
 
547
 
548
 
549
// Requesting data (DMA)
550
assign StartTxDataRead = TxBDRead & TxBDReady & ~TxPauseRq | GetNewTxData_wb;
551
assign ResetTxDataRead = DMACycleFinishedTx | TxRestartPulse | TxAbortPulse | TxDonePulse;
552
 
553
 
554
// Reading data
555
always @ (posedge WB_CLK_I or posedge Reset)
556
begin
557
  if(Reset)
558
    TxDataRead <=#Tp 1'b0;
559
  else
560
  if(StartTxDataRead & r_DmaEn)
561
    TxDataRead <=#Tp 1'b1;
562
  else
563
  if(ResetTxDataRead)
564
    TxDataRead <=#Tp 1'b0;
565
end
566
 
567
// Requesting tx data from the DMA
568
assign WB_REQ_O[0] = TxDataRead;
569
assign DMACycleFinishedTx = WB_REQ_O[0] & WB_ACK_I[0] & TxBDReady;
570
 
571
 
572
// Writing status back to the Tx buffer descriptor
573
assign StartTxStatusWrite = TxEn & ~BlockingTxStatusWrite & (TxDone_wb | TxAbort_wb | TxCtrlEndFrm_wb);
574
assign ResetTxStatusWrite = TxStatusWrite;
575
 
576
always @ (posedge WB_CLK_I or posedge Reset)
577
begin
578
  if(Reset)
579
    TxStatusWrite <=#Tp 1'b0;
580
  else
581
  if(StartTxStatusWrite)
582
    TxStatusWrite <=#Tp 1'b1;
583
  else
584
  if(ResetTxStatusWrite)
585
    TxStatusWrite <=#Tp 1'b0;
586
end
587
 
588
 
589
// Status writing must occur only once. Meanwhile it is blocked.
590
always @ (posedge WB_CLK_I or posedge Reset)
591
begin
592
  if(Reset)
593
    BlockingTxStatusWrite <=#Tp 1'b0;
594
  else
595
  if(StartTxStatusWrite)
596
    BlockingTxStatusWrite <=#Tp 1'b1;
597
  else
598
  if(~TxDone_wb & ~TxAbort_wb)
599
    BlockingTxStatusWrite <=#Tp 1'b0;
600
end
601
 
602
 
603
// After a tx status write is finished, a new tx buffer descriptor is read. Signal must be
604
// latched because new BD read doesn't occur immediately.
605
always @ (posedge WB_CLK_I or posedge Reset)
606
begin
607
  if(Reset)
608
    TxStatusWriteOccured <=#Tp 1'b0;
609
  else
610
  if(StartTxStatusWrite)
611
    TxStatusWriteOccured <=#Tp 1'b1;
612
  else
613
  if(StartTxBDRead)
614
    TxStatusWriteOccured <=#Tp 1'b0;
615
end
616
 
617
 
618
// TxBDRead state is activated only once. 
619
always @ (posedge WB_CLK_I or posedge Reset)
620
begin
621
  if(Reset)
622
    BlockingTxBDRead <=#Tp 1'b0;
623
  else
624
  if(StartTxBDRead)
625
    BlockingTxBDRead <=#Tp 1'b1;
626
  else
627
  if(TxStartFrm_wb | TxCtrlEndFrm_wb)
628
    BlockingTxBDRead <=#Tp 1'b0;
629
end
630
 
631
 
632
// Latching status from the tx buffer descriptor
633
// Data is avaliable one cycle after the access is started (at that time signal TxEn is not active)
634
always @ (posedge WB_CLK_I or posedge Reset)
635
begin
636
  if(Reset)
637
    TxStatus <=#Tp 32'h0;
638
  else
639
  if(TxBDRead & TxEn)
640
    TxStatus <=#Tp BDDataOut;
641
end
642
 
643
 
644
//Latching length from the buffer descriptor;
645
always @ (posedge WB_CLK_I or posedge Reset)
646
begin
647
  if(Reset)
648
    TxLength <=#Tp 16'h0;
649
  else
650
  if(TxBDRead & TxEn)
651
    TxLength <=#Tp BDDataOut[31:16];
652
  else
653
  if(GetNewTxData_wb & ~WillSendControlFrame)
654
    begin
655
      if(TxLength > 4)
656
        TxLength <=#Tp TxLength - 4;    // Length is subtracted at the data request
657
      else
658
        TxLength <=#Tp 16'h0;
659
    end
660
end
661
 
662
 
663
// Latching Rx buffer descriptor status
664
// Data is avaliable one cycle after the access is started (at that time signal RxEn is not active)
665
always @ (posedge WB_CLK_I or posedge Reset)
666
begin
667
  if(Reset)
668
    RxStatus <=#Tp 16'h0;
669
  else
670
  if(RxBDRead & RxEn)
671
    RxStatus <=#Tp BDDataOut[15:0];
672
end
673
 
674
 
675
// Signal GetNewTxData_wb that requests new data from the DMA must be latched since the DMA response
676
// might be delayed.
677
always @ (posedge WB_CLK_I or posedge Reset)
678
begin
679
  if(Reset)
680
    GetNewTxData_wb_latched <=#Tp 1'b0;
681
  else
682
  if(GetNewTxData_wb)
683
    GetNewTxData_wb_latched <=#Tp 1'b1;
684
  else
685
  if(DMACycleFinishedTx)
686
    GetNewTxData_wb_latched <=#Tp 1'b0;
687
end
688
 
689
 
690
// New tx data is avaliable after the DMA access is finished
691
always @ (posedge WB_CLK_I or posedge Reset)
692
begin
693
  if(Reset)
694
    NewTxDataAvaliable_wb <=#Tp 1'b0;
695
  else
696
  if(DMACycleFinishedTx & GetNewTxData_wb_latched)
697
    NewTxDataAvaliable_wb <=#Tp 1'b1;
698
  else
699
  if(NewTxDataAvaliable_wb)
700
    NewTxDataAvaliable_wb <=#Tp 1'b0;
701
end
702
 
703
 
704
// Tx Buffer descriptor is only read at the beginning. This signal is used for generation of the
705
// TxStartFrm_wb signal.
706
always @ (posedge WB_CLK_I or posedge Reset)
707
begin
708
  if(Reset)
709
    TxBDAccessed <=#Tp 1'b0;
710
  else
711
  if(TxBDRead)
712
    TxBDAccessed <=#Tp 1'b1;
713
  else
714
  if(TxStartFrm_wb)
715
    TxBDAccessed <=#Tp 1'b0;
716
end
717
 
718
 
719
// TxStartFrm_wb: indicator of the start frame (synchronized to WB_CLK_I)
720
always @ (posedge WB_CLK_I or posedge Reset)
721
begin
722
  if(Reset)
723
    TxStartFrm_wb <=#Tp 1'b0;
724
  else
725
  if(DMACycleFinishedTx & TxBDAccessed & ~TxStartFrm_wb)
726
    TxStartFrm_wb <=#Tp 1'b1;
727
  else
728
  if(TxStartFrm_wb)
729
    TxStartFrm_wb <=#Tp 1'b0;
730
end
731
 
732
 
733
// TxEndFrm_wb: indicator of the end of frame
734
assign TxEndFrm_wb = (TxLength <= 4) & TxUsedData;
735
 
736
 
737
// Input latch of the end-of-frame indicator
738
always @ (posedge WB_CLK_I or posedge Reset)
739
begin
740
  if(Reset)
741
    TxEndFrm_wbLatched <=#Tp 1'b0;
742
  else
743
  if(TxEndFrm_wb)
744
    TxEndFrm_wbLatched <=#Tp 1'b1;
745
  else
746
  if(TxRestartPulse | TxDonePulse | TxAbortPulse)
747
    TxEndFrm_wbLatched <=#Tp 1'b0;
748
end
749
 
750
 
751
// Marks which bytes are valid within the word.
752
assign TxValidBytes = (TxLength >= 4)? 2'b0 : TxLength[1:0];
753
 
754
 
755
// Latching valid bytes
756
always @ (posedge WB_CLK_I or posedge Reset)
757
begin
758
  if(Reset)
759
    TxValidBytesLatched <=#Tp 2'h0;
760
  else
761
  if(TxEndFrm_wb & ~TxEndFrm_wbLatched)
762
    TxValidBytesLatched <=#Tp TxValidBytes;
763
  else
764
  if(TxRestartPulse | TxDonePulse | TxAbortPulse)
765
    TxValidBytesLatched <=#Tp 2'h0;
766
end
767
 
768
 
769
// Input Tx data latch 
770
always @ (posedge WB_CLK_I or posedge Reset)
771
begin
772
  if(Reset)
773
    TxDataLatched_wb <=#Tp 32'h0;
774
  else
775
  if(DMACycleFinishedTx)
776
    TxDataLatched_wb <=#Tp WB_DAT_I;
777
end
778
 
779
 
780
// TxStartFrmRequest is set when a new frame is avaliable or when new data of the same frame is avaliable)
781
always @ (posedge WB_CLK_I or posedge Reset)
782
begin
783
  if(Reset)
784
    TxStartFrmRequest <=#Tp 1'b0;
785
  else
786
  if(TxStartFrm_wb | NewTxDataAvaliable_wb)
787
    TxStartFrmRequest <=#Tp TxStartFrm_wb;
788
end
789
 
790
 
791
// Bit 14 is used as a wrap bit. When active it indicates the last buffer descriptor in a row. After
792
// using this descriptor, first BD will be used again.
793
 
794
 
795
 
796
// TX
797
// bit 15 od tx je ready
798
// bit 14 od tx je interrupt (Tx buffer ali tx error bit se postavi v interrupt registru, ko se ta buffer odda)
799
// bit 13 od tx je wrap
800
// bit 12 od tx je pad
801
// bit 11 od tx je crc
802
// bit 10 od tx je last (crc se doda le ce je bit 11 in hkrati bit 10)
803
// bit 9  od tx je pause request (control frame)
804
    // Vsi zgornji biti gredo ven, spodnji biti (od 8 do 0) pa so statusni in se vpisejo po koncu oddajanja
805
// bit 8  od tx je defer indication
806
// bit 7  od tx je late collision
807
// bit 6  od tx je retransmittion limit
808
// bit 5  od tx je underrun
809
// bit 4  od tx je carrier sense lost
810
// bit [3:0] od tx je retry count
811
 
812
//assign TxBDReady      = TxStatus[15];     // already used
813
assign TxIRQEn          = TxStatus[14];
814
assign WrapTxStatusBit  = TxStatus[13];                                                   // ok povezan
815
assign PerPacketPad     = TxStatus[12];                                                   // ok povezan
816
assign PerPacketCrcEn   = TxStatus[11] & TxStatus[10];      // When last is also set      // ok povezan
817
//assign TxPauseRq      = TxStatus[9];      // already used
818
 
819
 
820
 
821
// RX
822
// bit 15 od rx je empty
823
// bit 14 od rx je interrupt (Rx buffer ali rx frame received se postavi v interrupt registru, ko se ta buffer zapre)
824
// bit 13 od rx je wrap
825
// bit 12 od rx je reserved
826
// bit 11 od rx je reserved
827
// bit 10 od rx je last (crc se doda le ce je bit 11 in hkrati bit 10)
828
// bit 9  od rx je pause request (control frame)
829
    // Vsi zgornji biti gredo ven, spodnji biti (od 8 do 0) pa so statusni in se vpisejo po koncu oddajanja
830
// bit 8  od rx je defer indication
831
// bit 7  od rx je late collision
832
// bit 6  od rx je retransmittion limit
833
// bit 5  od rx je underrun
834
// bit 4  od rx je carrier sense lost
835
// bit [3:0] od rx je retry count
836
 
837
assign WrapRxStatusBit = RxStatus[13];
838
 
839
 
840
// Temporary Tx and Rx buffer descriptor address 
841
assign TempTxBDAddress[7:0] = {8{ TxStatusWrite    & ~WrapTxStatusBit}} & (TxBDAddress + 1) ; // Tx BD increment or wrap (last BD)
842
assign TempRxBDAddress[7:0] = {8{ WrapRxStatusBit}} & (r_TxBDNum)       | // Using first Rx BD
843
                              {8{~WrapRxStatusBit}} & (RxBDAddress + 1) ; // Using next Rx BD (incremenrement address)
844
 
845
 
846
// Latching Tx buffer descriptor address
847
always @ (posedge WB_CLK_I or posedge Reset)
848
begin
849
  if(Reset)
850
    TxBDAddress <=#Tp 8'h0;
851
  else
852
  if(TxStatusWrite)
853
    TxBDAddress <=#Tp TempTxBDAddress;
854
end
855
 
856
 
857
// Latching Rx buffer descriptor address
858
always @ (posedge WB_CLK_I or posedge Reset)
859
begin
860
  if(Reset)
861
    RxBDAddress <=#Tp 8'h0;
862
  else
863
  if(TX_BD_NUM_Wr)                        // When r_TxBDNum is updated, RxBDAddress is also
864
    RxBDAddress <=#Tp WB_DAT_I[7:0];
865
  else
866
  if(RxStatusWrite)
867
    RxBDAddress <=#Tp TempRxBDAddress;
868
end
869
 
870
 
871
// Selecting Tx or Rx buffer descriptor address
872
always @ (posedge WB_CLK_I or posedge Reset)
873
begin
874
  if(Reset)
875
    BDAddress <=#Tp 8'h0;
876
  else
877
  if(TxEn)
878
    BDAddress <=#Tp TxBDAddress;
879
  else
880
    BDAddress <=#Tp RxBDAddress;
881
end
882
 
883
 
884
assign NewRxStatus[15:0] = {1'b0, WbWriteError, RxStatus[13:0]};
885
 
886
 
887
assign BDDataIn  = TxStatusWrite ? {TxStatus[31:9], 9'h0}
888
                                 : {16'h1399, NewRxStatus};
889
 
890
assign BDStatusWrite = TxStatusWrite | RxStatusWrite;
891
 
892
 
893
// Generating delayed signals
894
always @ (posedge WB_CLK_I or posedge Reset)
895
begin
896
  if(Reset)
897
    begin
898
      TxRestart_wb_q        <=#Tp 1'b0;
899
      TxDone_wb_q           <=#Tp 1'b0;
900
      TxAbort_wb_q          <=#Tp 1'b0;
901
      BDRead_q              <=#Tp 1'b0;
902
      DMACycleFinishedTx_q  <=#Tp 1'b0;
903
    end
904
  else
905
    begin
906
      TxRestart_wb_q        <=#Tp TxRetry_wb;
907
      TxDone_wb_q           <=#Tp TxDone_wb;
908
      TxAbort_wb_q          <=#Tp TxAbort_wb;
909
      BDRead_q              <=#Tp BDRead;
910
      DMACycleFinishedTx_q  <=#Tp DMACycleFinishedTx;
911
    end
912
end
913
 
914
 
915
// Signals used for various purposes
916
assign TxRestartPulse = TxRetry_wb   & ~TxRestart_wb_q;
917
assign TxDonePulse    = TxDone_wb    & ~TxDone_wb_q;
918
assign TxAbortPulse   = TxAbort_wb   & ~TxAbort_wb_q;
919
 
920
 
921
// Next descriptor for Tx DMA channel
922
always @ (posedge WB_CLK_I or posedge Reset)
923
begin
924
  if(Reset)
925
    WB_ND_O_TX <=#Tp 1'b0;
926
  else
927
  if(TxDonePulse | TxAbortPulse)
928
    WB_ND_O_TX <=#Tp 1'b1;
929
  else
930
  if(WB_ND_O_TX)
931
    WB_ND_O_TX <=#Tp 1'b0;
932
end
933
 
934
 
935
// Force next descriptor on DMA channel 0 (Tx)
936
assign WB_ND_O[0] = WB_ND_O_TX;
937
 
938
 
939
 
940
// Restart descriptor for DMA channel 0 (Tx)
941
always @ (posedge WB_CLK_I or posedge Reset)
942
begin
943
  if(Reset)
944
    WB_RD_O <=#Tp 1'b0;
945
  else
946
  if(TxRestartPulse)
947
    WB_RD_O <=#Tp 1'b1;
948
  else
949
  if(WB_RD_O)
950
    WB_RD_O <=#Tp 1'b0;
951
end
952
 
953
 
954
assign SetClearTxBDReady = ~TxUsedData & TxUsedData_q;
955
assign ResetClearTxBDReady = ClearTxBDReady | Reset;
956
 
957
 
958
always @ (posedge SetClearTxBDReady or posedge ResetClearTxBDReady)
959
begin
960
  if(ResetClearTxBDReady)
961
    ClearTxBDReadySync1 <=#Tp 1'b0;
962
  else
963
    ClearTxBDReadySync1 <=#Tp 1'b1;
964
end
965
 
966
always @ (posedge WB_CLK_I or posedge Reset)
967
begin
968
  if(Reset)
969
    ClearTxBDReadySync2 <=#Tp 1'b0;
970
  else
971
  if(ClearTxBDReadySync1 & ~ClearTxBDReady)
972
    ClearTxBDReadySync2 <=#Tp 1'b1;
973
  else
974
    ClearTxBDReadySync2 <=#Tp 1'b0;
975
end
976
 
977
 
978
always @ (posedge WB_CLK_I or posedge Reset)
979
begin
980
  if(Reset)
981
    ClearTxBDReady <=#Tp 1'b0;
982
  else
983
  if(ClearTxBDReadySync2 & ~ClearTxBDReady)
984
    ClearTxBDReady <=#Tp 1'b1;
985
  else
986
    ClearTxBDReady <=#Tp 1'b0;
987
end
988
 
989
 
990
 
991
// Latching and synchronizing the Tx pause request signal
992
eth_sync_clk1_clk2 syn1 (.clk1(MTxClk),  .clk2(WB_CLK_I),  .reset1(Reset),
993
                         .reset2(Reset), .set2(TxPauseRq), .sync_out(TPauseRqSync2)
994
                        );
995
 
996
 
997
always @ (posedge MTxClk or posedge Reset)
998
begin
999
  if(Reset)
1000
    TPauseRq <=#Tp 1'b0;
1001
  else
1002
  if(TPauseRq )
1003
    TPauseRq <=#Tp 1'b0;
1004
  else
1005
  if(TPauseRqSync2)
1006
    TPauseRq <=#Tp 1'b1;
1007
end
1008
 
1009
 
1010
 
1011
// Generating delayed signals
1012
always @ (posedge MTxClk or posedge Reset)
1013
begin
1014
  if(Reset)
1015
    begin
1016
      TxAbort_q     <=#Tp 1'b0;
1017
      TxDone_q      <=#Tp 1'b0;
1018
      TxRetry_q     <=#Tp 1'b0;
1019
      TxUsedData_q  <=#Tp 1'b0;
1020
    end
1021
  else
1022
    begin
1023
      TxAbort_q     <=#Tp TxAbort;
1024
      TxDone_q      <=#Tp TxDone;
1025
      TxRetry_q     <=#Tp TxRetry;
1026
      TxUsedData_q  <=#Tp TxUsedData;
1027
    end
1028
end
1029
 
1030
 
1031
 
1032
// Sinchronizing and evaluating tx data
1033
assign SetGotData = (TxStartFrm_wb | NewTxDataAvaliable_wb & ~TxAbort_wb & ~TxRetry_wb) & ~WB_CLK_I;
1034
 
1035
eth_sync_clk1_clk2 syn2 (.clk1(MTxClk),  .clk2(WB_CLK_I),   .reset1(Reset),
1036
                         .reset2(Reset), .set2(SetGotData), .sync_out(GotDataSync3));
1037
 
1038
 
1039
// Evaluating data. If abort or retry occured meanwhile than data is ignored.
1040
assign GotDataEvaluate = GotDataSync3 & ~GotData & (~TxRetry & ~TxAbort | (TxRetry | TxAbort) & (TxStartFrmRequest | TxStartFrm));
1041
 
1042
 
1043
// Indication of good data
1044
always @ (posedge MTxClk or posedge Reset)
1045
begin
1046
  if(Reset)
1047
    GotData <=#Tp 1'b0;
1048
  else
1049
  if(GotDataEvaluate)
1050
    GotData <=#Tp 1'b1;
1051
  else
1052
    GotData <=#Tp 1'b0;
1053
end
1054
 
1055
 
1056
// Tx start frame generation
1057
always @ (posedge MTxClk or posedge Reset)
1058
begin
1059
  if(Reset)
1060
    TxStartFrm <=#Tp 1'b0;
1061
  else
1062
  if(TxUsedData_q | TxAbort & ~TxAbort_q | TxRetry & ~TxRetry_q)
1063
    TxStartFrm <=#Tp 1'b0;
1064
  else
1065
  if(TxBDReady & GotData & TxStartFrmRequest)
1066
    TxStartFrm <=#Tp 1'b1;
1067
end
1068
 
1069
 
1070
// Indication of the last word
1071
always @ (posedge MTxClk or posedge Reset)
1072
begin
1073
  if(Reset)
1074
    LastWord <=#Tp 1'b0;
1075
  else
1076
  if((TxEndFrm | TxAbort | TxRetry) & Flop)
1077
    LastWord <=#Tp 1'b0;
1078
  else
1079
  if(TxUsedData & Flop & TxByteCnt == 2'h3)
1080
    LastWord <=#Tp TxEndFrm_wbLatched;
1081
end
1082
 
1083
 
1084
// Tx end frame generation
1085
always @ (posedge MTxClk or posedge Reset)
1086
begin
1087
  if(Reset)
1088
    TxEndFrm <=#Tp 1'b0;
1089
  else
1090
  if(Flop & TxEndFrm | TxAbort | TxRetry_q)
1091
    TxEndFrm <=#Tp 1'b0;
1092
  else
1093
  if(Flop & LastWord)
1094
    begin
1095
      case (TxValidBytesLatched)
1096
        1 : TxEndFrm <=#Tp TxByteCnt == 2'h0;
1097
        2 : TxEndFrm <=#Tp TxByteCnt == 2'h1;
1098
        3 : TxEndFrm <=#Tp TxByteCnt == 2'h2;
1099
 
1100
        default : TxEndFrm <=#Tp 1'b0;
1101
      endcase
1102
    end
1103
end
1104
 
1105
 
1106
// Tx data selection (latching)
1107
always @ (posedge MTxClk or posedge Reset)
1108
begin
1109
  if(Reset)
1110
    TxData <=#Tp 8'h0;
1111
  else
1112
  if(GotData & ~TxStartFrm & ~TxUsedData)
1113
    TxData <=#Tp TxDataLatched_wb[7:0];
1114
  else
1115
  if(TxUsedData & Flop)
1116
    begin
1117
      case(TxByteCnt)
1118
 
1119
        1 : TxData <=#Tp TxDataLatched[15:8];
1120
        2 : TxData <=#Tp TxDataLatched[23:16];
1121
        3 : TxData <=#Tp TxDataLatched[31:24];
1122
      endcase
1123
    end
1124
end
1125
 
1126
 
1127
// Latching tx data
1128
always @ (posedge MTxClk or posedge Reset)
1129
begin
1130
  if(Reset)
1131
    TxDataLatched[31:0] <=#Tp 32'h0;
1132
  else
1133
  if(GotData & ~TxUsedData & ~TxStartFrm)
1134
    TxDataLatched[31:0] <=#Tp TxDataLatched_wb[31:0];
1135
  else
1136
  if(TxUsedData & Flop & TxByteCnt == 2'h3)
1137
    TxDataLatched[31:0] <=#Tp TxDataLatched_wb[31:0];
1138
end
1139
 
1140
 
1141
// Generation of the DataNotAvaliable signal which is used for the generation of the TxUnderRun signal
1142
assign ResetDataNotAvaliable = DMACycleFinishedTx_q | Reset;
1143
assign SetDataNotAvaliable = GotData & ~TxUsedData & ~TxStartFrm | TxUsedData & Flop & TxByteCnt == 2'h3;
1144
 
1145
always @ (posedge MTxClk or posedge ResetDataNotAvaliable)
1146
begin
1147
  if(ResetDataNotAvaliable)
1148
    DataNotAvaliable <=#Tp 1'b0;
1149
  else
1150
  if(SetDataNotAvaliable) // data is latched here
1151
    DataNotAvaliable <=#Tp 1'b1;
1152
end
1153
 
1154
 
1155
// Tx under run
1156
always @ (posedge MTxClk or posedge Reset)
1157
begin
1158
  if(Reset)
1159
    TxUnderRun <=#Tp 1'b0;
1160
  else
1161
  if(TxAbort & ~TxAbort_q)
1162
    TxUnderRun <=#Tp 1'b0;
1163
  else
1164
  if(TxUsedData & Flop & TxByteCnt == 2'h3 & ~LastWord & DataNotAvaliable)
1165
    TxUnderRun <=#Tp 1'b1;
1166
end
1167
 
1168
 
1169
 
1170
// Tx Byte counter
1171
always @ (posedge MTxClk or posedge Reset)
1172
begin
1173
  if(Reset)
1174
    TxByteCnt <=#Tp 2'h0;
1175
  else
1176
  if(TxAbort_q | TxRetry_q)
1177
    TxByteCnt <=#Tp 2'h0;
1178
  else
1179
  if(TxStartFrm & ~TxUsedData)
1180
    TxByteCnt <=#Tp 2'h1;
1181
  else
1182
  if(TxUsedData & Flop)
1183
    TxByteCnt <=#Tp TxByteCnt + 1;
1184
end
1185
 
1186
 
1187
// Generation of the GetNewTxData signal
1188
always @ (posedge MTxClk or posedge Reset)
1189
begin
1190
  if(Reset)
1191
    GetNewTxData <=#Tp 1'b0;
1192
  else
1193
  if(GetNewTxData)
1194
    GetNewTxData <=#Tp 1'b0;
1195
  else
1196
  if(TxBDReady & GotData & ~(TxStartFrm | TxUsedData))
1197
     GetNewTxData <=#Tp 1'b1;
1198
  else
1199
  if(TxUsedData & ~TxEndFrm_wbLatched & TxByteCnt == 2'h3)
1200
    GetNewTxData <=#Tp ~LastWord;
1201
end
1202
 
1203
 
1204
// TxRetryLatched
1205
always @ (posedge MTxClk or posedge Reset)
1206
begin
1207
  if(Reset)
1208
    TxRetryLatched <=#Tp 1'b0;
1209
  else
1210
  if(TxStartFrm)
1211
    TxRetryLatched <=#Tp 1'b0;
1212
  else
1213
  if(TxRetry)
1214
    TxRetryLatched <=#Tp 1'b1;
1215
end
1216
 
1217
 
1218
// This section still needs to be changed due to ASIC demands
1219
assign ResetSyncGetNewTxData_wb = SyncGetNewTxData_wb3 | TxAbort_wb | TxRetry_wb | Reset;
1220
assign SetSyncGetNewTxData_wb = GetNewTxData;
1221
 
1222
 
1223
// Sync. stage 1
1224
always @ (posedge SetSyncGetNewTxData_wb or posedge ResetSyncGetNewTxData_wb)
1225
begin
1226
  if(ResetSyncGetNewTxData_wb)
1227
    SyncGetNewTxData_wb1 <=#Tp 1'b0;
1228
  else
1229
    SyncGetNewTxData_wb1 <=#Tp 1'b1;
1230
end
1231
 
1232
 
1233
// Sync. stage 2
1234
always @ (posedge WB_CLK_I or posedge Reset)
1235
begin
1236
  if(Reset)
1237
    SyncGetNewTxData_wb2 <=#Tp 1'b0;
1238
  else
1239
  if(SyncGetNewTxData_wb1 & ~GetNewTxData_wb & ~TxAbort_wb & ~TxRetry_wb)
1240
    SyncGetNewTxData_wb2 <=#Tp 1'b1;
1241
  else
1242
    SyncGetNewTxData_wb2 <=#Tp 1'b0;
1243
end
1244
 
1245
 
1246
// Sync. stage 3
1247
always @ (posedge WB_CLK_I or posedge Reset)
1248
begin
1249
  if(Reset)
1250
    SyncGetNewTxData_wb3 <=#Tp 1'b0;
1251
  else
1252
  if(SyncGetNewTxData_wb2 & ~GetNewTxData_wb & ~TxAbort_wb & ~TxRetry_wb)
1253
    SyncGetNewTxData_wb3 <=#Tp 1'b1;
1254
  else
1255
    SyncGetNewTxData_wb3 <=#Tp 1'b0;
1256
end
1257
 
1258
 
1259
// Synchronized request for a new tx data
1260
always @ (posedge WB_CLK_I or posedge Reset)
1261
begin
1262
  if(Reset)
1263
    GetNewTxData_wb <=#Tp 1'b0;
1264
  else
1265
  if(GetNewTxData_wb)
1266
    GetNewTxData_wb <=#Tp 1'b0;
1267
  else
1268
  if(SyncGetNewTxData_wb3 & ~GetNewTxData_wb & ~TxAbort_wb & ~TxRetry_wb)
1269
    GetNewTxData_wb <=#Tp 1'b1;
1270
end
1271
 
1272
 
1273
// Synchronizine transmit done signal
1274
// Sinchronizing and evaluating tx data
1275
eth_sync_clk1_clk2 syn4 (.clk1(WB_CLK_I), .clk2(MTxClk), .reset1(Reset),
1276
                         .reset2(Reset),  .set2(TxDone), .sync_out(TxDoneSync3)
1277
                        );
1278
 
1279
 
1280
// Syncronized signal TxDone_wb (sync. to WISHBONE clock)
1281
always @ (posedge WB_CLK_I or posedge Reset)
1282
begin
1283
  if(Reset)
1284
    TxDone_wb <=#Tp 1'b0;
1285
  else
1286
  if(TxStartFrm_wb | WillSendControlFrame)
1287
    TxDone_wb <=#Tp 1'b0;
1288
  else
1289
  if(TxDoneSync3 & ~TxStartFrmRequest)
1290
    TxDone_wb <=#Tp 1'b1;
1291
end
1292
 
1293
 
1294
assign ResetTxCtrlEndFrm_wb = TxCtrlEndFrm_wb | Reset;
1295
assign SetTxCtrlEndFrm_wb = TxCtrlEndFrm;
1296
 
1297
 
1298
// Sync stage 1
1299
always @ (posedge SetTxCtrlEndFrm_wb or posedge ResetTxCtrlEndFrm_wb)
1300
begin
1301
  if(ResetTxCtrlEndFrm_wb)
1302
    TxCtrlEndFrm_wbSync1 <=#Tp 1'b0;
1303
  else
1304
    TxCtrlEndFrm_wbSync1 <=#Tp 1'b1;
1305
end
1306
 
1307
 
1308
// Sync stage 2
1309
always @ (posedge WB_CLK_I or posedge Reset)
1310
begin
1311
  if(Reset)
1312
    TxCtrlEndFrm_wbSync2 <=#Tp 1'b0;
1313
  else
1314
  if(TxCtrlEndFrm_wbSync1 & ~TxCtrlEndFrm_wb)
1315
    TxCtrlEndFrm_wbSync2 <=#Tp 1'b1;
1316
  else
1317
    TxCtrlEndFrm_wbSync2 <=#Tp 1'b0;
1318
end
1319
 
1320
 
1321
// Synchronized Tx  control end frame
1322
always @ (posedge WB_CLK_I or posedge Reset)
1323
begin
1324
  if(Reset)
1325
    TxCtrlEndFrm_wb <=#Tp 1'b0;
1326
  else
1327
  if(TxCtrlEndFrm_wbSync2 & ~TxCtrlEndFrm_wb)
1328
    TxCtrlEndFrm_wb <=#Tp 1'b1;
1329
  else
1330
  if(StartTxStatusWrite)
1331
    TxCtrlEndFrm_wb <=#Tp 1'b0;
1332
end
1333
 
1334
 
1335
// Synchronizing TxRetry signal
1336
eth_sync_clk1_clk2 syn6 (.clk1(WB_CLK_I), .clk2(MTxClk),         .reset1(Reset),
1337
                         .reset2(Reset),  .set2(TxRetryLatched), .sync_out(TxRetrySync3));
1338
 
1339
 
1340
// Synchronized signal TxRetry_wb (synchronized to WISHBONE clock)
1341
always @ (posedge WB_CLK_I or posedge Reset)
1342
begin
1343
  if(Reset)
1344
    TxRetry_wb <=#Tp 1'b0;
1345
  else
1346
  if(TxStartFrm_wb | WillSendControlFrame)
1347
    TxRetry_wb <=#Tp 1'b0;
1348
  else
1349
  if(TxRetrySync3)
1350
    TxRetry_wb <=#Tp 1'b1;
1351
end
1352
 
1353
 
1354
// Synchronizing TxAbort signal
1355
eth_sync_clk1_clk2 syn7 (.clk1(WB_CLK_I), .clk2(MTxClk),  .reset1(Reset),
1356
                         .reset2(Reset),  .set2(TxAbort), .sync_out(TxAbortSync3));
1357
 
1358
 
1359
// Synchronized TxAbort_wb signal (synchronized to WISHBONE clock)
1360
always @ (posedge WB_CLK_I or posedge Reset)
1361
begin
1362
  if(Reset)
1363
    TxAbort_wb <=#Tp 1'b0;
1364
  else
1365
  if(TxStartFrm_wb)
1366
    TxAbort_wb <=#Tp 1'b0;
1367
  else
1368
  if(TxAbortSync3 & ~TxStartFrmRequest)
1369
    TxAbort_wb <=#Tp 1'b1;
1370
end
1371
 
1372
 
1373
// Reading of the next receive buffer descriptor starts after reception status is
1374
// written to the previous one.
1375
assign StartRxBDRead = RxEn & RxStatusWriteOccured;
1376
assign ResetRxBDRead = RxBDRead & RxBDReady;          // Rx BD is read until READY bit is set.
1377
 
1378
 
1379
// Latching READY status of the Rx buffer descriptor
1380
always @ (negedge WB_CLK_I or posedge Reset)
1381
begin
1382
  if(Reset)
1383
    RxBDReady <=#Tp 1'b0;
1384
  else
1385
  if(RxEn & RxBDRead)
1386
    RxBDReady <=#Tp BDDataOut[15];
1387
  else
1388
  if(RxStatusWrite)
1389
    RxBDReady <=#Tp 1'b0;
1390
end
1391
 
1392
 
1393
// Reading the Rx buffer descriptor
1394
always @ (posedge WB_CLK_I or posedge Reset)
1395
begin
1396
  if(Reset)
1397
    RxBDRead <=#Tp 1'b1;
1398
  else
1399
  if(StartRxBDRead)
1400
    RxBDRead <=#Tp 1'b1;
1401
  else
1402
  if(ResetRxBDRead)
1403
    RxBDRead <=#Tp 1'b0;
1404
end
1405
 
1406
 
1407
// Reception status is written back to the buffer descriptor after the end of frame is detected.
1408
//assign StartRxStatusWrite = RxEn & RxEndFrm_wb;
1409
assign StartRxStatusWrite = RxEn & RxEndFrm_wb;
1410
 
1411
 
1412
// Writing status back to the Rx buffer descriptor
1413
always @ (posedge WB_CLK_I or posedge Reset)
1414
begin
1415
  if(Reset)
1416
    RxStatusWrite <=#Tp 1'b0;
1417
  else
1418
  if(StartRxStatusWrite)
1419
    RxStatusWrite <=#Tp 1'b1;
1420
  else
1421
    RxStatusWrite <=#Tp 1'b0;
1422
end
1423
 
1424
 
1425
// Forcing next descriptor on DMA channel 1 (Rx)
1426
assign WB_ND_O[1] = RxStatusWrite;
1427
 
1428
 
1429
// Latched status that a status write occured.
1430
always @ (posedge WB_CLK_I or posedge Reset)
1431
begin
1432
  if(Reset)
1433
    RxStatusWriteOccured <=#Tp 1'b0;
1434
  else
1435
  if(StartRxStatusWrite)
1436
    RxStatusWriteOccured <=#Tp 1'b1;
1437
  else
1438
  if(StartRxBDRead)
1439
    RxStatusWriteOccured <=#Tp 1'b0;
1440
end
1441
 
1442
 
1443
 
1444
// Generation of the synchronized signal ShiftEnded that indicates end of reception
1445
eth_sync_clk1_clk2 syn8 (.clk1(MRxClk),  .clk2(WB_CLK_I),    .reset1(Reset),
1446
                         .reset2(Reset), .set2(RxEndFrm_wb), .sync_out(ShiftEnded)
1447
                        );
1448
 
1449
 
1450
// Indicating that last byte is being reveived
1451
always @ (posedge MRxClk or posedge Reset)
1452
begin
1453
  if(Reset)
1454
    LastByteIn <=#Tp 1'b0;
1455
  else
1456
  if(ShiftWillEnd & (&RxByteCnt))
1457
    LastByteIn <=#Tp 1'b0;
1458
  else
1459
  if(RxValid & RxBDReady & RxEndFrm & ~(&RxByteCnt))
1460
    LastByteIn <=#Tp 1'b1;
1461
end
1462
 
1463
 
1464
// Indicating that data reception will end
1465
always @ (posedge MRxClk or posedge Reset)
1466
begin
1467
  if(Reset)
1468
    ShiftWillEnd <=#Tp 1'b0;
1469
  else
1470
  if(ShiftEnded)
1471
    ShiftWillEnd <=#Tp 1'b0;
1472
  else
1473
  if(LastByteIn & (&RxByteCnt) | RxValid & RxEndFrm & (&RxByteCnt))
1474
    ShiftWillEnd <=#Tp 1'b1;
1475
end
1476
 
1477
 
1478
// Receive byte counter
1479
always @ (posedge MRxClk or posedge Reset)
1480
begin
1481
  if(Reset)
1482
    RxByteCnt <=#Tp 2'h0;
1483
  else
1484
  if(ShiftEnded)
1485
    RxByteCnt <=#Tp 2'h0;
1486
  else
1487
  if(RxValid & RxBDReady | LastByteIn)
1488
    RxByteCnt <=#Tp RxByteCnt + 1;
1489
end
1490
 
1491
 
1492
// Indicates how many bytes are valid within the last word
1493
always @ (posedge MRxClk or posedge Reset)
1494
begin
1495
  if(Reset)
1496
    RxValidBytes <=#Tp 2'h1;
1497
  else
1498
  if(ShiftEnded)
1499
    RxValidBytes <=#Tp 2'h1;
1500
  else
1501
  if(RxValid & ~LastByteIn & ~RxStartFrm)
1502
    RxValidBytes <=#Tp RxValidBytes + 1;
1503
end
1504
 
1505
 
1506
// There is a maximum 3 MRxClk delay between RxDataLatched2 and RxData_wb. In the meantime data
1507
// is stored to the RxDataLatched1. 
1508
always @ (posedge MRxClk or posedge Reset)
1509
begin
1510
  if(Reset)
1511
    RxDataLatched1       <=#Tp 16'h0;
1512
  else
1513
  if(RxValid & RxBDReady & ~LastByteIn & RxByteCnt == 2'h0)
1514
    RxDataLatched1[7:0]  <=#Tp RxData;
1515
  else
1516
  if(RxValid & RxBDReady & ~LastByteIn & RxByteCnt == 2'h1)
1517
    RxDataLatched1[15:8] <=#Tp RxData;
1518
end
1519
 
1520
 
1521
// Latching incoming data to buffer
1522
always @ (posedge MRxClk or posedge Reset)
1523
begin
1524
  if(Reset)
1525
    RxDataLatched2        <=#Tp 32'h0;
1526
  else
1527
  if(RxValid & RxBDReady & ~LastByteIn & RxByteCnt == 2'h2)
1528
    RxDataLatched2[23:0]  <=#Tp {RxData,RxDataLatched1};
1529
  else
1530
  if(RxValid & RxBDReady & ~LastByteIn & RxByteCnt == 2'h3)
1531
    RxDataLatched2[31:24] <=#Tp RxData;
1532
end
1533
 
1534
 
1535
// Indicating start of the reception process
1536
always @ (posedge MRxClk or posedge Reset)
1537
begin
1538
  if(Reset)
1539
    StartShifting <=#Tp 1'b0;
1540
  else
1541
  if((RxValid & RxBDReady & ~RxStartFrm & (&RxByteCnt)) | (ShiftWillEnd &  LastByteIn & (&RxByteCnt)))
1542
    StartShifting <=#Tp 1'b1;
1543
  else
1544
    StartShifting <=#Tp 1'b0;
1545
end
1546
 
1547
 
1548
// Synchronizing Rx start frame to the WISHBONE clock
1549
assign StartRxStartFrmSync1 = RxStartFrm & RxBDReady;
1550
 
1551
eth_sync_clk1_clk2 syn9 (.clk1(WB_CLK_I), .clk2(MRxClk),     .reset1(Reset),
1552
                         .reset2(Reset),  .set2(SetGotData), .sync_out(RxStartFrmSync3)
1553
                        );
1554
 
1555
 
1556
// Generating synchronized Rx start frame
1557
always @ ( posedge WB_CLK_I or posedge Reset)
1558
begin
1559
  if(Reset)
1560
    RxStartFrm_wb <=#Tp 1'b0;
1561
  else
1562
  if(RxStartFrmSync3 & ~RxStartFrm_wb)
1563
    RxStartFrm_wb <=#Tp 1'b1;
1564
  else
1565
    RxStartFrm_wb <=#Tp 1'b0;
1566
end
1567
 
1568
 
1569
// This section still needs to be changed due to ASIC demands
1570
assign ResetShifting_wb = LatchNow_wb | Reset;
1571
assign StartShifting_wb = StartShifting;
1572
 
1573
 
1574
// Sync. stage 1
1575
always @ (posedge StartShifting_wb or posedge ResetShifting_wb)
1576
begin
1577
  if(ResetShifting_wb)
1578
    Shifting_wb_Sync1 <=#Tp 1'b0;
1579
  else
1580
    Shifting_wb_Sync1 <=#Tp 1'b1;
1581
end
1582
 
1583
 
1584
// Sync. stage 2
1585
always @ (posedge WB_CLK_I or posedge Reset)
1586
begin
1587
  if(Reset)
1588
    Shifting_wb_Sync2 <=#Tp 1'b0;
1589
  else
1590
  if(Shifting_wb_Sync1 & ~RxDataValid_wb)
1591
    Shifting_wb_Sync2 <=#Tp 1'b1;
1592
  else
1593
    Shifting_wb_Sync2 <=#Tp 1'b0;
1594
end
1595
 
1596
 
1597
// Generating synchronized signal that will latch data for writing to the WISHBONE
1598
always @ (posedge WB_CLK_I or posedge Reset)
1599
begin
1600
  if(Reset)
1601
    LatchNow_wb <=#Tp 1'b0;
1602
  else
1603
  if(Shifting_wb_Sync2 & ~RxDataValid_wb)
1604
    LatchNow_wb <=#Tp 1'b1;
1605
  else
1606
    LatchNow_wb <=#Tp 1'b0;
1607
end
1608
 
1609
 
1610
// Indicating that valid data is avaliable
1611
always @ (posedge WB_CLK_I or posedge Reset)
1612
begin
1613
  if(Reset)
1614
    RxDataValid_wb <=#Tp 1'b0;
1615
  else
1616
  if(LatchNow_wb & ~RxDataValid_wb)
1617
    RxDataValid_wb <=#Tp 1'b1;
1618
  else
1619
  if(RxDataValid_wb)
1620
    RxDataValid_wb <=#Tp 1'b0;
1621
end
1622
 
1623
 
1624
// Forcing next descriptor in the DMA (Channel 1 is used for rx)
1625
always @ (posedge WB_CLK_I or posedge Reset)
1626
begin
1627
  if(Reset)
1628
    WB_REQ_O_RX <=#Tp 1'b0;
1629
  else
1630
  if(LatchNow_wb & ~RxDataValid_wb & r_DmaEn)
1631
    WB_REQ_O_RX <=#Tp 1'b1;
1632
  else
1633
  if(DMACycleFinishedRx)
1634
    WB_REQ_O_RX <=#Tp 1'b0;
1635
end
1636
 
1637
 
1638
assign WB_REQ_O[1] = WB_REQ_O_RX;
1639
assign DMACycleFinishedRx = WB_REQ_O[1] & WB_ACK_I[1];
1640
 
1641
 
1642
// WbWriteError is generated when the previous word is not written to the wishbone on time
1643
always @ (posedge WB_CLK_I or posedge Reset)
1644
begin
1645
  if(Reset)
1646
    WbWriteError <=#Tp 1'b0;
1647
  else
1648
  if(LatchNow_wb & ~RxDataValid_wb)
1649
    begin
1650
      if(WB_REQ_O[1] & ~WB_ACK_I[1])
1651
        WbWriteError <=#Tp 1'b1;
1652
    end
1653
  else
1654
  if(RxStartFrm_wb)
1655
    WbWriteError <=#Tp 1'b0;
1656
end
1657
 
1658
 
1659
// Assembling data that will be written to the WISHBONE
1660
always @ (posedge WB_CLK_I or posedge Reset)
1661
begin
1662
  if(Reset)
1663
    RxData_wb <=#Tp 32'h0;
1664
  else
1665
  if(LatchNow_wb & ~RxDataValid_wb & ~ShiftWillEnd)
1666
    RxData_wb <=#Tp RxDataLatched2;
1667
  else
1668
  if(LatchNow_wb & ~RxDataValid_wb & ShiftWillEnd)
1669
    case(RxValidBytes)
1670
 
1671
      1 : RxData_wb <=#Tp {24'h0,                       RxDataLatched1[7:0]};
1672
      2 : RxData_wb <=#Tp {16'h0,                       RxDataLatched1[15:0]};
1673
      3 : RxData_wb <=#Tp {8'h0, RxDataLatched2[23:16], RxDataLatched1[15:0]};
1674
    endcase
1675
end
1676
 
1677
 
1678
// Selecting the data for the WISHBONE
1679
assign WB_DAT_O[31:0] = BDRead? WB_BDDataOut : RxData_wb;
1680
 
1681
 
1682
// Generation of the end-of-frame signal
1683
always @ (posedge WB_CLK_I or posedge Reset)
1684
begin
1685
  if(Reset)
1686
    RxEndFrm_wb <=#Tp 1'b0;
1687
  else
1688
  if(LatchNow_wb & ~RxDataValid_wb & ShiftWillEnd)
1689
    RxEndFrm_wb <=#Tp 1'b1;
1690
  else
1691
  if(StartRxStatusWrite)
1692
    RxEndFrm_wb <=#Tp 1'b0;
1693
end
1694
 
1695
 
1696
// Interrupts
1697
assign TxB_IRQ = 1'b0;
1698
assign TxE_IRQ = 1'b0;
1699
assign RxB_IRQ = 1'b0;
1700
assign RxE_IRQ = 1'b0;
1701
assign Busy_IRQ = 1'b0;
1702
assign TxC_IRQ = 1'b0;
1703
assign RxC_IRQ = 1'b0;
1704
 
1705
 
1706
endmodule
1707
 

powered by: WebSVN 2.1.0

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