1 |
2 |
thorn_aitc |
//======================================================
|
2 |
|
|
// Aquarius Project
|
3 |
|
|
// SuperH-2 ISA Compatible RISC CPU
|
4 |
|
|
//------------------------------------------------------
|
5 |
|
|
// Module : Memory (ROM/RAM) in MCU
|
6 |
|
|
//------------------------------------------------------
|
7 |
|
|
// File : memory_fpga.v
|
8 |
|
|
// Library : none
|
9 |
|
|
// Description : 16KB RAM Module implemented by Xilinx Block RAM,
|
10 |
|
|
// : which can be initialized by INIT Constraints
|
11 |
|
|
// Simulator : Icarus Verilog (Cygwin)
|
12 |
|
|
// Synthesizer : Xilinx XST (Windows XP)
|
13 |
|
|
// Author : Thorn Aitch
|
14 |
|
|
//------------------------------------------------------
|
15 |
|
|
// Revision Number : 1
|
16 |
|
|
// Date of Change : 21st January 2003
|
17 |
|
|
// Creator : Thorn Aitch
|
18 |
|
|
// Description : Initial Design
|
19 |
|
|
//------------------------------------------------------
|
20 |
|
|
// Revision Number : 2
|
21 |
|
|
// Date of Change : 30th April 2003
|
22 |
|
|
// Modifier : Thorn Aitch
|
23 |
|
|
// Description : Release Version 1.0
|
24 |
|
|
//======================================================
|
25 |
|
|
// Copyright (C) 2002-2003, Thorn Aitch
|
26 |
|
|
//
|
27 |
|
|
// Designs can be altered while keeping list of
|
28 |
|
|
// modifications "the same as in GNU" No money can
|
29 |
|
|
// be earned by selling the designs themselves, but
|
30 |
|
|
// anyone can get money by selling the implementation
|
31 |
|
|
// of the design, such as ICs based on some cores,
|
32 |
|
|
// boards based on some schematics or Layouts, and
|
33 |
|
|
// even GUI interfaces to text mode drivers.
|
34 |
|
|
// "The same as GPL SW" Any update to the design
|
35 |
|
|
// should be documented and returned to the design.
|
36 |
|
|
// Any derivative work based on the IP should be free
|
37 |
|
|
// under OpenIP License. Derivative work means any
|
38 |
|
|
// update, change or improvement on the design.
|
39 |
|
|
// Any work based on the design can be either made
|
40 |
|
|
// free under OpenIP license or protected by any other
|
41 |
|
|
// license. Work based on the design means any work uses
|
42 |
|
|
// the OpenIP Licensed core as a building black without
|
43 |
|
|
// changing anything on it with any other blocks to
|
44 |
|
|
// produce larger design. There is NO WARRANTY on the
|
45 |
|
|
// functionality or performance of the design on the
|
46 |
|
|
// real hardware implementation.
|
47 |
|
|
// On the other hand, the SuperH-2 ISA (Instruction Set
|
48 |
|
|
// Architecture) executed by Aquarius is rigidly
|
49 |
|
|
// the property of Renesas Corp. Then you have all
|
50 |
|
|
// responsibility to judge if there are not any
|
51 |
|
|
// infringements to Renesas's rights regarding your
|
52 |
|
|
// Aquarius adoption into your design.
|
53 |
|
|
// By adopting Aquarius, the user assumes all
|
54 |
|
|
// responsibility for its use.
|
55 |
|
|
// This project may cause any damages around you, for
|
56 |
|
|
// example, loss of properties, data, money, profits,
|
57 |
|
|
// life, or business etc. By adopting this source,
|
58 |
|
|
// the user assumes all responsibility for its use.
|
59 |
|
|
//======================================================
|
60 |
|
|
|
61 |
|
|
`include "timescale.v"
|
62 |
|
|
`include "defines.v"
|
63 |
|
|
|
64 |
|
|
//*************************************************
|
65 |
|
|
// Module Definition
|
66 |
|
|
//*************************************************
|
67 |
|
|
module memory (
|
68 |
|
|
CLK,
|
69 |
|
|
CE, WE, SEL,
|
70 |
|
|
ADR, DATI, DATO
|
71 |
|
|
);
|
72 |
|
|
|
73 |
|
|
//-------------------
|
74 |
|
|
// Module I/O Signals
|
75 |
|
|
//-------------------
|
76 |
|
|
input CLK; // clock
|
77 |
|
|
input CE; // chip enable
|
78 |
|
|
input WE; // write enable (read = 0, write = 1)
|
79 |
|
|
input [3:0]SEL; // data valid position
|
80 |
|
|
input [13:0] ADR; // address
|
81 |
|
|
input [31:0] DATI; // write data
|
82 |
|
|
output [31:0] DATO; // read data
|
83 |
|
|
|
84 |
|
|
//-----------------
|
85 |
|
|
// Internal Signals
|
86 |
|
|
//-----------------
|
87 |
|
|
reg [7:0] RAM0HH [0:511];
|
88 |
|
|
reg [7:0] RAM0HL [0:511];
|
89 |
|
|
reg [7:0] RAM0LH [0:511];
|
90 |
|
|
reg [7:0] RAM0LL [0:511];
|
91 |
|
|
reg [7:0] RAM1HH [0:511];
|
92 |
|
|
reg [7:0] RAM1HL [0:511];
|
93 |
|
|
reg [7:0] RAM1LH [0:511];
|
94 |
|
|
reg [7:0] RAM1LL [0:511];
|
95 |
|
|
reg [7:0] RAM2HH [0:511];
|
96 |
|
|
reg [7:0] RAM2HL [0:511];
|
97 |
|
|
reg [7:0] RAM2LH [0:511];
|
98 |
|
|
reg [7:0] RAM2LL [0:511];
|
99 |
|
|
reg [7:0] RAM3HH [0:511];
|
100 |
|
|
reg [7:0] RAM3HL [0:511];
|
101 |
|
|
reg [7:0] RAM3LH [0:511];
|
102 |
|
|
reg [7:0] RAM3LL [0:511];
|
103 |
|
|
reg [7:0] RAM4HH [0:511];
|
104 |
|
|
reg [7:0] RAM4HL [0:511];
|
105 |
|
|
reg [7:0] RAM4LH [0:511];
|
106 |
|
|
reg [7:0] RAM4LL [0:511];
|
107 |
|
|
reg [7:0] RAM5HH [0:511];
|
108 |
|
|
reg [7:0] RAM5HL [0:511];
|
109 |
|
|
reg [7:0] RAM5LH [0:511];
|
110 |
|
|
reg [7:0] RAM5LL [0:511];
|
111 |
|
|
reg [7:0] RAM6HH [0:511];
|
112 |
|
|
reg [7:0] RAM6HL [0:511];
|
113 |
|
|
reg [7:0] RAM6LH [0:511];
|
114 |
|
|
reg [7:0] RAM6LL [0:511];
|
115 |
|
|
reg [7:0] RAM7HH [0:511];
|
116 |
|
|
reg [7:0] RAM7HL [0:511];
|
117 |
|
|
reg [7:0] RAM7LH [0:511];
|
118 |
|
|
reg [7:0] RAM7LL [0:511];
|
119 |
|
|
|
120 |
|
|
wire [31:0] DATO;
|
121 |
|
|
wire [31:0] DATOUT0;
|
122 |
|
|
wire [31:0] DATOUT1;
|
123 |
|
|
wire [31:0] DATOUT2;
|
124 |
|
|
wire [31:0] DATOUT3;
|
125 |
|
|
wire [31:0] DATOUT4;
|
126 |
|
|
wire [31:0] DATOUT5;
|
127 |
|
|
wire [31:0] DATOUT6;
|
128 |
|
|
wire [31:0] DATOUT7;
|
129 |
|
|
|
130 |
|
|
reg [8:0] ADR_RD;
|
131 |
|
|
reg [7:0] CERAM;
|
132 |
|
|
|
133 |
|
|
//---------------
|
134 |
|
|
// RAM Operation
|
135 |
|
|
//--------------
|
136 |
|
|
always @(ADR or CE)
|
137 |
|
|
begin
|
138 |
|
|
case ({CE, ADR[13:11]})
|
139 |
|
|
4'b1_000: CERAM <= 8'b00000001;
|
140 |
|
|
4'b1_001: CERAM <= 8'b00000010;
|
141 |
|
|
4'b1_010: CERAM <= 8'b00000100;
|
142 |
|
|
4'b1_011: CERAM <= 8'b00001000;
|
143 |
|
|
4'b1_100: CERAM <= 8'b00010000;
|
144 |
|
|
4'b1_101: CERAM <= 8'b00100000;
|
145 |
|
|
4'b1_110: CERAM <= 8'b01000000;
|
146 |
|
|
4'b1_111: CERAM <= 8'b10000000;
|
147 |
|
|
default: CERAM <= 8'b00000000;
|
148 |
|
|
endcase
|
149 |
|
|
end
|
150 |
|
|
|
151 |
|
|
always @(negedge CLK) begin
|
152 |
|
|
if (CERAM[0] & WE & SEL[3]) RAM0HH[ADR[10:2]] <= DATI[31:24];
|
153 |
|
|
if (CERAM[0] & WE & SEL[2]) RAM0HL[ADR[10:2]] <= DATI[23:16];
|
154 |
|
|
if (CERAM[0] & WE & SEL[1]) RAM0LH[ADR[10:2]] <= DATI[15: 8];
|
155 |
|
|
if (CERAM[0] & WE & SEL[0]) RAM0LL[ADR[10:2]] <= DATI[ 7: 0];
|
156 |
|
|
if (CERAM[1] & WE & SEL[3]) RAM1HH[ADR[10:2]] <= DATI[31:24];
|
157 |
|
|
if (CERAM[1] & WE & SEL[2]) RAM1HL[ADR[10:2]] <= DATI[23:16];
|
158 |
|
|
if (CERAM[1] & WE & SEL[1]) RAM1LH[ADR[10:2]] <= DATI[15: 8];
|
159 |
|
|
if (CERAM[1] & WE & SEL[0]) RAM1LL[ADR[10:2]] <= DATI[ 7: 0];
|
160 |
|
|
if (CERAM[2] & WE & SEL[3]) RAM2HH[ADR[10:2]] <= DATI[31:24];
|
161 |
|
|
if (CERAM[2] & WE & SEL[2]) RAM2HL[ADR[10:2]] <= DATI[23:16];
|
162 |
|
|
if (CERAM[2] & WE & SEL[1]) RAM2LH[ADR[10:2]] <= DATI[15: 8];
|
163 |
|
|
if (CERAM[2] & WE & SEL[0]) RAM2LL[ADR[10:2]] <= DATI[ 7: 0];
|
164 |
|
|
if (CERAM[3] & WE & SEL[3]) RAM3HH[ADR[10:2]] <= DATI[31:24];
|
165 |
|
|
if (CERAM[3] & WE & SEL[2]) RAM3HL[ADR[10:2]] <= DATI[23:16];
|
166 |
|
|
if (CERAM[3] & WE & SEL[1]) RAM3LH[ADR[10:2]] <= DATI[15: 8];
|
167 |
|
|
if (CERAM[3] & WE & SEL[0]) RAM3LL[ADR[10:2]] <= DATI[ 7: 0];
|
168 |
|
|
if (CERAM[4] & WE & SEL[3]) RAM4HH[ADR[10:2]] <= DATI[31:24];
|
169 |
|
|
if (CERAM[4] & WE & SEL[2]) RAM4HL[ADR[10:2]] <= DATI[23:16];
|
170 |
|
|
if (CERAM[4] & WE & SEL[1]) RAM4LH[ADR[10:2]] <= DATI[15: 8];
|
171 |
|
|
if (CERAM[4] & WE & SEL[0]) RAM4LL[ADR[10:2]] <= DATI[ 7: 0];
|
172 |
|
|
if (CERAM[5] & WE & SEL[3]) RAM5HH[ADR[10:2]] <= DATI[31:24];
|
173 |
|
|
if (CERAM[5] & WE & SEL[2]) RAM5HL[ADR[10:2]] <= DATI[23:16];
|
174 |
|
|
if (CERAM[5] & WE & SEL[1]) RAM5LH[ADR[10:2]] <= DATI[15: 8];
|
175 |
|
|
if (CERAM[5] & WE & SEL[0]) RAM5LL[ADR[10:2]] <= DATI[ 7: 0];
|
176 |
|
|
if (CERAM[6] & WE & SEL[3]) RAM6HH[ADR[10:2]] <= DATI[31:24];
|
177 |
|
|
if (CERAM[6] & WE & SEL[2]) RAM6HL[ADR[10:2]] <= DATI[23:16];
|
178 |
|
|
if (CERAM[6] & WE & SEL[1]) RAM6LH[ADR[10:2]] <= DATI[15: 8];
|
179 |
|
|
if (CERAM[6] & WE & SEL[0]) RAM6LL[ADR[10:2]] <= DATI[ 7: 0];
|
180 |
|
|
if (CERAM[7] & WE & SEL[3]) RAM7HH[ADR[10:2]] <= DATI[31:24];
|
181 |
|
|
if (CERAM[7] & WE & SEL[2]) RAM7HL[ADR[10:2]] <= DATI[23:16];
|
182 |
|
|
if (CERAM[7] & WE & SEL[1]) RAM7LH[ADR[10:2]] <= DATI[15: 8];
|
183 |
|
|
if (CERAM[7] & WE & SEL[0]) RAM7LL[ADR[10:2]] <= DATI[ 7: 0];
|
184 |
|
|
ADR_RD <= ADR[10:2];
|
185 |
|
|
end
|
186 |
|
|
|
187 |
|
|
assign DATOUT0[31:24] = (CERAM[0]) ? RAM0HH[ADR_RD] : 8'h00;
|
188 |
|
|
assign DATOUT0[23:16] = (CERAM[0]) ? RAM0HL[ADR_RD] : 8'h00;
|
189 |
|
|
assign DATOUT0[15: 8] = (CERAM[0]) ? RAM0LH[ADR_RD] : 8'h00;
|
190 |
|
|
assign DATOUT0[ 7: 0] = (CERAM[0]) ? RAM0LL[ADR_RD] : 8'h00;
|
191 |
|
|
assign DATOUT1[31:24] = (CERAM[1]) ? RAM1HH[ADR_RD] : 8'h00;
|
192 |
|
|
assign DATOUT1[23:16] = (CERAM[1]) ? RAM1HL[ADR_RD] : 8'h00;
|
193 |
|
|
assign DATOUT1[15: 8] = (CERAM[1]) ? RAM1LH[ADR_RD] : 8'h00;
|
194 |
|
|
assign DATOUT1[ 7: 0] = (CERAM[1]) ? RAM1LL[ADR_RD] : 8'h00;
|
195 |
|
|
assign DATOUT2[31:24] = (CERAM[2]) ? RAM2HH[ADR_RD] : 8'h00;
|
196 |
|
|
assign DATOUT2[23:16] = (CERAM[2]) ? RAM2HL[ADR_RD] : 8'h00;
|
197 |
|
|
assign DATOUT2[15: 8] = (CERAM[2]) ? RAM2LH[ADR_RD] : 8'h00;
|
198 |
|
|
assign DATOUT2[ 7: 0] = (CERAM[2]) ? RAM2LL[ADR_RD] : 8'h00;
|
199 |
|
|
assign DATOUT3[31:24] = (CERAM[3]) ? RAM3HH[ADR_RD] : 8'h00;
|
200 |
|
|
assign DATOUT3[23:16] = (CERAM[3]) ? RAM3HL[ADR_RD] : 8'h00;
|
201 |
|
|
assign DATOUT3[15: 8] = (CERAM[3]) ? RAM3LH[ADR_RD] : 8'h00;
|
202 |
|
|
assign DATOUT3[ 7: 0] = (CERAM[3]) ? RAM3LL[ADR_RD] : 8'h00;
|
203 |
|
|
assign DATOUT4[31:24] = (CERAM[4]) ? RAM4HH[ADR_RD] : 8'h00;
|
204 |
|
|
assign DATOUT4[23:16] = (CERAM[4]) ? RAM4HL[ADR_RD] : 8'h00;
|
205 |
|
|
assign DATOUT4[15: 8] = (CERAM[4]) ? RAM4LH[ADR_RD] : 8'h00;
|
206 |
|
|
assign DATOUT4[ 7: 0] = (CERAM[4]) ? RAM4LL[ADR_RD] : 8'h00;
|
207 |
|
|
assign DATOUT5[31:24] = (CERAM[5]) ? RAM5HH[ADR_RD] : 8'h00;
|
208 |
|
|
assign DATOUT5[23:16] = (CERAM[5]) ? RAM5HL[ADR_RD] : 8'h00;
|
209 |
|
|
assign DATOUT5[15: 8] = (CERAM[5]) ? RAM5LH[ADR_RD] : 8'h00;
|
210 |
|
|
assign DATOUT5[ 7: 0] = (CERAM[5]) ? RAM5LL[ADR_RD] : 8'h00;
|
211 |
|
|
assign DATOUT6[31:24] = (CERAM[6]) ? RAM6HH[ADR_RD] : 8'h00;
|
212 |
|
|
assign DATOUT6[23:16] = (CERAM[6]) ? RAM6HL[ADR_RD] : 8'h00;
|
213 |
|
|
assign DATOUT6[15: 8] = (CERAM[6]) ? RAM6LH[ADR_RD] : 8'h00;
|
214 |
|
|
assign DATOUT6[ 7: 0] = (CERAM[6]) ? RAM6LL[ADR_RD] : 8'h00;
|
215 |
|
|
assign DATOUT7[31:24] = (CERAM[7]) ? RAM7HH[ADR_RD] : 8'h00;
|
216 |
|
|
assign DATOUT7[23:16] = (CERAM[7]) ? RAM7HL[ADR_RD] : 8'h00;
|
217 |
|
|
assign DATOUT7[15: 8] = (CERAM[7]) ? RAM7LH[ADR_RD] : 8'h00;
|
218 |
|
|
assign DATOUT7[ 7: 0] = (CERAM[7]) ? RAM7LL[ADR_RD] : 8'h00;
|
219 |
|
|
|
220 |
|
|
assign DATO = DATOUT0 | DATOUT1 | DATOUT2 | DATOUT3
|
221 |
|
|
| DATOUT4 | DATOUT5 | DATOUT6 | DATOUT7;
|
222 |
|
|
|
223 |
|
|
//======================================================
|
224 |
|
|
endmodule
|
225 |
|
|
//======================================================
|