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

Subversion Repositories ethmac

[/] [ethmac/] [trunk/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 40

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

powered by: WebSVN 2.1.0

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