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

Subversion Repositories sdram

[/] [sdram/] [trunk/] [sdram.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jlee
`include "inc.h"
2
 
3 4 jlee
//*******************************************************************************
4
//  S Y N T H E Z I A B L E      S D R A M     C O N T R O L L E R    C O R E
5 2 jlee
//
6 4 jlee
//  This core adheres to the GNU Public License  
7
// 
8
//  This is a synthesizable Synchronous DRAM controller Core.  As it stands,
9
//  it is ready to work with 8Mbyte SDRAMs, organized as 2M x 32 at 100MHz
10
//  and 125MHz. For example: Samsung KM432S2030CT,  Fujitsu MB81F643242B.
11 2 jlee
//
12 4 jlee
//  The core has been carefully coded so as to be "platform-independent".  
13
//  It has been successfully compiled and simulated under three separate
14
//  FPGA/CPLD platforms:
15
//      Xilinx Foundation Base Express V2.1i
16
//      Altera Max+PlusII V9.21
17
//      Lattice ispExpert V7.0
18
//  
19
//  The interface to the host (i.e. microprocessor, DSP, etc) is synchronous
20
//  and supports ony one transfer at a time.  That is, burst-mode transfers
21
//  are not yet supported.  In may ways, the interface to this core is much
22
//  like that of a typical SRAM.  The hand-shaking between the host and the 
23
//  SDRAM core is done through the "sdram_busy_l" signal generated by the 
24
//  core.  Whenever this signal is active low, the host must hold the address,
25
//  data (if doing a write), size and the controls (cs, rd/wr).  
26
//
27
//  Connection Diagram:
28
//  SDRAM side:
29
//  sd_wr_l                     connect to -WR pin of SDRAM
30
//  sd_cs_l                     connect to -CS pin of SDRAM
31
//  sd_ras_l                    connect to -RAS pin of SDRAM
32
//  sd_cas_l                    connect to -CAS pin of SDRAM
33
//  sd_dqm[3:0]                 connect to the DQM3,DQM2,DQM1,DQM0 pins
34
//  sd_addx[10:0]               connect to the Address bus [10:0]
35
//  sd_data[31:0]               connect to the data bus [31:0]
36
//  sd_ba[1:0]                  connect to BA1, BA0 pins of SDRAM
37
//   
38
//  HOST side:
39
//  mp_addx[22:0]               connect to the address bus of the host. 
40
//                              23 bit address bus give access to 8Mbyte
41
//                              of the SDRAM, as byte, half-word (16bit)
42
//                              or word (32bit)
43
//  mp_data_in[31:0]            Unidirectional bus connected to the data out
44
//                              of the host. To use this, enable 
45
//                              "databus_is_unidirectional" in INC.H
46
//  mp_data_out[31:0]           Unidirectional bus connected to the data in 
47
//                              of the host.  To use this, enable
48
//                              "databus_is_unidirectional" in INC.H
49
//  mp_data[31:0]               Bi-directional bus connected to the host's
50
//                              data bus.  To use the bi-directionla bus,
51
//                              disable "databus_is_unidirectional" in INC.H
52
//  mp_rd_l                     Connect to the -RD output of the host
53
//  mp_wr_l                     Connect to the -WR output of the host
54
//  mp_cs_l                     Connect to the -CS of the host
55
//  mp_size[1:0]                Connect to the size output of the host
56
//                              if there is one.  When set to 0
57
//                              all trasnfers are 32 bits, when set to 1
58
//                              all transfers are 8 bits, and when set to
59
//                              2 all xfers are 16 bits.  If you want the
60
//                              data to be lower order aligned, turn on
61
//                              "align_data_bus" option in INC.H
62
//  sdram_busy_l                Connect this to the wait or hold equivalent
63
//                              input of the host.  The host, must hold the
64
//                              bus if it samples this signal as low.
65
//  sdram_mode_set_l            When a write occurs with this set low,
66
//                              the SDRAM's mode set register will be programmed
67
//                              with the data supplied on the data_bus[10:0].
68
//
69
//
70
//  Author:  Jeung Joon Lee  joon.lee@quantum.com,  cmosexod@ix.netcom.com
71
//  
72
//*******************************************************************************
73
//
74 2 jlee
//  Hierarchy:
75
//
76 4 jlee
//  SDRAM.V         Top Level Module
77 2 jlee
//  HOSTCONT.V      Controls the interfacing between the micro and the SDRAM
78
//  SDRAMCNT.V      This is the SDRAM controller.  All data passed to and from
79
//                  is with the HOSTCONT.
80
//  optional
81
//  MICRO.V         This is the built in SDRAM tester.  This module generates 
82
//                  a number of test logics which is used to test the SDRAM
83
//                  It is basically a Micro bus generator. 
84
//  
85 4 jlee
/*
86
*/
87 2 jlee
 
88
 
89
 
90
module sdram(
91
            // SYSTEM LEVEL CONNECTIONS
92
            sys_rst_l,
93 4 jlee
            sys_clk,
94 2 jlee
            // SDRAM CONNECTIONS
95 4 jlee
            sd_wr_l,
96 2 jlee
            sd_cs_l,
97 4 jlee
            sd_ras_l,
98
            sd_cas_l,
99
            sd_dqm,
100 2 jlee
            sd_addx,
101
            sd_data,
102
            sd_ba,
103
            // MICROPORCESSOR CONNECTION
104 4 jlee
            mp_addx
105
`ifdef databus_is_unidirectional
106
            ,
107
            mp_data_in,
108
            mp_data_out,
109
`else
110
            ,
111 2 jlee
            mp_data,
112 4 jlee
`endif
113 2 jlee
            mp_rd_l,
114
            mp_wr_l,
115
            mp_cs_l,
116
            sdram_mode_set_l,
117
            sdram_busy_l,
118 4 jlee
            mp_size,
119
            next_state
120
 
121 2 jlee
            // DEBUG
122
`ifdef show_debug
123 4 jlee
            ,
124 2 jlee
            next_state,
125 4 jlee
            mp_data_out_sd,
126
            mp_data_gate
127 2 jlee
            do_write,
128 4 jlee
            reg_mp_addx,
129
            reg_mp_data_mux,
130
            sd_addx_mux,
131
            sd_addx10_mux,
132
            next_state,
133
            doing_refresh,
134
            do_modeset,
135
            do_read,
136
            sd_addx_mux,
137
            sd_addx10_mux,
138
            autorefresh_cntr,
139
            autorefresh_cntr_l,
140
            pwrup,
141
            top_state,
142
            wr_cntr,
143
            mp_data_micro,
144
            mp_data_mux,
145
            sd_data_ena,
146
            mp_data_out,
147
            sd_addx_mux,
148
            sd_addx10_mux,
149
            sd_rd_ena
150 2 jlee
`endif
151
 );
152
 
153
 
154
 
155
 
156
 
157
// ****************************************
158
//
159
//   I/O  DEFINITION
160
//
161
// ****************************************
162
// SYSTEM LEVEL CONNECTIONS
163 4 jlee
input           sys_clk;                // global system clock.  Runs the sdram state machine
164
input           sys_rst_l;              // global active low asynchronous system reset
165 2 jlee
// SDRAM CONNECTIONS
166 4 jlee
output          sd_wr_l;                // SDRAM active low WRITE signal
167
output          sd_cs_l;                // SDRAM active low chip select signal
168
output          sd_ras_l;               // SDRAM active low RAS 
169
output          sd_cas_l;               // SDRAM active low CAS
170
output  [3:0]   sd_dqm;                 // SDRAM data masks
171
output  [10:0]  sd_addx;                // SDRAM multiplexed address bus
172
inout   [31:0]  sd_data;                // SDRAM birectional data bus 32 bit
173
output  [1:0]   sd_ba;                  // SDRAM bank address , aka A11
174
// MICROPROCESSOR CONNECTION
175
`ifdef databus_is_unidirectional
176
input   [31:0]  mp_data_in;
177
output  [31:0]  mp_data_out;
178
`else
179 2 jlee
`ifdef simulate_mp
180 4 jlee
inout   [31:0]  mp_data;
181 2 jlee
`else
182 4 jlee
output      [31:0]  mp_data;
183 2 jlee
`endif
184 4 jlee
`endif
185
`ifdef simulate_mp
186
output  [22:0]  mp_addx;                // HOST address bus. 23 bits for 8Mb
187
output          mp_rd_l;                // HOST active low READ 
188
output          mp_wr_l;                // HOST active low WRITE
189
output          mp_cs_l;                // HOST active low chip select
190
output          sdram_mode_set_l;
191
output  [1:0]   mp_size;                // 00=32bits, 10=16bits, 01=8bits
192
`else
193
input   [22:0]  mp_addx;                // HOST address bus. 23 bits for 8Mb
194
input           mp_rd_l;                // HOST active low READ 
195
input           mp_wr_l;                // HOST active low WRITE
196
input           mp_cs_l;                // HOST active low chip select
197
input           sdram_mode_set_l;
198
input   [1:0]   mp_size;                // 00=32bits, 10=16bits, 01=8bits
199
`endif
200
output          sdram_busy_l;
201
output  [3:0]   next_state;
202 2 jlee
// DEBUG
203
`ifdef show_debug
204 4 jlee
output  [31:0]  mp_data_out_sd;
205
output          mp_data_gate;
206 2 jlee
output          do_write;
207 4 jlee
output  [22:0]  reg_mp_addx;
208
output  [31:0]  reg_mp_data_mux;
209
output          sd_addx_mux;
210
output          sd_addx10_mux;
211
output          do_modeset;
212
output          do_read;
213
output          doing_refresh;
214
output  [3:0]   next_state;
215
output  [12:0]  autorefresh_cntr;
216
output          autorefresh_cntr_l;
217
output          pwrup;
218
output  [3:0]   top_state;
219
output  [7:0]   wr_cntr;
220
//output[31:0]  mp_data_micro;
221
output  [31:0]  mp_data_out;
222
//output        mp_data_mux;
223
output          sd_data_ena;
224 2 jlee
output          sd_rd_ena;
225
`endif
226
 
227
 
228
// INTER-MODULE CONNECTIONS
229
wire            do_modeset;
230
wire            do_read;
231
wire            do_write;
232
wire            doing_refresh;
233
wire            sd_addx_ena;
234
wire    [1:0]   sd_addx_mux;
235
wire    [1:0]   sd_addx10_mux;
236
wire            sd_rd_ena;
237
wire            sd_data_ena;
238
wire    [2:0]   modereg_cas_latency;
239
wire    [2:0]   modereg_burst_length;
240 4 jlee
wire    [3:0]   next_state;
241
wire    [31:0]  mp_data_out_sd;
242
wire    [31:0]  mp_data_in;
243
//wire  [31:0]  sd_data;
244 2 jlee
wire            mp_cs_l;
245
wire            mp_wr_l;
246
wire            mp_rd_l;
247
wire            mp_data_mux;
248 4 jlee
wire    [3:0]   autorefresh_cntr;
249
wire            autorefresh_cntr_l;
250
wire            pwrup;
251
wire    [3:0]   top_state;
252
wire    [22:0]  reg_mp_addx;
253
wire    [3:0]   decoded_dqm;
254
wire            do_write_ack;
255
wire            do_read_ack;
256
wire            do_modeset_ack;
257
wire    [31:0]  reg_mp_data_mux;
258
wire    [31:0]  sd_data_in;
259
wire    [31:0]  sd_data_out;
260
wire    [31:0]  reg_sd_data;
261 2 jlee
wire            sdram_mode_set_l;
262
wire            sys_clk;
263
wire            sdram_busy_l;
264 4 jlee
wire            mp_data_gate;
265
wire    [31:0]  mp_simulator_data;
266 2 jlee
 
267 4 jlee
//
268
// HOST sie DATA BUS DRISVERS
269
//
270
//
271
//
272
assign mp_data_gate = (~mp_rd_l & ~mp_cs_l);
273
// --- Unidirectional Data bus Mos
274
`ifdef databus_is_unidirectional
275
  `ifdef simulate_mp
276
     assign mp_data_out = mp_data_gate ? mp_data_out_sd : mp_simulator_data;
277
  `else
278
     assign mp_data_out = mp_data_gate ? mp_data_out_sd : 32'h00000000;
279
  `endif
280
// --- Bi-Directional Data bus Mode
281 2 jlee
`else
282 4 jlee
  `ifdef simulate_mp
283
     assign mp_data = mp_data_gate ? mp_data_out_sd : mp_simulator_data;
284
  `else
285
     bufif1 m0  (mp_data[0],  mp_data_out_sd[0],  mp_data_gate);
286
     bufif1 m1  (mp_data[1],  mp_data_out_sd[1],  mp_data_gate);
287
     bufif1 m2  (mp_data[2],  mp_data_out_sd[2],  mp_data_gate);
288
     bufif1 m3  (mp_data[3],  mp_data_out_sd[3],  mp_data_gate);
289
     bufif1 m4  (mp_data[4],  mp_data_out_sd[4],  mp_data_gate);
290
     bufif1 m5  (mp_data[5],  mp_data_out_sd[5],  mp_data_gate);
291
     bufif1 m6  (mp_data[6],  mp_data_out_sd[6],  mp_data_gate);
292
     bufif1 m7  (mp_data[7],  mp_data_out_sd[7],  mp_data_gate);
293
     bufif1 m8  (mp_data[8],  mp_data_out_sd[8],  mp_data_gate);
294
     bufif1 m9  (mp_data[9],  mp_data_out_sd[9],  mp_data_gate);
295
     bufif1 m10 (mp_data[10], mp_data_out_sd[10], mp_data_gate);
296
     bufif1 m11 (mp_data[11], mp_data_out_sd[11], mp_data_gate);
297
     bufif1 m12 (mp_data[12], mp_data_out_sd[12], mp_data_gate);
298
     bufif1 m13 (mp_data[13], mp_data_out_sd[13], mp_data_gate);
299
     bufif1 m14 (mp_data[14], mp_data_out_sd[14], mp_data_gate);
300
     bufif1 m15 (mp_data[15], mp_data_out_sd[15], mp_data_gate);
301
     bufif1 m16 (mp_data[16], mp_data_out_sd[16], mp_data_gate);
302
     bufif1 m17 (mp_data[17], mp_data_out_sd[17], mp_data_gate);
303
     bufif1 m18 (mp_data[18], mp_data_out_sd[18], mp_data_gate);
304
     bufif1 m19 (mp_data[19], mp_data_out_sd[19], mp_data_gate);
305
     bufif1 m20 (mp_data[20], mp_data_out_sd[20], mp_data_gate);
306
     bufif1 m21 (mp_data[21], mp_data_out_sd[21], mp_data_gate);
307
     bufif1 m22 (mp_data[22], mp_data_out_sd[22], mp_data_gate);
308
     bufif1 m23 (mp_data[23], mp_data_out_sd[23], mp_data_gate);
309
     bufif1 m24 (mp_data[24], mp_data_out_sd[24], mp_data_gate);
310
     bufif1 m25 (mp_data[25], mp_data_out_sd[25], mp_data_gate);
311
     bufif1 m26 (mp_data[26], mp_data_out_sd[26], mp_data_gate);
312
     bufif1 m27 (mp_data[27], mp_data_out_sd[27], mp_data_gate);
313
     bufif1 m28 (mp_data[28], mp_data_out_sd[28], mp_data_gate);
314
     bufif1 m29 (mp_data[29], mp_data_out_sd[29], mp_data_gate);
315
     bufif1 m30 (mp_data[30], mp_data_out_sd[30], mp_data_gate);
316
     bufif1 m31 (mp_data[31], mp_data_out_sd[31], mp_data_gate);
317
     assign mp_data_in = mp_data;
318
  `endif
319 2 jlee
`endif
320
 
321
 
322
//
323 4 jlee
// SDRAM side bidirectional data bus drivers
324
//assign sd_data    = sd_data_ena ? sd_data_out : 32'hzzzzzzzz;
325 2 jlee
//
326 4 jlee
bufif1 b0  (sd_data[0],  sd_data_out[0],  sd_data_ena);
327
bufif1 b1  (sd_data[1],  sd_data_out[1],  sd_data_ena);
328
bufif1 b2  (sd_data[2],  sd_data_out[2],  sd_data_ena);
329
bufif1 b3  (sd_data[3],  sd_data_out[3],  sd_data_ena);
330
bufif1 b4  (sd_data[4],  sd_data_out[4],  sd_data_ena);
331
bufif1 b5  (sd_data[5],  sd_data_out[5],  sd_data_ena);
332
bufif1 b6  (sd_data[6],  sd_data_out[6],  sd_data_ena);
333
bufif1 b7  (sd_data[7],  sd_data_out[7],  sd_data_ena);
334
bufif1 b8  (sd_data[8],  sd_data_out[8],  sd_data_ena);
335
bufif1 b9  (sd_data[9],  sd_data_out[9],  sd_data_ena);
336
bufif1 b10 (sd_data[10], sd_data_out[10], sd_data_ena);
337
bufif1 b11 (sd_data[11], sd_data_out[11], sd_data_ena);
338
bufif1 b12 (sd_data[12], sd_data_out[12], sd_data_ena);
339
bufif1 b13 (sd_data[13], sd_data_out[13], sd_data_ena);
340
bufif1 b14 (sd_data[14], sd_data_out[14], sd_data_ena);
341
bufif1 b15 (sd_data[15], sd_data_out[15], sd_data_ena);
342
bufif1 b16 (sd_data[16], sd_data_out[16], sd_data_ena);
343
bufif1 b17 (sd_data[17], sd_data_out[17], sd_data_ena);
344
bufif1 b18 (sd_data[18], sd_data_out[18], sd_data_ena);
345
bufif1 b19 (sd_data[19], sd_data_out[19], sd_data_ena);
346
bufif1 b20 (sd_data[20], sd_data_out[20], sd_data_ena);
347
bufif1 b21 (sd_data[21], sd_data_out[21], sd_data_ena);
348
bufif1 b22 (sd_data[22], sd_data_out[22], sd_data_ena);
349
bufif1 b23 (sd_data[23], sd_data_out[23], sd_data_ena);
350
bufif1 b24 (sd_data[24], sd_data_out[24], sd_data_ena);
351
bufif1 b25 (sd_data[25], sd_data_out[25], sd_data_ena);
352
bufif1 b26 (sd_data[26], sd_data_out[26], sd_data_ena);
353
bufif1 b27 (sd_data[27], sd_data_out[27], sd_data_ena);
354
bufif1 b28 (sd_data[28], sd_data_out[28], sd_data_ena);
355
bufif1 b29 (sd_data[29], sd_data_out[29], sd_data_ena);
356
bufif1 b30 (sd_data[30], sd_data_out[30], sd_data_ena);
357
bufif1 b31 (sd_data[31], sd_data_out[31], sd_data_ena);
358
assign sd_data_in = sd_data;
359 2 jlee
 
360
 
361
 
362
 
363
//
364 4 jlee
// INSTANTIATE THE SDRAM STATE MACHINE
365
//
366
sdramcnt MYSDRAMCNT(
367
             // system level stuff
368
                .sys_rst_l(sys_rst_l),
369
                .sys_clk(sys_clk),
370
 
371
             // SDRAM connections
372
                .sd_wr_l(sd_wr_l),
373
                .sd_cs_l(sd_cs_l),
374
                .sd_ras_l(sd_ras_l),
375
                .sd_cas_l(sd_cas_l),
376
                .sd_dqm(sd_dqm),
377
 
378
             // Host Controller connections
379
                .do_mode_set(do_modeset),
380
                .do_read(do_read),
381
                .do_write(do_write),
382
                .doing_refresh(doing_refresh),
383
                .sd_addx_mux(sd_addx_mux),
384
                .sd_addx10_mux(sd_addx10_mux),
385
                .sd_rd_ena(sd_rd_ena),
386
                .sd_data_ena(sd_data_ena),
387
                .modereg_cas_latency(modereg_cas_latency),
388
                .modereg_burst_length(modereg_burst_length),
389
                .mp_data_mux(mp_data_mux),
390
                .decoded_dqm(decoded_dqm),
391
                .do_write_ack(do_write_ack),
392
                .do_read_ack(do_read_ack),
393
                .do_modeset_ack(do_modeset_ack),
394
                .pwrup(pwrup),
395 2 jlee
 
396 4 jlee
            // debug
397
                .next_state(next_state),
398
                .autorefresh_cntr(autorefresh_cntr),
399
                .autorefresh_cntr_l(autorefresh_cntr_l)
400
    );
401 2 jlee
 
402
 
403
 
404 4 jlee
//
405
//  INSTANTIATE THE HOST INTERFACE LOGIC
406
// 
407
hostcont MYHOSTCONT(
408 2 jlee
            // system connections
409 4 jlee
                .sys_rst_l(sys_rst_l),
410
                .sys_clk(sys_clk),
411 2 jlee
 
412
            // microprocessor side connections
413 4 jlee
                .mp_addx(mp_addx),
414 2 jlee
`ifdef simulate_mp
415 4 jlee
                .mp_data_in(mp_simulator_data),
416 2 jlee
`else
417 4 jlee
                .mp_data_in(mp_data_in),
418 2 jlee
`endif
419 4 jlee
                .mp_data_out(mp_data_out_sd),
420
                .mp_rd_l(mp_rd_l),
421
                .mp_wr_l(mp_wr_l),
422
                .mp_cs_l(mp_cs_l),
423
                .sdram_mode_set_l(sdram_mode_set_l),
424
                .sdram_busy_l(sdram_busy_l),
425
                .mp_size(mp_size),
426 2 jlee
 
427
            // SDRAM side connections
428 4 jlee
                .sd_addx(sd_addx),
429
                .sd_data_in(sd_data),
430
                .sd_data_out(sd_data_out),
431
                .sd_ba(sd_ba),
432 2 jlee
 
433
            // SDRAMCNT side
434 4 jlee
                .sd_addx10_mux(sd_addx10_mux),
435
                .sd_addx_mux(sd_addx_mux),
436
                .sd_rd_ena(sd_rd_ena),
437
                .do_read(do_read),
438
                .do_write(do_write),
439
                .doing_refresh(doing_refresh),
440
                .do_modeset(do_modeset),
441
                .modereg_cas_latency(modereg_cas_latency),
442
                .modereg_burst_length(modereg_burst_length),
443
                .mp_data_mux(mp_data_mux),
444
                .decoded_dqm(decoded_dqm),
445
                .do_write_ack(do_write_ack),
446
                .do_read_ack(do_read_ack),
447
                .do_modeset_ack(do_modeset_ack),
448
                .pwrup(pwrup),
449 2 jlee
 
450
            // debug
451 4 jlee
                .reg_mp_data_mux(reg_mp_data_mux),
452
                .reg_mp_addx(reg_mp_addx),
453
                .reg_sd_data(reg_sd_data)
454 2 jlee
             );
455
 
456
 
457
`ifdef simulate_mp
458 4 jlee
micro   SDRAM_TESTER(
459 2 jlee
                // system connections
460 4 jlee
                .sys_clk(sys_clk),
461 2 jlee
                .sys_rst_l(sys_rst_l),
462
 
463 4 jlee
                // Connections to the HOSTCONT.V
464 2 jlee
                .sdram_busy_l(sdram_busy_l),
465
                .mp_addx(mp_addx),
466 4 jlee
                .mp_data_out(mp_simulator_data),
467
                .mp_data_in(mp_data_out_sd),
468 2 jlee
                .mp_wr_l(mp_wr_l),
469
                .mp_rd_l(mp_rd_l),
470
                .mp_cs_l(mp_cs_l),
471 4 jlee
                .mp_size(mp_size),
472 2 jlee
                .next_state(next_state),
473 4 jlee
                .data_is_correct(data_is_correct),
474
                .sdram_mode_set_l(sdram_mode_set_l),
475 2 jlee
 
476 4 jlee
                // debug
477
                .top_state(top_state)
478 2 jlee
);
479
`endif
480
 
481
endmodule
482
 
483 4 jlee
 

powered by: WebSVN 2.1.0

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