AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Files Variables
mig_7series_v1_9_ddr_if_post_fifo.v
1  //*****************************************************************************
2 // (c) Copyright 2008 - 2013 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 : mig_7series_v1_x_ddr_if_post_fifo.v
55 // /___/ /\ Date Last Modified : $date$
56 // \ \ / \ Date Created : Feb 08 2011
57 // \___\/\___\
58 //
59 //Device : 7 Series
60 //Design Name : DDR3 SDRAM
61 //Purpose : Extends the depth of a PHASER IN_FIFO up to 4 entries
62 //Reference :
63 //Revision History :
64 //*****************************************************************************
65 
66 `timescale 1 ps / 1 ps
67 
69  (
70  parameter TCQ = 100, // clk->out delay (sim only)
71  parameter DEPTH = 4, // # of entries
72  parameter WIDTH = 32 // data bus width
73  )
74  (
75  input clk, // clock
76  input rst, // synchronous reset
77  input [3:0] empty_in,
78  input rd_en_in,
79  input [WIDTH-1:0] d_in, // write data from controller
80  output empty_out,
81  output byte_rd_en,
82  output [WIDTH-1:0] d_out // write data to OUT_FIFO
83  );
84 
85  // # of bits used to represent read/write pointers
86  localparam PTR_BITS
87  = (DEPTH == 2) ? 1 :
88  (((DEPTH == 3) || (DEPTH == 4)) ? 2 : 'bx);
89 
90  integer i;
91 
92  reg [WIDTH-1:0] mem[0:DEPTH-1];
93 (* keep = "true", max_fanout = 3 *) reg [4:0] my_empty /* synthesis syn_maxfan = 3 **/;
94 (* keep = "true", max_fanout = 3 *) reg [1:0] my_full /* synthesis syn_maxfan = 3 **/;
95 (* keep = "true", max_fanout = 10 *) reg [PTR_BITS-1:0] rd_ptr /* synthesis syn_maxfan = 10 **/;
96 (* keep = "true", max_fanout = 10 *) reg [PTR_BITS-1:0] wr_ptr /* synthesis syn_maxfan = 10 **/;
97  wire [WIDTH-1:0] mem_out;
98 (* keep = "true", max_fanout = 10 *) wire wr_en /* synthesis syn_maxfan = 10 **/;
99 
100  task updt_ptrs;
101  input rd;
102  input wr;
103  reg [1:0] next_rd_ptr;
104  reg [1:0] next_wr_ptr;
105  begin
106  next_rd_ptr = (rd_ptr + 1'b1)%DEPTH;
107  next_wr_ptr = (wr_ptr + 1'b1)%DEPTH;
108  casez ({rd, wr, my_empty[1], my_full[1]})
109  4'b00zz: ; // No access, do nothing
110  4'b0100: begin
111  // Write when neither empty, nor full; check for full
112  wr_ptr <= #TCQ next_wr_ptr;
113  my_full[0] <= #TCQ (next_wr_ptr == rd_ptr);
114  my_full[1] <= #TCQ (next_wr_ptr == rd_ptr);
115  //mem[wr_ptr] <= #TCQ d_in;
116  end
117  4'b0110: begin
118  // Write when empty; no need to check for full
119  wr_ptr <= #TCQ next_wr_ptr;
120  my_empty <= #TCQ 5'b00000;
121  //mem[wr_ptr] <= #TCQ d_in;
122  end
123  4'b1000: begin
124  // Read when neither empty, nor full; check for empty
125  rd_ptr <= #TCQ next_rd_ptr;
126  my_empty[0] <= #TCQ (next_rd_ptr == wr_ptr);
127  my_empty[1] <= #TCQ (next_rd_ptr == wr_ptr);
128  my_empty[2] <= #TCQ (next_rd_ptr == wr_ptr);
129  my_empty[3] <= #TCQ (next_rd_ptr == wr_ptr);
130  my_empty[4] <= #TCQ (next_rd_ptr == wr_ptr);
131  end
132  4'b1001: begin
133  // Read when full; no need to check for empty
134  rd_ptr <= #TCQ next_rd_ptr;
135  my_full[0] <= #TCQ 1'b0;
136  my_full[1] <= #TCQ 1'b0;
137  end
138  4'b1100, 4'b1101, 4'b1110: begin
139  // Read and write when empty, full, or neither empty/full; no need
140  // to check for empty or full conditions
141  rd_ptr <= #TCQ next_rd_ptr;
142  wr_ptr <= #TCQ next_wr_ptr;
143  //mem[wr_ptr] <= #TCQ d_in;
144  end
145  4'b0101, 4'b1010: ;
146  // Read when empty, Write when full; Keep all pointers the same
147  // and don't change any of the flags (i.e. ignore the read/write).
148  // This might happen because a faulty DQS_FOUND calibration could
149  // result in excessive skew between when the various IN_FIFO's
150  // first become not empty. In this case, the data going to each
151  // post-FIFO/IN_FIFO should be read out and discarded
152  // synthesis translate_off
153  default: begin
154  // Covers any other cases, in particular for simulation if
155  // any signals are X's
156  $display("ERR %m @%t: Bad access: rd:%b,wr:%b,empty:%b,full:%b",
157  $time, rd, wr, my_empty[1], my_full[1]);
158  rd_ptr <= #TCQ 2'bxx;
159  wr_ptr <= #TCQ 2'bxx;
160  end
161  // synthesis translate_on
162  endcase
163  end
164  endtask
165 
166 
167  assign d_out = my_empty[4] ? d_in : mem_out;//mem[rd_ptr];
168  // The combined IN_FIFO + post FIFO is only "empty" when both are empty
169  assign empty_out = empty_in[0] & my_empty[0];
170  assign byte_rd_en = !empty_in[3] || !my_empty[3];
171 
172  always @(posedge clk)
173  if (rst) begin
174  my_empty <= #TCQ 5'b11111;
175  my_full <= #TCQ 2'b00;
176  rd_ptr <= #TCQ 'b0;
177  wr_ptr <= #TCQ 'b0;
178  end else begin
179  // Special mode: If IN_FIFO has data, and controller is reading at
180  // the same time, then operate post-FIFO in "passthrough" mode (i.e.
181  // don't update any of the read/write pointers, and route IN_FIFO
182  // data to post-FIFO data)
183  if (my_empty[1] && !my_full[1] && rd_en_in && !empty_in[1]) ;
184  else
185  // Otherwise, we're writing to FIFO when IN_FIFO is not empty,
186  // and reading from the FIFO based on the rd_en_in signal (read
187  // enable from controller). The functino updt_ptrs should catch
188  // an illegal conditions.
189  updt_ptrs(rd_en_in, !empty_in[1]);
190  end
191 
192 
193  assign wr_en = (!empty_in[2] & ((!rd_en_in & !my_full[0]) |
194  (rd_en_in & !my_empty[2])));
195 
196 
197  always @ (posedge clk)
198  begin
199  if (wr_en)
200  mem[wr_ptr] <= #TCQ d_in;
201  end
202 
203  assign mem_out = mem[rd_ptr];
204 
205 endmodule