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

Subversion Repositories wb2axip

[/] [wb2axip/] [trunk/] [rtl/] [migsdram.v] - Blame information for rev 7

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

Line No. Rev Author Line
1 6 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    migsdram.v
4
//
5
// Project:     Pipelined Wishbone to AXI converter
6
//
7
// Purpose:     This file isn't really a part of the synthesis implementation 
8
//              of the wb2axip project itself, but rather it is an example
9
//      of how the wb2axip project can be used to connect a MIG generated
10
//      IP component.
11
//              
12
//
13
// Creator:     Dan Gisselquist, Ph.D.
14
//              Gisselquist Technology, LLC
15
//
16
////////////////////////////////////////////////////////////////////////////////
17
//
18
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
19
//
20
// This program is free software (firmware): you can redistribute it and/or
21
// modify it under the terms of  the GNU General Public License as published
22
// by the Free Software Foundation, either version 3 of the License, or (at
23
// your option) any later version.
24
//
25
// This program is distributed in the hope that it will be useful, but WITHOUT
26
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
27
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
28
// for more details.
29
//
30
// You should have received a copy of the GNU General Public License along
31
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
32
// target there if the PDF file isn't present.)  If not, see
33
// <http://www.gnu.org/licenses/> for a copy.
34
//
35
// License:     GPL, v3, as defined and found on www.gnu.org,
36
//              http://www.gnu.org/licenses/gpl.html
37
//
38
//
39
////////////////////////////////////////////////////////////////////////////////
40
//
41
//
42
module  migsdram(i_clk, i_clk_200mhz, o_sys_clk, i_rst, o_sys_reset,
43
        // Wishbone components
44
                i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel,
45
                o_wb_ack, o_wb_stall, o_wb_data, o_wb_err,
46
        // SDRAM connections
47
                o_ddr_ck_p, o_ddr_ck_n,
48
                o_ddr_reset_n, o_ddr_cke,
49
                o_ddr_cs_n, o_ddr_ras_n, o_ddr_cas_n, o_ddr_we_n,
50
                o_ddr_ba, o_ddr_addr,
51
                o_ddr_odt, o_ddr_dm,
52
                io_ddr_dqs_p, io_ddr_dqs_n,
53
                io_ddr_data
54
        );
55
        parameter       DDRWIDTH = 16, WBDATAWIDTH=32;
56
        parameter       AXIDWIDTH = 6;
57
        // The SDRAM address bits (RAMABITS) are a touch more difficult to work
58
        // out.  Here we leave them as a fixed parameter, but there are 
59
        // consequences to this.  Specifically, the wishbone data width, the
60
        // wishbone address width, and this number have interactions not
61
        // well captured here.
62
        parameter       RAMABITS = 28;
63
        // All DDR3 memories have 8 timeslots.  This, if the DDR3 memory
64
        // has 16 bits to it (as above), the entire transaction must take
65
        // AXIWIDTH bits ...
66
        localparam      AXIWIDTH= DDRWIDTH *8;
67
        localparam      DW=WBDATAWIDTH;
68
        localparam      AW=(WBDATAWIDTH==32)? RAMABITS-2
69
                                :((WBDATAWIDTH==64) ? RAMABITS-3
70
                                :((WBDATAWIDTH==128) ? RAMABITS-4
71
                                : RAMABITS-5)); // (WBDATAWIDTH==256)
72
        localparam      SELW= (WBDATAWIDTH/8);
73
        //
74
        input                   i_clk, i_clk_200mhz, i_rst;
75
        output                  o_sys_clk;
76
        output  reg             o_sys_reset;
77
        //
78
        input                   i_wb_cyc, i_wb_stb, i_wb_we;
79
        input           [(AW-1):0]       i_wb_addr;
80
        input           [(DW-1):0]       i_wb_data;
81
        input           [(SELW-1):0]     i_wb_sel;
82
        output  wire                    o_wb_ack, o_wb_stall;
83
        output  wire    [(DW-1):0]       o_wb_data;
84
        output  wire                    o_wb_err;
85
        //
86
        output  wire    [0:0]             o_ddr_ck_p, o_ddr_ck_n;
87
        output  wire    [0:0]             o_ddr_cke;
88
        output  wire                    o_ddr_reset_n,
89
                                        o_ddr_ras_n, o_ddr_cas_n, o_ddr_we_n;
90
        output  wire    [0:0]                     o_ddr_cs_n;
91
        output  wire    [2:0]                    o_ddr_ba;
92
        output  wire    [13:0]                   o_ddr_addr;
93
        output  wire    [0:0]                     o_ddr_odt;
94
        output  wire    [(DDRWIDTH/8-1):0]       o_ddr_dm;
95
        inout   wire    [1:0]                    io_ddr_dqs_p, io_ddr_dqs_n;
96
        inout   wire    [(DDRWIDTH-1):0] io_ddr_data;
97
 
98
 
99
`define SDRAM_ACCESS
100
`ifdef  SDRAM_ACCESS
101
 
102
        wire    aresetn;
103
        assign  aresetn = 1'b1; // Never reset
104
 
105
        // Write address channel
106
        wire    [(AXIDWIDTH-1):0]        s_axi_awid;
107
        wire    [(RAMABITS-1):0] s_axi_awaddr;
108
        wire    [7:0]                    s_axi_awlen;
109
        wire    [2:0]                    s_axi_awsize;
110
        wire    [1:0]                    s_axi_awburst;
111
        wire    [0:0]                     s_axi_awlock;
112
        wire    [3:0]                    s_axi_awcache;
113
        wire    [2:0]                    s_axi_awprot;
114
        wire    [3:0]                    s_axi_awqos;
115
        wire                            s_axi_awvalid;
116
        wire                            s_axi_awready;
117
        // Writei data channel
118
        wire    [(AXIWIDTH-1):0] s_axi_wdata;
119
        wire    [(AXIWIDTH/8-1):0]       s_axi_wstrb;
120
        wire                            s_axi_wlast, s_axi_wvalid, s_axi_wready;
121
        // Write response channel
122
        wire                            s_axi_bready;
123
        wire    [(AXIDWIDTH-1):0]        s_axi_bid;
124
        wire    [1:0]                    s_axi_bresp;
125
        wire                            s_axi_bvalid;
126
 
127
        // Read address channel
128
        wire    [(AXIDWIDTH-1):0]        s_axi_arid;
129
        wire    [(RAMABITS-1):0] s_axi_araddr;
130
        wire    [7:0]                    s_axi_arlen;
131
        wire    [2:0]                    s_axi_arsize;
132
        wire    [1:0]                    s_axi_arburst;
133
        wire    [0:0]                     s_axi_arlock;
134
        wire    [3:0]                    s_axi_arcache;
135
        wire    [2:0]                    s_axi_arprot;
136
        wire    [3:0]                    s_axi_arqos;
137
        wire                            s_axi_arvalid;
138
        // Read response/data channel
139
        wire    [(AXIDWIDTH-1):0]        s_axi_rid;
140
        wire    [(AXIWIDTH-1):0] s_axi_rdata;
141
        wire    [1:0]                    s_axi_rresp;
142
        wire                            s_axi_rlast;
143
        wire                            s_axi_rvalid;
144
 
145
        // Other wires ...
146
        wire            init_calib_complete, mmcm_locked;
147
        wire            app_sr_active, app_ref_ack, app_zq_ack;
148
        wire            app_sr_req, app_ref_req, app_zq_req;
149
        wire            w_sys_reset;
150
        wire    [11:0]   w_device_temp;
151
 
152
 
153
        mig_axis        mig_sdram(
154
                .ddr3_ck_p(o_ddr_ck_p),         .ddr3_ck_n(o_ddr_ck_n),
155
                .ddr3_reset_n(o_ddr_reset_n),   .ddr3_cke(o_ddr_cke),
156
                .ddr3_cs_n(o_ddr_cs_n),         .ddr3_ras_n(o_ddr_ras_n),
157
                .ddr3_we_n(o_ddr_we_n),         .ddr3_cas_n(o_ddr_cas_n),
158
                .ddr3_ba(o_ddr_ba),             .ddr3_addr(o_ddr_addr),
159
                .ddr3_odt(o_ddr_odt),
160
                .ddr3_dqs_p(io_ddr_dqs_p),      .ddr3_dqs_n(io_ddr_dqs_n),
161
                .ddr3_dq(io_ddr_data),          .ddr3_dm(o_ddr_dm),
162
                //
163
                .sys_clk_i(i_clk),
164
                .clk_ref_i(i_clk_200mhz),
165
                .ui_clk(o_sys_clk),
166
                .ui_clk_sync_rst(w_sys_reset),
167
                .mmcm_locked(mmcm_locked),
168
                .aresetn(aresetn),
169
                .app_sr_req(1'b0),
170
                .app_ref_req(1'b0),
171
                .app_zq_req(1'b0),
172
                .app_sr_active(app_sr_active),
173
                .app_ref_ack(app_ref_ack),
174
                .app_zq_ack(app_zq_ack),
175
                //
176
                .s_axi_awid(s_axi_awid),        .s_axi_awaddr(s_axi_awaddr),
177
                .s_axi_awlen(s_axi_awlen),      .s_axi_awsize(s_axi_awsize),
178
                .s_axi_awburst(s_axi_awburst),  .s_axi_awlock(s_axi_awlock),
179
                .s_axi_awcache(s_axi_awcache),  .s_axi_awprot(s_axi_awprot),
180
                .s_axi_awqos(s_axi_awqos),      .s_axi_awvalid(s_axi_awvalid),
181
                .s_axi_awready(s_axi_awready),
182
                //
183
                .s_axi_wready(  s_axi_wready),
184
                .s_axi_wdata(   s_axi_wdata),
185
                .s_axi_wstrb(   s_axi_wstrb),
186
                .s_axi_wlast(   s_axi_wlast),
187
                .s_axi_wvalid(  s_axi_wvalid),
188
                //
189
                .s_axi_bready(s_axi_bready),    .s_axi_bid(s_axi_bid),
190
                .s_axi_bresp(s_axi_bresp),      .s_axi_bvalid(s_axi_bvalid),
191
                //
192
                .s_axi_arid(s_axi_arid),        .s_axi_araddr(s_axi_araddr),
193
                .s_axi_arlen(s_axi_arlen),      .s_axi_arsize(s_axi_arsize),
194
                .s_axi_arburst(s_axi_arburst),  .s_axi_arlock(s_axi_arlock),
195
                .s_axi_arcache(s_axi_arcache),  .s_axi_arprot(s_axi_arprot),
196
                .s_axi_arqos(s_axi_arqos),      .s_axi_arvalid(s_axi_arvalid),
197
                .s_axi_arready(s_axi_arready),
198
                // 
199
                .s_axi_rready(s_axi_rready),    .s_axi_rid(s_axi_rid),
200
                .s_axi_rdata(s_axi_rdata),      .s_axi_rresp(s_axi_rresp),
201
                .s_axi_rlast(s_axi_rlast),      .s_axi_rvalid(s_axi_rvalid),
202
                .init_calib_complete(init_calib_complete),
203
                .sys_rst(i_rst),
204
                .device_temp(w_device_temp)
205
                );
206
 
207
        wbm2axisp       #(
208
                        .C_AXI_ID_WIDTH(AXIDWIDTH),
209
                        .C_AXI_DATA_WIDTH(AXIWIDTH),
210
                        .C_AXI_ADDR_WIDTH(RAMABITS),
211
                        .AW(AW), .DW(DW)
212
                        )
213
                        bus_translator(
214
                                .i_clk(o_sys_clk),
215
                                // .i_reset(i_rst), // internally unused
216
                                // Write address channel signals
217
                                .o_axi_awid(    s_axi_awid),
218
                                .o_axi_awaddr(  s_axi_awaddr),
219
                                .o_axi_awlen(   s_axi_awlen),
220
                                .o_axi_awsize(  s_axi_awsize),
221
                                .o_axi_awburst( s_axi_awburst),
222
                                .o_axi_awlock(  s_axi_awlock),
223
                                .o_axi_awcache( s_axi_awcache),
224
                                .o_axi_awprot(  s_axi_awprot),  // s_axi_awqos
225
                                .o_axi_awqos(   s_axi_awqos),  // s_axi_awqos
226
                                .o_axi_awvalid( s_axi_awvalid),
227
                                .i_axi_awready( s_axi_awready),
228
                        //
229
                                .i_axi_wready(  s_axi_wready),
230
                                .o_axi_wdata(   s_axi_wdata),
231
                                .o_axi_wstrb(   s_axi_wstrb),
232
                                .o_axi_wlast(   s_axi_wlast),
233
                                .o_axi_wvalid(  s_axi_wvalid),
234
                        //
235
                                .o_axi_bready(  s_axi_bready),
236
                                .i_axi_bid(     s_axi_bid),
237
                                .i_axi_bresp(   s_axi_bresp),
238
                                .i_axi_bvalid(  s_axi_bvalid),
239
                        //
240
                                .i_axi_arready( s_axi_arready),
241
                                .o_axi_arid(    s_axi_arid),
242
                                .o_axi_araddr(  s_axi_araddr),
243
                                .o_axi_arlen(   s_axi_arlen),
244
                                .o_axi_arsize(  s_axi_arsize),
245
                                .o_axi_arburst( s_axi_arburst),
246
                                .o_axi_arlock(  s_axi_arlock),
247
                                .o_axi_arcache( s_axi_arcache),
248
                                .o_axi_arprot(  s_axi_arprot),
249
                                .o_axi_arqos(   s_axi_arqos),
250
                                .o_axi_arvalid( s_axi_arvalid),
251
                        //
252
                                .o_axi_rready(  s_axi_rready),
253
                                .i_axi_rid(     s_axi_rid),
254
                                .i_axi_rdata(   s_axi_rdata),
255
                                .i_axi_rresp(   s_axi_rresp),
256
                                .i_axi_rlast(   s_axi_rlast),
257
                                .i_axi_rvalid(  s_axi_rvalid),
258
                        //
259
                                .i_wb_cyc(      i_wb_cyc),
260
                                .i_wb_stb(      i_wb_stb),
261
                                .i_wb_we(       i_wb_we),
262
                                .i_wb_addr(     i_wb_addr),
263
                                .i_wb_data(     i_wb_data),
264
                                .i_wb_sel(      i_wb_sel),
265
                        //
266
                                .o_wb_ack(      o_wb_ack),
267
                                .o_wb_stall(    o_wb_stall),
268
                                .o_wb_data(     o_wb_data),
269
                                .o_wb_err(      o_wb_err)
270
                );
271
 
272
        // Convert from active low to active high, *and* hold the system in
273
        // reset until the memory comes up.     
274
        initial o_sys_reset = 1'b1;
275
        always @(posedge o_sys_clk)
276
                o_sys_reset <= (!w_sys_reset)
277
                                ||(!init_calib_complete)
278
                                ||(!mmcm_locked);
279
`else
280
        BUFG    sysclk(i_clk, o_sys_clk);
281
        initial o_sys_reset <= 1'b1;
282
        always  @(posedge i_clk)
283
                o_sys_reset <= 1'b1;
284
 
285
        OBUFDS ckobuf(.I(i_clk), .O(o_ddr_ck_p), .OB(o_ddr_ck_n));
286
 
287
        assign  o_ddr_reset_n   = 1'b0;
288
        assign  o_ddr_cke[0]     = 1'b0;
289
        assign  o_ddr_cs_n[0]    = 1'b1;
290
        assign  o_ddr_cas_n     = 1'b1;
291
        assign  o_ddr_ras_n     = 1'b1;
292
        assign  o_ddr_we_n      = 1'b1;
293
        assign  o_ddr_ba        = 3'h0;
294
        assign  o_ddr_addr      = 14'h00;
295
        assign  o_ddr_dm        = 2'b00;
296
        assign  io_ddr_data     = 16'h0;
297
 
298
        OBUFDS  dqsbufa(.I(i_clk), .O(io_ddr_dqs_p[1]), .OB(io_ddr_dqs_n[1]));
299
        OBUFDS  dqsbufb(.I(i_clk), .O(io_ddr_dqs_p[0]), .OB(io_ddr_dqs_n[0]));
300
 
301
`endif
302
 
303
endmodule
304
 
305
 

powered by: WebSVN 2.1.0

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