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

Subversion Repositories yifive

[/] [yifive/] [trunk/] [caravel_yifive/] [verilog/] [rtl/] [sdram_ctrl/] [src/] [top/] [sdrc_top.v] - Blame information for rev 19

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 dinesha
/*********************************************************************
2
 
3
  SDRAM Controller top 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 Top Module.
9
    Support 81/6/32 Bit SDRAM.
10
    Column Address is Programmable
11
    Bank Bit are 2 Bit
12
    Row Bits are 12 Bits
13
 
14
    This block integrate following sub modules
15
 
16
    sdrc_core
17
        SDRAM Controller file
18
    wb2sdrc
19
        This module transalate the bus protocl from wishbone to custome
20
        sdram controller
21
 
22
  To Do:
23
    nothing
24
 
25
  Author(s): Dinesh Annayya, dinesha@opencores.org
26
  Version  : 0.0 - 8th Jan 2012
27
                Initial version with 16/32 Bit SDRAM Support
28
           : 0.1 - 24th Jan 2012
29
                 8 Bit SDRAM Support is added
30
             0.2 - 31st Jan 2012
31
                 sdram_dq and sdram_pad_clk are internally generated
32
             0.3 - 26th April 2013
33
                  Sdram Address witdh is increased from 12 to 13bits
34
 
35
 
36
 Copyright (C) 2000 Authors and OPENCORES.ORG
37
 
38
 This source file may be used and distributed without
39
 restriction provided that this copyright statement is not
40
 removed from the file and that any derivative work contains
41
 the original copyright notice and the associated disclaimer.
42
 
43
 This source file is free software; you can redistribute it
44
 and/or modify it under the terms of the GNU Lesser General
45
 Public License as published by the Free Software Foundation;
46
 either version 2.1 of the License, or (at your option) any
47
later version.
48
 
49
 This source is distributed in the hope that it will be
50
 useful, but WITHOUT ANY WARRANTY; without even the implied
51
 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
52
 PURPOSE.  See the GNU Lesser General Public License for more
53
 details.
54
 
55
 You should have received a copy of the GNU Lesser General
56
 Public License along with this source; if not, download it
57
 from http://www.opencores.org/lgpl.shtml
58
 
59
*******************************************************************/
60
 
61
 
62
`include "sdrc_define.v"
63
module sdrc_top
64
           (
65
                    cfg_sdr_width       ,
66
                    cfg_colbits         ,
67
 
68
                // WB bus
69
                    wb_rst_i            ,
70
                    wb_clk_i            ,
71
 
72
                    wb_stb_i            ,
73
                    wb_ack_o            ,
74
                    wb_addr_i           ,
75
                    wb_we_i             ,
76
                    wb_dat_i            ,
77
                    wb_sel_i            ,
78
                    wb_dat_o            ,
79
                    wb_cyc_i            ,
80
                    wb_cti_i            ,
81
 
82
 
83
                /* Interface to SDRAMs */
84
                    sdram_clk           ,
85
                    sdram_resetn        ,
86
                    sdr_cs_n            ,
87
                    sdr_cke             ,
88
                    sdr_ras_n           ,
89
                    sdr_cas_n           ,
90
                    sdr_we_n            ,
91
                    sdr_dqm             ,
92
                    sdr_ba              ,
93
                    sdr_addr            ,
94
                    sdr_dq              ,
95
 
96
                /* Parameters */
97
                    sdr_init_done       ,
98
                    cfg_req_depth       ,               //how many req. buffer should hold
99
                    cfg_sdr_en          ,
100
                    cfg_sdr_mode_reg    ,
101
                    cfg_sdr_tras_d      ,
102
                    cfg_sdr_trp_d       ,
103
                    cfg_sdr_trcd_d      ,
104
                    cfg_sdr_cas         ,
105
                    cfg_sdr_trcar_d     ,
106
                    cfg_sdr_twr_d       ,
107
                    cfg_sdr_rfsh        ,
108
                    cfg_sdr_rfmax
109
            );
110
 
111
parameter      APP_AW   = 26;  // Application Address Width
112
parameter      APP_DW   = 32;  // Application Data Width 
113
parameter      APP_BW   = 4;   // Application Byte Width
114
parameter      APP_RW   = 9;   // Application Request Width
115
 
116
parameter      SDR_DW   = 16;  // SDR Data Width 
117
parameter      SDR_BW   = 2;   // SDR Byte Width
118
 
119
parameter      dw       = 32;  // data width
120
parameter      tw       = 8;   // tag id width
121
parameter      bl       = 9;   // burst_lenght_width 
122
 
123
//-----------------------------------------------
124
// Global Variable
125
// ----------------------------------------------
126
input                   sdram_clk          ; // SDRAM Clock 
127
input                   sdram_resetn       ; // Reset Signal
128
input [1:0]             cfg_sdr_width      ; // 2'b00 - 32 Bit SDR, 2'b01 - 16 Bit SDR, 2'b1x - 8 Bit
129
input [1:0]             cfg_colbits        ; // 2'b00 - 8 Bit column address, 
130
                                             // 2'b01 - 9 Bit, 10 - 10 bit, 11 - 11Bits
131
 
132
//--------------------------------------
133
// Wish Bone Interface
134
// -------------------------------------      
135
input                   wb_rst_i           ;
136
input                   wb_clk_i           ;
137
 
138
input                   wb_stb_i           ;
139
output                  wb_ack_o           ;
140
input [APP_AW-1:0]            wb_addr_i          ;
141
input                   wb_we_i            ; // 1 - Write, 0 - Read
142
input [dw-1:0]          wb_dat_i           ;
143
input [dw/8-1:0]        wb_sel_i           ; // Byte enable
144
output [dw-1:0]         wb_dat_o           ;
145
input                   wb_cyc_i           ;
146
input  [2:0]            wb_cti_i           ;
147
 
148
//------------------------------------------------
149
// Interface to SDRAMs
150
//------------------------------------------------
151
output                  sdr_cke             ; // SDRAM CKE
152
output                  sdr_cs_n            ; // SDRAM Chip Select
153
output                  sdr_ras_n           ; // SDRAM ras
154
output                  sdr_cas_n           ; // SDRAM cas
155
output                  sdr_we_n            ; // SDRAM write enable
156
output [SDR_BW-1:0]      sdr_dqm             ; // SDRAM Data Mask
157
output [1:0]             sdr_ba              ; // SDRAM Bank Enable
158
output [12:0]            sdr_addr            ; // SDRAM Address
159
inout [SDR_DW-1:0]       sdr_dq              ; // SDRA Data Input/output
160
 
161
//------------------------------------------------
162
// Configuration Parameter
163
//------------------------------------------------
164
output                  sdr_init_done       ; // Indicate SDRAM Initialisation Done
165
input [3:0]              cfg_sdr_tras_d      ; // Active to precharge delay
166
input [3:0]             cfg_sdr_trp_d       ; // Precharge to active delay
167
input [3:0]             cfg_sdr_trcd_d      ; // Active to R/W delay
168
input                   cfg_sdr_en          ; // Enable SDRAM controller
169
input [1:0]              cfg_req_depth       ; // Maximum Request accepted by SDRAM controller
170
input [12:0]             cfg_sdr_mode_reg    ;
171
input [2:0]              cfg_sdr_cas         ; // SDRAM CAS Latency
172
input [3:0]              cfg_sdr_trcar_d     ; // Auto-refresh period
173
input [3:0]             cfg_sdr_twr_d       ; // Write recovery delay
174
input [`SDR_RFSH_TIMER_W-1 : 0] cfg_sdr_rfsh;
175
input [`SDR_RFSH_ROW_CNT_W -1 : 0] cfg_sdr_rfmax;
176
 
177
//--------------------------------------------
178
// SDRAM controller Interface 
179
//--------------------------------------------
180
wire                  app_req            ; // SDRAM request
181
wire [APP_AW-1:0]     app_req_addr       ; // SDRAM Request Address
182
wire [bl-1:0]         app_req_len        ;
183
wire                  app_req_wr_n       ; // 0 - Write, 1 -> Read
184
wire                  app_req_ack        ; // SDRAM request Accepted
185
wire                  app_busy_n         ; // 0 -> sdr busy
186
wire [dw/8-1:0]       app_wr_en_n        ; // Active low sdr byte-wise write data valid
187
wire                  app_wr_next_req    ; // Ready to accept the next write
188
wire                  app_rd_valid       ; // sdr read valid
189
wire                  app_last_rd        ; // Indicate last Read of Burst Transfer
190
wire                  app_last_wr        ; // Indicate last Write of Burst Transfer
191
wire [dw-1:0]         app_wr_data        ; // sdr write data
192
wire  [dw-1:0]        app_rd_data        ; // sdr read data
193
 
194
/****************************************
195
*  These logic has to be implemented using Pads
196
*  **************************************/
197
wire  [SDR_DW-1:0]    pad_sdr_din         ; // SDRA Data Input
198
wire  [SDR_DW-1:0]    sdr_dout            ; // SDRAM Data Output
199
wire  [SDR_BW-1:0]    sdr_den_n           ; // SDRAM Data Output enable
200
 
201
 
202
assign   sdr_dq = (&sdr_den_n == 1'b0) ? sdr_dout :  {SDR_DW{1'bz}};
203
assign   pad_sdr_din = sdr_dq;
204
 
205
// sdram pad clock is routed back through pad
206
// SDRAM Clock from Pad, used for registering Read Data
207
wire #(1.0) sdram_pad_clk = sdram_clk;
208
 
209
/************** Ends Here **************************/
210
wb2sdrc #(.dw(dw),.tw(tw),.bl(bl)) u_wb2sdrc (
211
      // WB bus
212
          .wb_rst_i           (wb_rst_i           ) ,
213
          .wb_clk_i           (wb_clk_i           ) ,
214
 
215
          .wb_stb_i           (wb_stb_i           ) ,
216
          .wb_ack_o           (wb_ack_o           ) ,
217
          .wb_addr_i          (wb_addr_i          ) ,
218
          .wb_we_i            (wb_we_i            ) ,
219
          .wb_dat_i           (wb_dat_i           ) ,
220
          .wb_sel_i           (wb_sel_i           ) ,
221
          .wb_dat_o           (wb_dat_o           ) ,
222
          .wb_cyc_i           (wb_cyc_i           ) ,
223
          .wb_cti_i           (wb_cti_i           ) ,
224
 
225
 
226
      //SDRAM Controller Hand-Shake Signal 
227
          .sdram_clk          (sdram_clk          ) ,
228
          .sdram_resetn       (sdram_resetn       ) ,
229
          .sdr_req            (app_req            ) ,
230
          .sdr_req_addr       (app_req_addr       ) ,
231
          .sdr_req_len        (app_req_len        ) ,
232
          .sdr_req_wr_n       (app_req_wr_n       ) ,
233
          .sdr_req_ack        (app_req_ack        ) ,
234
          .sdr_busy_n         (app_busy_n         ) ,
235
          .sdr_wr_en_n        (app_wr_en_n        ) ,
236
          .sdr_wr_next        (app_wr_next_req    ) ,
237
          .sdr_rd_valid       (app_rd_valid       ) ,
238
          .sdr_last_rd        (app_last_rd        ) ,
239
          .sdr_wr_data        (app_wr_data        ) ,
240
          .sdr_rd_data        (app_rd_data        )
241
 
242
      );
243
 
244
 
245
sdrc_core #(.SDR_DW(SDR_DW) , .SDR_BW(SDR_BW)) u_sdrc_core (
246
          .clk                (sdram_clk          ) ,
247
          .pad_clk            (sdram_pad_clk      ) ,
248
          .reset_n            (sdram_resetn       ) ,
249
          .sdr_width          (cfg_sdr_width      ) ,
250
          .cfg_colbits        (cfg_colbits        ) ,
251
 
252
                /* Request from app */
253
          .app_req            (app_req            ) ,// Transfer Request
254
          .app_req_addr       (app_req_addr       ) ,// SDRAM Address
255
          .app_req_len        (app_req_len        ) ,// Burst Length (in 16 bit words)
256
          .app_req_wrap       (1'b0               ) ,// Wrap mode request 
257
          .app_req_wr_n       (app_req_wr_n       ) ,// 0 => Write request, 1 => read req
258
          .app_req_ack        (app_req_ack        ) ,// Request has been accepted
259
          .cfg_req_depth      (cfg_req_depth      ) ,//how many req. buffer should hold
260
 
261
          .app_wr_data        (app_wr_data        ) ,
262
          .app_wr_en_n        (app_wr_en_n        ) ,
263
          .app_rd_data        (app_rd_data        ) ,
264
          .app_rd_valid       (app_rd_valid       ) ,
265
          .app_last_rd        (app_last_rd        ) ,
266
          .app_last_wr        (app_last_wr        ) ,
267
          .app_wr_next_req    (app_wr_next_req    ) ,
268
          .sdr_init_done      (sdr_init_done      ) ,
269
          .app_req_dma_last   (app_req            ) ,
270
 
271
                /* Interface to SDRAMs */
272
          .sdr_cs_n           (sdr_cs_n           ) ,
273
          .sdr_cke            (sdr_cke            ) ,
274
          .sdr_ras_n          (sdr_ras_n          ) ,
275
          .sdr_cas_n          (sdr_cas_n          ) ,
276
          .sdr_we_n           (sdr_we_n           ) ,
277
          .sdr_dqm            (sdr_dqm            ) ,
278
          .sdr_ba             (sdr_ba             ) ,
279
          .sdr_addr           (sdr_addr           ) ,
280
          .pad_sdr_din        (pad_sdr_din        ) ,
281
          .sdr_dout           (sdr_dout           ) ,
282
          .sdr_den_n          (sdr_den_n          ) ,
283
 
284
                /* Parameters */
285
          .cfg_sdr_en         (cfg_sdr_en         ) ,
286
          .cfg_sdr_mode_reg   (cfg_sdr_mode_reg   ) ,
287
          .cfg_sdr_tras_d     (cfg_sdr_tras_d     ) ,
288
          .cfg_sdr_trp_d      (cfg_sdr_trp_d      ) ,
289
          .cfg_sdr_trcd_d     (cfg_sdr_trcd_d     ) ,
290
          .cfg_sdr_cas        (cfg_sdr_cas        ) ,
291
          .cfg_sdr_trcar_d    (cfg_sdr_trcar_d    ) ,
292
          .cfg_sdr_twr_d      (cfg_sdr_twr_d      ) ,
293
          .cfg_sdr_rfsh       (cfg_sdr_rfsh       ) ,
294
          .cfg_sdr_rfmax      (cfg_sdr_rfmax      )
295
               );
296
 
297
endmodule // sdrc_core

powered by: WebSVN 2.1.0

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