OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [hdl/] [boardsupport/] [v4/] [tx_client_fifo_8.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
//-----------------------------------------------------------------------------
2
// Title      : 8-bit Client to Local-link Transmitter FIFO
3
// Project    : Virtex-4 Embedded Tri-Mode Ethernet MAC Wrapper
4
// File       : tx_client_fifo_8.v
5
// Version    : 4.8
6
//-----------------------------------------------------------------------------
7
//
8
// (c) Copyright 2004-2010 Xilinx, Inc. All rights reserved.
9
//
10
// This file contains confidential and proprietary information
11
// of Xilinx, Inc. and is protected under U.S. and
12
// international copyright and other intellectual property
13
// laws.
14
//
15
// DISCLAIMER
16
// This disclaimer is not a license and does not grant any
17
// rights to the materials distributed herewith. Except as
18
// otherwise provided in a valid license issued to you by
19
// Xilinx, and to the maximum extent permitted by applicable
20
// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
21
// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
22
// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
23
// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
24
// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
25
// (2) Xilinx shall not be liable (whether in contract or tort,
26
// including negligence, or under any other theory of
27
// liability) for any loss or damage of any kind or nature
28
// related to, arising under or in connection with these
29
// materials, including for any direct, or any indirect,
30
// special, incidental, or consequential loss or damage
31
// (including loss of data, profits, goodwill, or any type of
32
// loss or damage suffered as a result of any action brought
33
// by a third party) even if such damage or loss was
34
// reasonably foreseeable or Xilinx had been advised of the
35
// possibility of the same.
36
//
37
// CRITICAL APPLICATIONS
38
// Xilinx products are not designed or intended to be fail-
39
// safe, or for use in any application requiring fail-safe
40
// performance, such as life-support or safety devices or
41
// systems, Class III medical devices, nuclear facilities,
42
// applications related to the deployment of airbags, or any
43
// other applications that could lead to death, personal
44
// injury, or severe property or environmental damage
45
// (individually and collectively, "Critical
46
// Applications"). Customer assumes the sole risk and
47
// liability of any use of Xilinx products in Critical
48
// Applications, subject only to applicable laws and
49
// regulations governing limitations on product liability.
50
//
51
// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
52
// PART OF THIS FILE AT ALL TIMES.
53
//
54
//-----------------------------------------------------------------------------
55
// Description: This is a transmitter side local link fifo implementation for
56
//              the design example of the Virtex-4 Ethernet MAC Wrapper
57
//              core.
58
//              
59
//              The transmit FIFO is created from 2 Block RAMs of size 2048
60
//              words of 8-bits per word, giving a total frame memory capacity
61
//              of 4096 bytes.
62
//
63
//              Valid frame data received from local link interface is written
64
//              into the Block RAM on the write clock.  The FIFO will store
65
//              frames upto 4kbytes in length.  If larger frames are written
66
//              to the FIFO the local-link interface will accept the rest of the
67
//              frame, but that frame will be dropped by the FIFO and
68
//              the overflow signal will be asserted.
69
//
70
//              The FIFO is designed to work with a minimum frame length of 14 bytes.
71
//              
72
//              When there is at least one complete frame in the FIFO,
73
//              the MAC transmitter client interface will be driven to
74
//              request frame transmission by placing the first byte of
75
//              the frame onto tx_data[7:0] and by asserting
76
//              tx_data_valid.  The MAC will later respond by asserting
77
//              tx_ack.  At this point the remaining frame data is read
78
//              out of the FIFO in a continuous burst. Data is read out
79
//              of the FIFO on the rd_clk.
80
//
81
//              If the generic FULL_DUPLEX_ONLY is set to false, the FIFO will
82
//              requeue and retransmit frames as requested by the MAC.  Once a
83
//              frame has been transmitted by the FIFO it is stored until the
84
//              possible retransmit window for that frame has expired.
85
//
86
//              The FIFO has been designed to operate with different clocks
87
//              on the write and read sides. The write clock (locallink clock)
88
//              can be an equal or faster frequency than the read clock (client clock).
89
//              The minimum write clock frequency is the read clock frequency divided
90
//              by 4.
91
//
92
//              The FIFO memory size can be increased by expanding the rd_addr
93
//              and wr_addr signal widths, to address further BRAMs.
94
//
95
//-----------------------------------------------------------------------------
96
 
97
`timescale 1ps / 1ps
98
 
99
 
100
module tx_client_fifo_8
101
    (
102
        // MAC Interface
103
        rd_clk,
104
        rd_sreset,
105
        rd_enable,
106
        tx_data,
107
        tx_data_valid,
108
        tx_ack,
109
        tx_collision,
110
        tx_retransmit,
111
        overflow,
112
 
113
        // Local-link Interface
114
        wr_clk,
115
        wr_sreset,
116
        wr_data,
117
        wr_sof_n,
118
        wr_eof_n,
119
        wr_src_rdy_n,
120
        wr_dst_rdy_n,
121
        wr_fifo_status
122
        );
123
 
124
  //---------------------------------------------------------------------------
125
  // Define Interface Signals
126
  //---------------------------------------------------------------------------
127
 
128
  // MAC Interface
129
  input        rd_clk;
130
  input        rd_sreset;
131
  input        rd_enable;
132
  output [7:0] tx_data;
133
  output       tx_data_valid;
134
  input        tx_ack;
135
  input        tx_collision;
136
  input        tx_retransmit;
137
  output       overflow;
138
 
139
  // Local-link Interface
140
  input        wr_clk;
141
  input        wr_sreset;
142
  input  [7:0] wr_data;
143
  input        wr_sof_n;
144
  input        wr_eof_n;
145
  input        wr_src_rdy_n;
146
  output       wr_dst_rdy_n;
147
  output [3:0] wr_fifo_status;
148
 
149
  // If FULL_DUPLEX_ONLY is 1 then all the half duplex logic in the FIFO is removed.
150
  // The default for the fifo is to include the half duplex functionality 
151
  parameter    FULL_DUPLEX_ONLY = 0;
152
 
153
  reg [7:0]    tx_data;
154
  reg          tx_data_valid;
155
  reg [3:0]    wr_fifo_status;
156
 
157
 
158
  //---------------------------------------------------------------------------
159
  // Define Internal Signals
160
  //---------------------------------------------------------------------------
161
 
162
  wire        GND;
163
  wire        VCC;
164
  wire [7:0]  GND_BUS;
165
 
166
  // Encode rd_state_machine states   
167
  parameter  IDLE_s = 4'b0000;      parameter  QUEUE1_s = 4'b0001;
168
  parameter  QUEUE2_s = 4'b0010;    parameter  QUEUE3_s = 4'b0011;
169
  parameter  QUEUE_ACK_s = 4'b0100; parameter  WAIT_ACK_s = 4'b0101;
170
  parameter  FRAME_s = 4'b0110;     parameter  DROP_s = 4'b0111;
171
  parameter  RETRANSMIT_s = 4'b1000;
172
 
173
  reg  [3:0]  rd_state;
174
  reg  [3:0]  rd_nxt_state;
175
 
176
  // Encode wr_state_machine states 
177
  parameter WAIT_s = 2'b00;  parameter DATA_s = 2'b01;
178
  parameter EOF_s = 2'b10;   parameter OVFLOW_s = 2'b11;
179
 
180
  reg  [1:0]  wr_state;
181
  reg  [1:0]  wr_nxt_state;
182
 
183
  reg  [7:0]  wr_data_bram;
184
  reg  [7:0]  wr_data_pipe[0:1];
185
  reg         wr_sof_pipe[0:1];
186
  reg         wr_eof_pipe[0:1];
187
  reg         wr_accept_pipe[0:1];
188
  reg         wr_accept_bram;
189
  reg  [0:0]  wr_eof_bram;
190
  reg  [11:0] wr_addr;
191
  wire        wr_addr_inc;
192
  wire        wr_start_addr_load;
193
  wire        wr_addr_reload;
194
  reg  [11:0] wr_start_addr;
195
  reg         wr_fifo_full;
196
  wire        wr_en;
197
  wire        wr_en_u;
198
  wire        wr_en_l;
199
  reg         wr_ovflow_dst_rdy;
200
  wire        wr_dst_rdy_int_n;
201
 
202
  reg         frame_in_fifo_sync;
203
  reg         frame_in_fifo;
204
  reg         rd_eof;
205
  reg         rd_eof_reg;
206
  reg         rd_eof_pipe;
207
  reg  [11:0] rd_addr;
208
  wire        rd_addr_inc;
209
  wire        rd_addr_reload;
210
  wire [7:0]  rd_data_bram_u;
211
  wire [7:0]  rd_data_bram_l;
212
  reg  [7:0]  rd_data_pipe_u;
213
  reg  [7:0]  rd_data_pipe_l;
214
  reg  [7:0]  rd_data_pipe;
215
  wire [0:0]  rd_eof_bram_u;
216
  wire [0:0]  rd_eof_bram_l;
217
  wire        rd_en;
218
  wire        rd_en_bram;
219
  reg         rd_bram_u;
220
  reg         rd_bram_u_reg;
221
 
222
  reg         rd_tran_frame_tog;
223
  reg         wr_tran_frame_tog;
224
  reg         wr_tran_frame_sync;
225
  reg         wr_tran_frame_delay;
226
  reg         rd_retran_frame_tog;
227
  reg         wr_retran_frame_tog;
228
  reg         wr_retran_frame_sync;
229
  reg         wr_retran_frame_delay;
230
  wire        wr_store_frame;
231
  reg         wr_transmit_frame;
232
  reg         wr_retransmit_frame;
233
  reg  [8:0]  wr_frames;
234
  reg         wr_frame_in_fifo;
235
 
236
  reg   [3:0] rd_16_count;
237
  wire        rd_txfer_en;
238
  reg  [11:0] rd_addr_txfer;
239
  reg         rd_txfer_tog;
240
  reg         wr_txfer_tog;
241
  reg         wr_txfer_tog_sync;
242
  reg         wr_txfer_tog_delay;
243
  wire        wr_txfer_en;
244
  reg  [11:0] wr_rd_addr;
245
  reg  [11:0] wr_addr_diff;
246
 
247
  reg         rd_drop_frame;
248
  reg         rd_retransmit;
249
  reg  [11:0] rd_start_addr;
250
  wire        rd_start_addr_load;
251
  wire        rd_start_addr_reload;
252
 
253
  reg  [11:0] rd_dec_addr;
254
 
255
  wire        rd_transmit_frame;
256
  wire        rd_retransmit_frame;
257
  reg         rd_col_window_expire;
258
  reg         rd_col_window_pipe[0:1];
259
  reg         wr_col_window_pipe[0:1];
260
 
261
  wire        wr_eof_state;
262
  reg         wr_eof_state_reg;
263
  wire        wr_fifo_overflow;
264
  reg  [9:0]  rd_slot_timer;
265
  reg         wr_col_window_expire;
266
  wire        rd_idle_state;
267
 
268
  reg         rd_enable_delay;
269
  reg         rd_enable_delay2;
270
 
271
 
272
  //---------------------------------------------------------------------------
273
  // Attributes for FIFO simulation and synthesis
274
  //---------------------------------------------------------------------------
275
  // ASYNC_REG attributes added to simulate actual behaviour under
276
  // asynchronous operating conditions.
277
  // synthesis attribute ASYNC_REG of wr_tran_frame_tog is "TRUE";
278
  // synthesis attribute ASYNC_REG of wr_retran_frame_tog is "TRUE";
279
  // synthesis attribute ASYNC_REG of frame_in_fifo_sync is "TRUE";
280
  // synthesis attribute ASYNC_REG of wr_rd_addr is "TRUE";
281
  // synthesis attribute ASYNC_REG of wr_txfer_tog is "TRUE";
282
  // synthesis attribute ASYNC_REG of wr_col_window_pipe[0] is "TRUE";
283
 
284
  // WRITE_MODE attributes added to Block RAM to mitigate port contention
285
  // synthesis attribute WRITE_MODE_A of ramgen_u is "READ_FIRST";
286
  // synthesis attribute WRITE_MODE_B of ramgen_u is "READ_FIRST";
287
  // synthesis attribute WRITE_MODE_A of ramgen_l is "READ_FIRST";
288
  // synthesis attribute WRITE_MODE_B of ramgen_l is "READ_FIRST";
289
 
290
 
291
 
292
  //---------------------------------------------------------------------------
293
  // Begin FIFO architecture
294
  //---------------------------------------------------------------------------
295
 
296
  assign GND = 1'b0;
297
  assign VCC = 1'b1;
298
  assign GND_BUS = 8'b0;
299
 
300
  // shouldn't have a functional impact - at 1G flop is high all the time
301
  // at other speeds it is high every other cycle with 2nd stage ensuring it is in phase with the normal
302
  // clk enable - THE ONLY PURPOSE OF THIS FLOP IS TO ENABLE THE rd_enable and rd_en FANOUT TO BE CONTROLLED
303
  always @(posedge rd_clk)
304
  begin
305
     rd_enable_delay <= rd_enable;
306
     rd_enable_delay2 <= rd_enable_delay;
307
  end
308
 
309
  //---------------------------------------------------------------------------
310
  // Write State machine and control
311
  //---------------------------------------------------------------------------
312
  // Write state machine
313
  // states are WAIT, DATA, EOF, OVFLOW
314
  // clock through next state of sm
315
  always @(posedge wr_clk)
316
  begin
317
     if (wr_sreset == 1'b1)
318
         wr_state <= WAIT_s;
319
     else
320
         wr_state <= wr_nxt_state;
321
  end
322
 
323
  // decode next state, combinitorial
324
  // should never be able to overflow whilst not in the data state.
325
  always @(wr_state or wr_sof_pipe[1] or wr_eof_pipe[0] or wr_eof_pipe[1] or wr_eof_bram[0] or wr_fifo_overflow)
326
  begin
327
  case (wr_state)
328
     WAIT_s : begin
329
        if (wr_sof_pipe[1] == 1'b1)
330
           wr_nxt_state <= DATA_s;
331
        else
332
           wr_nxt_state <= WAIT_s;
333
        end
334
     DATA_s : begin
335
        // wait for the end of frame to be detected
336
        if (wr_fifo_overflow == 1'b1 && wr_eof_pipe[0] == 1'b0 && wr_eof_pipe[1] == 1'b0)
337
           wr_nxt_state <= OVFLOW_s;
338
        else if (wr_eof_pipe[1] == 1'b1)
339
           wr_nxt_state <= EOF_s;
340
        else
341
           wr_nxt_state <= DATA_s;
342
        end
343
     EOF_s : begin
344
        // if the start of frame is already in the pipe, a back to back frame
345
        // transmission has occured.  move straight back to frame state
346
        if (wr_sof_pipe[1] == 1'b1)
347
           wr_nxt_state <= DATA_s;
348
        else if (wr_eof_bram[0] == 1'b1)
349
           wr_nxt_state <= WAIT_s;
350
        else
351
           wr_nxt_state <= EOF_s;
352
        end
353
     OVFLOW_s : begin
354
        // wait until the end of frame is reached before clearing the overflow
355
        if (wr_eof_bram[0] == 1'b1)
356
           wr_nxt_state <= WAIT_s;
357
        else
358
           wr_nxt_state <= OVFLOW_s;
359
        end
360
     default : begin
361
        wr_nxt_state <= WAIT_s;
362
        end
363
  endcase
364
  end
365
 
366
 
367
  // decode output signals.
368
  assign wr_en = (wr_state == OVFLOW_s) ? 1'b0 : wr_accept_bram;
369
  assign wr_en_l = wr_en & !wr_addr[11];
370
  assign wr_en_u = wr_en & wr_addr[11];
371
 
372
  assign wr_addr_inc = wr_en;
373
 
374
  assign wr_addr_reload = (wr_state == OVFLOW_s) ? 1'b1 : 1'b0;
375
  assign wr_start_addr_load = (wr_state == EOF_s && wr_nxt_state == WAIT_s) ? 1'b1 :
376
                              (wr_state == EOF_s && wr_nxt_state == DATA_s) ? 1'b1 : 1'b0;
377
 
378
 
379
  // pause the local link flow when the fifo is full.
380
  assign wr_dst_rdy_int_n = (wr_state == OVFLOW_s) ? wr_ovflow_dst_rdy : wr_fifo_full;
381
  assign wr_dst_rdy_n = wr_dst_rdy_int_n;
382
 
383
  // when in overflow and have captured ovflow eof send dst rdy high again.
384
  assign overflow = (wr_state == OVFLOW_s) ? 1'b1 : 1'b0;
385
 
386
  // when in overflow and have captured ovflow eof send dst rdy high again.
387
  always @(posedge wr_clk)
388
  begin
389
     if (wr_sreset == 1'b1)
390
        wr_ovflow_dst_rdy <= 1'b0;
391
     else
392
        begin
393
        if (wr_fifo_overflow == 1'b1 && wr_state == DATA_s)
394
            wr_ovflow_dst_rdy <= 1'b0;
395
        else if (wr_eof_n == 1'b0 && wr_src_rdy_n == 1'b0)
396
            wr_ovflow_dst_rdy <= 1'b1;
397
        end
398
  end
399
 
400
  // eof signals for use in overflow logic
401
  assign wr_eof_state = (wr_state == EOF_s) ? 1'b1 : 1'b0;
402
 
403
  always @(posedge wr_clk)
404
  begin
405
     if (wr_sreset == 1'b1)
406
        wr_eof_state_reg <= 1'b0;
407
     else
408
        wr_eof_state_reg <= wr_eof_state;
409
  end
410
 
411
  //---------------------------------------------------------------------------
412
  // Read state machine and control
413
  //---------------------------------------------------------------------------
414
 
415
  // clock through the read state machine
416
  always @(posedge rd_clk)
417
  begin
418
     if (rd_sreset == 1'b1)
419
        rd_state <= IDLE_s;
420
     else if (rd_enable == 1'b1)
421
        rd_state <= rd_nxt_state;
422
  end
423
 
424
  //---------------------------------------------------------------------------
425
  // Full Duplex Only State Machine
426
generate if (FULL_DUPLEX_ONLY == 1) begin : gen_fd_sm
427
  // decode the next state
428
  always @(rd_state or frame_in_fifo or rd_eof or tx_ack)
429
  begin
430
  case (rd_state)
431
           IDLE_s : begin
432
              // if there is a frame in the fifo start to queue the new frame
433
              // to the output
434
              if (frame_in_fifo == 1'b1)
435
                 rd_nxt_state <= QUEUE1_s;
436
              else
437
                 rd_nxt_state <= IDLE_s;
438
              end
439
           QUEUE1_s : begin
440
                 rd_nxt_state <= QUEUE2_s;
441
              end
442
           QUEUE2_s : begin
443
                 rd_nxt_state <= QUEUE3_s;
444
              end
445
           QUEUE3_s : begin
446
                 rd_nxt_state <= QUEUE_ACK_s;
447
              end
448
           QUEUE_ACK_s : begin
449
                 rd_nxt_state <= WAIT_ACK_s;
450
              end
451
           WAIT_ACK_s : begin
452
              // the output pipe line is fully loaded, so wait for ack from mac
453
              // before moving on
454
              if (tx_ack == 1'b1)
455
                 rd_nxt_state <= FRAME_s;
456
              else
457
                 rd_nxt_state <= WAIT_ACK_s;
458
              end
459
           FRAME_s : begin
460
              // when the end of frame has been reached wait another frame in
461
              // the fifo
462
              if (rd_eof == 1'b1)
463
                 rd_nxt_state <= IDLE_s;
464
              else
465
                 rd_nxt_state <= FRAME_s;
466
              end
467
           default : begin
468
                 rd_nxt_state <= IDLE_s;
469
              end
470
        endcase
471
  end
472
                                // full duplex state machine
473
 
474
end // gen_fd_sm
475
endgenerate
476
 
477
 
478
  //---------------------------------------------------------------------------
479
  // Full and Half Duplex State Machine
480
generate if (FULL_DUPLEX_ONLY != 1) begin : gen_hd_sm
481
  // decode the next state
482
  // should never receive a rd_drop_frame pulse outside of the Frame state
483
  always @(rd_state or frame_in_fifo or rd_eof_reg or tx_ack or rd_drop_frame or rd_retransmit)
484
  begin
485
  case (rd_state)
486
           IDLE_s : begin
487
              // if a retransmit request is detected go to retransmit state
488
              if (rd_retransmit == 1'b1)
489
                 rd_nxt_state <= RETRANSMIT_s;
490
              // if there is a frame in the fifo then queue the new frame to
491
              // the output
492
              else if (frame_in_fifo == 1'b1)
493
                 rd_nxt_state <= QUEUE1_s;
494
              else
495
                 rd_nxt_state <= IDLE_s;
496
              end
497
           QUEUE1_s : begin
498
              if (rd_retransmit == 1'b1)
499
                 rd_nxt_state <= RETRANSMIT_s;
500
              else
501
                rd_nxt_state <= QUEUE2_s;
502
              end
503
           QUEUE2_s : begin
504
              if (rd_retransmit == 1'b1)
505
                 rd_nxt_state <= RETRANSMIT_s;
506
              else
507
                 rd_nxt_state <= QUEUE3_s;
508
              end
509
           QUEUE3_s : begin
510
              if (rd_retransmit == 1'b1)
511
                 rd_nxt_state <= RETRANSMIT_s;
512
              else
513
                 rd_nxt_state <= QUEUE_ACK_s;
514
              end
515
           QUEUE_ACK_s : begin
516
              if (rd_retransmit == 1'b1)
517
                 rd_nxt_state <= RETRANSMIT_s;
518
              else
519
                 rd_nxt_state <= WAIT_ACK_s;
520
              end
521
           WAIT_ACK_s : begin
522
              // the output pipeline is now fully loaded so wait for ack from
523
              // mac before moving on.
524
              if (rd_retransmit == 1'b1)
525
                 rd_nxt_state <= RETRANSMIT_s;
526
              else if (tx_ack == 1'b1)
527
                 rd_nxt_state <= FRAME_s;
528
              else
529
                 rd_nxt_state <= WAIT_ACK_s;
530
              end
531
           FRAME_s : begin
532
              // if a collision only request, then must drop the rest of the
533
              // current frame, move to drop state
534
              if (rd_drop_frame == 1'b1)
535
                 rd_nxt_state <= DROP_s;
536
              else if (rd_retransmit == 1'b1)
537
                 rd_nxt_state <= RETRANSMIT_s;
538
              // continue transmitting frame until the end of the frame is
539
              // detected, then wait for a new frame to be sent.
540
              else if (rd_eof_reg == 1'b1)
541
                 rd_nxt_state <= IDLE_s;
542
              else
543
                 rd_nxt_state <= FRAME_s;
544
              end
545
           DROP_s : begin
546
              // wait until rest of frame has been cleared.
547
              if (rd_eof_reg == 1'b1)
548
                 rd_nxt_state <= IDLE_s;
549
              else
550
                 rd_nxt_state <= DROP_s;
551
              end
552
           RETRANSMIT_s : begin
553
              // reload the data pipe from the start of the frame
554
                 rd_nxt_state <= QUEUE1_s;
555
              end
556
           default : begin
557
                 rd_nxt_state <= IDLE_s;
558
              end
559
        endcase
560
  end
561
 
562
end // gen_hd_sm                               // half duplex state machine
563
endgenerate
564
 
565
  //---------------------------------------------------------------------------
566
  // decode output signals
567
  // decode output data
568
  always @(posedge rd_clk)
569
  begin
570
     if (rd_enable == 1'b1)
571
        begin
572
        if (rd_nxt_state == FRAME_s)
573
           tx_data <= rd_data_pipe;
574
        else
575
           begin
576
           case (rd_state)
577
              QUEUE_ACK_s :
578
                 tx_data <= rd_data_pipe;
579
              WAIT_ACK_s :
580
                 tx_data <= tx_data;
581
              FRAME_s :
582
                 tx_data <= rd_data_pipe;
583
              default :
584
                 tx_data <= 8'b0;
585
           endcase
586
           end
587
        end
588
  end
589
 
590
  // decode output data valid
591
  always @(posedge rd_clk)
592
  begin
593
     if (rd_enable == 1'b1)
594
        begin
595
        if (rd_nxt_state == FRAME_s)
596
           tx_data_valid <= ~(tx_collision && ~(tx_retransmit));
597
        else
598
           begin
599
           case (rd_state)
600
              QUEUE_ACK_s :
601
                 tx_data_valid <= 1'b1;
602
              WAIT_ACK_s :
603
                 tx_data_valid <= 1'b1;
604
              FRAME_s :
605
                 tx_data_valid <= ~(rd_nxt_state == DROP_s);
606
              default :
607
                 tx_data_valid <= 1'b0;
608
           endcase
609
           end
610
        end
611
  end
612
 
613
  //---------------------------------------------------------------------------
614
  // decode full duplex only control signals
615
generate if (FULL_DUPLEX_ONLY == 1) begin : gen_fd_decode
616
 
617
  assign rd_en = (rd_state == IDLE_s) ? 1'b0 :
618
                 (rd_nxt_state == FRAME_s) ? 1'b1 :
619
                 (rd_state == WAIT_ACK_s) ? 1'b0 : 1'b1;
620
 
621
  assign rd_addr_inc = rd_en;
622
 
623
  assign rd_addr_reload = (rd_state == FRAME_s && rd_nxt_state == IDLE_s) ? 1'b1 : 1'b0;
624
 
625
  // Transmit frame pulse is only 1 clock enabled pulse long.
626
  // Transmit frame pulse must never be more frequent than 64 clocks to allow toggle to cross clock domain
627
  assign rd_transmit_frame = (rd_state == WAIT_ACK_s && rd_nxt_state == FRAME_s) ? 1'b1 : 1'b0;
628
 
629
  // unused for full duplex only
630
  assign rd_start_addr_reload = 1'b0;
631
  assign rd_start_addr_load   = 1'b0;
632
  assign rd_retransmit_frame  = 1'b0;
633
 
634
end // gen_fd_decode                              // full duplex control signals
635
endgenerate
636
 
637
  //---------------------------------------------------------------------------
638
  // decode half duplex control signals
639
generate if (FULL_DUPLEX_ONLY != 1) begin : gen_hd_decode
640
 
641
  assign rd_en = (rd_state == IDLE_s) ? 1'b0 :
642
                 (rd_nxt_state == DROP_s && rd_eof == 1'b1) ? 1'b0 :
643
                 (rd_nxt_state == FRAME_s) ? 1'b1 :
644
                 (rd_state == RETRANSMIT_s) ? 1'b0 :
645
                 (rd_state == WAIT_ACK_s) ? 1'b0 : 1'b1;
646
 
647
  assign rd_addr_inc = rd_en;
648
 
649
  assign rd_addr_reload = (rd_state == FRAME_s && rd_nxt_state == IDLE_s) ? 1'b1 :
650
                          (rd_state == DROP_s && rd_nxt_state == IDLE_s) ? 1'b1 : 1'b0;
651
 
652
  assign rd_start_addr_reload = (rd_state == RETRANSMIT_s) ? 1'b1 : 1'b0;
653
 
654
  assign rd_start_addr_load = (rd_state == WAIT_ACK_s && rd_nxt_state == FRAME_s) ? 1'b1 :
655
                              (rd_col_window_expire == 1'b1) ? 1'b1 : 1'b0;
656
 
657
  // Transmit frame pulse must never be more frequent than 64 clocks to allow toggle to cross clock domain
658
  assign rd_transmit_frame = (rd_state == WAIT_ACK_s && rd_nxt_state == FRAME_s) ? 1'b1 : 1'b0;
659
 
660
  // Retransmit frame pulse must never be more frequent than 16 clocks to allow toggle to cross clock domain
661
  assign rd_retransmit_frame = (rd_state == RETRANSMIT_s) ? 1'b1 : 1'b0;
662
 
663
end // gen_hd_decode                           // half duplex control signals
664
endgenerate
665
 
666
  //---------------------------------------------------------------------------
667
  // Frame Count
668
  // We need to maintain a count of frames in the fifo, so that we know when a
669
  // frame is available for transmission.  The counter must be held on the
670
  // write clock domain as this is the faster clock.
671
  //---------------------------------------------------------------------------
672
 
673
  // A frame has been written to the fifo
674
  assign wr_store_frame = (wr_state == EOF_s && wr_nxt_state != EOF_s) ? 1'b1 : 1'b0;
675
 
676
  // generate a toggle to indicate when a frame has been transmitted from the fifo
677
  always @(posedge rd_clk)
678
  begin  // process
679
     if (rd_sreset == 1'b1)
680
         rd_tran_frame_tog <= 1'b0;
681
     else if (rd_enable == 1'b1)
682
        if (rd_transmit_frame == 1'b1)     // assumes EOF_s is valid for one clock
683
                                        // cycle only ever!  check
684
              rd_tran_frame_tog <= !rd_tran_frame_tog;
685
  end
686
 
687
  // move the read transmit frame signal onto the write clock domain
688
  always @(posedge wr_clk)
689
  begin
690
      if (wr_sreset == 1'b1)
691
         begin
692
            wr_tran_frame_tog  <= 1'b0;
693
            wr_tran_frame_sync <= 1'b0;
694
            wr_tran_frame_delay <= 1'b0;
695
            wr_transmit_frame   <= 1'b0;
696
         end
697
      else
698
        begin
699
           wr_tran_frame_tog  <= rd_tran_frame_tog;
700
           wr_tran_frame_sync <= wr_tran_frame_tog;
701
           wr_tran_frame_delay <= wr_tran_frame_sync;
702
           // edge detector
703
           if ((wr_tran_frame_delay ^ wr_tran_frame_sync) == 1'b1)
704
             wr_transmit_frame    <= 1'b1;
705
           else
706
             wr_transmit_frame    <= 1'b0;
707
        end
708
  end
709
 
710
  //---------------------------------------------------------------------------  
711
generate if (FULL_DUPLEX_ONLY == 1) begin : gen_fd_count
712
 
713
  // count the number of frames in the fifo.  the counter is incremented when a
714
  // frame is stored and decremented when a frame is transmitted.  Need to keep
715
  // the counter on the write clock as this is the fastest clock.
716
  always @(posedge wr_clk)
717
  begin
718
     if (wr_sreset == 1'b1)
719
        wr_frames <= 9'b0;
720
     else
721
        if ((wr_store_frame & !wr_transmit_frame) == 1'b1)
722
           wr_frames <= wr_frames + 1;
723
        else if ((!wr_store_frame & wr_transmit_frame) == 1'b1)
724
           wr_frames <= wr_frames - 1;
725
  end
726
 
727
end // gen_fd_count
728
endgenerate
729
 
730
  //---------------------------------------------------------------------------
731
generate if (FULL_DUPLEX_ONLY != 1) begin : gen_hd_count
732
 
733
  // generate a toggle to indicate when a frame has been transmitted from the fifo
734
  always @(posedge rd_clk)
735
  begin  // process
736
     if (rd_sreset == 1'b1)
737
        rd_retran_frame_tog <= 1'b0;
738
     else if (rd_enable == 1'b1)
739
        if (rd_retransmit_frame == 1'b1)     // assumes EOF_s is valid for one clock
740
                                   // cycle only ever!  check
741
           rd_retran_frame_tog <= !rd_retran_frame_tog;
742
  end
743
 
744
  // move the read transmit frame signal onto the write clock domain
745
  always @(posedge wr_clk)
746
  begin
747
     if (wr_sreset == 1'b1)
748
        begin
749
           wr_retran_frame_tog  <= 1'b0;
750
           wr_retran_frame_sync <= 1'b0;
751
           wr_retran_frame_delay <= 1'b0;
752
           wr_retransmit_frame  <= 1'b0;
753
        end
754
     else
755
        begin
756
           wr_retran_frame_tog  <= rd_retran_frame_tog;
757
           wr_retran_frame_sync <= wr_retran_frame_tog;
758
           wr_retran_frame_delay <= wr_retran_frame_sync;
759
           // edge detector
760
           if ((wr_retran_frame_delay ^ wr_retran_frame_sync) == 1'b1)
761
              wr_retransmit_frame    <= 1'b1;
762
           else
763
              wr_retransmit_frame    <= 1'b0;
764
        end
765
  end
766
 
767
  // count the number of frames in the fifo.  the counter is incremented when a
768
  // frame is stored or retransmitted and decremented when a frame is transmitted.  Need to keep
769
  // the counter on the write clock as this is the fastest clock.
770
  // Assumes transmit and retransmit cannot happen at same time
771
  always @(posedge wr_clk)
772
  begin
773
     if (wr_sreset == 1'b1)
774
        wr_frames <= 9'b0;
775
     else
776
        if ((wr_store_frame & wr_retransmit_frame) == 1'b1)
777
           wr_frames <= wr_frames + 2;
778
        else if (((wr_store_frame | wr_retransmit_frame) & !wr_transmit_frame) == 1'b1)
779
           wr_frames <= wr_frames + 1;
780
        else if (wr_transmit_frame == 1'b1 & !wr_store_frame)
781
           wr_frames <= wr_frames - 1;
782
  end
783
 
784
end // gen_hd_count
785
endgenerate
786
 
787
 
788
  //---------------------------------------------------------------------------
789
  // generate a frame in fifo signal for use in control logic
790
  always @(posedge wr_clk)
791
  begin
792
      if (wr_sreset == 1'b1)
793
         wr_frame_in_fifo <= 1'b0;
794
      else
795
         if (wr_frames != 9'b0)
796
            wr_frame_in_fifo <= 1'b1;
797
         else
798
            wr_frame_in_fifo <= 1'b0;
799
  end
800
 
801
  // register back onto read domain for use in the read logic
802
  always @(posedge rd_clk)
803
  begin
804
     if (rd_sreset == 1'b1)
805
        begin
806
           frame_in_fifo_sync <= 1'b0;
807
           frame_in_fifo <= 1'b0;
808
        end
809
     else if (rd_enable == 1'b1)
810
        begin
811
           frame_in_fifo_sync <= wr_frame_in_fifo;
812
           frame_in_fifo <= frame_in_fifo_sync;
813
        end
814
  end
815
 
816
 
817
  //---------------------------------------------------------------------------
818
  // Address counters
819
  //---------------------------------------------------------------------------
820
  // Address counters
821
  // write address is incremented when write enable signal has been asserted
822
  always @(posedge wr_clk)
823
  begin
824
     if (wr_sreset == 1'b1)
825
        wr_addr <= 12'b0;
826
     else if (wr_addr_reload == 1'b1)
827
        wr_addr <= wr_start_addr;
828
     else if (wr_addr_inc == 1'b1)
829
        wr_addr <= wr_addr + 1;
830
  end
831
 
832
  // store the start address incase the address must be reset
833
  always @(posedge wr_clk)
834
  begin
835
     if (wr_sreset == 1'b1)
836
        wr_start_addr <= 12'b0;
837
     else if (wr_start_addr_load == 1'b1)
838
        wr_start_addr <= wr_addr + 1;
839
  end
840
 
841
  //---------------------------------------------------------------------------
842
generate if (FULL_DUPLEX_ONLY == 1) begin : gen_fd_addr
843
  // read address is incremented when read enable signal has been asserted
844
  always @(posedge rd_clk)
845
  begin
846
     if (rd_sreset == 1'b1)
847
        rd_addr <= 12'b0;
848
     else if (rd_enable == 1'b1)
849
        if (rd_addr_reload == 1'b1)
850
           rd_addr <= rd_dec_addr;
851
        else if (rd_addr_inc == 1'b1)
852
           rd_addr <= rd_addr + 1;
853
  end
854
 
855
  // do not need to keep a start address, but the address is needed to
856
  // calculate fifo occupancy.
857
  always @(posedge rd_clk)
858
  begin
859
     if (rd_sreset == 1'b1)
860
        rd_start_addr <= 12'b0;
861
     else if (rd_enable == 1'b1)
862
        rd_start_addr <= rd_addr;
863
  end
864
 
865
 
866
 
867
end // gen_fd_addr                           // full duplex address counters
868
endgenerate
869
 
870
  //---------------------------------------------------------------------------
871
generate if (FULL_DUPLEX_ONLY != 1) begin : gen_hd_addr
872
  // read address is incremented when read enable signal has been asserted
873
  always @(posedge rd_clk)
874
  begin
875
     if (rd_sreset == 1'b1)
876
        rd_addr <= 12'b0;
877
     else if (rd_enable == 1'b1)
878
        if (rd_addr_reload == 1'b1)
879
           rd_addr <= rd_dec_addr;
880
        else if (rd_start_addr_reload == 1'b1)
881
           rd_addr <= rd_start_addr;
882
        else if (rd_addr_inc == 1'b1)
883
           rd_addr <= rd_addr + 1;
884
  end
885
 
886
  always @(posedge rd_clk)
887
  begin
888
     if (rd_sreset == 1'b1)
889
        rd_start_addr <= 12'b0;
890
     else if (rd_enable == 1'b1)
891
        if (rd_start_addr_load == 1'b1)
892
           rd_start_addr <= rd_addr - 4;
893
  end
894
 
895
  // Collision window expires after MAC has been transmitting for required slot
896
  // time.  This is 512 clock cycles at 1G.  Also if the end of frame has fully
897
  // been transmitted by the mac then a collision cannot occur.
898
  // this collision expire signal goes high at 768 cycles from the start of the
899
  // frame.
900
  // inefficient for short frames, however should be enough to prevent fifo
901
  // locking up.
902
  always @(posedge rd_clk)
903
  begin
904
     if (rd_sreset == 1'b1)
905
        rd_col_window_expire <= 1'b0;
906
     else if (rd_enable == 1'b1)
907
        if (rd_transmit_frame == 1'b1)
908
           rd_col_window_expire <= 1'b0;
909
        else if (rd_slot_timer[9:8] == 2'b11)
910
           rd_col_window_expire <= 1'b1;
911
  end
912
 
913
  assign rd_idle_state = (rd_state == IDLE_s) ? 1'b1 : 1'b0;
914
 
915
  always @(posedge rd_clk)
916
  begin
917
     if (rd_enable == 1'b1)
918
        begin
919
           rd_col_window_pipe[0] <= rd_col_window_expire & rd_idle_state;
920
           if (rd_txfer_en == 1'b1)
921
              rd_col_window_pipe[1] <= rd_col_window_pipe[0];
922
        end
923
  end
924
 
925
  always @(posedge rd_clk)
926
  begin
927
     if (rd_sreset == 1'b1)         // will not count until after first
928
                                    // frame is sent.
929
        rd_slot_timer <= 10'b0;
930
     else if (rd_enable == 1'b1)
931
        if (rd_transmit_frame == 1'b1)  // reset counter
932
           rd_slot_timer <= 10'b0;
933
        // do not allow counter to role over.
934
        // only count when frame is being transmitted.
935
        else if (rd_slot_timer != 10'b1111111111)
936
           rd_slot_timer <= rd_slot_timer + 1;
937
  end
938
 
939
 
940
end // gen_hd_addr                           // half duplex address counters
941
endgenerate
942
 
943
  always @(posedge rd_clk)
944
  begin
945
     if (rd_sreset == 1'b1)
946
           rd_dec_addr <= 12'b0;
947
     else if (rd_enable == 1'b1)
948
        if (rd_addr_inc == 1'b1)
949
           rd_dec_addr <= rd_addr - 1;
950
  end
951
 
952
  //---------------------------------------------------------------------------
953
  always @(posedge rd_clk)
954
  begin
955
     if (rd_sreset == 1'b1)
956
        begin
957
           rd_bram_u <= 1'b0;
958
           rd_bram_u_reg <= 1'b0;
959
        end
960
     else if (rd_enable == 1'b1)
961
        if (rd_addr_inc == 1'b1)
962
           begin
963
              rd_bram_u <= rd_addr[11];
964
              rd_bram_u_reg <= rd_bram_u;
965
           end
966
  end
967
 
968
  //---------------------------------------------------------------------------
969
  // Data Pipelines
970
  //---------------------------------------------------------------------------
971
  // register input signals to fifo
972
  // no reset to allow srl16 target
973
  always @(posedge wr_clk)
974
  begin
975
     wr_data_pipe[0] <= wr_data;
976
     if (wr_accept_pipe[0] == 1'b1)
977
        wr_data_pipe[1] <= wr_data_pipe[0];
978
     if (wr_accept_pipe[1] == 1'b1)
979
        wr_data_bram    <= wr_data_pipe[1];
980
  end
981
 
982
  // no reset to allow srl16 target
983
  always @(posedge wr_clk)
984
  begin
985
     wr_sof_pipe[0] <= !wr_sof_n;
986
     if (wr_accept_pipe[0] == 1'b1)
987
        wr_sof_pipe[1] <= wr_sof_pipe[0];
988
  end
989
 
990
  always @(posedge wr_clk)
991
  begin
992
     if (wr_sreset == 1'b1)
993
        begin
994
           wr_accept_pipe[0] <= 1'b0;
995
           wr_accept_pipe[1] <= 1'b0;
996
           wr_accept_bram    <= 1'b0;
997
        end
998
     else
999
        begin
1000
           wr_accept_pipe[0] <= !wr_src_rdy_n & !wr_dst_rdy_int_n;
1001
           wr_accept_pipe[1] <= wr_accept_pipe[0];
1002
           wr_accept_bram    <= wr_accept_pipe[1];
1003
        end
1004
  end
1005
 
1006
  always @(posedge wr_clk)
1007
  begin
1008
     wr_eof_pipe[0] <= !wr_eof_n;
1009
     if (wr_accept_pipe[0] == 1'b1)
1010
        wr_eof_pipe[1] <= wr_eof_pipe[0];
1011
     if (wr_accept_pipe[1] == 1'b1)
1012
        wr_eof_bram[0] <= wr_eof_pipe[1];
1013
  end
1014
 
1015
  // register data outputs from bram
1016
  // no reset to allow srl16 target
1017
  always @(posedge rd_clk)
1018
  begin
1019
     if (rd_enable == 1'b1)
1020
        if (rd_en == 1'b1)
1021
           begin
1022
              rd_data_pipe_u <= rd_data_bram_u;
1023
              rd_data_pipe_l <= rd_data_bram_l;
1024
              if (rd_bram_u_reg == 1'b1)
1025
                 rd_data_pipe <= rd_data_pipe_u;
1026
              else
1027
                 rd_data_pipe <= rd_data_pipe_l;
1028
           end
1029
  end
1030
 
1031
   // register data outputs from bram
1032
  // no reset to allow srl16 target
1033
  always @(posedge rd_clk)
1034
  begin
1035
     if (rd_enable == 1'b1)
1036
        if (rd_en == 1'b1)
1037
           begin
1038
              if (rd_bram_u == 1'b1)
1039
                 rd_eof_pipe <= rd_eof_bram_u[0];
1040
              else
1041
                 rd_eof_pipe <= rd_eof_bram_l[0];
1042
              rd_eof <= rd_eof_pipe;
1043
              rd_eof_reg <= rd_eof | rd_eof_pipe;
1044
           end
1045
  end
1046
 
1047
  //---------------------------------------------------------------------------
1048
generate if (FULL_DUPLEX_ONLY != 1) begin : gen_hd_input
1049
  // register the collision and retransmit signals
1050
  always @(posedge rd_clk)
1051
  begin
1052
     if (rd_enable == 1'b1)
1053
        rd_drop_frame <= tx_collision & !tx_retransmit;
1054
  end
1055
 
1056
  always @(posedge rd_clk)
1057
  begin
1058
     if (rd_enable == 1'b1)
1059
        rd_retransmit <= tx_collision & tx_retransmit;
1060
  end
1061
 
1062
end // gen_hd_input                        // half duplex register input
1063
endgenerate
1064
 
1065
  //---------------------------------------------------------------------------
1066
  // Fifo full functionality
1067
  //---------------------------------------------------------------------------
1068
  // when full duplex full functionality is difference between read and write addresses.
1069
  // when in half duplex is difference between read start and write addresses.
1070
  // Cannot use gray code this time as the read address and read start addresses jump by more than 1
1071
 
1072
  // generate an enable pulse for the read side every 16 read clocks.  This provides for the worst case
1073
  // situation where wr clk is 20Mhz and rd clk is 125 Mhz.
1074
  always @(posedge rd_clk)
1075
  begin
1076
     if (rd_sreset == 1'b1)
1077
        rd_16_count <= 4'b0;
1078
     else if (rd_enable == 1'b1)
1079
        rd_16_count <= rd_16_count + 1;
1080
  end
1081
 
1082
  assign rd_txfer_en = (rd_16_count == 4'b1111) ? 1'b1 : 1'b0;
1083
 
1084
  // register the start address on the enable pulse
1085
  always @(posedge rd_clk)
1086
  begin
1087
     if (rd_sreset == 1'b1)
1088
        rd_addr_txfer <= 12'b0;
1089
     else if (rd_enable == 1'b1)
1090
        begin
1091
        if (rd_txfer_en == 1'b1)
1092
           rd_addr_txfer <= rd_start_addr;
1093
        end
1094
  end
1095
 
1096
  // generate a toggle to indicate that the address has been loaded.
1097
  always @(posedge rd_clk)
1098
  begin
1099
     if (rd_sreset == 1'b1)
1100
        rd_txfer_tog <= 1'b0;
1101
     else if (rd_enable == 1'b1)
1102
        begin
1103
        if (rd_txfer_en == 1'b1)
1104
           rd_txfer_tog <= !rd_txfer_tog;
1105
        end
1106
  end
1107
 
1108
  // pass the toggle to the write side
1109
  always @(posedge wr_clk)
1110
  begin
1111
     if (wr_sreset == 1'b1)
1112
        begin
1113
           wr_txfer_tog <= 1'b0;
1114
           wr_txfer_tog_sync <= 1'b0;
1115
           wr_txfer_tog_delay <= 1'b0;
1116
        end
1117
     else
1118
        begin
1119
           wr_txfer_tog <= rd_txfer_tog;
1120
           wr_txfer_tog_sync <= wr_txfer_tog;
1121
           wr_txfer_tog_delay <= wr_txfer_tog_sync;
1122
        end
1123
  end
1124
 
1125
  // generate an enable pulse from the toggle, the address should have been steady on the wr clock input for at least one clock
1126
  assign wr_txfer_en = wr_txfer_tog_delay ^ wr_txfer_tog_sync;
1127
 
1128
  // capture the address on the write clock when the enable pulse is high.
1129
  always @(posedge wr_clk)
1130
  begin
1131
     if (wr_sreset == 1'b1)
1132
        wr_rd_addr <= 12'b0;
1133
     else if (wr_txfer_en == 1'b1)
1134
        wr_rd_addr <= rd_addr_txfer;
1135
  end
1136
 
1137
 
1138
  // Obtain the difference between write and read pointers
1139
  always @(posedge wr_clk)
1140
  begin
1141
     if (wr_sreset == 1'b1)
1142
        wr_addr_diff <= 12'b0;
1143
     else
1144
        wr_addr_diff <= wr_rd_addr - wr_addr;
1145
  end
1146
 
1147
 
1148
  // Detect when the FIFO is full
1149
  always @(posedge wr_clk)
1150
  begin
1151
     if (wr_sreset == 1'b1)
1152
        wr_fifo_full <= 1'b0;
1153
     else
1154
        // The FIFO is considered to be full if the write address
1155
        // pointer is within 1 to 3 of the read address pointer.
1156
        if (wr_addr_diff[11:4] == 8'b0 && wr_addr_diff[3:2] != 2'b0)
1157
           wr_fifo_full <= 1'b1;
1158
        else
1159
           wr_fifo_full <= 1'b0;
1160
  end
1161
 
1162
  // memory overflow occurs when the fifo is full and there are no frames
1163
  // available in the fifo for transmission.  If the collision window has
1164
  // expired and there are no frames in the fifo and the fifo is full, then the
1165
  // fifo is in an overflow state.  we must accept the rest of the incoming
1166
  // frame in overflow condition.
1167
 
1168
generate if (FULL_DUPLEX_ONLY == 1) begin : gen_fd_ovflow
1169
     // in full duplex mode, the fifo memory can only overflow if the fifo goes
1170
     // full but there is no frame available to be retranmsitted
1171
     // do not allow to go high when the frame count is being updated, ie wr_store_frame is asserted.
1172
     assign wr_fifo_overflow = (wr_fifo_full == 1'b1 && wr_frame_in_fifo == 1'b0
1173
                                   && wr_eof_state == 1'b0 && wr_eof_state_reg == 1'b0) ? 1'b1 : 1'b0;
1174
end // gen_fd_ovflow
1175
endgenerate
1176
 
1177
generate if (FULL_DUPLEX_ONLY != 1) begin : gen_hd_ovflow
1178
    // register wr col window to give address counter sufficient time to update.
1179
     // do not allow to go high when the frame count is being updated, ie wr_store_frame is asserted.
1180
    assign wr_fifo_overflow = (wr_fifo_full == 1'b1 && wr_frame_in_fifo == 1'b0
1181
                                  && wr_eof_state == 1'b0 && wr_eof_state_reg == 1'b0 && wr_col_window_expire == 1'b1) ? 1'b1 : 1'b0;
1182
 
1183
    // register rd_col_window signal
1184
    // this signal is long, and will remain high until overflow functionality
1185
    // has finished, so save just to register the once.
1186
    always @(posedge wr_clk)
1187
    begin  // process
1188
       if (wr_sreset == 1'b1)
1189
          begin
1190
             wr_col_window_pipe[0] <= 1'b0;
1191
             wr_col_window_pipe[1] <= 1'b0;
1192
             wr_col_window_expire  <= 1'b0;
1193
          end
1194
       else
1195
          begin
1196
             if (wr_txfer_en == 1'b1)
1197
                wr_col_window_pipe[0] <= rd_col_window_pipe[1];
1198
             wr_col_window_pipe[1] <= wr_col_window_pipe[0];
1199
             wr_col_window_expire <= wr_col_window_pipe[1];
1200
          end
1201
    end
1202
 
1203
end // gen_hd_ovflow
1204
endgenerate
1205
 
1206
 
1207
 
1208
  //--------------------------------------------------------------------
1209
  // Create FIFO Status Signals in the Write Domain
1210
  //--------------------------------------------------------------------
1211
 
1212
  // The FIFO status signal is four bits which represents the occupancy
1213
  // of the FIFO in 16'ths.  To generate this signal we therefore only
1214
  // need to compare the 4 most significant bits of the write address
1215
  // pointer with the 4 most significant bits of the read address 
1216
  // pointer.
1217
 
1218
  // The 4 most significant bits of the write pointer minus the 4 msb of
1219
  // the read pointer gives us our FIFO status.
1220
  always @(posedge wr_clk)
1221
  begin
1222
     if (wr_sreset == 1'b1)
1223
        wr_fifo_status <= 4'b0;
1224
     else
1225
        if (wr_addr_diff == 12'b0)
1226
           wr_fifo_status <= 4'b0;
1227
        else
1228
           begin
1229
              wr_fifo_status[3] <= !wr_addr_diff[11];
1230
              wr_fifo_status[2] <= !wr_addr_diff[10];
1231
              wr_fifo_status[1] <= !wr_addr_diff[9];
1232
              wr_fifo_status[0] <= !wr_addr_diff[8];
1233
           end
1234
  end
1235
 
1236
  //---------------------------------------------------------------------------
1237
  // Memory
1238
  //---------------------------------------------------------------------------
1239
  assign rd_en_bram = rd_en & rd_enable_delay2;
1240
 
1241
  // Block Ram for lower address space (rx_addr(11) = 1'b0)
1242
  defparam ramgen_l.WRITE_MODE_A = "READ_FIRST";
1243
  defparam ramgen_l.WRITE_MODE_B = "READ_FIRST";
1244
  RAMB16_S9_S9 ramgen_l (
1245
      .WEA  (wr_en_l),
1246
      .ENA  (VCC),
1247
      .SSRA (wr_sreset),
1248
      .CLKA (wr_clk),
1249
      .ADDRA(wr_addr[10:0]),
1250
      .DIA  (wr_data_bram),
1251
      .DIPA (wr_eof_bram),
1252
      .DOA  (),
1253
      .DOPA (),
1254
      .WEB  (GND),
1255
      .ENB  (rd_en_bram),
1256
      .SSRB (rd_sreset),
1257
      .CLKB (rd_clk),
1258
      .ADDRB(rd_addr[10:0]),
1259
      .DIB  (GND_BUS[7:0]),
1260
      .DIPB (GND_BUS[0:0]),
1261
      .DOB  (rd_data_bram_l),
1262
      .DOPB (rd_eof_bram_l));
1263
 
1264
    // Block Ram for lower address space (rx_addr(11) = 1'b0)
1265
  defparam ramgen_u.WRITE_MODE_A = "READ_FIRST";
1266
  defparam ramgen_u.WRITE_MODE_B = "READ_FIRST";
1267
  RAMB16_S9_S9 ramgen_u (
1268
      .WEA  (wr_en_u),
1269
      .ENA  (VCC),
1270
      .SSRA (wr_sreset),
1271
      .CLKA (wr_clk),
1272
      .ADDRA(wr_addr[10:0]),
1273
      .DIA  (wr_data_bram),
1274
      .DIPA (wr_eof_bram),
1275
      .DOA  (),
1276
      .DOPA (),
1277
      .WEB  (GND),
1278
      .ENB  (rd_en_bram),
1279
      .SSRB (rd_sreset),
1280
      .CLKB (rd_clk),
1281
      .ADDRB(rd_addr[10:0]),
1282
      .DIB  (GND_BUS[7:0]),
1283
      .DIPB (GND_BUS[0:0]),
1284
      .DOB  (rd_data_bram_u),
1285
      .DOPB (rd_eof_bram_u));
1286
 
1287
 
1288
 
1289
endmodule

powered by: WebSVN 2.1.0

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