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

Subversion Repositories sdr_ctrl

[/] [sdr_ctrl/] [trunk/] [rtl/] [core/] [sdrc_core.v] - Blame information for rev 47

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 dinesha
/*********************************************************************
2
 
3
  SDRAM Controller Core File
4
 
5
  This file is part of the sdram controller project
6
  http://www.opencores.org/cores/sdr_ctrl/
7
 
8
  Description: SDRAM Controller Core Module
9
    2 types of SDRAMs are supported, 1Mx16 2 bank, or 4Mx16 4 bank.
10
    This block integrate following sub modules
11
 
12
    sdrc_bs_convert
13 33 dinesha
        convert the system side 32 bit into equvailent 8/16/32 SDR format
14 3 dinesha
    sdrc_req_gen
15
        This module takes requests from the app, chops them to burst booundaries
16
        if wrap=0, decodes the bank and passe the request to bank_ctl
17
   sdrc_xfr_ctl
18
      This module takes requests from sdr_bank_ctl, runs the transfer and
19
      controls data flow to/from the app. At the end of the transfer it issues a
20
      burst terminate if not at the end of a burst and another command to this
21
      bank is not available.
22
 
23
   sdrc_bank_ctl
24
      This module takes requests from sdr_req_gen, checks for page hit/miss and
25
      issues precharge/activate commands and then passes the request to
26
      sdr_xfr_ctl.
27
 
28
 
29
  Assumption: SDRAM Pads should be placed near to this module. else
30
  user should add a FF near the pads
31
 
32
  To Do:
33
    nothing
34
 
35
  Author(s):
36
      - Dinesh Annayya, dinesha@opencores.org
37 44 dinesha
  Version  : 0.0 - 8th Jan 2012
38 16 dinesha
                Initial version with 16/32 Bit SDRAM Support
39 44 dinesha
           : 0.1 - 24th Jan 2012
40 16 dinesha
                 8 Bit SDRAM Support is added
41 44 dinesha
             0.2 - 2nd Feb 2012
42
                 Improved the command pipe structure to accept up-to 4 command of different bank.
43 3 dinesha
 
44
 
45
 Copyright (C) 2000 Authors and OPENCORES.ORG
46
 
47
 This source file may be used and distributed without
48
 restriction provided that this copyright statement is not
49
 removed from the file and that any derivative work contains
50
 the original copyright notice and the associated disclaimer.
51
 
52
 This source file is free software; you can redistribute it
53
 and/or modify it under the terms of the GNU Lesser General
54
 Public License as published by the Free Software Foundation;
55
 either version 2.1 of the License, or (at your option) any
56
later version.
57
 
58
 This source is distributed in the hope that it will be
59
 useful, but WITHOUT ANY WARRANTY; without even the implied
60
 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
61
 PURPOSE.  See the GNU Lesser General Public License for more
62
 details.
63
 
64
 You should have received a copy of the GNU Lesser General
65
 Public License along with this source; if not, download it
66
 from http://www.opencores.org/lgpl.shtml
67
 
68
*******************************************************************/
69
 
70
 
71 37 dinesha
`include "sdrc_define.v"
72 3 dinesha
module sdrc_core
73
           (
74 4 dinesha
                clk,
75
                pad_clk,
76 3 dinesha
                reset_n,
77
                sdr_width,
78 13 dinesha
                cfg_colbits,
79 3 dinesha
 
80
                /* Request from app */
81
                app_req,                // Transfer Request
82
                app_req_addr,           // SDRAM Address
83
                app_req_len,            // Burst Length (in 16 bit words)
84
                app_req_wrap,           // Wrap mode request (xfr_len = 4)
85
                app_req_wr_n,           // 0 => Write request, 1 => read req
86
                app_req_ack,            // Request has been accepted
87
                cfg_req_depth,          //how many req. buffer should hold
88
 
89
                app_wr_data,
90
                app_wr_en_n,
91 45 dinesha
                app_last_wr,
92
 
93 3 dinesha
                app_rd_data,
94
                app_rd_valid,
95 31 dinesha
                app_last_rd,
96 3 dinesha
                app_wr_next_req,
97
                sdr_init_done,
98
                app_req_dma_last,
99
 
100
                /* Interface to SDRAMs */
101
                sdr_cs_n,
102
                sdr_cke,
103
                sdr_ras_n,
104
                sdr_cas_n,
105
                sdr_we_n,
106
                sdr_dqm,
107
                sdr_ba,
108
                sdr_addr,
109
                pad_sdr_din,
110
                sdr_dout,
111
                sdr_den_n,
112
 
113
                /* Parameters */
114
                cfg_sdr_en,
115
                cfg_sdr_mode_reg,
116
                cfg_sdr_tras_d,
117
                cfg_sdr_trp_d,
118
                cfg_sdr_trcd_d,
119
                cfg_sdr_cas,
120
                cfg_sdr_trcar_d,
121
                cfg_sdr_twr_d,
122
                cfg_sdr_rfsh,
123
                cfg_sdr_rfmax);
124
 
125
parameter  APP_AW   = 30;  // Application Address Width
126
parameter  APP_DW   = 32;  // Application Data Width 
127
parameter  APP_BW   = 4;   // Application Byte Width
128
parameter  APP_RW   = 9;   // Application Request Width
129
 
130
parameter  SDR_DW   = 16;  // SDR Data Width 
131
parameter  SDR_BW   = 2;   // SDR Byte Width
132
 
133
 
134
//-----------------------------------------------
135
// Global Variable
136
// ----------------------------------------------
137 4 dinesha
input                   clk                 ; // SDRAM Clock 
138
input                   pad_clk             ; // SDRAM Clock from Pad, used for registering Read Data
139 3 dinesha
input                   reset_n             ; // Reset Signal
140 16 dinesha
input [1:0]             sdr_width           ; // 2'b00 - 32 Bit SDR, 2'b01 - 16 Bit SDR, 2'b1x - 8 Bit
141 13 dinesha
input [1:0]             cfg_colbits         ; // 2'b00 - 8 Bit column address, 2'b01 - 9 Bit, 10 - 10 bit, 11 - 11Bits
142 3 dinesha
 
143 13 dinesha
 
144 3 dinesha
//------------------------------------------------
145
// Request from app
146
//------------------------------------------------
147
input                   app_req             ; // Application Request
148
input [APP_AW-1:0]       app_req_addr        ; // Address 
149
input                   app_req_wr_n        ; // 0 - Write, 1 - Read
150
input                   app_req_wrap        ; // Address Wrap
151
output                  app_req_ack         ; // Application Request Ack
152
 
153
input [APP_DW-1:0]       app_wr_data         ; // Write Data
154
output                  app_wr_next_req     ; // Next Write Data Request
155
input [APP_BW-1:0]       app_wr_en_n         ; // Byte wise Write Enable
156 45 dinesha
output                  app_last_wr         ; // Last Write trannsfer of a given Burst
157 3 dinesha
output [APP_DW-1:0]      app_rd_data         ; // Read Data
158
output                  app_rd_valid        ; // Read Valid
159 31 dinesha
output                  app_last_rd         ; // Last Read Transfer of a given Burst
160 3 dinesha
 
161
//------------------------------------------------
162
// Interface to SDRAMs
163
//------------------------------------------------
164
output                  sdr_cke             ; // SDRAM CKE
165
output                  sdr_cs_n            ; // SDRAM Chip Select
166
output                  sdr_ras_n           ; // SDRAM ras
167
output                  sdr_cas_n           ; // SDRAM cas
168
output                  sdr_we_n            ; // SDRAM write enable
169
output [SDR_BW-1:0]      sdr_dqm             ; // SDRAM Data Mask
170
output [1:0]             sdr_ba              ; // SDRAM Bank Enable
171
output [11:0]            sdr_addr            ; // SDRAM Address
172
input [SDR_DW-1:0]       pad_sdr_din         ; // SDRA Data Input
173
output [SDR_DW-1:0]      sdr_dout            ; // SDRAM Data Output
174
output [SDR_BW-1:0]      sdr_den_n           ; // SDRAM Data Output enable
175
 
176
//------------------------------------------------
177
// Configuration Parameter
178
//------------------------------------------------
179 13 dinesha
output                  sdr_init_done       ; // Indicate SDRAM Initialisation Done
180
input [3:0]              cfg_sdr_tras_d      ; // Active to precharge delay
181
input [3:0]             cfg_sdr_trp_d       ; // Precharge to active delay
182
input [3:0]             cfg_sdr_trcd_d      ; // Active to R/W delay
183
input                   cfg_sdr_en          ; // Enable SDRAM controller
184
input [1:0]              cfg_req_depth       ; // Maximum Request accepted by SDRAM controller
185
input [APP_RW-1:0]       app_req_len         ; // Application Burst Request length in 32 bit 
186 3 dinesha
input [11:0]             cfg_sdr_mode_reg    ;
187 13 dinesha
input [2:0]              cfg_sdr_cas         ; // SDRAM CAS Latency
188
input [3:0]              cfg_sdr_trcar_d     ; // Auto-refresh period
189
input [3:0]             cfg_sdr_twr_d       ; // Write recovery delay
190 3 dinesha
input [`SDR_RFSH_TIMER_W-1 : 0] cfg_sdr_rfsh;
191
input [`SDR_RFSH_ROW_CNT_W -1 : 0] cfg_sdr_rfmax;
192
input                   app_req_dma_last;    // this signal should close the bank
193
 
194
/****************************************************************************/
195
// Internal Nets
196
 
197
// SDR_REQ_GEN
198
wire [`SDR_REQ_ID_W-1:0]r2b_req_id;
199
wire [1:0]               r2b_ba;
200
wire [11:0]              r2b_raddr;
201
wire [11:0]              r2b_caddr;
202
wire [APP_RW-1:0]        r2b_len;
203
 
204
// SDR BANK CTL
205
wire [`SDR_REQ_ID_W-1:0]b2x_id;
206
wire [1:0]               b2x_ba;
207
wire [11:0]              b2x_addr;
208
wire [APP_RW-1:0]        b2x_len;
209
wire [1:0]               b2x_cmd;
210
 
211
// SDR_XFR_CTL
212
wire [3:0]               x2b_pre_ok;
213
wire [`SDR_REQ_ID_W-1:0]xfr_id;
214
wire [APP_DW-1:0]        app_rd_data;
215
wire                    sdr_cs_n, sdr_cke, sdr_ras_n, sdr_cas_n, sdr_we_n;
216
wire [SDR_BW-1:0]        sdr_dqm;
217
wire [1:0]               sdr_ba;
218
wire [11:0]              sdr_addr;
219
wire [SDR_DW-1:0]        sdr_dout;
220
wire [SDR_DW-1:0]        sdr_dout_int;
221
wire [SDR_BW-1:0]        sdr_den_n;
222
wire [SDR_BW-1:0]        sdr_den_n_int;
223
 
224
wire [1:0]               xfr_bank_sel;
225
 
226
wire [APP_AW-1:0]        app_req_addr;
227
wire [APP_RW-1:0]        app_req_len;
228
 
229
wire [APP_DW-1:0]        app_wr_data;
230 45 dinesha
wire [SDR_DW-1:0]        a2x_wrdt       ;
231 3 dinesha
wire [APP_BW-1:0]        app_wr_en_n;
232 45 dinesha
wire [SDR_BW-1:0]        a2x_wren_n;
233 3 dinesha
 
234
//wire [31:0] app_rd_data;
235 45 dinesha
wire [SDR_DW-1:0]        x2a_rddt;
236 3 dinesha
 
237
 
238
// synopsys translate_off 
239
   wire [3:0]           sdr_cmd;
240
   assign sdr_cmd = {sdr_cs_n, sdr_ras_n, sdr_cas_n, sdr_we_n};
241
// synopsys translate_on 
242
 
243 45 dinesha
assign sdr_den_n = sdr_den_n_int ;
244
assign sdr_dout  = sdr_dout_int ;
245 3 dinesha
 
246
 
247 23 dinesha
// To meet the timing at read path, read data is registered w.r.t pad_sdram_clock and register back to sdram_clk
248
// assumption, pad_sdram_clk is synhronous and delayed clock of sdram_clk.
249
// register w.r.t pad sdram clk
250
reg [SDR_DW-1:0] pad_sdr_din1;
251
reg [SDR_DW-1:0] pad_sdr_din2;
252
always@(posedge pad_clk) begin
253
   pad_sdr_din1 <= pad_sdr_din;
254
end
255
 
256
always@(posedge clk) begin
257
   pad_sdr_din2 <= pad_sdr_din1;
258
end
259
 
260 45 dinesha
 
261 3 dinesha
   /****************************************************************************/
262
   // Instantiate sdr_req_gen
263
   // This module takes requests from the app, chops them to burst booundaries
264
   // if wrap=0, decodes the bank and passe the request to bank_ctl
265
 
266 9 dinesha
sdrc_req_gen #(.SDR_DW(SDR_DW) , .SDR_BW(SDR_BW)) u_req_gen (
267 4 dinesha
          .clk                (clk          ),
268 3 dinesha
          .reset_n            (reset_n            ),
269 13 dinesha
          .cfg_colbits        (cfg_colbits        ),
270 47 dinesha
          .sdr_width          (sdr_width          ),
271 3 dinesha
 
272 47 dinesha
        /* Req to xfr_ctl */
273
          .r2x_idle           (r2x_idle           ),
274
 
275 3 dinesha
        /* Request from app */
276 45 dinesha
          .req                (app_req            ),
277 3 dinesha
          .req_id             (4'b0               ),
278 45 dinesha
          .req_addr           (app_req_addr       ),
279
          .req_len            (app_req_len        ),
280 3 dinesha
          .req_wrap           (app_req_wrap       ),
281
          .req_wr_n           (app_req_wr_n       ),
282 45 dinesha
          .req_ack            (app_req_ack        ),
283 3 dinesha
 
284
       /* Req to bank_ctl */
285
          .r2b_req            (r2b_req            ),
286
          .r2b_req_id         (r2b_req_id         ),
287
          .r2b_start          (r2b_start          ),
288
          .r2b_last           (r2b_last           ),
289
          .r2b_wrap           (r2b_wrap           ),
290
          .r2b_ba             (r2b_ba             ),
291
          .r2b_raddr          (r2b_raddr          ),
292
          .r2b_caddr          (r2b_caddr          ),
293
          .r2b_len            (r2b_len            ),
294
          .r2b_write          (r2b_write          ),
295
          .b2r_ack            (b2r_ack            ),
296 47 dinesha
          .b2r_arb_ok         (b2r_arb_ok         )
297 3 dinesha
     );
298
 
299
   /****************************************************************************/
300
   // Instantiate sdr_bank_ctl
301
   // This module takes requests from sdr_req_gen, checks for page hit/miss and
302
   // issues precharge/activate commands and then passes the request to
303
   // sdr_xfr_ctl. 
304
 
305 9 dinesha
sdrc_bank_ctl #(.SDR_DW(SDR_DW) ,  .SDR_BW(SDR_BW)) u_bank_ctl (
306 4 dinesha
          .clk                (clk          ),
307 3 dinesha
          .reset_n            (reset_n            ),
308
          .a2b_req_depth      (cfg_req_depth      ),
309
 
310
      /* Req from req_gen */
311
          .r2b_req            (r2b_req            ),
312
          .r2b_req_id         (r2b_req_id         ),
313
          .r2b_start          (r2b_start          ),
314
          .r2b_last           (r2b_last           ),
315
          .r2b_wrap           (r2b_wrap           ),
316
          .r2b_ba             (r2b_ba             ),
317
          .r2b_raddr          (r2b_raddr          ),
318
          .r2b_caddr          (r2b_caddr          ),
319
          .r2b_len            (r2b_len            ),
320
          .r2b_write          (r2b_write          ),
321
          .b2r_arb_ok         (b2r_arb_ok         ),
322
          .b2r_ack            (b2r_ack            ),
323
 
324
      /* Transfer request to xfr_ctl */
325
          .b2x_idle           (b2x_idle           ),
326
          .b2x_req            (b2x_req            ),
327
          .b2x_start          (b2x_start          ),
328
          .b2x_last           (b2x_last           ),
329
          .b2x_wrap           (b2x_wrap           ),
330
          .b2x_id             (b2x_id             ),
331
          .b2x_ba             (b2x_ba             ),
332
          .b2x_addr           (b2x_addr           ),
333
          .b2x_len            (b2x_len            ),
334
          .b2x_cmd            (b2x_cmd            ),
335
          .x2b_ack            (x2b_ack            ),
336
 
337
      /* Status from xfr_ctl */
338
          .b2x_tras_ok        (b2x_tras_ok        ),
339
          .x2b_refresh        (x2b_refresh        ),
340
          .x2b_pre_ok         (x2b_pre_ok         ),
341
          .x2b_act_ok         (x2b_act_ok         ),
342
          .x2b_rdok           (x2b_rdok           ),
343
          .x2b_wrok           (x2b_wrok           ),
344
 
345
      /* for generate cuurent xfr address msb */
346 45 dinesha
          .sdr_req_norm_dma_last(app_req_dma_last),
347 3 dinesha
          .xfr_bank_sel       (xfr_bank_sel       ),
348
 
349
       /* SDRAM Timing */
350
          .tras_delay         (cfg_sdr_tras_d     ),
351
          .trp_delay          (cfg_sdr_trp_d      ),
352
          .trcd_delay         (cfg_sdr_trcd_d     )
353
      );
354
 
355
   /****************************************************************************/
356
   // Instantiate sdr_xfr_ctl
357
   // This module takes requests from sdr_bank_ctl, runs the transfer and
358
   // controls data flow to/from the app. At the end of the transfer it issues a
359
   // burst terminate if not at the end of a burst and another command to this
360
   // bank is not available.
361
 
362 9 dinesha
sdrc_xfr_ctl #(.SDR_DW(SDR_DW) ,  .SDR_BW(SDR_BW)) u_xfr_ctl (
363 4 dinesha
          .clk                (clk          ),
364 3 dinesha
          .reset_n            (reset_n            ),
365
 
366
      /* Transfer request from bank_ctl */
367
          .r2x_idle           (r2x_idle           ),
368
          .b2x_idle           (b2x_idle           ),
369
          .b2x_req            (b2x_req            ),
370
          .b2x_start          (b2x_start          ),
371
          .b2x_last           (b2x_last           ),
372
          .b2x_wrap           (b2x_wrap           ),
373
          .b2x_id             (b2x_id             ),
374
          .b2x_ba             (b2x_ba             ),
375
          .b2x_addr           (b2x_addr           ),
376
          .b2x_len            (b2x_len            ),
377
          .b2x_cmd            (b2x_cmd            ),
378
          .x2b_ack            (x2b_ack            ),
379
 
380
       /* Status to bank_ctl, req_gen */
381
          .b2x_tras_ok        (b2x_tras_ok        ),
382
          .x2b_refresh        (x2b_refresh        ),
383
          .x2b_pre_ok         (x2b_pre_ok         ),
384
          .x2b_act_ok         (x2b_act_ok         ),
385
          .x2b_rdok           (x2b_rdok           ),
386
          .x2b_wrok           (x2b_wrok           ),
387
 
388
       /* SDRAM I/O */
389
          .sdr_cs_n           (sdr_cs_n           ),
390
          .sdr_cke            (sdr_cke            ),
391
          .sdr_ras_n          (sdr_ras_n          ),
392
          .sdr_cas_n          (sdr_cas_n          ),
393
          .sdr_we_n           (sdr_we_n           ),
394
          .sdr_dqm            (sdr_dqm            ),
395
          .sdr_ba             (sdr_ba             ),
396
          .sdr_addr           (sdr_addr           ),
397 23 dinesha
          .sdr_din            (pad_sdr_din2       ),
398 3 dinesha
          .sdr_dout           (sdr_dout_int       ),
399
          .sdr_den_n          (sdr_den_n_int      ),
400
      /* Data Flow to the app */
401 45 dinesha
          .x2a_rdstart        (x2a_rdstart        ),
402
          .x2a_wrstart        (x2a_wrstart        ),
403 3 dinesha
          .x2a_id             (xfr_id             ),
404 44 dinesha
          .x2a_rdlast         (x2a_rdlast         ),
405 45 dinesha
          .x2a_wrlast         (x2a_wrlast         ),
406
          .a2x_wrdt           (a2x_wrdt           ),
407
          .a2x_wren_n         (a2x_wren_n         ),
408
          .x2a_wrnext         (x2a_wrnext         ),
409
          .x2a_rddt           (x2a_rddt           ),
410
          .x2a_rdok           (x2a_rdok           ),
411 3 dinesha
          .sdr_init_done      (sdr_init_done      ),
412
 
413
      /* SDRAM Parameters */
414
          .sdram_enable       (cfg_sdr_en         ),
415
          .sdram_mode_reg     (cfg_sdr_mode_reg   ),
416
 
417
      /* current xfr bank */
418
          .xfr_bank_sel       (xfr_bank_sel       ),
419
 
420
      /* SDRAM Timing */
421
          .cas_latency        (cfg_sdr_cas        ),
422
          .trp_delay          (cfg_sdr_trp_d      ),
423
          .trcar_delay        (cfg_sdr_trcar_d    ),
424
          .twr_delay          (cfg_sdr_twr_d      ),
425
          .rfsh_time          (cfg_sdr_rfsh       ),
426
          .rfsh_rmax          (cfg_sdr_rfmax      )
427
    );
428
 
429 33 dinesha
   /****************************************************************************/
430
   // Instantiate sdr_bs_convert
431
   //    This model handle the bus with transaltion from application layer to
432
   //       8/16/32 SDRAM Memory format
433
   //     During Write Phase, this block split the data as per SDRAM Width
434
   //     During Read Phase, This block does the re-packing based on SDRAM
435
   //     Width
436
   //---------------------------------------------------------------------------
437 9 dinesha
sdrc_bs_convert #(.SDR_DW(SDR_DW) ,  .SDR_BW(SDR_BW)) u_bs_convert (
438 4 dinesha
          .clk                (clk          ),
439 3 dinesha
          .reset_n            (reset_n            ),
440
          .sdr_width          (sdr_width          ),
441
 
442 44 dinesha
   /* Control Signal from xfr ctrl */
443 45 dinesha
          // Read Interface Inputs
444
          .x2a_rdstart        (x2a_rdstart        ),
445 44 dinesha
          .x2a_rdlast         (x2a_rdlast         ),
446 45 dinesha
          .x2a_rdok           (x2a_rdok           ),
447
          // Read Interface outputs
448
          .x2a_rddt           (x2a_rddt           ),
449 44 dinesha
 
450 45 dinesha
          // Write Interface, Inputs
451
          .x2a_wrstart        (x2a_wrstart        ),
452
          .x2a_wrlast         (x2a_wrlast         ),
453
          .x2a_wrnext         (x2a_wrnext         ),
454 44 dinesha
 
455 45 dinesha
          // Write Interface, Outputs
456
          .a2x_wrdt           (a2x_wrdt           ),
457
          .a2x_wren_n         (a2x_wren_n         ),
458 44 dinesha
 
459 45 dinesha
   /* Control Signal from sdrc_bank_ctl  */
460
 
461 44 dinesha
   /*  Control Signal from/to to application i/f  */
462 3 dinesha
          .app_wr_data        (app_wr_data        ),
463
          .app_wr_en_n        (app_wr_en_n        ),
464
          .app_wr_next        (app_wr_next_req    ),
465 45 dinesha
          .app_last_wr        (app_last_wr        ),
466 3 dinesha
          .app_rd_data        (app_rd_data        ),
467 45 dinesha
          .app_rd_valid       (app_rd_valid       ),
468
          .app_last_rd        (app_last_rd        )
469 44 dinesha
 
470 3 dinesha
       );
471
 
472
endmodule // sdrc_core

powered by: WebSVN 2.1.0

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