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

Subversion Repositories minsoc

[/] [minsoc/] [trunk/] [utils/] [contributions/] [initialized_onchip_ram/] [minsoc_onchip_ram_top_altera.v] - Blame information for rev 74

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

Line No. Rev Author Line
1 40 rfajardo
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////             Generic Wishbone controller for                  ////
4
////              Single-Port Synchronous RAM                     ////
5
////                                                              ////
6
////  This file is part of memory library available from          ////
7
////  http://www.opencores.org/cvsweb.shtml/minsoc/               ////
8
////                                                              ////
9
////  Description                                                 ////
10
////  This Wishbone controller connects to the wrapper of         ////
11
////  the single-port synchronous memory interface.               ////
12
////  Besides universal memory due to onchip_ram it provides a    ////
13
////  generic way to set the depth of the memory.                 ////
14
////                                                              ////
15
////  To Do:                                                      ////
16
////                                                              ////
17
////  Author(s):                                                  ////
18
////      - Raul Fajardo, rfajardo@gmail.com                      ////
19
////                                                              ////
20
//////////////////////////////////////////////////////////////////////
21
////                                                              ////
22
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
23
////                                                              ////
24
//// This source file may be used and distributed without         ////
25
//// restriction provided that this copyright statement is not    ////
26
//// removed from the file and that any derivative work contains  ////
27
//// the original copyright notice and the associated disclaimer. ////
28
////                                                              ////
29
//// This source file is free software; you can redistribute it   ////
30
//// and/or modify it under the terms of the GNU Lesser General   ////
31
//// Public License as published by the Free Software Foundation; ////
32
//// either version 2.1 of the License, or (at your option) any   ////
33
//// later version.                                               ////
34
////                                                              ////
35
//// This source is distributed in the hope that it will be       ////
36
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
37
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
38
//// PURPOSE.  See the GNU Lesser General Public License for more ////
39
//// details.                                                     ////
40
////                                                              ////
41
//// You should have received a copy of the GNU Lesser General    ////
42
//// Public License along with this source; if not, download it   ////
43
//// from http://www.gnu.org/licenses/lgpl.html                   ////
44
////                                                              ////
45
//////////////////////////////////////////////////////////////////////
46
//
47
// Revision History
48
//
49
// Revision 1.1 2009/10/02 16:49      fajardo
50
// Not using the oe signal (output enable) from 
51
// memories, instead multiplexing the outputs
52
// between the different instantiated blocks
53
//
54
//
55
// Revision 1.0 2009/08/18 15:15:00   fajardo
56
// Created interface and tested
57
//
58
`include "minsoc_defines.v"
59
 
60
`define mem_init_file "uart-nocache.mif" //specific memory initalization file name, which can be intel hex(.hex) or Altera mif file 
61
                                         //if no initalization file used, give a name of "UNUSED"
62
 
63
module minsoc_onchip_ram_top (
64
  wb_clk_i, wb_rst_i,
65
 
66
  wb_dat_i, wb_dat_o, wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i,
67
  wb_stb_i, wb_ack_o, wb_err_o
68
);
69
 
70
// 
71
// Parameters 
72
//
73
parameter    adr_width = 13;            //Memory address width, is composed by blocks of aw_int, is not allowed to be less than 12
74
localparam    aw_int = 11;              //11 = 2048
75
localparam    blocks = (1<<(adr_width-aw_int)); //generated memory contains "blocks" memory blocks of 2048x32 2048 depth x32 bit data
76
 
77
// 
78
// I/O Ports 
79
// 
80
input      wb_clk_i;
81
input      wb_rst_i;
82
 
83
// 
84
// WB slave i/f 
85
// 
86
input  [31:0]   wb_dat_i;
87
output [31:0]   wb_dat_o;
88
input  [31:0]   wb_adr_i;
89
input  [3:0]    wb_sel_i;
90
input      wb_we_i;
91
input      wb_cyc_i;
92
input      wb_stb_i;
93
output     wb_ack_o;
94
output     wb_err_o;
95
 
96
// 
97
// Internal regs and wires 
98
// 
99
wire    we;
100
wire [3:0]  be_i;
101
wire [31:0]  wb_dat_o;
102
reg    ack_we;
103
reg    ack_re;
104
// 
105
// Aliases and simple assignments 
106
// 
107
assign wb_ack_o = ack_re | ack_we;
108
assign wb_err_o = wb_cyc_i & wb_stb_i & (|wb_adr_i[23:adr_width+2]);  // If Access to > (8-bit leading prefix ignored) 
109
assign we = wb_cyc_i & wb_stb_i & wb_we_i & (|wb_sel_i[3:0]);
110
assign be_i = (wb_cyc_i & wb_stb_i) * wb_sel_i;
111
 
112
// 
113
// Write acknowledge 
114
// 
115
always @ (negedge wb_clk_i or posedge wb_rst_i)
116
begin
117
if (wb_rst_i)
118
    ack_we <= 1'b0;
119
  else
120
  if (wb_cyc_i & wb_stb_i & wb_we_i & ~ack_we)
121
    ack_we <= #1 1'b1;
122
  else
123
    ack_we <= #1 1'b0;
124
end
125
 
126
// 
127
// read acknowledge 
128
// 
129
always @ (posedge wb_clk_i or posedge wb_rst_i)
130
begin
131
  if (wb_rst_i)
132
    ack_re <= 1'b0;
133
  else
134
  if (wb_cyc_i & wb_stb_i & ~wb_err_o & ~wb_we_i & ~ack_re)
135
    ack_re <= #1 1'b1;
136
  else
137
    ack_re <= #1 1'b0;
138
end
139
 
140
`ifdef ALTERA_FPGA    //only for altera memory initialization
141
 
142
//2^adr_width x 32bit single-port ram.
143
altsyncram altsyncram_component (
144
                                .wren_a (we),
145
                                .clock0 (wb_clk_i),
146
                                .byteena_a (be_i),
147
                                .address_a (wb_adr_i[adr_width+1:2]),
148
                                .data_a (wb_dat_i),
149
                                .q_a (wb_dat_o),
150
                                .aclr0 (1'b0),
151
                                .aclr1 (1'b0),
152
                                .address_b (1'b1),
153
                                .addressstall_a (1'b0),
154
                                .addressstall_b (1'b0),
155
                                .byteena_b (1'b1),
156
                                .clock1 (1'b1),
157
                                .clocken0 (1'b1),
158
                                .clocken1 (1'b1),
159
                                .clocken2 (1'b1),
160
                                .clocken3 (1'b1),
161
                                .data_b (1'b1),
162
                                .eccstatus (),
163
                                .q_b (),
164
                                .rden_a (1'b1),
165
                                .rden_b (1'b1),
166
                                .wren_b (1'b0));
167
        defparam
168
                altsyncram_component.clock_enable_input_a = "BYPASS",
169
                altsyncram_component.clock_enable_output_a = "BYPASS",
170
                altsyncram_component.init_file = `mem_init_file,
171
                altsyncram_component.intended_device_family = "Stratix III",
172
                altsyncram_component.lpm_hint = "ENABLE_RUNTIME_MOD=NO",
173
                altsyncram_component.lpm_type = "altsyncram",
174
                altsyncram_component.operation_mode = "SINGLE_PORT",
175
                altsyncram_component.outdata_aclr_a = "NONE",
176
                altsyncram_component.outdata_reg_a = "UNREGISTERED",
177
                altsyncram_component.power_up_uninitialized = "FALSE",
178
                altsyncram_component.read_during_write_mode_port_a = "NEW_DATA_NO_NBE_READ",
179
                altsyncram_component.numwords_a = (1<<adr_width),
180
                altsyncram_component.widthad_a = adr_width,
181
                altsyncram_component.width_a = 32,
182
                altsyncram_component.byte_size = 8,
183
                altsyncram_component.width_byteena_a = 4;
184
 
185
 
186
`else               //other FPGA Type
187
//Generic (multiple inputs x 1 output) MUX
188
localparam mux_in_nr = blocks;
189
localparam slices = adr_width-aw_int;
190
localparam mux_out_nr = blocks-1;
191
 
192
wire [31:0] int_dat_o[0:mux_in_nr-1];
193
wire [31:0] mux_out[0:mux_out_nr-1];
194
 
195
generate
196
genvar j, k;
197
        for (j=0; j<slices; j=j+1) begin : SLICES
198
                for (k=0; k<(mux_in_nr>>(j+1)); k=k+1) begin : MUX
199
                        if (j==0) begin
200
                                mux2 #
201
                (
202
                    .dw(32)
203
                )
204
                mux_int(
205
                    .sel( wb_adr_i[aw_int+2+j] ),
206
                    .in1( int_dat_o[k*2] ),
207
                                    .in2( int_dat_o[k*2+1] ),
208
                    .out( mux_out[k] )
209
                );
210
                        end
211
                        else begin
212
                                mux2 #
213
                (
214
                    .dw(32)
215
                )
216
                mux_int(
217
                    .sel( wb_adr_i[aw_int+2+j] ),
218
                                    .in1( mux_out[(mux_in_nr-(mux_in_nr>>(j-1)))+k*2] ),
219
                                    .in2( mux_out[(mux_in_nr-(mux_in_nr>>(j-1)))+k*2+1] ),
220
                                    .out( mux_out[(mux_in_nr-(mux_in_nr>>j))+k] )
221
                );
222
                        end
223
                end
224
        end
225
endgenerate
226
 
227
//last output = total output
228
assign wb_dat_o = mux_out[mux_out_nr-1];
229
 
230
//(mux_in_nr-(mux_in_nr>>j)): 
231
//-Given sum of 2^i | i = x -> y series can be resumed to 2^(y+1)-2^x
232
//so, with this expression I'm evaluating how many times the internal loop has been run
233
 
234
wire [blocks-1:0] bank;
235
 
236
generate
237
genvar i;
238
    for (i=0; i < blocks; i=i+1) begin : MEM
239
 
240
        assign bank[i] = wb_adr_i[adr_width+1:aw_int+2] == i;
241
 
242
        //BANK0
243
        minsoc_onchip_ram block_ram_0 (
244
            .clk(wb_clk_i),
245
            .rst(wb_rst_i),
246
            .addr(wb_adr_i[aw_int+1:2]),
247
            .di(wb_dat_i[7:0]),
248
            .doq(int_dat_o[i][7:0]),
249
            .we(we & bank[i]),
250
            .oe(1'b1),
251
            .ce(be_i[0])
252
        );
253
 
254
 
255
        minsoc_onchip_ram block_ram_1 (
256
            .clk(wb_clk_i),
257
            .rst(wb_rst_i),
258
            .addr(wb_adr_i[aw_int+1:2]),
259
            .di(wb_dat_i[15:8]),
260
            .doq(int_dat_o[i][15:8]),
261
            .we(we & bank[i]),
262
            .oe(1'b1),
263
            .ce(be_i[1])
264
        );
265
 
266
        minsoc_onchip_ram block_ram_2 (
267
            .clk(wb_clk_i),
268
            .rst(wb_rst_i),
269
            .addr(wb_adr_i[aw_int+1:2]),
270
            .di(wb_dat_i[23:16]),
271
            .doq(int_dat_o[i][23:16]),
272
            .we(we & bank[i]),
273
            .oe(1'b1),
274
            .ce(be_i[2])
275
        );
276
 
277
        minsoc_onchip_ram block_ram_3 (
278
            .clk(wb_clk_i),
279
            .rst(wb_rst_i),
280
            .addr(wb_adr_i[aw_int+1:2]),
281
            .di(wb_dat_i[31:24]),
282
            .doq(int_dat_o[i][31:24]),
283
            .we(we & bank[i]),
284
            .oe(1'b1),
285
            .ce(be_i[3])
286
        );
287
 
288
    end
289
endgenerate
290
`endif
291
 
292
endmodule
293
 
294
module mux2(sel,in1,in2,out);
295
 
296
parameter dw = 32;
297
 
298
input sel;
299
input [dw-1:0] in1, in2;
300
output reg [dw-1:0] out;
301
 
302
always @ (sel or in1 or in2)
303
begin
304
        case (sel)
305
                1'b0: out = in1;
306
                1'b1: out = in2;
307
        endcase
308
end
309
 
310
endmodule

powered by: WebSVN 2.1.0

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