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 16

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

powered by: WebSVN 2.1.0

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