1 |
2 |
tak.sugawa |
//Jun.29.2004 w0,w1,w2,w3 bug fix
|
2 |
|
|
//Jun.30.2004 endian bug fix
|
3 |
|
|
//Jul.1.2004 endian bug fix
|
4 |
|
|
//Apr.2.2005 Change Port Address
|
5 |
|
|
`include "define.h"
|
6 |
|
|
`define COMB_MOUT
|
7 |
|
|
`define COMB_MOUT_IR
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
`define NO_SIGNED_MOUT
|
11 |
|
|
module ram_module_altera(clock,sync_reset,IR,MOUT,Paddr,Daddr,wren,datain,access_mode,M_signed,
|
12 |
|
|
uread_port,write_busy);
|
13 |
|
|
input clock,sync_reset;
|
14 |
|
|
input wren;
|
15 |
|
|
input [31:0] datain;
|
16 |
|
|
input M_signed;
|
17 |
|
|
input [7:0] uread_port;
|
18 |
|
|
input write_busy;//Apr.2.2005
|
19 |
|
|
`ifdef RAM32K
|
20 |
|
|
|
21 |
|
|
input [14:0] Paddr,Daddr;//4KB address
|
22 |
|
|
reg [14:0] DaddrD;
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
`endif
|
26 |
|
|
|
27 |
|
|
`ifdef RAM16K
|
28 |
|
|
|
29 |
|
|
input [13:0] Paddr,Daddr;//4KB address
|
30 |
|
|
reg [13:0] DaddrD;
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
`endif
|
34 |
|
|
|
35 |
|
|
`ifdef RAM4K
|
36 |
|
|
input [11:0] Paddr,Daddr;//4KB address
|
37 |
|
|
reg [11:0] DaddrD;
|
38 |
|
|
|
39 |
|
|
`endif
|
40 |
|
|
|
41 |
|
|
output [31:0] IR;//Instrcuntion Register
|
42 |
|
|
output [31:0] MOUT;//data out
|
43 |
|
|
input [1:0] access_mode;
|
44 |
|
|
|
45 |
|
|
reg [31:0] IR;
|
46 |
|
|
reg [31:0] MOUT;
|
47 |
|
|
reg [1:0] access_modeD;
|
48 |
|
|
|
49 |
|
|
wire [7:0] a0,a1,a2,a3;
|
50 |
|
|
wire [7:0] b0,b1,b2,b3;
|
51 |
|
|
wire [7:0] dport0,dport1,dport2,dport3;
|
52 |
|
|
wire w0,w1,w2,w3;
|
53 |
|
|
wire uread_port_access=`UART_PORT_ADDRESS==Daddr;
|
54 |
|
|
|
55 |
|
|
reg uread_access_reg;
|
56 |
|
|
|
57 |
|
|
assign dport0=datain[7:0] ;
|
58 |
|
|
assign dport1=access_mode !=`BYTE_ACCESS ? datain[15:8] : datain[7:0];
|
59 |
|
|
assign dport2=access_mode==`LONG_ACCESS ? datain[23:16] : datain[7:0];
|
60 |
|
|
assign dport3=access_mode==`LONG_ACCESS ? datain[31:24] :
|
61 |
|
|
access_mode==`WORD_ACCESS ? datain[15:8] : datain[7:0];
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
`ifdef RAM32K
|
65 |
|
|
ram8192x8_3 ram0(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[14:2]),
|
66 |
|
|
.data_b(dport0),.address_b(Daddr[14:2]),.wren_b(w0),.clock(clock),
|
67 |
|
|
.q_a(a0),.q_b(b0));
|
68 |
|
|
|
69 |
|
|
ram8192x8_2 ram1(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[14:2]),
|
70 |
|
|
.data_b(dport1),.address_b(Daddr[14:2]),.wren_b(w1),.clock(clock),
|
71 |
|
|
.q_a(a1),.q_b(b1));
|
72 |
|
|
|
73 |
|
|
ram8192x8_1 ram2(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[14:2]),
|
74 |
|
|
.data_b(dport2),.address_b(Daddr[14:2]),.wren_b(w2),.clock(clock),
|
75 |
|
|
.q_a(a2),.q_b(b2));
|
76 |
|
|
|
77 |
|
|
ram8192x8_0 ram3(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[14:2]),
|
78 |
|
|
.data_b(dport3),.address_b(Daddr[14:2]),.wren_b(w3),.clock(clock),
|
79 |
|
|
.q_a(a3),.q_b(b3));
|
80 |
|
|
|
81 |
|
|
`endif
|
82 |
|
|
`ifdef RAM16K
|
83 |
|
|
`ifdef ALTERA
|
84 |
|
|
ram4096x8_3 ram0(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[13:2]),
|
85 |
|
|
.data_b(dport0),.address_b(Daddr[13:2]),.wren_b(w0),.clock(clock),
|
86 |
|
|
.q_a(a0),.q_b(b0));
|
87 |
|
|
|
88 |
|
|
ram4096x8_2 ram1(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[13:2]),
|
89 |
|
|
.data_b(dport1),.address_b(Daddr[13:2]),.wren_b(w1),.clock(clock),
|
90 |
|
|
.q_a(a1),.q_b(b1));
|
91 |
|
|
|
92 |
|
|
ram4092x8_1 ram2(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[13:2]),
|
93 |
|
|
.data_b(dport2),.address_b(Daddr[13:2]),.wren_b(w2),.clock(clock),
|
94 |
|
|
.q_a(a2),.q_b(b2));
|
95 |
|
|
|
96 |
|
|
ram4092x8_0 ram3(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[13:2]),
|
97 |
|
|
.data_b(dport3),.address_b(Daddr[13:2]),.wren_b(w3),.clock(clock),
|
98 |
|
|
.q_a(a3),.q_b(b3));
|
99 |
|
|
`else
|
100 |
|
|
ram1k3 ram0(.addra(Paddr[13:2]),
|
101 |
|
|
.dinb(dport0),.addrb(Daddr[13:2]),.web(w0),.clka(clock),.clkb(clock),
|
102 |
|
|
.douta(a0),.doutb(b0));
|
103 |
|
|
ram1k2 ram1(.addra(Paddr[13:2]),
|
104 |
|
|
.dinb(dport1),.addrb(Daddr[13:2]),.web(w1),.clka(clock),.clkb(clock),
|
105 |
|
|
.douta(a1),.doutb(b1));
|
106 |
|
|
ram1k1 ram2(.addra(Paddr[13:2]),
|
107 |
|
|
.dinb(dport2),.addrb(Daddr[13:2]),.web(w2),.clka(clock),.clkb(clock),
|
108 |
|
|
.douta(a2),.doutb(b2));
|
109 |
|
|
ram1k0 ram3(.addra(Paddr[13:2]),
|
110 |
|
|
.dinb(dport3),.addrb(Daddr[13:2]),.web(w3),.clka(clock),.clkb(clock),
|
111 |
|
|
.douta(a3),.doutb(b3));
|
112 |
|
|
`endif
|
113 |
|
|
`endif
|
114 |
|
|
|
115 |
|
|
`ifdef RAM4K
|
116 |
|
|
ram_1k_3 ram0(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[11:2]),
|
117 |
|
|
.data_b(dport0),.address_b(Daddr[11:2]),.wren_b(w0),.clock(clock),
|
118 |
|
|
.q_a(a0),.q_b(b0));
|
119 |
|
|
|
120 |
|
|
ram_1k_2 ram1(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[11:2]),
|
121 |
|
|
.data_b(dport1),.address_b(Daddr[11:2]),.wren_b(w1),.clock(clock),
|
122 |
|
|
.q_a(a1),.q_b(b1));
|
123 |
|
|
|
124 |
|
|
ram_1k_1 ram2(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[11:2]),
|
125 |
|
|
.data_b(dport2),.address_b(Daddr[11:2]),.wren_b(w2),.clock(clock),
|
126 |
|
|
.q_a(a2),.q_b(b2));
|
127 |
|
|
|
128 |
|
|
ram_1k_0 ram3(.data_a(8'h00),.wren_a(1'b0),.address_a(Paddr[11:2]),
|
129 |
|
|
.data_b(dport3),.address_b(Daddr[11:2]),.wren_b(w3),.clock(clock),
|
130 |
|
|
.q_a(a3),.q_b(b3));
|
131 |
|
|
|
132 |
|
|
`endif
|
133 |
|
|
|
134 |
|
|
wire temp=( access_mode==`BYTE_ACCESS && Daddr[1:0]==2'b00);
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
assign w3= wren &&
|
138 |
|
|
( access_mode==`LONG_ACCESS ||
|
139 |
|
|
( access_mode==`WORD_ACCESS && !Daddr[1] ) ||
|
140 |
|
|
( access_mode==`BYTE_ACCESS && Daddr[1:0]==2'b00));
|
141 |
|
|
assign w2= wren &&
|
142 |
|
|
( access_mode==`LONG_ACCESS ||
|
143 |
|
|
( access_mode==`WORD_ACCESS && !Daddr[1]) ||
|
144 |
|
|
( Daddr[1:0]==2'b01));
|
145 |
|
|
assign w1= wren &&
|
146 |
|
|
( access_mode==`LONG_ACCESS ||
|
147 |
|
|
( access_mode==`WORD_ACCESS && Daddr[1]) ||
|
148 |
|
|
( Daddr[1:0]==2'b10));
|
149 |
|
|
assign w0= wren &&
|
150 |
|
|
( access_mode==`LONG_ACCESS ||
|
151 |
|
|
( access_mode==`WORD_ACCESS && Daddr[1]) ||
|
152 |
|
|
( Daddr[1:0]==2'b11));
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
//IR
|
156 |
|
|
|
157 |
|
|
`ifdef COMB_MOUT_IR
|
158 |
|
|
|
159 |
|
|
always @(*) IR={a3,a2,a1,a0};
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
`else
|
163 |
|
|
always @(posedge clock) begin
|
164 |
|
|
if (sync_reset) IR <=0;
|
165 |
|
|
else IR <={a3,a2,a1,a0};
|
166 |
|
|
|
167 |
|
|
end
|
168 |
|
|
`endif
|
169 |
|
|
|
170 |
|
|
always @(posedge clock) begin
|
171 |
|
|
if (access_modeD==`LONG_ACCESS) begin
|
172 |
|
|
if(uread_access_reg) begin
|
173 |
|
|
MOUT <={23'h00_0000,write_busy,uread_port};
|
174 |
|
|
end else
|
175 |
|
|
MOUT <={b3,b2,b1,b0};
|
176 |
|
|
|
177 |
|
|
end else if (access_modeD==`WORD_ACCESS) begin
|
178 |
|
|
case (DaddrD[1])
|
179 |
|
|
1'b0: if(M_signed) MOUT <={{16{b3[7]}},b3,b2};//Jul.1.2004
|
180 |
|
|
else MOUT <={16'h0000,b3,b2};
|
181 |
|
|
1'b1: if(M_signed) MOUT <={{16{b1[7]}},b1,b0};//Jul.1.2004
|
182 |
|
|
else MOUT <={16'h0000,b1,b0};
|
183 |
|
|
endcase
|
184 |
|
|
end else begin//BYTE ACCESSS
|
185 |
|
|
case (DaddrD[1:0])
|
186 |
|
|
2'b00:if(M_signed) MOUT <={{24{b3[7]}},b3};
|
187 |
|
|
else MOUT <={16'h0000,8'h00,b3};
|
188 |
|
|
2'b01:if(M_signed) MOUT <={{24{b2[7]}},b2};
|
189 |
|
|
else MOUT <={16'h0000,8'h00,b2};
|
190 |
|
|
2'b10:if(M_signed) MOUT <={{24{b1[7]}},b1};
|
191 |
|
|
else MOUT <={16'h0000,8'h00,b1};
|
192 |
|
|
2'b11:if(M_signed) MOUT <={{24{b0[7]}},b0};
|
193 |
|
|
else MOUT <={16'h0000,8'h00,b0};
|
194 |
|
|
endcase
|
195 |
|
|
end
|
196 |
|
|
end
|
197 |
|
|
|
198 |
|
|
always @(posedge clock) begin
|
199 |
|
|
access_modeD<=access_mode;
|
200 |
|
|
DaddrD<=Daddr;
|
201 |
|
|
uread_access_reg<=uread_port_access;//Jul.7.2004
|
202 |
|
|
end
|
203 |
|
|
endmodule
|
204 |
|
|
|
205 |
|
|
|