| 1 |
4 |
jlee |
//*******************************************************************************
|
| 2 |
6 |
jlee |
// S Y N T H E S I Z A B L E S D R A M C O N T R O L L E R C O R E
|
| 3 |
4 |
jlee |
//
|
| 4 |
|
|
// This core adheres to the GNU Public License
|
| 5 |
|
|
//
|
| 6 |
|
|
// This is a synthesizable Synchronous DRAM controller Core. As it stands,
|
| 7 |
|
|
// it is ready to work with 8Mbyte SDRAMs, organized as 2M x 32 at 100MHz
|
| 8 |
|
|
// and 125MHz. For example: Samsung KM432S2030CT, Fujitsu MB81F643242B.
|
| 9 |
|
|
//
|
| 10 |
|
|
// The core has been carefully coded so as to be "platform-independent".
|
| 11 |
|
|
// It has been successfully compiled and simulated under three separate
|
| 12 |
|
|
// FPGA/CPLD platforms:
|
| 13 |
|
|
// Xilinx Foundation Base Express V2.1i
|
| 14 |
|
|
// Altera Max+PlusII V9.21
|
| 15 |
|
|
// Lattice ispExpert V7.0
|
| 16 |
|
|
//
|
| 17 |
|
|
// The interface to the host (i.e. microprocessor, DSP, etc) is synchronous
|
| 18 |
|
|
// and supports ony one transfer at a time. That is, burst-mode transfers
|
| 19 |
|
|
// are not yet supported. In may ways, the interface to this core is much
|
| 20 |
|
|
// like that of a typical SRAM. The hand-shaking between the host and the
|
| 21 |
|
|
// SDRAM core is done through the "sdram_busy_l" signal generated by the
|
| 22 |
|
|
// core. Whenever this signal is active low, the host must hold the address,
|
| 23 |
|
|
// data (if doing a write), size and the controls (cs, rd/wr).
|
| 24 |
|
|
//
|
| 25 |
|
|
// Connection Diagram:
|
| 26 |
|
|
// SDRAM side:
|
| 27 |
|
|
// sd_wr_l connect to -WR pin of SDRAM
|
| 28 |
|
|
// sd_cs_l connect to -CS pin of SDRAM
|
| 29 |
|
|
// sd_ras_l connect to -RAS pin of SDRAM
|
| 30 |
|
|
// sd_cas_l connect to -CAS pin of SDRAM
|
| 31 |
|
|
// sd_dqm[3:0] connect to the DQM3,DQM2,DQM1,DQM0 pins
|
| 32 |
|
|
// sd_addx[10:0] connect to the Address bus [10:0]
|
| 33 |
|
|
// sd_data[31:0] connect to the data bus [31:0]
|
| 34 |
|
|
// sd_ba[1:0] connect to BA1, BA0 pins of SDRAM
|
| 35 |
|
|
//
|
| 36 |
|
|
// HOST side:
|
| 37 |
|
|
// mp_addx[22:0] connect to the address bus of the host.
|
| 38 |
|
|
// 23 bit address bus give access to 8Mbyte
|
| 39 |
|
|
// of the SDRAM, as byte, half-word (16bit)
|
| 40 |
|
|
// or word (32bit)
|
| 41 |
|
|
// mp_data_in[31:0] Unidirectional bus connected to the data out
|
| 42 |
|
|
// of the host. To use this, enable
|
| 43 |
|
|
// "databus_is_unidirectional" in INC.H
|
| 44 |
|
|
// mp_data_out[31:0] Unidirectional bus connected to the data in
|
| 45 |
|
|
// of the host. To use this, enable
|
| 46 |
|
|
// "databus_is_unidirectional" in INC.H
|
| 47 |
|
|
// mp_data[31:0] Bi-directional bus connected to the host's
|
| 48 |
|
|
// data bus. To use the bi-directionla bus,
|
| 49 |
|
|
// disable "databus_is_unidirectional" in INC.H
|
| 50 |
|
|
// mp_rd_l Connect to the -RD output of the host
|
| 51 |
|
|
// mp_wr_l Connect to the -WR output of the host
|
| 52 |
|
|
// mp_cs_l Connect to the -CS of the host
|
| 53 |
|
|
// mp_size[1:0] Connect to the size output of the host
|
| 54 |
|
|
// if there is one. When set to 0
|
| 55 |
|
|
// all trasnfers are 32 bits, when set to 1
|
| 56 |
|
|
// all transfers are 8 bits, and when set to
|
| 57 |
|
|
// 2 all xfers are 16 bits. If you want the
|
| 58 |
|
|
// data to be lower order aligned, turn on
|
| 59 |
|
|
// "align_data_bus" option in INC.H
|
| 60 |
|
|
// sdram_busy_l Connect this to the wait or hold equivalent
|
| 61 |
|
|
// input of the host. The host, must hold the
|
| 62 |
|
|
// bus if it samples this signal as low.
|
| 63 |
|
|
// sdram_mode_set_l When a write occurs with this set low,
|
| 64 |
|
|
// the SDRAM's mode set register will be programmed
|
| 65 |
|
|
// with the data supplied on the data_bus[10:0].
|
| 66 |
|
|
//
|
| 67 |
|
|
//
|
| 68 |
|
|
// Author: Jeung Joon Lee joon.lee@quantum.com, cmosexod@ix.netcom.com
|
| 69 |
|
|
//
|
| 70 |
|
|
//*******************************************************************************
|
| 71 |
|
|
//
|
| 72 |
|
|
// Hierarchy:
|
| 73 |
|
|
//
|
| 74 |
|
|
// SDRAM.V Top Level Module
|
| 75 |
|
|
// HOSTCONT.V Controls the interfacing between the micro and the SDRAM
|
| 76 |
|
|
// SDRAMCNT.V This is the SDRAM controller. All data passed to and from
|
| 77 |
|
|
// is with the HOSTCONT.
|
| 78 |
|
|
// optional
|
| 79 |
|
|
// MICRO.V This is the built in SDRAM tester. This module generates
|
| 80 |
|
|
// a number of test logics which is used to test the SDRAM
|
| 81 |
|
|
// It is basically a Micro bus generator.
|
| 82 |
|
|
//
|
| 83 |
|
|
/*
|
| 84 |
|
|
*/
|
| 85 |
|
|
|
| 86 |
|
|
|
| 87 |
2 |
jlee |
// Uncomment below to use the microprocessor bus simulator
|
| 88 |
4 |
jlee |
// This will turn this IP into a "SDRAM" tester.
|
| 89 |
|
|
// Once you enable this option, choose the test mode in
|
| 90 |
|
|
// the file "tst_inc.h"
|
| 91 |
2 |
jlee |
// ====================
|
| 92 |
4 |
jlee |
//`define simulate_mp
|
| 93 |
2 |
jlee |
|
| 94 |
|
|
// Uncomment the below to enable the debug pins
|
| 95 |
4 |
jlee |
// If you are in an FPGA/CPLD platform be *CAREFULL*. This will
|
| 96 |
|
|
// generate a lot of pins. Use it with causion.
|
| 97 |
2 |
jlee |
// ====================
|
| 98 |
|
|
//`define show_debug
|
| 99 |
|
|
|
| 100 |
|
|
|
| 101 |
|
|
// Common definition stuff
|
| 102 |
|
|
`define HI 1'b1
|
| 103 |
|
|
`define LO 1'b0
|
| 104 |
4 |
jlee |
`define X 1'bx
|
| 105 |
2 |
jlee |
|
| 106 |
|
|
//***********************************************************
|
| 107 |
|
|
// U S E R M O D I F I A B L E S
|
| 108 |
|
|
//***********************************************************
|
| 109 |
|
|
|
| 110 |
|
|
// The number of refreshses done at power up. 16 by default
|
| 111 |
4 |
jlee |
`define power_up_ref_cntr_limit 3
|
| 112 |
2 |
jlee |
|
| 113 |
|
|
// The number of refreshes done during normal refresh cycle.
|
| 114 |
|
|
// Set this to be 2048 for "burst" refreshes, and
|
| 115 |
|
|
// set this to be 1 for "regular" refreshes
|
| 116 |
|
|
`define auto_ref_cntr_limit 1
|
| 117 |
|
|
|
| 118 |
|
|
// Refresh Frequency in Hz.
|
| 119 |
|
|
// For burst refresh use 33Hz (30mS)
|
| 120 |
|
|
// For normal refresh use 66666Hz (15uS)
|
| 121 |
4 |
jlee |
`define Frefresh 66666
|
| 122 |
2 |
jlee |
|
| 123 |
4 |
jlee |
// Type of Data Bus
|
| 124 |
|
|
// Unididrectiona: the top hierachy module SDRAM.V will have seperate 32 bit
|
| 125 |
|
|
// data buses for reads and writes. This is useful for embedding the
|
| 126 |
|
|
// core in a larger core.
|
| 127 |
|
|
// Birectional: the top hierarchy module SDRAM.V will have a biredirectional 32bit
|
| 128 |
|
|
// data bus. This is useful if the SDRAM controller core is to be a
|
| 129 |
|
|
// stand-alone module.
|
| 130 |
|
|
//
|
| 131 |
|
|
// Comment the below for bidirectional bus, and UNcomment for unidirectional
|
| 132 |
|
|
`define databus_is_unidirectional
|
| 133 |
|
|
|
| 134 |
|
|
// SDRAM DATA BUS TYPE
|
| 135 |
|
|
//
|
| 136 |
|
|
//
|
| 137 |
|
|
`define sdram_data_bus_is_unidirectional
|
| 138 |
|
|
|
| 139 |
|
|
|
| 140 |
|
|
// DATA BUS ALIGNING
|
| 141 |
|
|
// With this option enabled (uncomment below) half-word accesses are aligned to lower
|
| 142 |
|
|
// bus DATA[15:0], and byte accesses are aligned to DATA[7:0]. This is ideal when a
|
| 143 |
|
|
// 8 bit micro or host wants to access all of the space of the 16/32 bit SDRAM.
|
| 144 |
|
|
|
| 145 |
|
|
// data bus aligning ON: (uncomment the below define)
|
| 146 |
|
|
// a 16 bit write should have the data to the SDRAM controller on D[15:0].
|
| 147 |
|
|
// a 16 bit read will have the data returned by the SDRAM conroller on D[15:0].
|
| 148 |
|
|
// a 8 bit write should have the data to the SDRAM controller on D[7:0].
|
| 149 |
|
|
// a 8 bit read will have the data returned by the SDRAM controller on D[7:0].
|
| 150 |
|
|
//
|
| 151 |
|
|
// data bus aligning OFF: (comment the below define)
|
| 152 |
|
|
// a 16 bit write should have the data to the SDRAM controller on D[31:16] or
|
| 153 |
|
|
// D[15:0] depending on the state of A[1] (A[1]=1, on D[31:16], A[1]=0 on
|
| 154 |
|
|
// D[15:0].
|
| 155 |
|
|
// a 16 bit read will have the data returned by the SDRAM controller on D[31:16]
|
| 156 |
|
|
// or D[15:0], based on the state of A[1].
|
| 157 |
|
|
// similar thought process for 8 bit write and reads.
|
| 158 |
|
|
//
|
| 159 |
|
|
//`define align_data_bus
|
| 160 |
|
|
|
| 161 |
|
|
|
| 162 |
2 |
jlee |
// SDRAM clock frequency in Hz.
|
| 163 |
|
|
// Set this to whatever the clock rate is
|
| 164 |
4 |
jlee |
`define Fsystem 2000000
|
| 165 |
|
|
//`define Fsystem 100000000
|
| 166 |
2 |
jlee |
|
| 167 |
|
|
|
| 168 |
|
|
|
| 169 |
4 |
jlee |
|
| 170 |
|
|
// DEFAULT MODE-REGISTER values
|
| 171 |
|
|
// The below is programmed to the mode regsiter at
|
| 172 |
|
|
// powerup
|
| 173 |
|
|
`define default_mode_reg_BURST_LENGHT 3'b000
|
| 174 |
|
|
`define defulat_mode_reg_BURST_TYPE 1'b0
|
| 175 |
|
|
`define default_mode_reg_CAS_LATENCY 3'b010
|
| 176 |
|
|
|
| 177 |
|
|
|
| 178 |
2 |
jlee |
//***********************************************************
|
| 179 |
|
|
// D O N O T M O D I F Y
|
| 180 |
|
|
//***********************************************************
|
| 181 |
|
|
// Interval between refreshes in SDRAM clk ticks
|
| 182 |
|
|
`define RC `Fsystem/`Frefresh
|
| 183 |
|
|
|
| 184 |
|
|
// Width of the refresh counter. Default 20. log2(`RC)/log2
|
| 185 |
|
|
// use 8 bits for 15uS interval with 12.5MHz clock
|
| 186 |
4 |
jlee |
//`define BW 8
|
| 187 |
|
|
`define BW 20
|
| 188 |
2 |
jlee |
|
| 189 |
|
|
// The refresh delay counter width
|
| 190 |
4 |
jlee |
`define RD 3
|
| 191 |
2 |
jlee |
|
| 192 |
|
|
// This sets the number of delay cycles right after the refresh command
|
| 193 |
4 |
jlee |
`define AUTO_REFRESH_WIDTH 1
|
| 194 |
2 |
jlee |
|
| 195 |
|
|
// MAin SDRAM controller state machine definition
|
| 196 |
|
|
`define TS 4
|
| 197 |
|
|
`define TSn `TS-1
|
| 198 |
|
|
|
| 199 |
4 |
jlee |
`define state_idle `TS'b0001
|
| 200 |
|
|
`define state_set_ras `TS'b0011
|
| 201 |
|
|
`define state_ras_dly `TS'b0010
|
| 202 |
|
|
`define state_set_cas `TS'b0110
|
| 203 |
|
|
`define state_cas_latency1 `TS'b0111
|
| 204 |
|
|
`define state_cas_latency2 `TS'b0101
|
| 205 |
|
|
`define state_write `TS'b0100
|
| 206 |
|
|
`define state_read `TS'b1100
|
| 207 |
|
|
`define state_auto_refresh `TS'b1101
|
| 208 |
|
|
`define state_auto_refresh_dly `TS'b1111
|
| 209 |
|
|
`define state_precharge `TS'b1110
|
| 210 |
|
|
`define state_powerup `TS'b1010
|
| 211 |
|
|
`define state_modeset `TS'b1011
|
| 212 |
6 |
jlee |
`define state_delay_Trp `TS'b0000
|
| 213 |
|
|
`define state_delay_Tras1 `TS'b1000
|
| 214 |
|
|
`define state_delay_Tras2 `TS'b1001
|
| 215 |
2 |
jlee |
|
| 216 |
|
|
// Fresh timer states
|
| 217 |
|
|
`define state_count 3'b001
|
| 218 |
|
|
`define state_halt 3'b010
|
| 219 |
|
|
`define state_reset 3'b100
|
| 220 |
|
|
|