OpenCores
URL https://opencores.org/ocsvn/yifive/yifive/trunk

Subversion Repositories yifive

[/] [yifive/] [trunk/] [caravel_yifive/] [verilog/] [rtl/] [sdram_ctrl/] [src/] [core/] [sdrc_core.v] - Blame information for rev 21

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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