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 13

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

powered by: WebSVN 2.1.0

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