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 23

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 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
265
// assumption, pad_sdram_clk is synhronous and delayed clock of sdram_clk.
266
// register w.r.t pad sdram clk
267
reg [SDR_DW-1:0] pad_sdr_din1;
268
reg [SDR_DW-1:0] pad_sdr_din2;
269
always@(posedge pad_clk) begin
270
   pad_sdr_din1 <= pad_sdr_din;
271
end
272
 
273
always@(posedge clk) begin
274
   pad_sdr_din2 <= pad_sdr_din1;
275
end
276
 
277 3 dinesha
   /****************************************************************************/
278
   // Instantiate sdr_req_gen
279
   // This module takes requests from the app, chops them to burst booundaries
280
   // if wrap=0, decodes the bank and passe the request to bank_ctl
281
 
282 9 dinesha
sdrc_req_gen #(.SDR_DW(SDR_DW) , .SDR_BW(SDR_BW)) u_req_gen (
283 4 dinesha
          .clk                (clk          ),
284 3 dinesha
          .reset_n            (reset_n            ),
285 13 dinesha
          .cfg_colbits        (cfg_colbits        ),
286 3 dinesha
 
287
        /* Request from app */
288
          .r2x_idle           (r2x_idle           ),
289
          .req                (app_req_int        ),
290
          .req_id             (4'b0               ),
291
          .req_addr           (app_req_addr_int   ),
292
          .req_addr_mask      (app_req_addr_mask  ),
293
          .req_len            (app_req_len_int    ),
294
          .req_wrap           (app_req_wrap       ),
295
          .req_wr_n           (app_req_wr_n       ),
296
          .req_ack            (app_req_ack_int      ),
297
          .sdr_core_busy_n    (sdr_core_busy_n    ),
298
 
299
       /* Req to bank_ctl */
300
          .r2b_req            (r2b_req            ),
301
          .r2b_req_id         (r2b_req_id         ),
302
          .r2b_start          (r2b_start          ),
303
          .r2b_last           (r2b_last           ),
304
          .r2b_wrap           (r2b_wrap           ),
305
          .r2b_ba             (r2b_ba             ),
306
          .r2b_raddr          (r2b_raddr          ),
307
          .r2b_caddr          (r2b_caddr          ),
308
          .r2b_len            (r2b_len            ),
309
          .r2b_write          (r2b_write          ),
310
          .b2r_ack            (b2r_ack            ),
311
          .b2r_arb_ok         (b2r_arb_ok         ),
312
          .sdr_width          (sdr_width          ),
313
          .sdr_init_done      (sdr_init_done      )
314
     );
315
 
316
   /****************************************************************************/
317
   // Instantiate sdr_bank_ctl
318
   // This module takes requests from sdr_req_gen, checks for page hit/miss and
319
   // issues precharge/activate commands and then passes the request to
320
   // sdr_xfr_ctl. 
321
 
322 9 dinesha
sdrc_bank_ctl #(.SDR_DW(SDR_DW) ,  .SDR_BW(SDR_BW)) u_bank_ctl (
323 4 dinesha
          .clk                (clk          ),
324 3 dinesha
          .reset_n            (reset_n            ),
325
          .a2b_req_depth      (cfg_req_depth      ),
326
 
327
      /* Req from req_gen */
328
          .r2b_req            (r2b_req            ),
329
          .r2b_req_id         (r2b_req_id         ),
330
          .r2b_start          (r2b_start          ),
331
          .r2b_last           (r2b_last           ),
332
          .r2b_wrap           (r2b_wrap           ),
333
          .r2b_ba             (r2b_ba             ),
334
          .r2b_raddr          (r2b_raddr          ),
335
          .r2b_caddr          (r2b_caddr          ),
336
          .r2b_len            (r2b_len            ),
337
          .r2b_write          (r2b_write          ),
338
          .b2r_arb_ok         (b2r_arb_ok         ),
339
          .b2r_ack            (b2r_ack            ),
340
 
341
      /* Transfer request to xfr_ctl */
342
          .b2x_idle           (b2x_idle           ),
343
          .b2x_req            (b2x_req            ),
344
          .b2x_start          (b2x_start          ),
345
          .b2x_last           (b2x_last           ),
346
          .b2x_wrap           (b2x_wrap           ),
347
          .b2x_id             (b2x_id             ),
348
          .b2x_ba             (b2x_ba             ),
349
          .b2x_addr           (b2x_addr           ),
350
          .b2x_len            (b2x_len            ),
351
          .b2x_cmd            (b2x_cmd            ),
352
          .x2b_ack            (x2b_ack            ),
353
 
354
      /* Status from xfr_ctl */
355
          .b2x_tras_ok        (b2x_tras_ok        ),
356
          .x2b_refresh        (x2b_refresh        ),
357
          .x2b_pre_ok         (x2b_pre_ok         ),
358
          .x2b_act_ok         (x2b_act_ok         ),
359
          .x2b_rdok           (x2b_rdok           ),
360
          .x2b_wrok           (x2b_wrok           ),
361
 
362
      /* for generate cuurent xfr address msb */
363
          .sdr_req_norm_dma_last(app_req_dma_last_int),
364
          .xfr_bank_sel       (xfr_bank_sel       ),
365
 
366
       /* SDRAM Timing */
367
          .tras_delay         (cfg_sdr_tras_d     ),
368
          .trp_delay          (cfg_sdr_trp_d      ),
369
          .trcd_delay         (cfg_sdr_trcd_d     )
370
      );
371
 
372
   /****************************************************************************/
373
   // Instantiate sdr_xfr_ctl
374
   // This module takes requests from sdr_bank_ctl, runs the transfer and
375
   // controls data flow to/from the app. At the end of the transfer it issues a
376
   // burst terminate if not at the end of a burst and another command to this
377
   // bank is not available.
378
 
379 9 dinesha
sdrc_xfr_ctl #(.SDR_DW(SDR_DW) ,  .SDR_BW(SDR_BW)) u_xfr_ctl (
380 4 dinesha
          .clk                (clk          ),
381 3 dinesha
          .reset_n            (reset_n            ),
382
 
383
      /* Transfer request from bank_ctl */
384
          .r2x_idle           (r2x_idle           ),
385
          .b2x_idle           (b2x_idle           ),
386
          .b2x_req            (b2x_req            ),
387
          .b2x_start          (b2x_start          ),
388
          .b2x_last           (b2x_last           ),
389
          .b2x_wrap           (b2x_wrap           ),
390
          .b2x_id             (b2x_id             ),
391
          .b2x_ba             (b2x_ba             ),
392
          .b2x_addr           (b2x_addr           ),
393
          .b2x_len            (b2x_len            ),
394
          .b2x_cmd            (b2x_cmd            ),
395
          .x2b_ack            (x2b_ack            ),
396
 
397
       /* Status to bank_ctl, req_gen */
398
          .b2x_tras_ok        (b2x_tras_ok        ),
399
          .x2b_refresh        (x2b_refresh        ),
400
          .x2b_pre_ok         (x2b_pre_ok         ),
401
          .x2b_act_ok         (x2b_act_ok         ),
402
          .x2b_rdok           (x2b_rdok           ),
403
          .x2b_wrok           (x2b_wrok           ),
404
 
405
       /* SDRAM I/O */
406
          .sdr_cs_n           (sdr_cs_n           ),
407
          .sdr_cke            (sdr_cke            ),
408
          .sdr_ras_n          (sdr_ras_n          ),
409
          .sdr_cas_n          (sdr_cas_n          ),
410
          .sdr_we_n           (sdr_we_n           ),
411
          .sdr_dqm            (sdr_dqm            ),
412
          .sdr_ba             (sdr_ba             ),
413
          .sdr_addr           (sdr_addr           ),
414 23 dinesha
          .sdr_din            (pad_sdr_din2       ),
415 3 dinesha
          .sdr_dout           (sdr_dout_int       ),
416
          .sdr_den_n          (sdr_den_n_int      ),
417
 
418
      /* Data Flow to the app */
419
          .x2a_rdstart        (xfr_rdstart        ),
420
          .x2a_wrstart        (xfr_wrstart        ),
421
          .x2a_id             (xfr_id             ),
422
          .x2a_rdlast         (xfr_rdlast         ),
423
          .x2a_wrlast         (xfr_wrlast         ),
424
          .app_wrdt           (add_wr_data_int    ),
425 4 dinesha
          .app_wren_n         (app_wr_en_n_int    ),
426 3 dinesha
          .x2a_wrnext         (app_wr_next_int    ),
427
          .x2a_rddt           (app_rd_data_int    ),
428
          .x2a_rdok           (app_rd_valid_int   ),
429
          .sdr_init_done      (sdr_init_done      ),
430
 
431
      /* SDRAM Parameters */
432
          .sdram_enable       (cfg_sdr_en         ),
433
          .sdram_mode_reg     (cfg_sdr_mode_reg   ),
434
 
435
      /* current xfr bank */
436
          .xfr_bank_sel       (xfr_bank_sel       ),
437
 
438
      /* SDRAM Timing */
439
          .cas_latency        (cfg_sdr_cas        ),
440
          .trp_delay          (cfg_sdr_trp_d      ),
441
          .trcar_delay        (cfg_sdr_trcar_d    ),
442
          .twr_delay          (cfg_sdr_twr_d      ),
443
          .rfsh_time          (cfg_sdr_rfsh       ),
444
          .rfsh_rmax          (cfg_sdr_rfmax      )
445
    );
446
 
447 9 dinesha
sdrc_bs_convert #(.SDR_DW(SDR_DW) ,  .SDR_BW(SDR_BW)) u_bs_convert (
448 4 dinesha
          .clk                (clk          ),
449 3 dinesha
          .reset_n            (reset_n            ),
450
          .sdr_width          (sdr_width          ),
451
 
452
          .app_req_addr       (app_req_addr       ),
453
          .app_req_addr_int   (app_req_addr_int   ),
454
          .app_req_len        (app_req_len        ),
455
          .app_req_len_int    (app_req_len_int    ),
456
          .app_sdr_req        (app_req            ),
457
          .app_sdr_req_int    (app_req_int        ),
458
          .app_req_dma_last   (app_req_dma_last   ),
459
          .app_req_dma_last_int(app_req_dma_last_int),
460
          .app_req_wr_n       (app_req_wr_n       ),
461 4 dinesha
          .app_req_ack_int    (app_req_ack_int    ),
462 3 dinesha
          .app_req_ack        (app_req_ack        ),
463
 
464
          .app_wr_data        (app_wr_data        ),
465
          .app_wr_data_int    (add_wr_data_int    ),
466
          .app_wr_en_n        (app_wr_en_n        ),
467
          .app_wr_en_n_int    (app_wr_en_n_int    ),
468
          .app_wr_next_int    (app_wr_next_int    ),
469
          .app_wr_next        (app_wr_next_req    ),
470
 
471
          .app_rd_data_int    (app_rd_data_int    ),
472
          .app_rd_data        (app_rd_data        ),
473
          .app_rd_valid_int   (app_rd_valid_int   ),
474
          .app_rd_valid       (app_rd_valid       )
475
       );
476
 
477
endmodule // sdrc_core

powered by: WebSVN 2.1.0

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