6420010a69024ac5ca95fdd77f56341ae39777f6
[fleet.git] / src / edu / berkeley / fleet / fpga / greg / ddr2_infrastructure.v
1 //*****************************************************************************
2 // DISCLAIMER OF LIABILITY
3 // 
4 // This text/file contains proprietary, confidential
5 // information of Xilinx, Inc., is distributed under license
6 // from Xilinx, Inc., and may be used, copied and/or
7 // disclosed only pursuant to the terms of a valid license
8 // agreement with Xilinx, Inc. Xilinx hereby grants you a 
9 // license to use this text/file solely for design, simulation, 
10 // implementation and creation of design files limited 
11 // to Xilinx devices or technologies. Use with non-Xilinx 
12 // devices or technologies is expressly prohibited and 
13 // immediately terminates your license unless covered by
14 // a separate agreement.
15 //
16 // Xilinx is providing this design, code, or information 
17 // "as-is" solely for use in developing programs and 
18 // solutions for Xilinx devices, with no obligation on the 
19 // part of Xilinx to provide support. By providing this design, 
20 // code, or information as one possible implementation of 
21 // this feature, application or standard, Xilinx is making no 
22 // representation that this implementation is free from any 
23 // claims of infringement. You are responsible for 
24 // obtaining any rights you may require for your implementation. 
25 // Xilinx expressly disclaims any warranty whatsoever with 
26 // respect to the adequacy of the implementation, including 
27 // but not limited to any warranties or representations that this
28 // implementation is free from claims of infringement, implied 
29 // warranties of merchantability or fitness for a particular 
30 // purpose.
31 //
32 // Xilinx products are not intended for use in life support
33 // appliances, devices, or systems. Use in such applications is
34 // expressly prohibited.
35 //
36 // Any modifications that are made to the Source Code are 
37 // done at the user\92s sole risk and will be unsupported.
38 //
39 // Copyright (c) 2006-2007 Xilinx, Inc. All rights reserved.
40 //
41 // This copyright and support notice must be retained as part 
42 // of this text at all times. 
43 //*****************************************************************************
44 //   ____  ____
45 //  /   /\/   /
46 // /___/  \  /    Vendor: Xilinx
47 // \   \   \/     Version: 2.3
48 //  \   \         Application: MIG
49 //  /   /         Filename: ddr2_infrastructure.v
50 // /___/   /\     Date Last Modified: $Date: 2008/05/08 15:20:47 $
51 // \   \  /  \    Date Created: Wed Aug 16 2006
52 //  \___\/\___\
53 //
54 //Device: Virtex-5
55 //Design Name: DDR2
56 //Purpose:
57 //   Clock distribution and reset synchronization
58 //Reference:
59 //Revision History:
60 //*****************************************************************************
61
62 `timescale 1ns/1ps
63
64 module ddr2_infrastructure #
65   (
66    parameter RST_ACT_LOW  = 1
67    )
68   (
69    input clk0,
70    input clk90,
71    input clk200,
72    input clkdiv0,
73    input dcm_lock,
74    input  sys_rst_n,
75    input  idelay_ctrl_rdy,
76    output rst0,
77    output rst90,
78    output rst200,
79    output rstdiv0
80    );
81
82   // # of clock cycles to delay deassertion of reset. Needs to be a fairly
83   // high number not so much for metastability protection, but to give time
84   // for reset (i.e. stable clock cycles) to propagate through all state
85   // machines and to all control signals (i.e. not all control signals have
86   // resets, instead they rely on base state logic being reset, and the effect
87   // of that reset propagating through the logic). Need this because we may not
88   // be getting stable clock cycles while reset asserted (i.e. since reset
89   // depends on DCM lock status)
90   localparam RST_SYNC_NUM = 25;
91
92   reg [RST_SYNC_NUM-1:0]     rst0_sync_r    /* synthesis syn_maxfan = 10 */;
93   reg [RST_SYNC_NUM-1:0]     rst200_sync_r  /* synthesis syn_maxfan = 10 */;
94   reg [RST_SYNC_NUM-1:0]     rst90_sync_r   /* synthesis syn_maxfan = 10 */;
95   reg [(RST_SYNC_NUM/2)-1:0] rstdiv0_sync_r /* synthesis syn_maxfan = 10 */;
96   wire                       rst_tmp;
97   wire                       sys_clk_ibufg;
98   wire                       sys_rst;
99
100   assign sys_rst = RST_ACT_LOW ? ~sys_rst_n: sys_rst_n;
101
102
103
104   //***************************************************************************
105   // Reset synchronization
106   // NOTES:
107   //   1. shut down the whole operation if the DCM hasn't yet locked (and by
108   //      inference, this means that external SYS_RST_IN has been asserted -
109   //      DCM deasserts DCM_LOCK as soon as SYS_RST_IN asserted)
110   //   2. In the case of all resets except rst200, also assert reset if the
111   //      IDELAY master controller is not yet ready
112   //   3. asynchronously assert reset. This was we can assert reset even if
113   //      there is no clock (needed for things like 3-stating output buffers).
114   //      reset deassertion is synchronous.
115   //***************************************************************************
116
117   assign rst_tmp = sys_rst | ~dcm_lock | ~idelay_ctrl_rdy;
118
119   // synthesis attribute max_fanout of rst0_sync_r is 10
120   always @(posedge clk0 or posedge rst_tmp)
121     if (rst_tmp)
122       rst0_sync_r <= {RST_SYNC_NUM{1'b1}};
123     else
124       // logical left shift by one (pads with 0)
125       rst0_sync_r <= rst0_sync_r << 1;
126
127   // synthesis attribute max_fanout of rstdiv0_sync_r is 10
128   always @(posedge clkdiv0 or posedge rst_tmp)
129     if (rst_tmp)
130       rstdiv0_sync_r <= {(RST_SYNC_NUM/2){1'b1}};
131     else
132       // logical left shift by one (pads with 0)
133       rstdiv0_sync_r <= rstdiv0_sync_r << 1;
134
135   // synthesis attribute max_fanout of rst90_sync_r is 10
136   always @(posedge clk90 or posedge rst_tmp)
137     if (rst_tmp)
138       rst90_sync_r <= {RST_SYNC_NUM{1'b1}};
139     else
140       rst90_sync_r <= rst90_sync_r << 1;
141
142   // make sure CLK200 doesn't depend on IDELAY_CTRL_RDY, else chicken n' egg
143    // synthesis attribute max_fanout of rst200_sync_r is 10
144   always @(posedge clk200 or negedge dcm_lock)
145     if (!dcm_lock)
146       rst200_sync_r <= {RST_SYNC_NUM{1'b1}};
147     else
148       rst200_sync_r <= rst200_sync_r << 1;
149
150
151   assign rst0    = rst0_sync_r[RST_SYNC_NUM-1];
152   assign rst90   = rst90_sync_r[RST_SYNC_NUM-1];
153   assign rst200  = rst200_sync_r[RST_SYNC_NUM-1];
154   assign rstdiv0 = rstdiv0_sync_r[(RST_SYNC_NUM/2)-1];
155
156 endmodule