|
特权同学的那个SDRAM程序,有疑问,求高手解答
[复制链接]
最近研究特权同学的sdram代码,有个疑问,请高手解答:
问题是:在读写工作状态时,如果自动刷新时间到了(15us时间到),而此时工作状态
非 `W_IDLE,也就是有sdram_ref_req(有自动刷新请求),但是到不了 `W_AR(自动刷新状态);
那岂不是错过一次自动刷新请求了?
代码如下,求助,谢谢!
//------------------------------------------------------------------------------
//15us计时,每60ms全部4096行存储区进行一次自刷新
// ( 存储体中电容的数据有效保存期上限是64ms )
//------------------------------------------------------------------------------
reg[10:0] cnt_15us; //计数寄存器
always @ (posedge clk or negedge rst_n)
if(!rst_n) cnt_15us <= 11'd0;
else if(cnt_15us < 11'd1499) cnt_15us <= cnt_15us+1'b1; // 60ms(64ms)/4096=15us循环计数
else cnt_15us <= 11'd0;
always @ (posedge clk or negedge rst_n)
if(!rst_n) sdram_ref_req <= 1'b0;
else if(cnt_15us == 11'd1498) sdram_ref_req <= 1'b1; //产生自刷新请求
else if(sdram_ref_ack) sdram_ref_req <= 1'b0; //已响应自刷新
//------------------------------------------------------------------------------
//SDRAM的读写以及自刷新操作状态机
//------------------------------------------------------------------------------
reg[3:0] work_state_r; // SDRAM读写状态
reg sys_r_wn; // SDRAM读/写控制信号
always @ (posedge clk or negedge rst_n) begin
if(!rst_n) work_state_r <= `W_IDLE;
else
case (work_state_r)
`W_IDLE: if(sdram_ref_req & sdram_init_done) begin
work_state_r <= `W_AR; //定时自刷新请求
sys_r_wn <= 1'b1;
end
else if(sdram_wr_req & sdram_init_done) begin
work_state_r <= `W_ACTIVE;//写SDRAM
sys_r_wn <= 1'b0;
end
else if(sdram_rd_req && sdram_init_done) begin
work_state_r <= `W_ACTIVE;//读SDRAM
sys_r_wn <= 1'b1;
end
else begin
work_state_r <= `W_IDLE;
sys_r_wn <= 1'b1;
end
//行有效状态
`W_ACTIVE: if(TRCD_CLK == 0)
if(sys_r_wn) work_state_r <= `W_READ;
else work_state_r <= `W_WRITE;
else work_state_r <= `W_TRCD;
`W_TRCD: if(`end_trcd)
if(sys_r_wn) work_state_r <= `W_READ;
else work_state_r <= `W_WRITE;
else work_state_r <= `W_TRCD;
// SDRAM读数据状态
`W_READ: work_state_r <= `W_CL;
`W_CL: work_state_r <= (`end_tcl) ? `W_RD:`W_CL;
`W_RD: work_state_r <= (`end_tread) ? `W_RWAIT:`W_RD; //后面需要添加一个读完成后的预充电等待状态
`W_RWAIT: work_state_r <= (`end_trwait) ? `W_IDLE:`W_RWAIT;
// SDRAM写数据状态
`W_WRITE: work_state_r <= `W_WD;
`W_WD: work_state_r <= (`end_twrite) ? `W_TDAL:`W_WD;
`W_TDAL: work_state_r <= (`end_tdal) ? `W_IDLE:`W_TDAL;
// SDRAM自动刷新状态
`W_AR: work_state_r <= (TRFC_CLK == 0) ? `W_IDLE:`W_TRFC;
`W_TRFC: work_state_r <= (`end_trfc) ? `W_IDLE:`W_TRFC;
default: work_state_r <= `W_IDLE;
endcase
end
|
|