使用说明
-
SDRAM初始化代码说明:
sdr.v : SDRAM模型
sdram_init.v 初始化SDRAM控制器
sdram_init_tb.v 初始化测试文件 -
仿真时令:
iverilog -o wave_sdram_init sdr.v sdram_init.v sdram_init_tb.v
vvp wave_sdram_init
gtkwave sdram_init_tb.vcd -
SDRAM控制器代码说明:
sdram_control.v :SDRAM控制器
sdram_control_tb.v :SDRAM控制器测试代码
sdr.v : SDRAM模型
sdram_init.v 初始化SDRAM控制器 -
仿真时令:
iverilog -o wave_sdram_control sdr.v sdram_control_tb.v sdram_control.v sdram_init.v
vvp wave_sdram_control
gtkwave sdram_control_tb.vcd
代码
- sdr_parameters.h 是SDRAM参数信息
/****************************************************************************************
*
* Disclaimer This software code and all associated documentation, comments or other
* of Warranty: information (collectively "Software") is provided "AS IS" without
* warranty of any kind. MICRON TECHNOLOGY, INC. ("MTI") EXPRESSLY
* DISCLAIMS ALL WARRANTIES EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO, NONINFRINGEMENT OF THIRD PARTY RIGHTS, AND ANY IMPLIED WARRANTIES
* OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE. MTI DOES NOT
* WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS, OR THAT THE
* OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE.
* FURTHERMORE, MTI DOES NOT MAKE ANY REPRESENTATIONS REGARDING THE USE OR
* THE RESULTS OF THE USE OF THE SOFTWARE IN TERMS OF ITS CORRECTNESS,
* ACCURACY, RELIABILITY, OR OTHERWISE. THE ENTIRE RISK ARISING OUT OF USE
* OR PERFORMANCE OF THE SOFTWARE REMAINS WITH YOU. IN NO EVENT SHALL MTI,
* ITS AFFILIATED COMPANIES OR THEIR SUPPLIERS BE LIABLE FOR ANY DIRECT,
* INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR SPECIAL DAMAGES (INCLUDING,
* WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION,
* OR LOSS OF INFORMATION) ARISING OUT OF YOUR USE OF OR INABILITY TO USE
* THE SOFTWARE, EVEN IF MTI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES. Because some jurisdictions prohibit the exclusion or
* limitation of liability for consequential or incidental damages, the
* above limitation may not apply to you.
*
* Copyright 2005 Micron Technology, Inc. All rights reserved.
*
* bhoffman - 07/18/06
*
****************************************************************************************/
// Timing parameters based on Speed Grade and part type (Y37M)
`define sg6a
`define den256Mb
`define x16 // SYMBOL UNITS DESCRIPTION
// ------ ----- -----------
`ifdef sg6a // Timing Parameters for -6A (CL = 3)
parameter tCK = 6.0; // tCK ns Nominal Clock Cycle Time
parameter tCK3_min = 6.0; // tCK ns Nominal Clock Cycle Time
parameter tCK2_min = 10.0; // tCK ns Nominal Clock Cycle Time
parameter tCK1_min = 20.0; // tCK ns Nominal Clock Cycle Time
parameter tAC3 = 5.4; // tAC3 ns Access time from CLK (pos edge) CL = 3
parameter tAC2 = 7.5; // tAC2 ns Access time from CLK (pos edge) CL = 2
parameter tAC1 = 17.0; // tAC1 ns Parameter definition for compilation - CL = 1 illegal for sg75
parameter tHZ3 = 5.4; // tHZ3 ns Data Out High Z time - CL = 3
parameter tHZ2 = 7.5; // tHZ2 ns Data Out High Z time - CL = 2
parameter tHZ1 = 17.0; // tHZ1 ns Parameter definition for compilation - CL = 1 illegal for sg75
parameter tOH = 3.0; // tOH ns Data Out Hold time
parameter tMRD = 2.0; // tMRD tCK Load Mode Register command cycle time (2 * tCK)
parameter tRAS = 42.0; // tRAS ns Active to Precharge command time
parameter tRC = 60.0; // tRC ns Active to Active/Auto Refresh command time
parameter tRFC = 60.0; // tRFC ns Refresh to Refresh Command interval time
parameter tRCD = 18.0; // tRCD ns Active to Read/Write command time
parameter tRP = 18.0; // tRP ns Precharge command period
parameter tRRD = 2.0; // tRRD tCK Active bank a to Active bank b command time (2 * tCK)
parameter tWRa = 6.0; // tWR ns Write recovery time (auto-precharge mode - must add 1 CLK)
parameter tWRm = 12.0; // tWR ns Write recovery time
`elsif sg7e // Timing Parameters for -7E (CL = 3)
parameter tCK = 7.0; // tCK ns Nominal Clock Cycle Time
parameter tCK3_min = 7.0; // tCK ns Nominal Clock Cycle Time
parameter tCK2_min = 7.5; // tCK ns Nominal Clock Cycle Time
parameter tCK1_min = 0.0; // tCK ns Nominal Clock Cycle Time
parameter tAC3 = 5.4; // tAC3 ns Access time from CLK (pos edge) CL = 3
parameter tAC2 = 5.4; // tAC2 ns Access time from CLK (pos edge) CL = 2
parameter tAC1 = 0.0; // tAC1 ns Parameter definition for compilation - CL = 1 illegal for sg75
parameter tHZ3 = 5.4; // tHZ3 ns Data Out High Z time - CL = 3
parameter tHZ2 = 5.4; // tHZ2 ns Data Out High Z time - CL = 2
parameter tHZ1 = 0.0; // tHZ1 ns Parameter definition for compilation - CL = 1 illegal for sg75
parameter tOH = 2.7; // tOH ns Data Out Hold time
parameter tMRD = 2.0; // tMRD tCK Load Mode Register command cycle time (2 * tCK)
parameter tRAS = 37.0; // tRAS ns Active to Precharge command time
parameter tRC = 60.0; // tRC ns Active to Active/Auto Refresh command time
parameter tRFC = 66.0; // tRFC ns Refresh to Refresh Command interval time
parameter tRCD = 15.0; // tRCD ns Active to Read/Write command time
parameter tRP = 15.0; // tRP ns Precharge command period
parameter tRRD = 2.0; // tRRD tCK Active bank a to Active bank b command time (2 * tCK)
parameter tWRa = 7.0; // tWR ns Write recovery time (auto-precharge mode - must add 1 CLK)
parameter tWRm = 14.0; // tWR ns Write recovery time
`else `define sg75 // Timing Parameters for -75 (CL = 3)
parameter tCK = 7.5; // tCK ns Nominal Clock Cycle Time
parameter tCK3_min = 7.5; // tCK ns Nominal Clock Cycle Time
parameter tCK2_min = 10.0; // tCK ns Nominal Clock Cycle Time
parameter tCK1_min = 0.0; // tCK ns Nominal Clock Cycle Time
parameter tAC3 = 5.4; // tAC3 ns Access time from CLK (pos edge) CL = 3
parameter tAC2 = 6.0; // tAC2 ns Access time from CLK (pos edge) CL = 2
parameter tAC1 = 0.0; // tAC1 ns Parameter definition for compilation - CL = 1 illegal for sg75
parameter tHZ3 = 5.4; // tHZ3 ns Data Out High Z time - CL = 3
parameter tHZ2 = 6.0; // tHZ2 ns Data Out High Z time - CL = 2
parameter tHZ1 = 0.0; // tHZ1 ns Parameter definition for compilation - CL = 1 illegal for sg75
parameter tOH = 2.7; // tOH ns Data Out Hold time
parameter tMRD = 2.0; // tMRD tCK Load Mode Register command cycle time (2 * tCK)
parameter tRAS = 44.0; // tRAS ns Active to Precharge command time
parameter tRC = 66.0; // tRC ns Active to Active/Auto Refresh command time
parameter tRFC = 66.0; // tRFC ns Refresh to Refresh Command interval time
parameter tRCD = 20.0; // tRCD ns Active to Read/Write command time
parameter tRP = 20.0; // tRP ns Precharge command period
parameter tRRD = 2.0; // tRRD tCK Active bank a to Active bank b command time (2 * tCK)
parameter tWRa = 7.5; // tWR ns Write recovery time (auto-precharge mode - must add 1 CLK)
parameter tWRm = 15.0; // tWR ns Write recovery time
`endif
// Size Parameters based on Part Width
`ifdef den64Mb
`ifdef x4
parameter ADDR_BITS = 12; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 12; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 10; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 4; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 1; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`elsif x8
parameter ADDR_BITS = 12; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 12; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 9; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 8; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 1; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`else `define x16
parameter ADDR_BITS = 12; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 12; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 8; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 16; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 2; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`endif
`elsif den128Mb
`ifdef x4
parameter ADDR_BITS = 12; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 12; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 11; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 4; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 1; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`elsif x8
parameter ADDR_BITS = 12; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 12; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 10; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 8; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 1; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`else `define x16
parameter ADDR_BITS = 12; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 12; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 9; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 16; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 2; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`endif
`elsif den256Mb
`ifdef x4
parameter ADDR_BITS = 13; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 13; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 11; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 4; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 1; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`elsif x8
parameter ADDR_BITS = 13; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 13; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 10; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 8; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 1; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`else `define x16
parameter ADDR_BITS = 13; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 13; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 9; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 16; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 2; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`endif
`else `define den512Mb
`ifdef x4
parameter ADDR_BITS = 13; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 13; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 12; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 4; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 1; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`elsif x8
parameter ADDR_BITS = 13; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 13; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 11; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 8; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 1; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`else `define x16
parameter ADDR_BITS = 13; // Set this parameter to control how many Address bits are used
parameter ROW_BITS = 13; // Set this parameter to control how many Row bits are used
parameter COL_BITS = 10; // Set this parameter to control how many Column bits are used
parameter DQ_BITS = 16; // Set this parameter to control how many Data bits are used
parameter DM_BITS = 2; // Set this parameter to control how many DM bits are used
parameter BA_BITS = 2; // Bank bits
`endif
`endif
// Other Parameters
parameter mem_sizes = 2**(ROW_BITS+COL_BITS) - 1;
- Sdram_Params.h 是SDRAM控制器宏定义
// 地址和数据位宽
`define ASIZE 13 //SDRAM地址位宽
`define DSIZE 16 //SDRAM数据位宽
`define BSIZE 2 //SDRAM的bank地址位宽
//操作命令{CS_N,RAS_N,CAS_N,WE}
parameter C_NOP = 4'b0111, //空操作命令
C_PRE = 4'b0010, //预充电命令
C_AREF = 4'b0001, //自动刷新命令
C_MSET = 4'b0000, //加载模式寄存器命令
C_ACT = 4'b0011, //激活命令
C_RD = 4'b0101, //读命令
C_WR = 4'b0100; //写命令
//////////// 133 MHz ///////////////
/*
parameter INIT_PRE = 26600; //初始化等待时间>100us,取200us
parameter REF_PRE = 3; //tRP >=18ns,取30ns
parameter REF_REF = 10; //tRFC >=60ns,取100ns
parameter AUTO_REF = 2000; //自动刷新周期<64ms/4096=15625ns
parameter LMR_ACT = 2; //装载模式寄存器到可激活延时(2个时钟周期)
parameter WR_PRE = 2; //WRITE re