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

Subversion Repositories minsoc

[/] [minsoc/] [trunk/] [rtl/] [verilog/] [minsoc_onchip_ram_top.v] - Blame information for rev 4

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

Line No. Rev Author Line
1 2 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
//
50
// Revision 1.0 2009/08/18 15:15:00   fajardo
51
// Created interface and tested
52
//
53
 
54
 
55
module minsoc_onchip_ram_top (
56
  wb_clk_i, wb_rst_i,
57
 
58
  wb_dat_i, wb_dat_o, wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i,
59
  wb_stb_i, wb_ack_o, wb_err_o
60
);
61
 
62
// 
63
// Parameters 
64
//
65
parameter    aw_int = 11;               //11 = 2048
66
parameter    adr_width = 13;            //Memory address width, is composed by blocks of aw_int, is not allowed to be less than 12
67
parameter    blocks = (1<<(adr_width-aw_int)); //generated memory contains "blocks" memory blocks of 2048x32 2048 depth x32 bit data
68
 
69
// 
70
// I/O Ports 
71
// 
72
input      wb_clk_i;
73
input      wb_rst_i;
74
 
75
// 
76
// WB slave i/f 
77
// 
78
input  [31:0]   wb_dat_i;
79
output [31:0]   wb_dat_o;
80
input  [31:0]   wb_adr_i;
81
input  [3:0]    wb_sel_i;
82
input      wb_we_i;
83
input      wb_cyc_i;
84
input      wb_stb_i;
85
output     wb_ack_o;
86
output     wb_err_o;
87
 
88
// 
89
// Internal regs and wires 
90
// 
91
wire    we;
92
wire [3:0]  be_i;
93
wire [31:0]  wb_dat_o;
94
reg    ack_we;
95
reg    ack_re;
96
// 
97
// Aliases and simple assignments 
98
// 
99
assign wb_ack_o = ack_re | ack_we;
100
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) 
101
assign we = wb_cyc_i & wb_stb_i & wb_we_i & (|wb_sel_i[3:0]);
102
assign be_i = (wb_cyc_i & wb_stb_i) * wb_sel_i;
103
 
104
// 
105
// Write acknowledge 
106
// 
107
always @ (negedge wb_clk_i or posedge wb_rst_i)
108
begin
109
if (wb_rst_i)
110
    ack_we <= 1'b0;
111
  else
112
  if (wb_cyc_i & wb_stb_i & wb_we_i & ~ack_we)
113
    ack_we <= #1 1'b1;
114
  else
115
    ack_we <= #1 1'b0;
116
end
117
 
118
// 
119
// read acknowledge 
120
// 
121
always @ (posedge wb_clk_i or posedge wb_rst_i)
122
begin
123
  if (wb_rst_i)
124
    ack_re <= 1'b0;
125
  else
126
  if (wb_cyc_i & wb_stb_i & ~wb_err_o & ~wb_we_i & ~ack_re)
127
    ack_re <= #1 1'b1;
128
  else
129
    ack_re <= #1 1'b0;
130
end
131
 
132
wire [blocks-1:0] bank;
133
 
134
generate
135
genvar i;
136
    for (i=0; i < blocks; i=i+1) begin : MEM
137
 
138
        assign bank[i] = wb_adr_i[adr_width+1:aw_int+2] == i;
139
 
140
        //BANK0
141
        minsoc_onchip_ram block_ram_0 (
142
            .clk(wb_clk_i),
143
            .rst(wb_rst_i),
144
            .addr(wb_adr_i[aw_int+1:2]),
145
            .di(wb_dat_i[7:0]),
146
            .doq(wb_dat_o[7:0]),
147
            .we(we & bank[i]),
148
            .oe(bank[i]),
149
            .ce(be_i[0]));
150
 
151
 
152
        minsoc_onchip_ram block_ram_1 (
153
            .clk(wb_clk_i),
154
            .rst(wb_rst_i),
155
            .addr(wb_adr_i[aw_int+1:2]),
156
            .di(wb_dat_i[15:8]),
157
            .doq(wb_dat_o[15:8]),
158
            .we(we & bank[i]),
159
            .oe(bank[i]),
160
            .ce(be_i[1]));
161
 
162
        minsoc_onchip_ram block_ram_2 (
163
            .clk(wb_clk_i),
164
            .rst(wb_rst_i),
165
            .addr(wb_adr_i[aw_int+1:2]),
166
            .di(wb_dat_i[23:16]),
167
            .doq(wb_dat_o[23:16]),
168
            .we(we & bank[i]),
169
            .oe(bank[i]),
170
            .ce(be_i[2]));
171
 
172
        minsoc_onchip_ram block_ram_3 (
173
            .clk(wb_clk_i),
174
            .rst(wb_rst_i),
175
            .addr(wb_adr_i[aw_int+1:2]),
176
            .di(wb_dat_i[31:24]),
177
            .doq(wb_dat_o[31:24]),
178
            .we(we & bank[i]),
179
            .oe(bank[i]),
180
            .ce(be_i[3]));
181
 
182
    end
183
endgenerate
184
 
185
endmodule
186
 

powered by: WebSVN 2.1.0

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