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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_14/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 60

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

powered by: WebSVN 2.1.0

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