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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_7/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 54

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

powered by: WebSVN 2.1.0

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