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 15

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_mode_reg,
111
                cfg_sdr_tras_d,
112
                cfg_sdr_trp_d,
113
                cfg_sdr_trcd_d,
114
                cfg_sdr_cas,
115
                cfg_sdr_trcar_d,
116
                cfg_sdr_twr_d,
117
                cfg_sdr_rfsh,
118
                cfg_sdr_rfmax);
119
 
120
parameter  APP_AW   = 30;  // Application Address Width
121
parameter  APP_DW   = 32;  // Application Data Width 
122
parameter  APP_BW   = 4;   // Application Byte Width
123
parameter  APP_RW   = 9;   // Application Request Width
124
 
125
parameter  SDR_DW   = 16;  // SDR Data Width 
126
parameter  SDR_BW   = 2;   // SDR Byte Width
127
 
128
 
129
//-----------------------------------------------
130
// Global Variable
131
// ----------------------------------------------
132 4 dinesha
input                   clk                 ; // SDRAM Clock 
133
input                   pad_clk             ; // SDRAM Clock from Pad, used for registering Read Data
134 3 dinesha
input                   reset_n             ; // Reset Signal
135
input                   sdr_width           ; // 0 - 32 Bit SDR, 1 - 16 Bit SDR
136 13 dinesha
input [1:0]             cfg_colbits         ; // 2'b00 - 8 Bit column address, 2'b01 - 9 Bit, 10 - 10 bit, 11 - 11Bits
137 3 dinesha
 
138 13 dinesha
 
139 3 dinesha
//------------------------------------------------
140
// Request from app
141
//------------------------------------------------
142
input                   app_req             ; // Application Request
143
input [APP_AW-1:0]       app_req_addr        ; // Address 
144
input [APP_AW-2:0]      app_req_addr_mask   ; // Address Mask
145
input                   app_req_wr_n        ; // 0 - Write, 1 - Read
146
input                   app_req_wrap        ; // Address Wrap
147
output                  app_req_ack         ; // Application Request Ack
148
output                  sdr_core_busy_n     ; // 0 - busy, 1 - free
149
 
150
input [APP_DW-1:0]       app_wr_data         ; // Write Data
151
output                  app_wr_next_req     ; // Next Write Data Request
152
input [APP_BW-1:0]       app_wr_en_n         ; // Byte wise Write Enable
153
output [APP_DW-1:0]      app_rd_data         ; // Read Data
154
output                  app_rd_valid        ; // Read Valid
155
 
156
//------------------------------------------------
157
// Interface to SDRAMs
158
//------------------------------------------------
159
output                  sdr_cke             ; // SDRAM CKE
160
output                  sdr_cs_n            ; // SDRAM Chip Select
161
output                  sdr_ras_n           ; // SDRAM ras
162
output                  sdr_cas_n           ; // SDRAM cas
163
output                  sdr_we_n            ; // SDRAM write enable
164
output [SDR_BW-1:0]      sdr_dqm             ; // SDRAM Data Mask
165
output [1:0]             sdr_ba              ; // SDRAM Bank Enable
166
output [11:0]            sdr_addr            ; // SDRAM Address
167
input [SDR_DW-1:0]       pad_sdr_din         ; // SDRA Data Input
168
output [SDR_DW-1:0]      sdr_dout            ; // SDRAM Data Output
169
output [SDR_BW-1:0]      sdr_den_n           ; // SDRAM Data Output enable
170
 
171
//------------------------------------------------
172
// Configuration Parameter
173
//------------------------------------------------
174 13 dinesha
output                  sdr_init_done       ; // Indicate SDRAM Initialisation Done
175
input [3:0]              cfg_sdr_tras_d      ; // Active to precharge delay
176
input [3:0]             cfg_sdr_trp_d       ; // Precharge to active delay
177
input [3:0]             cfg_sdr_trcd_d      ; // Active to R/W delay
178
input                   cfg_sdr_en          ; // Enable SDRAM controller
179
input [1:0]              cfg_req_depth       ; // Maximum Request accepted by SDRAM controller
180
input [APP_RW-1:0]       app_req_len         ; // Application Burst Request length in 32 bit 
181 3 dinesha
input [11:0]             cfg_sdr_mode_reg    ;
182 13 dinesha
input [2:0]              cfg_sdr_cas         ; // SDRAM CAS Latency
183
input [3:0]              cfg_sdr_trcar_d     ; // Auto-refresh period
184
input [3:0]             cfg_sdr_twr_d       ; // Write recovery delay
185 3 dinesha
input [`SDR_RFSH_TIMER_W-1 : 0] cfg_sdr_rfsh;
186
input [`SDR_RFSH_ROW_CNT_W -1 : 0] cfg_sdr_rfmax;
187
input                   app_req_dma_last;    // this signal should close the bank
188
 
189
/****************************************************************************/
190
// Internal Nets
191
 
192
// SDR_REQ_GEN
193
wire                    r2x_idle, app_req_ack,app_req_ack_int;
194
wire                    app_req_dma_last_int;
195
wire                    r2b_req, r2b_start, r2b_last, r2b_write;
196
wire [`SDR_REQ_ID_W-1:0]r2b_req_id;
197
wire [1:0]               r2b_ba;
198
wire [11:0]              r2b_raddr;
199
wire [11:0]              r2b_caddr;
200
wire [APP_RW-1:0]        r2b_len;
201
 
202
// SDR BANK CTL
203
wire                    b2r_ack, b2x_idle;
204
wire                    b2x_req, b2x_start, b2x_last, b2x_tras_ok;
205
wire [`SDR_REQ_ID_W-1:0]b2x_id;
206
wire [1:0]               b2x_ba;
207
wire                    b2x_ba_last;
208
wire [11:0]              b2x_addr;
209
wire [APP_RW-1:0]        b2x_len;
210
wire [1:0]               b2x_cmd;
211
 
212
// SDR_XFR_CTL
213
wire                    x2b_ack;
214
wire [3:0]               x2b_pre_ok;
215
wire                    x2b_refresh, x2b_act_ok, x2b_rdok, x2b_wrok;
216
wire                    xfr_rdstart, xfr_rdlast;
217
wire                    xfr_wrstart, xfr_wrlast;
218
wire [`SDR_REQ_ID_W-1:0]xfr_id;
219
wire [APP_DW-1:0]        app_rd_data;
220
wire                    app_wr_next_req, app_rd_valid;
221
wire                    sdr_cs_n, sdr_cke, sdr_ras_n, sdr_cas_n, sdr_we_n;
222
wire [SDR_BW-1:0]        sdr_dqm;
223
wire [1:0]               sdr_ba;
224
wire [11:0]              sdr_addr;
225
wire [SDR_DW-1:0]        sdr_dout;
226
wire [SDR_DW-1:0]        sdr_dout_int;
227
wire [SDR_BW-1:0]        sdr_den_n;
228
wire [SDR_BW-1:0]        sdr_den_n_int;
229
 
230
wire [1:0]               xfr_bank_sel;
231
 
232
wire [APP_AW:0]          app_req_addr_int;
233
wire [APP_AW-1:0]        app_req_addr;
234
wire [APP_RW-1:0]        app_req_len_int;
235
wire [APP_RW-1:0]        app_req_len;
236
 
237
wire [APP_DW-1:0]        app_wr_data;
238
wire [SDR_DW-1:0]        add_wr_data_int;
239
wire [APP_BW-1:0]        app_wr_en_n;
240
wire [SDR_BW-1:0]        app_wr_en_n_int;
241
 
242
//wire [31:0] app_rd_data;
243
wire [SDR_DW-1:0]        app_rd_data_int;
244
 
245
//
246
wire                     app_req_int;
247
wire                     r2b_wrap;
248
wire                     b2r_arb_ok;
249
wire                     b2x_wrap;
250
wire                     app_wr_next_int;
251
wire                     app_rd_valid_int;
252
 
253
// synopsys translate_off 
254
   wire [3:0]           sdr_cmd;
255
   assign sdr_cmd = {sdr_cs_n, sdr_ras_n, sdr_cas_n, sdr_we_n};
256
// synopsys translate_on 
257
 
258
   assign sdr_den_n = sdr_width ? {2'b00,sdr_den_n_int[1:0]} : sdr_den_n_int;
259
   assign sdr_dout = sdr_width ? {16'h0000,sdr_dout_int[15:0]} : sdr_dout_int;
260
 
261
 
262
   /****************************************************************************/
263
   // Instantiate sdr_req_gen
264
   // This module takes requests from the app, chops them to burst booundaries
265
   // if wrap=0, decodes the bank and passe the request to bank_ctl
266
 
267 9 dinesha
sdrc_req_gen #(.SDR_DW(SDR_DW) , .SDR_BW(SDR_BW)) u_req_gen (
268 4 dinesha
          .clk                (clk          ),
269 3 dinesha
          .reset_n            (reset_n            ),
270 13 dinesha
          .cfg_colbits        (cfg_colbits        ),
271 3 dinesha
 
272
        /* Request from app */
273
          .r2x_idle           (r2x_idle           ),
274
          .req                (app_req_int        ),
275
          .req_id             (4'b0               ),
276
          .req_addr           (app_req_addr_int   ),
277
          .req_addr_mask      (app_req_addr_mask  ),
278
          .req_len            (app_req_len_int    ),
279
          .req_wrap           (app_req_wrap       ),
280
          .req_wr_n           (app_req_wr_n       ),
281
          .req_ack            (app_req_ack_int      ),
282
          .sdr_core_busy_n    (sdr_core_busy_n    ),
283
 
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
          .b2r_arb_ok         (b2r_arb_ok         ),
297
          .sdr_width          (sdr_width          ),
298
          .sdr_init_done      (sdr_init_done      )
299
     );
300
 
301
   /****************************************************************************/
302
   // Instantiate sdr_bank_ctl
303
   // This module takes requests from sdr_req_gen, checks for page hit/miss and
304
   // issues precharge/activate commands and then passes the request to
305
   // sdr_xfr_ctl. 
306
 
307 9 dinesha
sdrc_bank_ctl #(.SDR_DW(SDR_DW) ,  .SDR_BW(SDR_BW)) u_bank_ctl (
308 4 dinesha
          .clk                (clk          ),
309 3 dinesha
          .reset_n            (reset_n            ),
310
          .a2b_req_depth      (cfg_req_depth      ),
311
 
312
      /* Req from req_gen */
313
          .r2b_req            (r2b_req            ),
314
          .r2b_req_id         (r2b_req_id         ),
315
          .r2b_start          (r2b_start          ),
316
          .r2b_last           (r2b_last           ),
317
          .r2b_wrap           (r2b_wrap           ),
318
          .r2b_ba             (r2b_ba             ),
319
          .r2b_raddr          (r2b_raddr          ),
320
          .r2b_caddr          (r2b_caddr          ),
321
          .r2b_len            (r2b_len            ),
322
          .r2b_write          (r2b_write          ),
323
          .b2r_arb_ok         (b2r_arb_ok         ),
324
          .b2r_ack            (b2r_ack            ),
325
 
326
      /* Transfer request to xfr_ctl */
327
          .b2x_idle           (b2x_idle           ),
328
          .b2x_req            (b2x_req            ),
329
          .b2x_start          (b2x_start          ),
330
          .b2x_last           (b2x_last           ),
331
          .b2x_wrap           (b2x_wrap           ),
332
          .b2x_id             (b2x_id             ),
333
          .b2x_ba             (b2x_ba             ),
334
          .b2x_addr           (b2x_addr           ),
335
          .b2x_len            (b2x_len            ),
336
          .b2x_cmd            (b2x_cmd            ),
337
          .x2b_ack            (x2b_ack            ),
338
 
339
      /* Status from xfr_ctl */
340
          .b2x_tras_ok        (b2x_tras_ok        ),
341
          .x2b_refresh        (x2b_refresh        ),
342
          .x2b_pre_ok         (x2b_pre_ok         ),
343
          .x2b_act_ok         (x2b_act_ok         ),
344
          .x2b_rdok           (x2b_rdok           ),
345
          .x2b_wrok           (x2b_wrok           ),
346
 
347
      /* for generate cuurent xfr address msb */
348
          .sdr_req_norm_dma_last(app_req_dma_last_int),
349
          .xfr_bank_sel       (xfr_bank_sel       ),
350
 
351
       /* SDRAM Timing */
352
          .tras_delay         (cfg_sdr_tras_d     ),
353
          .trp_delay          (cfg_sdr_trp_d      ),
354
          .trcd_delay         (cfg_sdr_trcd_d     )
355
      );
356
 
357
   /****************************************************************************/
358
   // Instantiate sdr_xfr_ctl
359
   // This module takes requests from sdr_bank_ctl, runs the transfer and
360
   // controls data flow to/from the app. At the end of the transfer it issues a
361
   // burst terminate if not at the end of a burst and another command to this
362
   // bank is not available.
363
 
364 9 dinesha
sdrc_xfr_ctl #(.SDR_DW(SDR_DW) ,  .SDR_BW(SDR_BW)) u_xfr_ctl (
365 4 dinesha
          .clk                (clk          ),
366 3 dinesha
          .reset_n            (reset_n            ),
367
 
368
      /* Transfer request from bank_ctl */
369
          .r2x_idle           (r2x_idle           ),
370
          .b2x_idle           (b2x_idle           ),
371
          .b2x_req            (b2x_req            ),
372
          .b2x_start          (b2x_start          ),
373
          .b2x_last           (b2x_last           ),
374
          .b2x_wrap           (b2x_wrap           ),
375
          .b2x_id             (b2x_id             ),
376
          .b2x_ba             (b2x_ba             ),
377
          .b2x_addr           (b2x_addr           ),
378
          .b2x_len            (b2x_len            ),
379
          .b2x_cmd            (b2x_cmd            ),
380
          .x2b_ack            (x2b_ack            ),
381
 
382
       /* Status to bank_ctl, req_gen */
383
          .b2x_tras_ok        (b2x_tras_ok        ),
384
          .x2b_refresh        (x2b_refresh        ),
385
          .x2b_pre_ok         (x2b_pre_ok         ),
386
          .x2b_act_ok         (x2b_act_ok         ),
387
          .x2b_rdok           (x2b_rdok           ),
388
          .x2b_wrok           (x2b_wrok           ),
389
 
390
       /* SDRAM I/O */
391
          .sdr_cs_n           (sdr_cs_n           ),
392
          .sdr_cke            (sdr_cke            ),
393
          .sdr_ras_n          (sdr_ras_n          ),
394
          .sdr_cas_n          (sdr_cas_n          ),
395
          .sdr_we_n           (sdr_we_n           ),
396
          .sdr_dqm            (sdr_dqm            ),
397
          .sdr_ba             (sdr_ba             ),
398
          .sdr_addr           (sdr_addr           ),
399
          .sdr_din            (pad_sdr_din        ),
400
          .sdr_dout           (sdr_dout_int       ),
401
          .sdr_den_n          (sdr_den_n_int      ),
402
 
403
      /* Data Flow to the app */
404
          .x2a_rdstart        (xfr_rdstart        ),
405
          .x2a_wrstart        (xfr_wrstart        ),
406
          .x2a_id             (xfr_id             ),
407
          .x2a_rdlast         (xfr_rdlast         ),
408
          .x2a_wrlast         (xfr_wrlast         ),
409
          .app_wrdt           (add_wr_data_int    ),
410 4 dinesha
          .app_wren_n         (app_wr_en_n_int    ),
411 3 dinesha
          .x2a_wrnext         (app_wr_next_int    ),
412
          .x2a_rddt           (app_rd_data_int    ),
413
          .x2a_rdok           (app_rd_valid_int   ),
414
          .sdr_init_done      (sdr_init_done      ),
415
 
416
      /* SDRAM Parameters */
417
          .sdram_enable       (cfg_sdr_en         ),
418
          .sdram_mode_reg     (cfg_sdr_mode_reg   ),
419
 
420
      /* current xfr bank */
421
          .xfr_bank_sel       (xfr_bank_sel       ),
422
 
423
      /* SDRAM Timing */
424
          .cas_latency        (cfg_sdr_cas        ),
425
          .trp_delay          (cfg_sdr_trp_d      ),
426
          .trcar_delay        (cfg_sdr_trcar_d    ),
427
          .twr_delay          (cfg_sdr_twr_d      ),
428
          .rfsh_time          (cfg_sdr_rfsh       ),
429
          .rfsh_rmax          (cfg_sdr_rfmax      )
430
    );
431
 
432 9 dinesha
sdrc_bs_convert #(.SDR_DW(SDR_DW) ,  .SDR_BW(SDR_BW)) u_bs_convert (
433 4 dinesha
          .clk                (clk          ),
434 3 dinesha
          .reset_n            (reset_n            ),
435
          .sdr_width          (sdr_width          ),
436
 
437
          .app_req_addr       (app_req_addr       ),
438
          .app_req_addr_int   (app_req_addr_int   ),
439
          .app_req_len        (app_req_len        ),
440
          .app_req_len_int    (app_req_len_int    ),
441
          .app_sdr_req        (app_req            ),
442
          .app_sdr_req_int    (app_req_int        ),
443
          .app_req_dma_last   (app_req_dma_last   ),
444
          .app_req_dma_last_int(app_req_dma_last_int),
445
          .app_req_wr_n       (app_req_wr_n       ),
446 4 dinesha
          .app_req_ack_int    (app_req_ack_int    ),
447 3 dinesha
          .app_req_ack        (app_req_ack        ),
448
 
449
          .app_wr_data        (app_wr_data        ),
450
          .app_wr_data_int    (add_wr_data_int    ),
451
          .app_wr_en_n        (app_wr_en_n        ),
452
          .app_wr_en_n_int    (app_wr_en_n_int    ),
453
          .app_wr_next_int    (app_wr_next_int    ),
454
          .app_wr_next        (app_wr_next_req    ),
455
 
456
          .app_rd_data_int    (app_rd_data_int    ),
457
          .app_rd_data        (app_rd_data        ),
458
          .app_rd_valid_int   (app_rd_valid_int   ),
459
          .app_rd_valid       (app_rd_valid       )
460
       );
461
 
462
endmodule // sdrc_core

powered by: WebSVN 2.1.0

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