1 |
2 |
des00 |
//
|
2 |
|
|
// Project : High-Speed SDRAM Controller with adaptive bank management and command pipeline
|
3 |
|
|
//
|
4 |
|
|
// Project Nick : HSSDRC
|
5 |
|
|
//
|
6 |
|
|
// Version : 1.0-beta
|
7 |
|
|
//
|
8 |
|
|
// Revision : $Revision: 1.1 $
|
9 |
|
|
//
|
10 |
|
|
// Date : $Date: 2008-03-06 13:52:43 $
|
11 |
|
|
//
|
12 |
|
|
// Workfile : hssdrc_addr_path_p1.v
|
13 |
|
|
//
|
14 |
|
|
// Description : coder for translate logical onehot command to sdram command
|
15 |
|
|
//
|
16 |
|
|
// HSSDRC is licensed under MIT License
|
17 |
|
|
//
|
18 |
|
|
// Copyright (c) 2007-2008, Denis V.Shekhalev (des00@opencores.org)
|
19 |
|
|
//
|
20 |
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
21 |
|
|
// this software and associated documentation files (the "Software"), to deal in
|
22 |
|
|
// the Software without restriction, including without limitation the rights to
|
23 |
|
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
24 |
|
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
25 |
|
|
// subject to the following conditions:
|
26 |
|
|
//
|
27 |
|
|
// The above copyright notice and this permission notice shall be included in all
|
28 |
|
|
// copies or substantial portions of the Software.
|
29 |
|
|
//
|
30 |
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
31 |
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
32 |
|
|
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
33 |
|
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
34 |
|
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
35 |
|
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
36 |
|
|
//
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
`include "hssdrc_timescale.vh"
|
40 |
|
|
|
41 |
|
|
`include "hssdrc_define.vh"
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
module hssdrc_addr_path_p1(
|
45 |
|
|
clk ,
|
46 |
|
|
reset ,
|
47 |
|
|
sclr ,
|
48 |
|
|
//
|
49 |
|
|
arb_pre_all ,
|
50 |
|
|
arb_refr ,
|
51 |
|
|
arb_pre ,
|
52 |
|
|
arb_act ,
|
53 |
|
|
arb_read ,
|
54 |
|
|
arb_write ,
|
55 |
|
|
arb_lmr ,
|
56 |
|
|
arb_rowa ,
|
57 |
|
|
arb_cola ,
|
58 |
|
|
arb_ba ,
|
59 |
|
|
//
|
60 |
|
|
addr ,
|
61 |
|
|
ba ,
|
62 |
|
|
cke ,
|
63 |
|
|
cs_n ,
|
64 |
|
|
ras_n ,
|
65 |
|
|
cas_n ,
|
66 |
|
|
we_n
|
67 |
|
|
);
|
68 |
|
|
|
69 |
|
|
input wire clk;
|
70 |
|
|
input wire reset;
|
71 |
|
|
input wire sclr;
|
72 |
|
|
|
73 |
|
|
//--------------------------------------------------------------------------------------------------
|
74 |
|
|
// interface from output arbiter
|
75 |
|
|
//--------------------------------------------------------------------------------------------------
|
76 |
|
|
|
77 |
|
|
input wire arb_pre_all ;
|
78 |
|
|
input wire arb_refr ;
|
79 |
|
|
input wire arb_pre ;
|
80 |
|
|
input wire arb_act ;
|
81 |
|
|
input wire arb_read ;
|
82 |
|
|
input wire arb_write ;
|
83 |
|
|
input wire arb_lmr ;
|
84 |
|
|
input rowa_t arb_rowa ;
|
85 |
|
|
input cola_t arb_cola ;
|
86 |
|
|
input ba_t arb_ba ;
|
87 |
|
|
|
88 |
|
|
//--------------------------------------------------------------------------------------------------
|
89 |
|
|
// interface to sdram
|
90 |
|
|
//--------------------------------------------------------------------------------------------------
|
91 |
|
|
|
92 |
|
|
output sdram_addr_t addr;
|
93 |
|
|
output ba_t ba;
|
94 |
|
|
output logic cke;
|
95 |
|
|
output logic cs_n;
|
96 |
|
|
output logic ras_n;
|
97 |
|
|
output logic cas_n;
|
98 |
|
|
output logic we_n;
|
99 |
|
|
|
100 |
|
|
//
|
101 |
|
|
//
|
102 |
|
|
//
|
103 |
|
|
|
104 |
|
|
logic [3:0] cs_n__ras_n__cas_n__we_n;
|
105 |
|
|
|
106 |
|
|
sdram_addr_t addr_latched;
|
107 |
|
|
ba_t ba_latched;
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
//--------------------------------------------------------------------------------------------------
|
111 |
|
|
//
|
112 |
|
|
//--------------------------------------------------------------------------------------------------
|
113 |
|
|
|
114 |
|
|
always_ff @(posedge clk or posedge reset) begin : logical_command_decode
|
115 |
|
|
if (reset)
|
116 |
|
|
cs_n__ras_n__cas_n__we_n <= 4'b1111; // inheribit nop
|
117 |
|
|
else if (sclr)
|
118 |
|
|
cs_n__ras_n__cas_n__we_n <= 4'b1111; // inheribit nop
|
119 |
|
|
else begin
|
120 |
|
|
unique case (1'b1)
|
121 |
|
|
arb_pre_all : cs_n__ras_n__cas_n__we_n <= 4'b0010; // Pre
|
122 |
|
|
arb_refr : cs_n__ras_n__cas_n__we_n <= 4'b0001; // Refr
|
123 |
|
|
arb_pre : cs_n__ras_n__cas_n__we_n <= 4'b0010; // Pre
|
124 |
|
|
arb_act : cs_n__ras_n__cas_n__we_n <= 4'b0011; // Act
|
125 |
|
|
arb_write : cs_n__ras_n__cas_n__we_n <= 4'b0100; // Write
|
126 |
|
|
arb_read : cs_n__ras_n__cas_n__we_n <= 4'b0101; // Read
|
127 |
|
|
arb_lmr : cs_n__ras_n__cas_n__we_n <= 4'b0000; // Lmr (data == address)
|
128 |
|
|
default : cs_n__ras_n__cas_n__we_n <= 4'b0111;
|
129 |
|
|
endcase
|
130 |
|
|
end
|
131 |
|
|
end
|
132 |
|
|
|
133 |
|
|
//
|
134 |
|
|
// don't use clocking disable
|
135 |
|
|
//
|
136 |
|
|
|
137 |
|
|
assign cke = 1'b1;
|
138 |
|
|
|
139 |
|
|
// synthesis translate_off
|
140 |
|
|
initial begin
|
141 |
|
|
{cs_n, ras_n, cas_n, we_n} <= 4'b1111; // only to disable mt48lc2m warnings
|
142 |
|
|
end
|
143 |
|
|
// synthesis translate_on
|
144 |
|
|
|
145 |
|
|
always_ff @(posedge clk or posedge reset) begin : sdram_control_register
|
146 |
|
|
if (reset) {cs_n, ras_n, cas_n, we_n} <= 4'b1111; // inheribit nop
|
147 |
|
|
else if (sclr) {cs_n, ras_n, cas_n, we_n} <= 4'b1111; // inheribit nop
|
148 |
|
|
else {cs_n, ras_n, cas_n, we_n} <= cs_n__ras_n__cas_n__we_n;
|
149 |
|
|
end
|
150 |
|
|
|
151 |
|
|
always_ff @(posedge clk) begin : sdram_mux_addr_path
|
152 |
|
|
|
153 |
|
|
ba_latched <= arb_ba;
|
154 |
|
|
ba <= ba_latched;
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
if (arb_act | arb_lmr)
|
158 |
|
|
addr_latched <= ResizeRowa(arb_rowa);
|
159 |
|
|
else
|
160 |
|
|
addr_latched <= ResizeCola(arb_cola, arb_pre_all);
|
161 |
|
|
|
162 |
|
|
addr <= addr_latched;
|
163 |
|
|
end
|
164 |
|
|
|
165 |
|
|
//--------------------------------------------------------------------------------------------------
|
166 |
|
|
// function to get sdram address from row address. row address is transfered during
|
167 |
|
|
// act/lmr sdram command and is directly mapped to row address.
|
168 |
|
|
//--------------------------------------------------------------------------------------------------
|
169 |
|
|
|
170 |
|
|
function sdram_addr_t ResizeRowa (input rowa_t rowa);
|
171 |
|
|
int i;
|
172 |
|
|
sdram_addr_t addr_resized;
|
173 |
|
|
|
174 |
|
|
for (i = 0; i < pSdramAddrBits; i++) begin
|
175 |
|
|
if (pRowaBits > i)
|
176 |
|
|
addr_resized[i] = rowa[i];
|
177 |
|
|
else
|
178 |
|
|
addr_resized[i] = 1'b0;
|
179 |
|
|
end
|
180 |
|
|
|
181 |
|
|
return addr_resized;
|
182 |
|
|
endfunction
|
183 |
|
|
|
184 |
|
|
//--------------------------------------------------------------------------------------------------
|
185 |
|
|
// function to get sdram address from column address. column address is transfered during :
|
186 |
|
|
// 1. read/write sdram command and A10 is autoprecharge bit and if pColaBits > 10 then
|
187 |
|
|
// cola [$:10] is mapped to addr [$:11].
|
188 |
|
|
// 2. pre sdram command and A10 is select all banks bit
|
189 |
|
|
//--------------------------------------------------------------------------------------------------
|
190 |
|
|
|
191 |
|
|
function sdram_addr_t ResizeCola (input cola_t cola, input bit pre_all);
|
192 |
|
|
int i;
|
193 |
|
|
sdram_addr_t addr_resized;
|
194 |
|
|
|
195 |
|
|
for (i = 0; i < pSdramAddrBits; i++) begin
|
196 |
|
|
if (i < 10) begin
|
197 |
|
|
if (pColaBits > i)
|
198 |
|
|
addr_resized[i] = cola[i];
|
199 |
|
|
else
|
200 |
|
|
addr_resized[i] = 1'b0;
|
201 |
|
|
end
|
202 |
|
|
else if (i == 10) begin
|
203 |
|
|
addr_resized[i] = pre_all; // Autoprecharge is not used -> A10 is always 1'b0 then read/write active
|
204 |
|
|
end
|
205 |
|
|
else begin
|
206 |
|
|
if (pColaBits > i)
|
207 |
|
|
addr_resized[i] = cola[i-1];
|
208 |
|
|
else
|
209 |
|
|
addr_resized[i] = 1'b0;
|
210 |
|
|
end
|
211 |
|
|
end
|
212 |
|
|
|
213 |
|
|
return addr_resized;
|
214 |
|
|
endfunction
|
215 |
|
|
|
216 |
|
|
endmodule
|