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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_1/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 43

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

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

powered by: WebSVN 2.1.0

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