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 42

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

powered by: WebSVN 2.1.0

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