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 50

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 50 dinesha
                   Improved the command pipe structure to accept up-to
43
                   4 command of different bank.
44
             0.3 - 7th Feb 2012
45
                   Bug fix for parameter defination for request length has changed from 9 to 12
46 3 dinesha
 
47
 
48
 Copyright (C) 2000 Authors and OPENCORES.ORG
49
 
50
 This source file may be used and distributed without
51
 restriction provided that this copyright statement is not
52
 removed from the file and that any derivative work contains
53
 the original copyright notice and the associated disclaimer.
54
 
55
 This source file is free software; you can redistribute it
56
 and/or modify it under the terms of the GNU Lesser General
57
 Public License as published by the Free Software Foundation;
58
 either version 2.1 of the License, or (at your option) any
59
later version.
60
 
61
 This source is distributed in the hope that it will be
62
 useful, but WITHOUT ANY WARRANTY; without even the implied
63
 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
64
 PURPOSE.  See the GNU Lesser General Public License for more
65
 details.
66
 
67
 You should have received a copy of the GNU Lesser General
68
 Public License along with this source; if not, download it
69
 from http://www.opencores.org/lgpl.shtml
70
 
71
*******************************************************************/
72
 
73
 
74 37 dinesha
`include "sdrc_define.v"
75 3 dinesha
module sdrc_core
76
           (
77 4 dinesha
                clk,
78
                pad_clk,
79 3 dinesha
                reset_n,
80
                sdr_width,
81 13 dinesha
                cfg_colbits,
82 3 dinesha
 
83
                /* Request from app */
84
                app_req,                // Transfer Request
85
                app_req_addr,           // SDRAM Address
86
                app_req_len,            // Burst Length (in 16 bit words)
87
                app_req_wrap,           // Wrap mode request (xfr_len = 4)
88
                app_req_wr_n,           // 0 => Write request, 1 => read req
89
                app_req_ack,            // Request has been accepted
90
                cfg_req_depth,          //how many req. buffer should hold
91
 
92
                app_wr_data,
93
                app_wr_en_n,
94 45 dinesha
                app_last_wr,
95
 
96 3 dinesha
                app_rd_data,
97
                app_rd_valid,
98 31 dinesha
                app_last_rd,
99 3 dinesha
                app_wr_next_req,
100
                sdr_init_done,
101
                app_req_dma_last,
102
 
103
                /* Interface to SDRAMs */
104
                sdr_cs_n,
105
                sdr_cke,
106
                sdr_ras_n,
107
                sdr_cas_n,
108
                sdr_we_n,
109
                sdr_dqm,
110
                sdr_ba,
111
                sdr_addr,
112
                pad_sdr_din,
113
                sdr_dout,
114
                sdr_den_n,
115
 
116
                /* Parameters */
117
                cfg_sdr_en,
118
                cfg_sdr_mode_reg,
119
                cfg_sdr_tras_d,
120
                cfg_sdr_trp_d,
121
                cfg_sdr_trcd_d,
122
                cfg_sdr_cas,
123
                cfg_sdr_trcar_d,
124
                cfg_sdr_twr_d,
125
                cfg_sdr_rfsh,
126
                cfg_sdr_rfmax);
127
 
128
parameter  APP_AW   = 30;  // Application Address Width
129
parameter  APP_DW   = 32;  // Application Data Width 
130
parameter  APP_BW   = 4;   // Application Byte Width
131
parameter  APP_RW   = 9;   // Application Request Width
132
 
133
parameter  SDR_DW   = 16;  // SDR Data Width 
134
parameter  SDR_BW   = 2;   // SDR Byte Width
135
 
136 50 dinesha
parameter  REQ_BW   = 12;   //  Request Width
137 3 dinesha
 
138
//-----------------------------------------------
139
// Global Variable
140
// ----------------------------------------------
141 4 dinesha
input                   clk                 ; // SDRAM Clock 
142
input                   pad_clk             ; // SDRAM Clock from Pad, used for registering Read Data
143 3 dinesha
input                   reset_n             ; // Reset Signal
144 16 dinesha
input [1:0]             sdr_width           ; // 2'b00 - 32 Bit SDR, 2'b01 - 16 Bit SDR, 2'b1x - 8 Bit
145 13 dinesha
input [1:0]             cfg_colbits         ; // 2'b00 - 8 Bit column address, 2'b01 - 9 Bit, 10 - 10 bit, 11 - 11Bits
146 3 dinesha
 
147 13 dinesha
 
148 3 dinesha
//------------------------------------------------
149
// Request from app
150
//------------------------------------------------
151
input                   app_req             ; // Application Request
152
input [APP_AW-1:0]       app_req_addr        ; // Address 
153
input                   app_req_wr_n        ; // 0 - Write, 1 - Read
154
input                   app_req_wrap        ; // Address Wrap
155
output                  app_req_ack         ; // Application Request Ack
156
 
157
input [APP_DW-1:0]       app_wr_data         ; // Write Data
158
output                  app_wr_next_req     ; // Next Write Data Request
159
input [APP_BW-1:0]       app_wr_en_n         ; // Byte wise Write Enable
160 45 dinesha
output                  app_last_wr         ; // Last Write trannsfer of a given Burst
161 3 dinesha
output [APP_DW-1:0]      app_rd_data         ; // Read Data
162
output                  app_rd_valid        ; // Read Valid
163 31 dinesha
output                  app_last_rd         ; // Last Read Transfer of a given Burst
164 3 dinesha
 
165
//------------------------------------------------
166
// Interface to SDRAMs
167
//------------------------------------------------
168
output                  sdr_cke             ; // SDRAM CKE
169
output                  sdr_cs_n            ; // SDRAM Chip Select
170
output                  sdr_ras_n           ; // SDRAM ras
171
output                  sdr_cas_n           ; // SDRAM cas
172
output                  sdr_we_n            ; // SDRAM write enable
173
output [SDR_BW-1:0]      sdr_dqm             ; // SDRAM Data Mask
174
output [1:0]             sdr_ba              ; // SDRAM Bank Enable
175
output [11:0]            sdr_addr            ; // SDRAM Address
176
input [SDR_DW-1:0]       pad_sdr_din         ; // SDRA Data Input
177
output [SDR_DW-1:0]      sdr_dout            ; // SDRAM Data Output
178
output [SDR_BW-1:0]      sdr_den_n           ; // SDRAM Data Output enable
179
 
180
//------------------------------------------------
181
// Configuration Parameter
182
//------------------------------------------------
183 13 dinesha
output                  sdr_init_done       ; // Indicate SDRAM Initialisation Done
184
input [3:0]              cfg_sdr_tras_d      ; // Active to precharge delay
185
input [3:0]             cfg_sdr_trp_d       ; // Precharge to active delay
186
input [3:0]             cfg_sdr_trcd_d      ; // Active to R/W delay
187
input                   cfg_sdr_en          ; // Enable SDRAM controller
188
input [1:0]              cfg_req_depth       ; // Maximum Request accepted by SDRAM controller
189
input [APP_RW-1:0]       app_req_len         ; // Application Burst Request length in 32 bit 
190 3 dinesha
input [11:0]             cfg_sdr_mode_reg    ;
191 13 dinesha
input [2:0]              cfg_sdr_cas         ; // SDRAM CAS Latency
192
input [3:0]              cfg_sdr_trcar_d     ; // Auto-refresh period
193
input [3:0]             cfg_sdr_twr_d       ; // Write recovery delay
194 3 dinesha
input [`SDR_RFSH_TIMER_W-1 : 0] cfg_sdr_rfsh;
195
input [`SDR_RFSH_ROW_CNT_W -1 : 0] cfg_sdr_rfmax;
196
input                   app_req_dma_last;    // this signal should close the bank
197
 
198
/****************************************************************************/
199
// Internal Nets
200
 
201
// SDR_REQ_GEN
202
wire [`SDR_REQ_ID_W-1:0]r2b_req_id;
203
wire [1:0]               r2b_ba;
204
wire [11:0]              r2b_raddr;
205
wire [11:0]              r2b_caddr;
206 50 dinesha
wire [REQ_BW-1:0]        r2b_len;
207 3 dinesha
 
208
// SDR BANK CTL
209
wire [`SDR_REQ_ID_W-1:0]b2x_id;
210
wire [1:0]               b2x_ba;
211
wire [11:0]              b2x_addr;
212 50 dinesha
wire [REQ_BW-1:0]        b2x_len;
213 3 dinesha
wire [1:0]               b2x_cmd;
214
 
215
// SDR_XFR_CTL
216
wire [3:0]               x2b_pre_ok;
217
wire [`SDR_REQ_ID_W-1:0]xfr_id;
218
wire [APP_DW-1:0]        app_rd_data;
219
wire                    sdr_cs_n, sdr_cke, sdr_ras_n, sdr_cas_n, sdr_we_n;
220
wire [SDR_BW-1:0]        sdr_dqm;
221
wire [1:0]               sdr_ba;
222
wire [11:0]              sdr_addr;
223
wire [SDR_DW-1:0]        sdr_dout;
224
wire [SDR_DW-1:0]        sdr_dout_int;
225
wire [SDR_BW-1:0]        sdr_den_n;
226
wire [SDR_BW-1:0]        sdr_den_n_int;
227
 
228
wire [1:0]               xfr_bank_sel;
229
 
230
wire [APP_AW-1:0]        app_req_addr;
231
wire [APP_RW-1:0]        app_req_len;
232
 
233
wire [APP_DW-1:0]        app_wr_data;
234 45 dinesha
wire [SDR_DW-1:0]        a2x_wrdt       ;
235 3 dinesha
wire [APP_BW-1:0]        app_wr_en_n;
236 45 dinesha
wire [SDR_BW-1:0]        a2x_wren_n;
237 3 dinesha
 
238
//wire [31:0] app_rd_data;
239 45 dinesha
wire [SDR_DW-1:0]        x2a_rddt;
240 3 dinesha
 
241
 
242
// synopsys translate_off 
243
   wire [3:0]           sdr_cmd;
244
   assign sdr_cmd = {sdr_cs_n, sdr_ras_n, sdr_cas_n, sdr_we_n};
245
// synopsys translate_on 
246
 
247 45 dinesha
assign sdr_den_n = sdr_den_n_int ;
248
assign sdr_dout  = sdr_dout_int ;
249 3 dinesha
 
250
 
251 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
252
// assumption, pad_sdram_clk is synhronous and delayed clock of sdram_clk.
253
// register w.r.t pad sdram clk
254
reg [SDR_DW-1:0] pad_sdr_din1;
255
reg [SDR_DW-1:0] pad_sdr_din2;
256
always@(posedge pad_clk) begin
257
   pad_sdr_din1 <= pad_sdr_din;
258
end
259
 
260
always@(posedge clk) begin
261
   pad_sdr_din2 <= pad_sdr_din1;
262
end
263
 
264 45 dinesha
 
265 3 dinesha
   /****************************************************************************/
266
   // Instantiate sdr_req_gen
267
   // This module takes requests from the app, chops them to burst booundaries
268
   // if wrap=0, decodes the bank and passe the request to bank_ctl
269
 
270 9 dinesha
sdrc_req_gen #(.SDR_DW(SDR_DW) , .SDR_BW(SDR_BW)) u_req_gen (
271 4 dinesha
          .clk                (clk          ),
272 3 dinesha
          .reset_n            (reset_n            ),
273 13 dinesha
          .cfg_colbits        (cfg_colbits        ),
274 47 dinesha
          .sdr_width          (sdr_width          ),
275 3 dinesha
 
276 47 dinesha
        /* Req to xfr_ctl */
277
          .r2x_idle           (r2x_idle           ),
278
 
279 3 dinesha
        /* Request from app */
280 45 dinesha
          .req                (app_req            ),
281 3 dinesha
          .req_id             (4'b0               ),
282 45 dinesha
          .req_addr           (app_req_addr       ),
283
          .req_len            (app_req_len        ),
284 3 dinesha
          .req_wrap           (app_req_wrap       ),
285
          .req_wr_n           (app_req_wr_n       ),
286 45 dinesha
          .req_ack            (app_req_ack        ),
287 3 dinesha
 
288
       /* Req to bank_ctl */
289
          .r2b_req            (r2b_req            ),
290
          .r2b_req_id         (r2b_req_id         ),
291
          .r2b_start          (r2b_start          ),
292
          .r2b_last           (r2b_last           ),
293
          .r2b_wrap           (r2b_wrap           ),
294
          .r2b_ba             (r2b_ba             ),
295
          .r2b_raddr          (r2b_raddr          ),
296
          .r2b_caddr          (r2b_caddr          ),
297
          .r2b_len            (r2b_len            ),
298
          .r2b_write          (r2b_write          ),
299
          .b2r_ack            (b2r_ack            ),
300 47 dinesha
          .b2r_arb_ok         (b2r_arb_ok         )
301 3 dinesha
     );
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 45 dinesha
          .sdr_req_norm_dma_last(app_req_dma_last),
351 3 dinesha
          .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 23 dinesha
          .sdr_din            (pad_sdr_din2       ),
402 3 dinesha
          .sdr_dout           (sdr_dout_int       ),
403
          .sdr_den_n          (sdr_den_n_int      ),
404
      /* Data Flow to the app */
405 45 dinesha
          .x2a_rdstart        (x2a_rdstart        ),
406
          .x2a_wrstart        (x2a_wrstart        ),
407 3 dinesha
          .x2a_id             (xfr_id             ),
408 44 dinesha
          .x2a_rdlast         (x2a_rdlast         ),
409 45 dinesha
          .x2a_wrlast         (x2a_wrlast         ),
410
          .a2x_wrdt           (a2x_wrdt           ),
411
          .a2x_wren_n         (a2x_wren_n         ),
412
          .x2a_wrnext         (x2a_wrnext         ),
413
          .x2a_rddt           (x2a_rddt           ),
414
          .x2a_rdok           (x2a_rdok           ),
415 3 dinesha
          .sdr_init_done      (sdr_init_done      ),
416
 
417
      /* SDRAM Parameters */
418
          .sdram_enable       (cfg_sdr_en         ),
419
          .sdram_mode_reg     (cfg_sdr_mode_reg   ),
420
 
421
      /* current xfr bank */
422
          .xfr_bank_sel       (xfr_bank_sel       ),
423
 
424
      /* SDRAM Timing */
425
          .cas_latency        (cfg_sdr_cas        ),
426
          .trp_delay          (cfg_sdr_trp_d      ),
427
          .trcar_delay        (cfg_sdr_trcar_d    ),
428
          .twr_delay          (cfg_sdr_twr_d      ),
429
          .rfsh_time          (cfg_sdr_rfsh       ),
430
          .rfsh_rmax          (cfg_sdr_rfmax      )
431
    );
432
 
433 33 dinesha
   /****************************************************************************/
434
   // Instantiate sdr_bs_convert
435
   //    This model handle the bus with transaltion from application layer to
436
   //       8/16/32 SDRAM Memory format
437
   //     During Write Phase, this block split the data as per SDRAM Width
438
   //     During Read Phase, This block does the re-packing based on SDRAM
439
   //     Width
440
   //---------------------------------------------------------------------------
441 9 dinesha
sdrc_bs_convert #(.SDR_DW(SDR_DW) ,  .SDR_BW(SDR_BW)) u_bs_convert (
442 4 dinesha
          .clk                (clk          ),
443 3 dinesha
          .reset_n            (reset_n            ),
444
          .sdr_width          (sdr_width          ),
445
 
446 44 dinesha
   /* Control Signal from xfr ctrl */
447 45 dinesha
          // Read Interface Inputs
448
          .x2a_rdstart        (x2a_rdstart        ),
449 44 dinesha
          .x2a_rdlast         (x2a_rdlast         ),
450 45 dinesha
          .x2a_rdok           (x2a_rdok           ),
451
          // Read Interface outputs
452
          .x2a_rddt           (x2a_rddt           ),
453 44 dinesha
 
454 45 dinesha
          // Write Interface, Inputs
455
          .x2a_wrstart        (x2a_wrstart        ),
456
          .x2a_wrlast         (x2a_wrlast         ),
457
          .x2a_wrnext         (x2a_wrnext         ),
458 44 dinesha
 
459 45 dinesha
          // Write Interface, Outputs
460
          .a2x_wrdt           (a2x_wrdt           ),
461
          .a2x_wren_n         (a2x_wren_n         ),
462 44 dinesha
 
463 45 dinesha
   /* Control Signal from sdrc_bank_ctl  */
464
 
465 44 dinesha
   /*  Control Signal from/to to application i/f  */
466 3 dinesha
          .app_wr_data        (app_wr_data        ),
467
          .app_wr_en_n        (app_wr_en_n        ),
468
          .app_wr_next        (app_wr_next_req    ),
469 45 dinesha
          .app_last_wr        (app_last_wr        ),
470 3 dinesha
          .app_rd_data        (app_rd_data        ),
471 45 dinesha
          .app_rd_valid       (app_rd_valid       ),
472
          .app_last_rd        (app_last_rd        )
473 44 dinesha
 
474 3 dinesha
       );
475
 
476
endmodule // sdrc_core

powered by: WebSVN 2.1.0

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