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

Subversion Repositories wb2axip

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

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

powered by: WebSVN 2.1.0

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