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 48

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

powered by: WebSVN 2.1.0

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