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

Subversion Repositories sdram

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jlee
`include "tst_inc.h"
2
`include "inc.h"
3 4 jlee
 
4
 
5
//*******************************************************************************
6 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
7 4 jlee
//
8
//  This core adheres to the GNU Public License  
9
// 
10
//  This is a synthesizable Synchronous DRAM controller Core.  As it stands,
11
//  it is ready to work with 8Mbyte SDRAMs, organized as 2M x 32 at 100MHz
12
//  and 125MHz. For example: Samsung KM432S2030CT,  Fujitsu MB81F643242B.
13
//
14
//  The core has been carefully coded so as to be "platform-independent".  
15
//  It has been successfully compiled and simulated under three separate
16
//  FPGA/CPLD platforms:
17
//      Xilinx Foundation Base Express V2.1i
18
//      Altera Max+PlusII V9.21
19
//      Lattice ispExpert V7.0
20
//  
21
//  The interface to the host (i.e. microprocessor, DSP, etc) is synchronous
22
//  and supports ony one transfer at a time.  That is, burst-mode transfers
23
//  are not yet supported.  In may ways, the interface to this core is much
24
//  like that of a typical SRAM.  The hand-shaking between the host and the 
25
//  SDRAM core is done through the "sdram_busy_l" signal generated by the 
26
//  core.  Whenever this signal is active low, the host must hold the address,
27
//  data (if doing a write), size and the controls (cs, rd/wr).  
28
//
29
//  Connection Diagram:
30
//  SDRAM side:
31
//  sd_wr_l                     connect to -WR pin of SDRAM
32
//  sd_cs_l                     connect to -CS pin of SDRAM
33
//  sd_ras_l                    connect to -RAS pin of SDRAM
34
//  sd_cas_l                    connect to -CAS pin of SDRAM
35
//  sd_dqm[3:0]                 connect to the DQM3,DQM2,DQM1,DQM0 pins
36
//  sd_addx[10:0]               connect to the Address bus [10:0]
37
//  sd_data[31:0]               connect to the data bus [31:0]
38
//  sd_ba[1:0]                  connect to BA1, BA0 pins of SDRAM
39
//   
40
//  HOST side:
41
//  mp_addx[22:0]               connect to the address bus of the host. 
42
//                              23 bit address bus give access to 8Mbyte
43
//                              of the SDRAM, as byte, half-word (16bit)
44
//                              or word (32bit)
45
//  mp_data_in[31:0]            Unidirectional bus connected to the data out
46
//                              of the host. To use this, enable 
47
//                              "databus_is_unidirectional" in INC.H
48
//  mp_data_out[31:0]           Unidirectional bus connected to the data in 
49
//                              of the host.  To use this, enable
50
//                              "databus_is_unidirectional" in INC.H
51
//  mp_data[31:0]               Bi-directional bus connected to the host's
52
//                              data bus.  To use the bi-directionla bus,
53
//                              disable "databus_is_unidirectional" in INC.H
54
//  mp_rd_l                     Connect to the -RD output of the host
55
//  mp_wr_l                     Connect to the -WR output of the host
56
//  mp_cs_l                     Connect to the -CS of the host
57
//  mp_size[1:0]                Connect to the size output of the host
58
//                              if there is one.  When set to 0
59
//                              all trasnfers are 32 bits, when set to 1
60
//                              all transfers are 8 bits, and when set to
61
//                              2 all xfers are 16 bits.  If you want the
62
//                              data to be lower order aligned, turn on
63
//                              "align_data_bus" option in INC.H
64
//  sdram_busy_l                Connect this to the wait or hold equivalent
65
//                              input of the host.  The host, must hold the
66
//                              bus if it samples this signal as low.
67
//  sdram_mode_set_l            When a write occurs with this set low,
68
//                              the SDRAM's mode set register will be programmed
69
//                              with the data supplied on the data_bus[10:0].
70
//
71
//
72
//  Author:  Jeung Joon Lee  joon.lee@quantum.com,  cmosexod@ix.netcom.com
73
//  
74
//*******************************************************************************
75
//
76
//  Hierarchy:
77
//
78
//  SDRAM.V         Top Level Module
79
//  HOSTCONT.V      Controls the interfacing between the micro and the SDRAM
80
//  SDRAMCNT.V      This is the SDRAM controller.  All data passed to and from
81
//                  is with the HOSTCONT.
82
//  optional
83
//  MICRO.V         This is the built in SDRAM tester.  This module generates 
84
//                  a number of test logics which is used to test the SDRAM
85
//                  It is basically a Micro bus generator. 
86
//  
87
/*
88
*/
89 2 jlee
module micro(
90
                // system connections
91 4 jlee
                sys_clk,
92 2 jlee
                sys_rst_l,
93
 
94
                // Connections to the HOSTCONT.V
95
                sdram_busy_l,
96
                mp_addx,
97 4 jlee
                mp_data_out,
98
                mp_data_in,
99 2 jlee
                mp_wr_l,
100
                mp_rd_l,
101
                mp_cs_l,
102 4 jlee
                mp_size,
103 2 jlee
                next_state,
104 4 jlee
                data_is_correct,
105
                sdram_mode_set_l,
106 2 jlee
 
107 4 jlee
                // debug
108
                top_state
109 2 jlee
);
110
 
111
 
112 4 jlee
// ****************************************
113
//
114
//   I/O  DEFINITION
115
//
116
// ****************************************
117 2 jlee
// system connections
118 4 jlee
input           sys_clk;            // main system clock
119 2 jlee
input           sys_rst_l;          // main system reset
120
 
121
// connections to the SDRAM CONTROLLER
122
input           sdram_busy_l;
123 4 jlee
output  [22:0]  mp_addx;
124 2 jlee
output          mp_wr_l;
125
output          mp_rd_l;
126
output          mp_cs_l;
127 4 jlee
output  [1:0]   mp_size;
128
input   [3:0]   next_state;
129
output  [31:0]  mp_data_out;        // data bus to the SDRAM controller
130
input   [31:0]  mp_data_in;         // data bus from the SDRAM controller
131
output          data_is_correct;
132
output          sdram_mode_set_l;
133 2 jlee
 
134
// debug
135 4 jlee
output  [3:0]   top_state;
136 2 jlee
 
137
// Intermodule connections
138 4 jlee
wire    [7:0]   bus_state;
139
wire            data_ena;
140
wire    [31:0]  mp_data_out;
141
wire    [31:0]  mp_data_in;
142
wire    [1:0]   mp_size;
143 2 jlee
 
144
// Memory element definitions
145 4 jlee
reg     [3:0]   top_state;
146
reg             mp_cs_l;
147
reg             mp_wr_l;
148
reg             mp_rd_l;
149
reg     [31:0]  reg_mp_data_out;
150
reg     [22:0]  reg_mp_addx;
151
reg     [22:0]  reg_byte_counter;
152
reg             data_is_correct;
153
reg             sdram_mode_set_l;
154 2 jlee
 
155
 
156
/*
157
** SINGLE WRITE FOLLOWED BY GAP THEN FOLLOWED BY SINGLE READ TEST
158
**
159
*/
160
`ifdef do_read_write_test
161
`endif
162
 
163
 
164
/*
165
** BURST WRITE FOLLOWED BY GAP THEN FOLLOWED BY BURST READ TEST
166
**
167
*/
168
`ifdef do_burst_write_read_test
169
 
170
`endif
171
 
172
 
173
/*
174
** A ONE-TIME BURST WRITE FOLLOWED BY GAP THEN FOLLOWED BY MANY BURST READ TEST
175
**
176
*/
177
`ifdef do_single_burst_write_read_test
178
 
179 4 jlee
// the number of  write/read in the test
180
`define     RW_COUNT           23'h000015
181
// number of clock ticks between the reads.
182
`define     GAP_DELAY          23'h000030
183
// define the amount of address delta
184
`define     MP_ADDX_DELTA       23'h000001
185
// define the amount of data delta
186
`define     MP_DATA_DELTA       32'h01010101
187 2 jlee
 
188
 
189 4 jlee
// Micro Simulator State Machine State Definitions
190
`define         powerup_delay            4'h0
191
`define         burst_write_cs           4'h1
192
`define         burst_write_assert_wr    4'h2
193
`define         burst_write_wait_4_busy  4'h3
194
`define         burst_write_deassert_wr  4'h4
195
`define         burst_wr_rd_delay        4'h5
196
`define         burst_read_cs            4'h6
197
`define         burst_read_assert_rd     4'h7
198
`define         burst_read_wait_4_busy   4'h8
199
`define         burst_read_deassert_rd   4'h9
200
`define         request_modereg          4'ha
201 2 jlee
 
202 4 jlee
`define         SIZE_IS_BYTE        2'b01
203
`define         SIZE_IS_HALF_WORD   2'b10
204
`define         SIZE_IS_WORD        2'b00
205 2 jlee
 
206 4 jlee
 
207
assign  mp_size      = `SIZE_IS_BYTE;
208
assign  mp_addx      = reg_mp_addx;
209
assign  mp_data_out  = reg_mp_data_out;
210
 
211
always @(posedge sys_clk or negedge sys_rst_l)
212 2 jlee
  if (~sys_rst_l) begin
213 4 jlee
     top_state          <= `powerup_delay;      // initialze state
214
     mp_cs_l <= `HI;
215
     mp_wr_l <= `HI;
216
     mp_rd_l <= `HI;
217
     reg_mp_addx        <= 23'h000000;          // reset address counter
218
     reg_mp_data_out    <= 32'h00000000;        // reset data counter
219
     reg_byte_counter   <= 23'h000000;          // clear byte counter
220
     data_is_correct    <= `HI;                 // correct by default
221
     sdram_mode_set_l   <= `HI;                 // do not issue mode reg change by default
222 2 jlee
  end
223
  else case (top_state)
224 4 jlee
 
225
     // Wait until the SDRAM has completed its power-up sequences
226 2 jlee
     `powerup_delay:  begin
227 4 jlee
          sdram_mode_set_l <= `HI;
228
          if (next_state==`state_idle)
229
            top_state <= `burst_write_cs;// go and do burst write
230
          else
231
            top_state <= `powerup_delay;
232 2 jlee
      end
233
 
234 4 jlee
     // Assert MP CS to begin the write
235
     `burst_write_cs:  begin
236
         mp_cs_l  <= `LO;
237
         top_state   <= `burst_write_assert_wr;
238 2 jlee
     end
239
 
240 4 jlee
    // Assert MP WR 
241
    `burst_write_assert_wr: begin
242
         mp_wr_l <= `LO;
243
         top_state <= `burst_write_wait_4_busy;
244
    end
245
 
246
    // Wait until the SDRAM controller is no longer busy
247
    `burst_write_wait_4_busy:
248
         if (~sdram_busy_l)
249
            top_state <= `burst_write_wait_4_busy;
250
         else
251
            top_state <= `burst_write_deassert_wr;
252 2 jlee
 
253 4 jlee
    // Deassert the WR, and check to see if it has completed all writes     
254
    `burst_write_deassert_wr:  begin
255
        mp_wr_l   <= `HI;       // deassert WR
256
        if (reg_byte_counter == `RW_COUNT) begin
257
            reg_mp_addx <= 0;
258
            reg_mp_data_out <= 0;
259
            reg_byte_counter <= 0;              // reset the counter
260
            mp_cs_l <= `HI;
261
            top_state <= `burst_wr_rd_delay;
262
        end else begin
263
            reg_mp_addx      <= reg_mp_addx      + `MP_ADDX_DELTA;
264
            reg_mp_data_out  <= reg_mp_data_out  + `MP_DATA_DELTA;
265
            reg_byte_counter <= reg_byte_counter + 1;       // one IO done
266
            top_state <= `burst_write_assert_wr;
267
        end
268
    end
269
 
270
    // Wait here and kill GAP_DELAY number of cycles
271
    `burst_wr_rd_delay:
272
        if (reg_byte_counter != `GAP_DELAY) begin
273
            reg_byte_counter <= reg_byte_counter + 1;
274
            top_state <= `burst_wr_rd_delay;
275
        end else begin
276
            reg_byte_counter <= 23'h000000;
277
            top_state <= `burst_read_cs;
278
        end
279 2 jlee
 
280 4 jlee
     // Assert MP CS to prepare for reads
281
     `burst_read_cs: begin
282
        mp_cs_l <= `LO;     // assert CS
283
        top_state <= `burst_read_assert_rd;
284 2 jlee
      end
285 4 jlee
 
286
      // Assert MP RD
287
     `burst_read_assert_rd: begin
288
        mp_rd_l <= `LO;
289
        top_state <= `burst_read_wait_4_busy;
290
     end
291 2 jlee
 
292 4 jlee
     // Wait until the SDRAM Controller is no longer busy
293
     `burst_read_wait_4_busy:
294
        if (~sdram_busy_l)
295
            top_state <= `burst_read_wait_4_busy;
296
        else
297
            top_state <= `burst_read_deassert_rd;
298
 
299
 
300
     // Deassert MP RD and Prepare for the next resd, 
301
     `burst_read_deassert_rd: begin
302
        if (mp_data_in != reg_mp_data_out)  begin
303
            data_is_correct <= `LO;
304
        end
305
        mp_rd_l   <= `HI;       // deassert RD
306
        if (reg_byte_counter == `RW_COUNT) begin
307
            reg_mp_addx <= 0;
308
            reg_mp_data_out <= 0;
309
            reg_byte_counter <= 0;              // reset the counter
310
            mp_cs_l <= `HI;
311
            top_state <= `burst_wr_rd_delay;
312
        end else begin
313
            reg_mp_addx      <= reg_mp_addx      + `MP_ADDX_DELTA;  // increment addx
314
            reg_mp_data_out  <= reg_mp_data_out  + `MP_DATA_DELTA;  // increment data expected
315
            reg_byte_counter <= reg_byte_counter + 1;       // one IO done
316
            top_state <= `burst_read_assert_rd;
317
        end
318
     end
319
 
320 2 jlee
  endcase
321
 
322
 
323
`endif
324
 
325
 
326
endmodule
327
 

powered by: WebSVN 2.1.0

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