1 |
3 |
dinesha |
/*********************************************************************
|
2 |
|
|
|
3 |
|
|
SDRAM Controller Request Generation
|
4 |
|
|
|
5 |
|
|
This file is part of the sdram controller project
|
6 |
|
|
http://www.opencores.org/cores/sdr_ctrl/
|
7 |
|
|
|
8 |
|
|
Description: SDRAM Controller Reguest Generation
|
9 |
|
|
The 2Mx32 SDRAM is addressed by a 21 bit address,
|
10 |
|
|
each loation is 32 bits wide.
|
11 |
|
|
This 21 bit address is mapped as follows:
|
12 |
|
|
ADDR [7:0] : Column Address (256 columns)
|
13 |
|
|
ADDR [18:8] : Row Address (2K Rows)
|
14 |
|
|
ADDR [20:19] : Bank Address (2 banks)
|
15 |
|
|
|
16 |
|
|
The 4Mx16 SDRAM is addressed by a 22 bit address,
|
17 |
|
|
each loation is 16 bits wide.
|
18 |
|
|
This 22 bit address is mapped as follows:
|
19 |
|
|
ADDR [7:0] : Column Address (256 columns)
|
20 |
|
|
ADDR [21:10] : Row Address (4K Rows)
|
21 |
|
|
ADDR [21:20] : Bank Address (4 banks)
|
22 |
|
|
|
23 |
|
|
The 8Mx16 SDRAM is addressed by a 23 bit address,
|
24 |
|
|
each loation is 16 bits wide.
|
25 |
|
|
This 23 bit address is mapped as follows:
|
26 |
|
|
ADDR [8:0] : Column Address (512 columns)
|
27 |
|
|
ADDR [20:9] : Row Address (4K Rows)
|
28 |
|
|
ADDR [22:21] : Bank Address (4 banks)
|
29 |
|
|
|
30 |
|
|
The SDRAMs are operated in 4 beat burst mode.
|
31 |
|
|
This module takes requests from the mc,
|
32 |
|
|
chops them to page boundaries if wrap=0,
|
33 |
|
|
and passes the request to bank_ctl
|
34 |
|
|
|
35 |
|
|
To Do:
|
36 |
|
|
nothing
|
37 |
|
|
|
38 |
|
|
Author(s):
|
39 |
|
|
- Dinesh Annayya, dinesha@opencores.org
|
40 |
|
|
Version : 1.0 - 8th Jan 2012
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
Copyright (C) 2000 Authors and OPENCORES.ORG
|
45 |
|
|
|
46 |
|
|
This source file may be used and distributed without
|
47 |
|
|
restriction provided that this copyright statement is not
|
48 |
|
|
removed from the file and that any derivative work contains
|
49 |
|
|
the original copyright notice and the associated disclaimer.
|
50 |
|
|
|
51 |
|
|
This source file is free software; you can redistribute it
|
52 |
|
|
and/or modify it under the terms of the GNU Lesser General
|
53 |
|
|
Public License as published by the Free Software Foundation;
|
54 |
|
|
either version 2.1 of the License, or (at your option) any
|
55 |
|
|
later version.
|
56 |
|
|
|
57 |
|
|
This source is distributed in the hope that it will be
|
58 |
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied
|
59 |
|
|
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
60 |
|
|
PURPOSE. See the GNU Lesser General Public License for more
|
61 |
|
|
details.
|
62 |
|
|
|
63 |
|
|
You should have received a copy of the GNU Lesser General
|
64 |
|
|
Public License along with this source; if not, download it
|
65 |
|
|
from http://www.opencores.org/lgpl.shtml
|
66 |
|
|
|
67 |
|
|
*******************************************************************/
|
68 |
|
|
|
69 |
|
|
`include "sdrc.def"
|
70 |
|
|
|
71 |
|
|
module sdrc_req_gen (clk,
|
72 |
|
|
reset_n,
|
73 |
|
|
|
74 |
|
|
/* Request from app */
|
75 |
|
|
req, // Transfer Request
|
76 |
|
|
req_id, // ID for this transfer
|
77 |
|
|
req_addr, // SDRAM Address
|
78 |
|
|
req_addr_mask,
|
79 |
|
|
req_len, // Burst Length (in 32 bit words)
|
80 |
|
|
req_wrap, // Wrap mode request (xfr_len = 4)
|
81 |
|
|
req_wr_n, // 0 => Write request, 1 => read req
|
82 |
|
|
req_ack, // Request has been accepted
|
83 |
|
|
sdr_core_busy_n, // SDRAM Core Busy Indication
|
84 |
|
|
sdr_dev_config, // sdram configuration
|
85 |
|
|
|
86 |
|
|
/* Req to bank_ctl */
|
87 |
|
|
r2x_idle,
|
88 |
|
|
r2b_req, // request
|
89 |
|
|
r2b_req_id, // ID
|
90 |
|
|
r2b_start, // First chunk of burst
|
91 |
|
|
r2b_last, // Last chunk of burst
|
92 |
|
|
r2b_wrap, // Wrap Mode
|
93 |
|
|
r2b_ba, // bank address
|
94 |
|
|
r2b_raddr, // row address
|
95 |
|
|
r2b_caddr, // col address
|
96 |
|
|
r2b_len, // length
|
97 |
|
|
r2b_write, // write request
|
98 |
|
|
b2r_ack,
|
99 |
|
|
b2r_arb_ok,
|
100 |
|
|
sdr_width,
|
101 |
|
|
sdr_init_done);
|
102 |
|
|
|
103 |
|
|
parameter APP_AW = 30; // Application Address Width
|
104 |
|
|
parameter APP_DW = 32; // Application Data Width
|
105 |
|
|
parameter APP_BW = 4; // Application Byte Width
|
106 |
|
|
parameter APP_RW = 9; // Application Request Width
|
107 |
|
|
|
108 |
|
|
parameter SDR_DW = 16; // SDR Data Width
|
109 |
|
|
parameter SDR_BW = 2; // SDR Byte Width
|
110 |
|
|
|
111 |
|
|
input clk, reset_n;
|
112 |
|
|
|
113 |
|
|
/* Request from app */
|
114 |
|
|
input req;
|
115 |
|
|
input [`SDR_REQ_ID_W-1:0] req_id;
|
116 |
|
|
input [APP_AW:0] req_addr;
|
117 |
|
|
input [APP_AW-2:0] req_addr_mask;
|
118 |
|
|
input [APP_RW-1:0] req_len;
|
119 |
|
|
input req_wr_n, req_wrap;
|
120 |
|
|
output req_ack, sdr_core_busy_n;
|
121 |
|
|
|
122 |
|
|
/* Req to bank_ctl */
|
123 |
|
|
output r2x_idle, r2b_req, r2b_start, r2b_last,
|
124 |
|
|
r2b_write, r2b_wrap;
|
125 |
|
|
output [`SDR_REQ_ID_W-1:0] r2b_req_id;
|
126 |
|
|
output [1:0] r2b_ba;
|
127 |
|
|
output [11:0] r2b_raddr;
|
128 |
|
|
output [11:0] r2b_caddr;
|
129 |
|
|
output [APP_RW-1:0] r2b_len;
|
130 |
|
|
input b2r_ack, b2r_arb_ok, sdr_init_done;
|
131 |
|
|
//
|
132 |
|
|
input sdr_width;
|
133 |
|
|
input [1:0] sdr_dev_config;
|
134 |
|
|
|
135 |
|
|
/****************************************************************************/
|
136 |
|
|
// Internal Nets
|
137 |
|
|
|
138 |
|
|
`define REQ_IDLE 1'b0
|
139 |
|
|
`define REQ_ACTIVE 1'b1
|
140 |
|
|
|
141 |
|
|
reg req_st, next_req_st;
|
142 |
|
|
reg r2x_idle, req_ack, r2b_req, r2b_start,
|
143 |
|
|
r2b_write, req_idle, req_ld, lcl_wrap;
|
144 |
|
|
reg [`SDR_REQ_ID_W-1:0] r2b_req_id;
|
145 |
|
|
reg [APP_RW-1:0] lcl_req_len;
|
146 |
|
|
|
147 |
|
|
wire r2b_last, page_ovflw;
|
148 |
|
|
wire [APP_RW-1:0] r2b_len, next_req_len;
|
149 |
|
|
wire [APP_RW:0] max_r2b_len;
|
150 |
|
|
|
151 |
|
|
wire [1:0] r2b_ba;
|
152 |
|
|
wire [11:0] r2b_raddr;
|
153 |
|
|
wire [11:0] r2b_caddr;
|
154 |
|
|
|
155 |
|
|
reg [APP_AW-1:0] curr_sdr_addr, sdr_addrs_mask;
|
156 |
|
|
wire [APP_AW-1:0] next_sdr_addr, next_sdr_addr1;
|
157 |
|
|
|
158 |
|
|
//
|
159 |
|
|
// The maximum length for no page overflow is 200h/100h - caddr. Split a request
|
160 |
|
|
// into 2 or more requests if it crosses a page boundary.
|
161 |
|
|
// For non-queue accesses req_addr_mask is set to all 1 and the accesses
|
162 |
|
|
// proceed linearly.
|
163 |
|
|
// All queues end on a 512 byte boundary (actually a 1K boundary). For Q
|
164 |
|
|
// accesses req_addr_mask is set to LSB of 1 and MSB of 0 to constrain the
|
165 |
|
|
// accesses within the space for a Q. When splitting and calculating the next
|
166 |
|
|
// address only the LSBs are incremented, the MSBs remain = req_addr.
|
167 |
|
|
//
|
168 |
|
|
assign max_r2b_len = (sdr_width == 1'b0) ? ((sdr_dev_config == `SDR_CONFIG_IS_32M) ? (12'h200 - r2b_caddr) : (12'h100 - r2b_caddr)) :
|
169 |
|
|
(sdr_dev_config == `SDR_CONFIG_IS_8M) ? (12'h100 - r2b_caddr) : (12'h200 - r2b_caddr);
|
170 |
|
|
|
171 |
|
|
assign page_ovflw = ({1'b0, lcl_req_len} > max_r2b_len) ? ~lcl_wrap : 1'b0;
|
172 |
|
|
|
173 |
|
|
assign r2b_len = (page_ovflw) ? max_r2b_len : lcl_req_len;
|
174 |
|
|
|
175 |
|
|
assign next_req_len = lcl_req_len - r2b_len;
|
176 |
|
|
|
177 |
|
|
assign next_sdr_addr1 = curr_sdr_addr + r2b_len;
|
178 |
|
|
|
179 |
|
|
// Wrap back based on the mask
|
180 |
|
|
assign next_sdr_addr = (sdr_addrs_mask & next_sdr_addr1) |
|
181 |
|
|
(~sdr_addrs_mask & curr_sdr_addr);
|
182 |
|
|
|
183 |
|
|
assign sdr_core_busy_n = req_idle & b2r_arb_ok & sdr_init_done;
|
184 |
|
|
|
185 |
|
|
assign r2b_wrap = lcl_wrap;
|
186 |
|
|
|
187 |
|
|
assign r2b_last = ~page_ovflw;
|
188 |
|
|
//
|
189 |
|
|
//
|
190 |
|
|
//
|
191 |
|
|
always @ (posedge clk) begin
|
192 |
|
|
|
193 |
|
|
r2b_start <= (req_ack) ? 1'b1 :
|
194 |
|
|
(b2r_ack) ? 1'b0 : r2b_start;
|
195 |
|
|
|
196 |
|
|
r2b_write <= (req_ack) ? ~req_wr_n : r2b_write;
|
197 |
|
|
|
198 |
|
|
r2b_req_id <= (req_ack) ? req_id : r2b_req_id;
|
199 |
|
|
|
200 |
|
|
lcl_wrap <= (req_ack) ? req_wrap : lcl_wrap;
|
201 |
|
|
|
202 |
|
|
lcl_req_len <= (req_ack) ? req_len :
|
203 |
|
|
(req_ld) ? next_req_len : lcl_req_len;
|
204 |
|
|
|
205 |
|
|
curr_sdr_addr <= (req_ack) ? req_addr :
|
206 |
|
|
(req_ld) ? next_sdr_addr : curr_sdr_addr;
|
207 |
|
|
|
208 |
|
|
sdr_addrs_mask <= (req_ack) ? (sdr_width ? {req_addr_mask,req_addr_mask[0]} : req_addr_mask) : sdr_addrs_mask;
|
209 |
|
|
|
210 |
|
|
end // always @ (posedge clk)
|
211 |
|
|
|
212 |
|
|
always @ (*) begin
|
213 |
|
|
|
214 |
|
|
case (req_st) // synopsys full_case parallel_case
|
215 |
|
|
|
216 |
|
|
`REQ_IDLE : begin
|
217 |
|
|
r2x_idle = ~req;
|
218 |
|
|
req_idle = 1'b1;
|
219 |
|
|
req_ack = req & b2r_arb_ok;
|
220 |
|
|
req_ld = 1'b0;
|
221 |
|
|
r2b_req = 1'b0;
|
222 |
|
|
next_req_st = (req & b2r_arb_ok) ? `REQ_ACTIVE : `REQ_IDLE;
|
223 |
|
|
end // case: `REQ_IDLE
|
224 |
|
|
|
225 |
|
|
`REQ_ACTIVE : begin
|
226 |
|
|
r2x_idle = 1'b0;
|
227 |
|
|
req_idle = 1'b0;
|
228 |
|
|
req_ack = 1'b0;
|
229 |
|
|
req_ld = b2r_ack;
|
230 |
|
|
r2b_req = 1'b1; // req_gen to bank_req
|
231 |
|
|
next_req_st = (b2r_ack & r2b_last) ? `REQ_IDLE : `REQ_ACTIVE;
|
232 |
|
|
end // case: `REQ_ACTIVE
|
233 |
|
|
|
234 |
|
|
endcase // case(req_st)
|
235 |
|
|
|
236 |
|
|
end // always @ (req_st or ....)
|
237 |
|
|
|
238 |
|
|
always @ (posedge clk)
|
239 |
|
|
if (~reset_n) begin
|
240 |
|
|
req_st <= `REQ_IDLE;
|
241 |
|
|
end // if (~reset_n)
|
242 |
|
|
else begin
|
243 |
|
|
req_st <= next_req_st;
|
244 |
|
|
end // else: !if(~reset_n)
|
245 |
|
|
//
|
246 |
|
|
// addrs bits for the bank, row and column
|
247 |
|
|
//
|
248 |
|
|
// SDR_CONFIG_IS_8M 2'b00
|
249 |
|
|
// SDR_CONFIG_IS_16M 2'b01
|
250 |
|
|
// SDR_CONFIG_IS_32M 2'b10
|
251 |
|
|
// SDR_CONFIG_IS_LGCY 2'b11
|
252 |
|
|
//
|
253 |
|
|
assign r2b_ba = ({sdr_width,sdr_dev_config} == {1'b0,`SDR_CONFIG_IS_8M}) ? curr_sdr_addr[20:19] :
|
254 |
|
|
({sdr_width,sdr_dev_config} == {1'b0,`SDR_CONFIG_IS_16M}) ? curr_sdr_addr[21:20] :
|
255 |
|
|
({sdr_width,sdr_dev_config} == {1'b0,`SDR_CONFIG_IS_32M}) ? curr_sdr_addr[22:21] :
|
256 |
|
|
({sdr_width,sdr_dev_config} == {1'b1,`SDR_CONFIG_IS_8M}) ? curr_sdr_addr[21:20] :
|
257 |
|
|
({sdr_width,sdr_dev_config} == {1'b1,`SDR_CONFIG_IS_16M}) ? curr_sdr_addr[22:21]:
|
258 |
|
|
({sdr_width,sdr_dev_config} == {1'b1,`SDR_CONFIG_IS_32M}) ? curr_sdr_addr[23:22] : curr_sdr_addr[9:8];
|
259 |
|
|
|
260 |
|
|
assign r2b_caddr = ({sdr_width,sdr_dev_config} == {1'b0,`SDR_CONFIG_IS_8M}) ? {4'b0, curr_sdr_addr[7:0]} :
|
261 |
|
|
({sdr_width,sdr_dev_config} == {1'b0,`SDR_CONFIG_IS_16M}) ? {4'b0, curr_sdr_addr[7:0]} :
|
262 |
|
|
({sdr_width,sdr_dev_config} == {1'b0,`SDR_CONFIG_IS_32M}) ? {3'b0, curr_sdr_addr[8:0]} :
|
263 |
|
|
({sdr_width,sdr_dev_config} == {1'b1,`SDR_CONFIG_IS_8M}) ? {3'b0, curr_sdr_addr[7:0]} :
|
264 |
|
|
({sdr_width,sdr_dev_config} == {1'b1,`SDR_CONFIG_IS_16M}) ? {3'b0, curr_sdr_addr[8:0]} :
|
265 |
|
|
({sdr_width,sdr_dev_config} == {1'b1,`SDR_CONFIG_IS_32M}) ? {2'b0, curr_sdr_addr[8:0]} : {4'b0, curr_sdr_addr[7:0]};
|
266 |
|
|
|
267 |
|
|
assign r2b_raddr = ({sdr_width,sdr_dev_config} == {1'b0,`SDR_CONFIG_IS_8M}) ? {1'b0, curr_sdr_addr[18:8]} :
|
268 |
|
|
({sdr_width,sdr_dev_config} == {1'b0,`SDR_CONFIG_IS_16M}) ? curr_sdr_addr[19:8] :
|
269 |
|
|
({sdr_width,sdr_dev_config} == {1'b0,`SDR_CONFIG_IS_32M}) ? curr_sdr_addr[20:9] :
|
270 |
|
|
({sdr_width,sdr_dev_config} == {1'b1,`SDR_CONFIG_IS_8M}) ? {1'b0,curr_sdr_addr[19:8]} :
|
271 |
|
|
({sdr_width,sdr_dev_config} == {1'b1,`SDR_CONFIG_IS_16M}) ? curr_sdr_addr[20:9] :
|
272 |
|
|
({sdr_width,sdr_dev_config} == {1'b1,`SDR_CONFIG_IS_32M}) ? curr_sdr_addr[21:9] : {1'b0, curr_sdr_addr[20:10]};
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
endmodule // sdr_req_gen
|