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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_1/] [rtl/] [verilog/] [eth_wishbone.v] - Blame information for rev 41

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

powered by: WebSVN 2.1.0

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