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_decoder_state.v
|
13 |
|
|
//
|
14 |
|
|
// Description : sdram command sequence decoder
|
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_timing.vh"
|
42 |
|
|
`include "hssdrc_define.vh"
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
module hssdrc_decoder_state (
|
46 |
|
|
clk ,
|
47 |
|
|
reset ,
|
48 |
|
|
sclr ,
|
49 |
|
|
//
|
50 |
|
|
ba_map_update ,
|
51 |
|
|
ba_map_clear ,
|
52 |
|
|
ba_map_pre_act_rw ,
|
53 |
|
|
ba_map_act_rw ,
|
54 |
|
|
ba_map_rw ,
|
55 |
|
|
ba_map_all_close ,
|
56 |
|
|
//
|
57 |
|
|
arb_write ,
|
58 |
|
|
arb_read ,
|
59 |
|
|
arb_refr ,
|
60 |
|
|
arb_rowa ,
|
61 |
|
|
arb_cola ,
|
62 |
|
|
arb_ba ,
|
63 |
|
|
arb_burst ,
|
64 |
|
|
arb_chid ,
|
65 |
|
|
arb_ready ,
|
66 |
|
|
//
|
67 |
|
|
dec_pre_all ,
|
68 |
|
|
dec_refr ,
|
69 |
|
|
dec_pre ,
|
70 |
|
|
dec_act ,
|
71 |
|
|
dec_read ,
|
72 |
|
|
dec_write ,
|
73 |
|
|
//
|
74 |
|
|
dec_pre_all_enable,
|
75 |
|
|
dec_refr_enable ,
|
76 |
|
|
dec_pre_enable ,
|
77 |
|
|
dec_act_enable ,
|
78 |
|
|
dec_read_enable ,
|
79 |
|
|
dec_write_enable ,
|
80 |
|
|
//
|
81 |
|
|
dec_locked ,
|
82 |
|
|
dec_last ,
|
83 |
|
|
//
|
84 |
|
|
dec_rowa ,
|
85 |
|
|
dec_cola ,
|
86 |
|
|
dec_ba ,
|
87 |
|
|
dec_chid ,
|
88 |
|
|
//
|
89 |
|
|
dec_burst
|
90 |
|
|
);
|
91 |
|
|
|
92 |
|
|
input wire clk ;
|
93 |
|
|
input wire reset;
|
94 |
|
|
input wire sclr ;
|
95 |
|
|
|
96 |
|
|
//--------------------------------------------------------------------------------------------------
|
97 |
|
|
// bank map interface
|
98 |
|
|
//--------------------------------------------------------------------------------------------------
|
99 |
|
|
|
100 |
|
|
output logic ba_map_update ;
|
101 |
|
|
output logic ba_map_clear ;
|
102 |
|
|
input wire ba_map_pre_act_rw ;
|
103 |
|
|
input wire ba_map_act_rw ;
|
104 |
|
|
input wire ba_map_rw ;
|
105 |
|
|
input wire ba_map_all_close ;
|
106 |
|
|
|
107 |
|
|
//--------------------------------------------------------------------------------------------------
|
108 |
|
|
// interface from input arbiter
|
109 |
|
|
//--------------------------------------------------------------------------------------------------
|
110 |
|
|
|
111 |
|
|
input wire arb_write ;
|
112 |
|
|
input wire arb_read ;
|
113 |
|
|
input wire arb_refr ;
|
114 |
|
|
input rowa_t arb_rowa ;
|
115 |
|
|
input cola_t arb_cola ;
|
116 |
|
|
input ba_t arb_ba ;
|
117 |
|
|
input burst_t arb_burst ;
|
118 |
|
|
input chid_t arb_chid ;
|
119 |
|
|
output logic arb_ready ;
|
120 |
|
|
|
121 |
|
|
//--------------------------------------------------------------------------------------------------
|
122 |
|
|
// inteface to output arbiter
|
123 |
|
|
//--------------------------------------------------------------------------------------------------
|
124 |
|
|
|
125 |
|
|
// logical commands
|
126 |
|
|
output logic dec_pre_all ;
|
127 |
|
|
output logic dec_refr ;
|
128 |
|
|
output logic dec_pre ;
|
129 |
|
|
output logic dec_act ;
|
130 |
|
|
output logic dec_read ;
|
131 |
|
|
output logic dec_write ;
|
132 |
|
|
// logical commands en
|
133 |
|
|
input wire dec_pre_all_enable ;
|
134 |
|
|
input wire dec_refr_enable ;
|
135 |
|
|
input wire dec_pre_enable ;
|
136 |
|
|
input wire dec_act_enable ;
|
137 |
|
|
input wire dec_read_enable ;
|
138 |
|
|
input wire dec_write_enable ;
|
139 |
|
|
// addititional signal
|
140 |
|
|
output logic dec_locked ;
|
141 |
|
|
output logic dec_last ;
|
142 |
|
|
// control path
|
143 |
|
|
output rowa_t dec_rowa ;
|
144 |
|
|
output cola_t dec_cola ;
|
145 |
|
|
output ba_t dec_ba ;
|
146 |
|
|
output chid_t dec_chid ;
|
147 |
|
|
//
|
148 |
|
|
output sdram_burst_t dec_burst ;
|
149 |
|
|
|
150 |
|
|
//--------------------------------------------------------------------------------------------------
|
151 |
|
|
//
|
152 |
|
|
//--------------------------------------------------------------------------------------------------
|
153 |
|
|
|
154 |
|
|
localparam int cTrp_m1 = cTrp - 1;
|
155 |
|
|
localparam int cTrcd_m1 = cTrcd - 1;
|
156 |
|
|
|
157 |
|
|
typedef enum {
|
158 |
|
|
STATE_RESET_BIT , // need for create simple true ready condition
|
159 |
|
|
STATE_IDLE_BIT ,
|
160 |
|
|
STATE_DECODE_BIT ,
|
161 |
|
|
STATE_PRE_BIT ,
|
162 |
|
|
STATE_TRP_BIT ,
|
163 |
|
|
STATE_ACT_BIT ,
|
164 |
|
|
STATE_TRCD_BIT ,
|
165 |
|
|
STATE_RW_BIT ,
|
166 |
|
|
STATE_ADDR_INC_BIT,
|
167 |
|
|
STATE_PRE_ALL_BIT ,
|
168 |
|
|
STATE_REFR_BIT
|
169 |
|
|
} state_bits_e;
|
170 |
|
|
|
171 |
|
|
//--------------------------------------------------------------------------------------------------
|
172 |
|
|
//
|
173 |
|
|
//--------------------------------------------------------------------------------------------------
|
174 |
|
|
|
175 |
|
|
enum bit [10:0] {
|
176 |
|
|
STATE_RESET = (11'h1 << STATE_RESET_BIT) ,
|
177 |
|
|
STATE_IDLE = (11'h1 << STATE_IDLE_BIT) ,
|
178 |
|
|
STATE_DECODE = (11'h1 << STATE_DECODE_BIT) ,
|
179 |
|
|
STATE_PRE = (11'h1 << STATE_PRE_BIT) ,
|
180 |
|
|
STATE_TRP = (11'h1 << STATE_TRP_BIT) ,
|
181 |
|
|
STATE_ACT = (11'h1 << STATE_ACT_BIT) ,
|
182 |
|
|
STATE_TRCD = (11'h1 << STATE_TRCD_BIT) ,
|
183 |
|
|
STATE_RW = (11'h1 << STATE_RW_BIT) ,
|
184 |
|
|
STATE_ADDR_INC = (11'h1 << STATE_ADDR_INC_BIT) ,
|
185 |
|
|
STATE_PRE_ALL = (11'h1 << STATE_PRE_ALL_BIT) ,
|
186 |
|
|
STATE_REFR = (11'h1 << STATE_REFR_BIT)
|
187 |
|
|
} state, next_state;
|
188 |
|
|
|
189 |
|
|
logic refr_mode ;
|
190 |
|
|
logic write_mode ;
|
191 |
|
|
|
192 |
|
|
logic burst_done ;
|
193 |
|
|
logic early_burst_done;
|
194 |
|
|
|
195 |
|
|
cola_t cola_latched ;
|
196 |
|
|
rowa_t rowa_latched ;
|
197 |
|
|
ba_t ba_latched ;
|
198 |
|
|
chid_t chid_latched ;
|
199 |
|
|
|
200 |
|
|
logic [3:0] burst_latched ;
|
201 |
|
|
logic [3:0] burst_shift_cnt ;
|
202 |
|
|
|
203 |
|
|
logic [3:0] available_burst ;
|
204 |
|
|
|
205 |
|
|
logic [3:0] remained_burst ;
|
206 |
|
|
logic [1:0] remained_burst_high ;
|
207 |
|
|
logic [1:0] remained_burst_low ;
|
208 |
|
|
logic [1:0] remained_burst_low_latched;
|
209 |
|
|
|
210 |
|
|
logic [3:0] last_used_burst;
|
211 |
|
|
|
212 |
|
|
wire trp_cnt_done;
|
213 |
|
|
wire trcd_cnt_done;
|
214 |
|
|
|
215 |
|
|
//--------------------------------------------------------------------------------------------------
|
216 |
|
|
// use shift register instead of counter for trp time count
|
217 |
|
|
//--------------------------------------------------------------------------------------------------
|
218 |
|
|
|
219 |
|
|
generate
|
220 |
|
|
if (cTrp_m1 <= 1) begin : no_trp_cnt_generate
|
221 |
|
|
|
222 |
|
|
assign trp_cnt_done = 1'b1;
|
223 |
|
|
|
224 |
|
|
end
|
225 |
|
|
else begin : trp_cnt_generate
|
226 |
|
|
|
227 |
|
|
logic [cTrp_m1-2:0] trp_cnt;
|
228 |
|
|
|
229 |
|
|
always_ff @(posedge clk) begin
|
230 |
|
|
if (state [STATE_TRP_BIT])
|
231 |
|
|
trp_cnt <= (trp_cnt << 1) | 1'b1;
|
232 |
|
|
else
|
233 |
|
|
trp_cnt <= '0;
|
234 |
|
|
end
|
235 |
|
|
|
236 |
|
|
assign trp_cnt_done = trp_cnt [cTrp_m1-2];
|
237 |
|
|
|
238 |
|
|
end
|
239 |
|
|
endgenerate
|
240 |
|
|
|
241 |
|
|
//--------------------------------------------------------------------------------------------------
|
242 |
|
|
// use shift register instead of counter for trcd time count
|
243 |
|
|
//--------------------------------------------------------------------------------------------------
|
244 |
|
|
|
245 |
|
|
generate
|
246 |
|
|
if (cTrcd_m1 <= 1) begin : no_trcd_cnt_generate
|
247 |
|
|
|
248 |
|
|
assign trcd_cnt_done = 1'b1;
|
249 |
|
|
|
250 |
|
|
end
|
251 |
|
|
else begin : trcd_cnt_generate
|
252 |
|
|
|
253 |
|
|
logic [cTrcd_m1-2:0] trcd_cnt;
|
254 |
|
|
|
255 |
|
|
always_ff @(posedge clk) begin
|
256 |
|
|
if (state [STATE_TRCD_BIT])
|
257 |
|
|
trcd_cnt <= (trcd_cnt << 1) | 1'b1;
|
258 |
|
|
else
|
259 |
|
|
trcd_cnt <= '0;
|
260 |
|
|
end
|
261 |
|
|
|
262 |
|
|
assign trcd_cnt_done = trcd_cnt [cTrcd_m1-2];
|
263 |
|
|
|
264 |
|
|
end
|
265 |
|
|
endgenerate
|
266 |
|
|
|
267 |
|
|
//--------------------------------------------------------------------------------------------------
|
268 |
|
|
//
|
269 |
|
|
//--------------------------------------------------------------------------------------------------
|
270 |
|
|
|
271 |
|
|
always_comb begin : fsm_jump_decode
|
272 |
|
|
|
273 |
|
|
next_state = STATE_RESET;
|
274 |
|
|
|
275 |
|
|
unique case (1'b1)
|
276 |
|
|
|
277 |
|
|
state [STATE_RESET_BIT] : begin
|
278 |
|
|
next_state = STATE_IDLE;
|
279 |
|
|
end
|
280 |
|
|
|
281 |
|
|
state [STATE_IDLE_BIT] : begin
|
282 |
|
|
if (arb_write | arb_read | arb_refr)
|
283 |
|
|
next_state = STATE_DECODE;
|
284 |
|
|
else
|
285 |
|
|
next_state = STATE_IDLE;
|
286 |
|
|
end
|
287 |
|
|
//
|
288 |
|
|
// decode branch
|
289 |
|
|
//
|
290 |
|
|
state [STATE_DECODE_BIT] : begin
|
291 |
|
|
if (refr_mode) begin : shorten_refresh_decode
|
292 |
|
|
|
293 |
|
|
if (ba_map_all_close)
|
294 |
|
|
next_state = STATE_REFR;
|
295 |
|
|
else
|
296 |
|
|
next_state = STATE_PRE_ALL;
|
297 |
|
|
|
298 |
|
|
end
|
299 |
|
|
else begin : mode_of_rw_decode
|
300 |
|
|
|
301 |
|
|
if (ba_map_pre_act_rw)
|
302 |
|
|
next_state = STATE_PRE;
|
303 |
|
|
else if (ba_map_rw)
|
304 |
|
|
next_state = STATE_RW;
|
305 |
|
|
else // if (ba_map_act_rw)
|
306 |
|
|
next_state = STATE_ACT;
|
307 |
|
|
|
308 |
|
|
end
|
309 |
|
|
end
|
310 |
|
|
//
|
311 |
|
|
// pre branch
|
312 |
|
|
//
|
313 |
|
|
state [STATE_PRE_BIT] : begin
|
314 |
|
|
if (dec_pre_enable)
|
315 |
|
|
|
316 |
|
|
if (cTrp_m1 == 0)
|
317 |
|
|
next_state = STATE_ACT;
|
318 |
|
|
else
|
319 |
|
|
next_state = STATE_TRP;
|
320 |
|
|
|
321 |
|
|
else
|
322 |
|
|
next_state = STATE_PRE;
|
323 |
|
|
end
|
324 |
|
|
|
325 |
|
|
state [STATE_TRP_BIT] : begin
|
326 |
|
|
if (trp_cnt_done)
|
327 |
|
|
next_state = STATE_ACT;
|
328 |
|
|
else
|
329 |
|
|
next_state = STATE_TRP;
|
330 |
|
|
end
|
331 |
|
|
//
|
332 |
|
|
// act branch
|
333 |
|
|
//
|
334 |
|
|
state [STATE_ACT_BIT] : begin
|
335 |
|
|
if (dec_act_enable)
|
336 |
|
|
|
337 |
|
|
if (cTrcd_m1 == 0)
|
338 |
|
|
next_state = STATE_RW;
|
339 |
|
|
else
|
340 |
|
|
next_state = STATE_TRCD;
|
341 |
|
|
|
342 |
|
|
else
|
343 |
|
|
next_state = STATE_ACT;
|
344 |
|
|
end
|
345 |
|
|
|
346 |
|
|
state [STATE_TRCD_BIT] : begin
|
347 |
|
|
if (trcd_cnt_done)
|
348 |
|
|
next_state = STATE_RW;
|
349 |
|
|
else
|
350 |
|
|
next_state = STATE_TRCD;
|
351 |
|
|
end
|
352 |
|
|
//
|
353 |
|
|
// data branch
|
354 |
|
|
//
|
355 |
|
|
state [STATE_RW_BIT] : begin
|
356 |
|
|
if ((dec_write_enable & write_mode) | (dec_read_enable & ~write_mode)) begin : burst_done_decode
|
357 |
|
|
|
358 |
|
|
if (burst_done)
|
359 |
|
|
next_state = STATE_IDLE;
|
360 |
|
|
else
|
361 |
|
|
next_state = STATE_ADDR_INC;
|
362 |
|
|
|
363 |
|
|
end
|
364 |
|
|
else begin
|
365 |
|
|
next_state = STATE_RW;
|
366 |
|
|
end
|
367 |
|
|
end
|
368 |
|
|
|
369 |
|
|
state [STATE_ADDR_INC_BIT] : begin
|
370 |
|
|
next_state = STATE_RW;
|
371 |
|
|
end
|
372 |
|
|
//
|
373 |
|
|
// refresh breanch
|
374 |
|
|
//
|
375 |
|
|
state [STATE_PRE_ALL_BIT] : begin
|
376 |
|
|
if (dec_pre_all_enable)
|
377 |
|
|
next_state = STATE_REFR;
|
378 |
|
|
else
|
379 |
|
|
next_state = STATE_PRE_ALL;
|
380 |
|
|
end
|
381 |
|
|
|
382 |
|
|
state [STATE_REFR_BIT] : begin
|
383 |
|
|
if (dec_refr_enable)
|
384 |
|
|
next_state = STATE_IDLE;
|
385 |
|
|
else
|
386 |
|
|
next_state = STATE_REFR;
|
387 |
|
|
end
|
388 |
|
|
|
389 |
|
|
endcase
|
390 |
|
|
end
|
391 |
|
|
|
392 |
|
|
//---------------------------------------------------------------------------------------------------
|
393 |
|
|
//
|
394 |
|
|
//---------------------------------------------------------------------------------------------------
|
395 |
|
|
|
396 |
|
|
always_ff @(posedge clk or posedge reset) begin : fsm_register_process
|
397 |
|
|
if (reset) state <= STATE_RESET;
|
398 |
|
|
else if (sclr) state <= STATE_RESET;
|
399 |
|
|
else state <= next_state;
|
400 |
|
|
end
|
401 |
|
|
|
402 |
|
|
//---------------------------------------------------------------------------------------------------
|
403 |
|
|
//
|
404 |
|
|
//---------------------------------------------------------------------------------------------------
|
405 |
|
|
|
406 |
|
|
assign arb_ready = state[STATE_IDLE_BIT];
|
407 |
|
|
|
408 |
|
|
assign dec_pre_all = state[STATE_PRE_ALL_BIT];
|
409 |
|
|
assign dec_refr = state[STATE_REFR_BIT];
|
410 |
|
|
assign dec_pre = state[STATE_PRE_BIT];
|
411 |
|
|
assign dec_act = state[STATE_ACT_BIT];
|
412 |
|
|
assign dec_read = state[STATE_RW_BIT] & ~write_mode;
|
413 |
|
|
assign dec_write = state[STATE_RW_BIT] & write_mode;
|
414 |
|
|
assign dec_last = state[STATE_RW_BIT] & burst_done ;
|
415 |
|
|
|
416 |
|
|
//
|
417 |
|
|
// instead of decode state_refr_bit & state_pre_all_bit we can use refresh mode register
|
418 |
|
|
//
|
419 |
|
|
|
420 |
|
|
assign dec_locked = refr_mode;
|
421 |
|
|
|
422 |
|
|
//--------------------------------------------------------------------------------------------------
|
423 |
|
|
//
|
424 |
|
|
//--------------------------------------------------------------------------------------------------
|
425 |
|
|
|
426 |
|
|
assign ba_map_update = state[STATE_DECODE_BIT] & ~refr_mode;
|
427 |
|
|
assign ba_map_clear = state[STATE_DECODE_BIT] & refr_mode;
|
428 |
|
|
|
429 |
|
|
always_ff @(posedge clk) begin : mode_logic
|
430 |
|
|
if (state [STATE_IDLE_BIT]) begin
|
431 |
|
|
refr_mode <= arb_refr;
|
432 |
|
|
write_mode <= arb_write;
|
433 |
|
|
end
|
434 |
|
|
end
|
435 |
|
|
|
436 |
|
|
//--------------------------------------------------------------------------------------------------
|
437 |
|
|
//
|
438 |
|
|
//--------------------------------------------------------------------------------------------------
|
439 |
|
|
|
440 |
|
|
always_ff @(posedge clk) begin : addr_chid_logic
|
441 |
|
|
|
442 |
|
|
if (state[STATE_IDLE_BIT]) begin
|
443 |
|
|
rowa_latched <= arb_rowa;
|
444 |
|
|
ba_latched <= arb_ba;
|
445 |
|
|
chid_latched <= arb_chid;
|
446 |
|
|
end
|
447 |
|
|
|
448 |
|
|
if (state[STATE_IDLE_BIT])
|
449 |
|
|
cola_latched <= arb_cola;
|
450 |
|
|
else if (state[STATE_ADDR_INC_BIT])
|
451 |
|
|
cola_latched <= cola_latched + last_used_burst;
|
452 |
|
|
|
453 |
|
|
end
|
454 |
|
|
|
455 |
|
|
assign dec_cola = cola_latched;
|
456 |
|
|
assign dec_rowa = rowa_latched;
|
457 |
|
|
assign dec_ba = ba_latched;
|
458 |
|
|
assign dec_chid = chid_latched;
|
459 |
|
|
|
460 |
|
|
|
461 |
|
|
//--------------------------------------------------------------------------------------------------
|
462 |
|
|
// alligned burst max cycles is 4
|
463 |
|
|
// burst [3:2] == 0 & burst[1:0] <= available_burst. 1 cycle is burst
|
464 |
|
|
// burst [3:2] != 0 & burst[1:0] <= available_burst. 1 cycle is burst shift_cnt burst_done
|
465 |
|
|
// burst [ 1.. 4] : encoded with [ 4'd0 : 4'd3] : cycle is 1 : burst_shift_cnt = 4'b0000 1
|
466 |
|
|
// burst [ 5.. 8] : encoded with [ 4'd4 : 4'd7] : cycle is 2 : burst_shift_cnt = 4'b0001 0
|
467 |
|
|
// burst [ 9..12] : encoded with [ 4'd8 : 4'd11] : cycle is 3 : burst_shift_cnt = 4'b0010 0
|
468 |
|
|
// burst [13..16] : encoded with [4'd12 : 4'd15] : cycle is 4 : burst_shift_cnt = 4'b0100 0
|
469 |
|
|
//
|
470 |
|
|
|
471 |
|
|
// not alligned burst max cycles is 5 shift_cnt burst_done
|
472 |
|
|
// burst [ 1.. 4] : encoded with [ 4'd0 : 4'd3] : cycle is 2 : burst_shift_cnt = 4'b0001 0
|
473 |
|
|
// burst [ 5.. 8] : encoded with [ 4'd4 : 4'd7] : cycle is 3 : burst_shift_cnt = 4'b0010 0
|
474 |
|
|
// burst [ 9..12] : encoded with [ 4'd8 : 4'd11] : cycle is 4 : burst_shift_cnt = 4'b0100 0
|
475 |
|
|
// burst [13..16] : encoded with [4'd12 : 4'd15] : cycle is 5 : burst_shift_cnt = 4'b1000 0
|
476 |
|
|
//--------------------------------------------------------------------------------------------------
|
477 |
|
|
|
478 |
|
|
always_ff @(posedge clk) begin : burst_latch_logic
|
479 |
|
|
if (state[STATE_IDLE_BIT])
|
480 |
|
|
burst_latched = arb_burst;
|
481 |
|
|
end
|
482 |
|
|
|
483 |
|
|
// remember that burst has -1 offset
|
484 |
|
|
// available burst has -1 offset too
|
485 |
|
|
|
486 |
|
|
assign available_burst = 4'b0011 - {2'b00, cola_latched[1:0]};
|
487 |
|
|
|
488 |
|
|
assign remained_burst = burst_latched - available_burst - 1'b1;
|
489 |
|
|
assign remained_burst_high = remained_burst[3:2];
|
490 |
|
|
assign remained_burst_low = remained_burst[1:0];
|
491 |
|
|
|
492 |
|
|
assign early_burst_done = burst_shift_cnt[0];
|
493 |
|
|
|
494 |
|
|
always_ff @(posedge clk) begin : burst_logic
|
495 |
|
|
if (state[STATE_DECODE_BIT]) begin
|
496 |
|
|
|
497 |
|
|
if (burst_latched <= available_burst) begin
|
498 |
|
|
|
499 |
|
|
burst_shift_cnt <= '0;
|
500 |
|
|
|
501 |
|
|
burst_done <= 1'b1; // only 1 transaction will be
|
502 |
|
|
dec_burst <= burst_latched[1:0];
|
503 |
|
|
|
504 |
|
|
end
|
505 |
|
|
else begin
|
506 |
|
|
|
507 |
|
|
burst_shift_cnt <= '0;
|
508 |
|
|
burst_shift_cnt[remained_burst_high] <= 1'b1;
|
509 |
|
|
|
510 |
|
|
remained_burst_low_latched <= remained_burst_low;
|
511 |
|
|
|
512 |
|
|
burst_done <= 1'b0; // more then 2 transaction will be
|
513 |
|
|
|
514 |
|
|
dec_burst <= available_burst[1:0];
|
515 |
|
|
last_used_burst <= {2'b00, available_burst[1:0]} + 1'b1; // + 1 is compensation of -1 offset
|
516 |
|
|
|
517 |
|
|
end
|
518 |
|
|
end
|
519 |
|
|
else if (state[STATE_ADDR_INC_BIT]) begin
|
520 |
|
|
|
521 |
|
|
burst_shift_cnt <= burst_shift_cnt >> 1;
|
522 |
|
|
|
523 |
|
|
burst_done <= early_burst_done;
|
524 |
|
|
//
|
525 |
|
|
if (early_burst_done)
|
526 |
|
|
dec_burst <= remained_burst_low_latched; // no transaction any more
|
527 |
|
|
else
|
528 |
|
|
dec_burst <= 2'b11;
|
529 |
|
|
//
|
530 |
|
|
last_used_burst <= 4'b0011 + 1'b1;
|
531 |
|
|
end
|
532 |
|
|
end
|
533 |
|
|
|
534 |
|
|
endmodule
|