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

Subversion Repositories hpdmc

[/] [hpdmc/] [trunk/] [hpdmc_ddr32/] [rtl/] [hpdmc.v] - Blame information for rev 21

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 lekernel
/*
2
 * Milkymist VJ SoC
3
 * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, version 3 of the License.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
 
18
module hpdmc #(
19
        parameter csr_addr = 4'h0,
20
        /*
21
         * The depth of the SDRAM array, in bytes.
22
         * Capacity (in bytes) is 2^sdram_depth.
23
         */
24
        parameter sdram_depth = 26,
25
 
26
        /*
27
         * The number of column address bits of the SDRAM.
28
         */
29
        parameter sdram_columndepth = 9
30
) (
31
        input sys_clk,
32
        input sys_clk_n,
33
        /*
34
         * Clock used to generate DQS.
35
         * Typically sys_clk phased out by 90 degrees,
36
         * as data is sent synchronously to sys_clk.
37
         */
38
        input dqs_clk,
39
        input dqs_clk_n,
40
 
41
        input sys_rst,
42
 
43
        /* Control interface */
44
        input [13:0] csr_a,
45
        input csr_we,
46
        input [31:0] csr_di,
47
        output [31:0] csr_do,
48
 
49
        /* Simple FML 4x64 interface to the memory contents */
50
        input [sdram_depth-1:0] fml_adr,
51
        input fml_stb,
52
        input fml_we,
53
        output fml_ack,
54
        input [7:0] fml_sel,
55
        input [63:0] fml_di,
56
        output [63:0] fml_do,
57
 
58
        /* SDRAM interface.
59
         * The SDRAM clock should be driven synchronously to the system clock.
60
         * It is not generated inside this core so you can take advantage of
61
         * architecture-dependent clocking resources to generate a clean
62
         * differential clock.
63
         */
64
        output reg sdram_cke,
65
        output reg sdram_cs_n,
66
        output reg sdram_we_n,
67
        output reg sdram_cas_n,
68
        output reg sdram_ras_n,
69
        output reg [12:0] sdram_adr,
70
        output reg [1:0] sdram_ba,
71
 
72
        output [3:0] sdram_dm,
73
        inout [31:0] sdram_dq,
74
        inout [3:0] sdram_dqs,
75
 
76
        /* Interface to the DCM generating DQS */
77
        output dqs_psen,
78
        output dqs_psincdec,
79
        input dqs_psdone,
80
 
81
        input [1:0] pll_stat
82
);
83
 
84
/* Register all control signals, leaving the possibility to use IOB registers */
85
wire sdram_cke_r;
86
wire sdram_cs_n_r;
87
wire sdram_we_n_r;
88
wire sdram_cas_n_r;
89
wire sdram_ras_n_r;
90
wire [12:0] sdram_adr_r;
91
wire [1:0] sdram_ba_r;
92
 
93
always @(posedge sys_clk) begin
94
        sdram_cke <= sdram_cke_r;
95
        sdram_cs_n <= sdram_cs_n_r;
96
        sdram_we_n <= sdram_we_n_r;
97
        sdram_cas_n <= sdram_cas_n_r;
98
        sdram_ras_n <= sdram_ras_n_r;
99
        sdram_ba <= sdram_ba_r;
100
        sdram_adr <= sdram_adr_r;
101
end
102
 
103
/* Mux the control signals according to the "bypass" selection.
104
 * CKE always comes from the control interface.
105
 */
106
wire bypass;
107
 
108
wire sdram_cs_n_bypass;
109
wire sdram_we_n_bypass;
110
wire sdram_cas_n_bypass;
111
wire sdram_ras_n_bypass;
112
wire [12:0] sdram_adr_bypass;
113
wire [1:0] sdram_ba_bypass;
114
 
115
wire sdram_cs_n_mgmt;
116
wire sdram_we_n_mgmt;
117
wire sdram_cas_n_mgmt;
118
wire sdram_ras_n_mgmt;
119
wire [12:0] sdram_adr_mgmt;
120
wire [1:0] sdram_ba_mgmt;
121
 
122
assign sdram_cs_n_r = bypass ? sdram_cs_n_bypass : sdram_cs_n_mgmt;
123
assign sdram_we_n_r = bypass ? sdram_we_n_bypass : sdram_we_n_mgmt;
124
assign sdram_cas_n_r = bypass ? sdram_cas_n_bypass : sdram_cas_n_mgmt;
125
assign sdram_ras_n_r = bypass ? sdram_ras_n_bypass : sdram_ras_n_mgmt;
126
assign sdram_adr_r = bypass ? sdram_adr_bypass : sdram_adr_mgmt;
127
assign sdram_ba_r = bypass ? sdram_ba_bypass : sdram_ba_mgmt;
128
 
129
/* Control interface */
130
wire sdram_rst;
131
 
132
wire [2:0] tim_rp;
133
wire [2:0] tim_rcd;
134
wire tim_cas;
135
wire [10:0] tim_refi;
136
wire [3:0] tim_rfc;
137
wire [1:0] tim_wr;
138
 
139
wire idelay_rst;
140
wire idelay_ce;
141
wire idelay_inc;
142
 
143
hpdmc_ctlif #(
144
        .csr_addr(csr_addr)
145
) ctlif (
146
        .sys_clk(sys_clk),
147
        .sys_rst(sys_rst),
148
 
149
        .csr_a(csr_a),
150
        .csr_we(csr_we),
151
        .csr_di(csr_di),
152
        .csr_do(csr_do),
153
 
154
        .bypass(bypass),
155
        .sdram_rst(sdram_rst),
156
 
157
        .sdram_cke(sdram_cke_r),
158
        .sdram_cs_n(sdram_cs_n_bypass),
159
        .sdram_we_n(sdram_we_n_bypass),
160
        .sdram_cas_n(sdram_cas_n_bypass),
161
        .sdram_ras_n(sdram_ras_n_bypass),
162
        .sdram_adr(sdram_adr_bypass),
163
        .sdram_ba(sdram_ba_bypass),
164
 
165
        .tim_rp(tim_rp),
166
        .tim_rcd(tim_rcd),
167
        .tim_cas(tim_cas),
168
        .tim_refi(tim_refi),
169
        .tim_rfc(tim_rfc),
170
        .tim_wr(tim_wr),
171
 
172
        .idelay_rst(idelay_rst),
173
        .idelay_ce(idelay_ce),
174
        .idelay_inc(idelay_inc),
175
 
176
        .dqs_psen(dqs_psen),
177
        .dqs_psincdec(dqs_psincdec),
178
        .dqs_psdone(dqs_psdone),
179
 
180
        .pll_stat(pll_stat)
181
);
182
 
183
/* SDRAM management unit */
184
wire mgmt_stb;
185
wire mgmt_we;
186
wire [sdram_depth-3-1:0] mgmt_address;
187
wire mgmt_ack;
188
 
189
wire read;
190
wire write;
191
wire [3:0] concerned_bank;
192
wire read_safe;
193
wire write_safe;
194
wire [3:0] precharge_safe;
195
 
196
hpdmc_mgmt #(
197
        .sdram_depth(sdram_depth),
198
        .sdram_columndepth(sdram_columndepth)
199
) mgmt (
200
        .sys_clk(sys_clk),
201
        .sdram_rst(sdram_rst),
202
 
203
        .tim_rp(tim_rp),
204
        .tim_rcd(tim_rcd),
205
        .tim_refi(tim_refi),
206
        .tim_rfc(tim_rfc),
207
 
208
        .stb(mgmt_stb),
209
        .we(mgmt_we),
210
        .address(mgmt_address),
211
        .ack(mgmt_ack),
212
 
213
        .read(read),
214
        .write(write),
215
        .concerned_bank(concerned_bank),
216
        .read_safe(read_safe),
217
        .write_safe(write_safe),
218
        .precharge_safe(precharge_safe),
219
 
220
        .sdram_cs_n(sdram_cs_n_mgmt),
221
        .sdram_we_n(sdram_we_n_mgmt),
222
        .sdram_cas_n(sdram_cas_n_mgmt),
223
        .sdram_ras_n(sdram_ras_n_mgmt),
224
        .sdram_adr(sdram_adr_mgmt),
225
        .sdram_ba(sdram_ba_mgmt)
226
);
227
 
228
/* Bus interface */
229
wire data_ack;
230
 
231
hpdmc_busif #(
232
        .sdram_depth(sdram_depth)
233
) busif (
234
        .sys_clk(sys_clk),
235
        .sdram_rst(sdram_rst),
236
 
237
        .fml_adr(fml_adr),
238
        .fml_stb(fml_stb),
239
        .fml_we(fml_we),
240
        .fml_ack(fml_ack),
241
 
242
        .mgmt_stb(mgmt_stb),
243
        .mgmt_we(mgmt_we),
244
        .mgmt_address(mgmt_address),
245
        .mgmt_ack(mgmt_ack),
246
 
247
        .data_ack(data_ack)
248
);
249
 
250
/* Data path controller */
251
wire direction;
252
wire direction_r;
253
 
254
hpdmc_datactl datactl(
255
        .sys_clk(sys_clk),
256
        .sdram_rst(sdram_rst),
257
 
258
        .read(read),
259
        .write(write),
260
        .concerned_bank(concerned_bank),
261
        .read_safe(read_safe),
262
        .write_safe(write_safe),
263
        .precharge_safe(precharge_safe),
264
 
265
        .ack(data_ack),
266
        .direction(direction),
267
        .direction_r(direction_r),
268
 
269
        .tim_cas(tim_cas),
270
        .tim_wr(tim_wr)
271
);
272
 
273
/* Data path */
274
hpdmc_ddrio ddrio(
275
        .sys_clk(sys_clk),
276
        .sys_clk_n(sys_clk_n),
277
        .dqs_clk(dqs_clk),
278
        .dqs_clk_n(dqs_clk_n),
279
 
280
        .direction(direction),
281
        .direction_r(direction_r),
282
        /* Bit meaning is the opposite between
283
         * the FML selection signal and SDRAM DM pins.
284
         */
285
        .mo(~fml_sel),
286
        .do(fml_di),
287
        .di(fml_do),
288
 
289
        .sdram_dm(sdram_dm),
290
        .sdram_dq(sdram_dq),
291
        .sdram_dqs(sdram_dqs),
292
 
293
        .idelay_rst(idelay_rst),
294
        .idelay_ce(idelay_ce),
295
        .idelay_inc(idelay_inc)
296
);
297
 
298
endmodule

powered by: WebSVN 2.1.0

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