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

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [examples/] [memfifo/] [fpga-2.04b/] [ipcore_dir/] [mem0/] [user_design/] [sim/] [read_posted_fifo.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
//*****************************************************************************
2
// (c) Copyright 2008-2009 Xilinx, Inc. All rights reserved.
3
//
4
// This file contains confidential and proprietary information
5
// of Xilinx, Inc. and is protected under U.S. and
6
// international copyright and other intellectual property
7
// laws.
8
//
9
// DISCLAIMER
10
// This disclaimer is not a license and does not grant any
11
// rights to the materials distributed herewith. Except as
12
// otherwise provided in a valid license issued to you by
13
// Xilinx, and to the maximum extent permitted by applicable
14
// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
15
// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
16
// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
17
// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
18
// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
19
// (2) Xilinx shall not be liable (whether in contract or tort,
20
// including negligence, or under any other theory of
21
// liability) for any loss or damage of any kind or nature
22
// related to, arising under or in connection with these
23
// materials, including for any direct, or any indirect,
24
// special, incidental, or consequential loss or damage
25
// (including loss of data, profits, goodwill, or any type of
26
// loss or damage suffered as a result of any action brought
27
// by a third party) even if such damage or loss was
28
// reasonably foreseeable or Xilinx had been advised of the
29
// possibility of the same.
30
//
31
// CRITICAL APPLICATIONS
32
// Xilinx products are not designed or intended to be fail-
33
// safe, or for use in any application requiring fail-safe
34
// performance, such as life-support or safety devices or
35
// systems, Class III medical devices, nuclear facilities,
36
// applications related to the deployment of airbags, or any
37
// other applications that could lead to death, personal
38
// injury, or severe property or environmental damage
39
// (individually and collectively, "Critical
40
// Applications"). Customer assumes the sole risk and
41
// liability of any use of Xilinx products in Critical
42
// Applications, subject only to applicable laws and
43
// regulations governing limitations on product liability.
44
//
45
// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
46
// PART OF THIS FILE AT ALL TIMES.
47
//
48
//*****************************************************************************
49
//   ____  ____
50
//  /   /\/   /
51
// /___/  \  /    Vendor: Xilinx
52
// \   \   \/     Version: %version
53
//  \   \         Application: MIG
54
//  /   /         Filename: read_posted_fifo.v
55
// /___/   /\     Date Last Modified: 
56
// \   \  /  \    Date Created: 
57
//  \___\/\___\
58
//
59
//Device: Spartan6
60
//Design Name: DDR/DDR2/DDR3/LPDDR 
61
//Purpose: This module instantiated by read_data_path module and sits between 
62
//         mcb_flow_control module and read_data_gen module to buffer up the 
63
//         commands that has sent to memory controller.
64
//Reference:
65
//Revision History:
66
//                  2010/01/09/   Corrected dfifo_has_enough_room threshold logic.
67
//                                It has to set higher in Read Only port.
68
//*****************************************************************************
69
`timescale 1ps/1ps
70
 
71
  module read_posted_fifo #
72
  (
73
   parameter TCQ           = 100,
74
   parameter FAMILY     = "SPARTAN6",
75
   parameter MEM_BURST_LEN = 4,
76
 
77
   parameter ADDR_WIDTH = 32,
78
   parameter BL_WIDTH = 6
79
  )
80
  (
81
   input                   clk_i,
82
   input                   rst_i,
83
   output reg                 cmd_rdy_o,
84
   input                   cmd_valid_i,
85
   input                   data_valid_i,
86
   input [ADDR_WIDTH-1:0]  addr_i,
87
   input [BL_WIDTH-1:0]    bl_i,
88
   input                   user_bl_cnt_is_1,
89
   input [2:0]           cmd_sent,
90
   input [5:0]           bl_sent  ,
91
   input                 cmd_en_i ,
92
 
93
 
94
   input                   gen_rdy_i,
95
   output                  gen_valid_o,
96
   output [ADDR_WIDTH-1:0] gen_addr_o,
97
   output [BL_WIDTH-1:0]   gen_bl_o,
98
   output [6:0]           rd_buff_avail_o,
99
   input                   rd_mdata_fifo_empty,
100
   output                  rd_mdata_en
101
 
102
   );
103
 
104
reg empty_r;
105
reg rd_first_data;
106
 
107
   wire full;
108
   wire empty;
109
   wire wr_en;
110
   reg rd_en;
111
   reg data_valid_r;
112
   reg user_bl_cnt_not_1;
113
    reg [6:0] buf_avail_r;
114
    reg [6:0] rd_data_received_counts;
115
    reg [6:0] rd_data_counts_asked;
116
 
117
      reg dfifo_has_enough_room;
118
    reg [1:0] wait_cnt;
119
    reg wait_done;
120
 
121
  assign rd_mdata_en = rd_en;
122
 
123
   assign rd_buff_avail_o = buf_avail_r;
124
   always @ (posedge clk_i)
125
       cmd_rdy_o <= #TCQ !full  & dfifo_has_enough_room & wait_done;
126
 
127
   always @ (posedge clk_i)
128
   begin
129
   if (rst_i)
130
       wait_cnt <= #TCQ 'b0;
131
   else if (cmd_rdy_o && cmd_valid_i)
132
       wait_cnt <= #TCQ 2'b10;
133
   else if (wait_cnt > 0)
134
         wait_cnt <= #TCQ wait_cnt - 1;
135
 
136
   end
137
 
138
   always @(posedge clk_i)
139
   begin
140
   if (rst_i)
141
      wait_done <= #TCQ 1'b1;
142
   else if (cmd_rdy_o && cmd_valid_i)
143
      wait_done <= #TCQ 1'b0;
144
   else if (wait_cnt == 0)
145
      wait_done <= #TCQ 1'b1;
146
   else
147
      wait_done <= #TCQ 1'b0;
148
 
149
   end
150
 
151
   reg dfifo_has_enough_room_d1;
152
   always @ (posedge clk_i)
153
   begin // prbs_blen from cmd_gen is random, it can be two 64 in consecutive
154
         // the logic here to prevent cmd_gen send any further read command if
155
         // any large bl command has been sent.
156
 
157
       dfifo_has_enough_room <= #TCQ (buf_avail_r >= 62  ) ? 1'b1: 1'b0;
158
 
159
       dfifo_has_enough_room_d1 <= #TCQ dfifo_has_enough_room ;
160
   end
161
 
162
 
163
   assign wr_en    = cmd_valid_i & !full  & dfifo_has_enough_room_d1 & wait_done;
164
 
165
 
166
   always @ (posedge clk_i)
167
       data_valid_r <= #TCQ data_valid_i;
168
 
169
 
170
  always @ (posedge clk_i)
171
  begin
172
  if (data_valid_i && user_bl_cnt_is_1)  // current count is 1 and data_is_valie, then next cycle is not 1
173
     user_bl_cnt_not_1 <= #TCQ 1'b1;
174
  else
175
     user_bl_cnt_not_1 <= #TCQ 1'b0;
176
  end
177
 
178
 always @ (posedge clk_i)
179
 begin
180
 if (rst_i) begin
181
    rd_data_counts_asked <= #TCQ 'b0;
182
    end
183
 else if (cmd_en_i && cmd_sent[0] == 1) begin
184
 
185
    rd_data_counts_asked <= #TCQ rd_data_counts_asked + (bl_sent + 7'b0000001) ;
186
 
187
    end
188
 end
189
 
190
 always @ (posedge clk_i)
191
 begin
192
 if (rst_i) begin
193
     rd_data_received_counts <= #TCQ 'b0;
194
     end
195
 else if (data_valid_i) begin
196
     rd_data_received_counts <= #TCQ rd_data_received_counts + 1;
197
     end
198
 end
199
 
200
 // calculate how many buf still available
201
 always @ (posedge clk_i)
202
                  // MCB FIFO size is 64.
203
                  // buf_available is calculated by:
204
                  // FIFO DEPTH - ( Write Poitner - Read Pointer)
205
     buf_avail_r <= #TCQ 64 - (rd_data_counts_asked - rd_data_received_counts);
206
 
207
 
208
 
209
   always @(gen_rdy_i, empty,empty_r,rd_mdata_fifo_empty,rd_first_data ,data_valid_i,data_valid_r,user_bl_cnt_not_1)
210
   begin
211
        if (FAMILY == "SPARTAN6")
212
            rd_en = gen_rdy_i & !empty;
213
        else
214
             if ( MEM_BURST_LEN == 4)
215
                   rd_en = (~empty & empty_r & ~rd_first_data) | (~rd_mdata_fifo_empty & ~empty ) | (user_bl_cnt_not_1 & data_valid_i);
216
             else
217
                   rd_en = (data_valid_i & ~data_valid_r) | (user_bl_cnt_not_1 & data_valid_i);
218
 
219
        end
220
 
221
   always @ (posedge clk_i)
222
        empty_r <= #TCQ empty;
223
 
224
   always @ (posedge clk_i)
225
   begin
226
   if (rst_i)
227
       rd_first_data <= #TCQ 1'b0;
228
   else if (~empty && empty_r)
229
       rd_first_data <= #TCQ 1'b1;
230
   end
231
 
232
 
233
 
234
   assign gen_valid_o = !empty;
235
   afifo #
236
   (
237
    .TCQ               (TCQ),
238
    .DSIZE         (BL_WIDTH+ADDR_WIDTH),
239
    .FIFO_DEPTH    (16),
240
    .ASIZE         (4),
241
    .SYNC          (1)  // set the SYNC to 1 because rd_clk = wr_clk to reduce latency 
242
 
243
 
244
   )
245
   rd_fifo
246
   (
247
    .wr_clk        (clk_i),
248
    .rst           (rst_i),
249
    .wr_en         (wr_en),
250
    .wr_data       ({bl_i,addr_i}),
251
    .rd_en         (rd_en),
252
    .rd_clk        (clk_i),
253
    .rd_data       ({gen_bl_o,gen_addr_o}),
254
    .full          (full),
255
    .empty         (empty),
256
    .almost_full   ()
257
 
258
   );
259
 
260
 
261
 
262
 
263
 
264
endmodule

powered by: WebSVN 2.1.0

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