集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1197|回复: 1

SDRAM页写状态机设计程序——仅供参考

[复制链接]
fpga_feixiang 发表于 2019-11-26 17:54:02 | 显示全部楼层 |阅读模式
/*--------------------------------------------
        模块名称 : SDRAM写模块
        模块说明 : 当有写事件发生时:1.发送激活命令、行地址、bank地址
                                                                                 2.经过tRCD之后,发送写命令、列地址、写数据、a[10]拉高标志自动刷新
                                                                                 3.继续发送第二个数据(BL=2)
        --2015-10-08
--------------------------------------------*/


module sdr_write(wr_rst_n, sys_clk, int_addr, wr_done, wr_bus, int_dq, out_en, local_wdata, wr_data_ok);

        input sys_clk;
        input wr_rst_n;
        input [24:0] int_addr;
        input [15:0] local_wdata;
        output reg wr_done;
        output reg [19:0] wr_bus;
        output reg [15:0] int_dq;
        output reg out_en;
        output reg wr_data_ok;

        localparam s0 = 3'b000;
        localparam s1 = 3'b001;
        localparam s2 = 3'b010;
        localparam s3 = 3'b011;
        localparam s4 = 3'b100;
        localparam s5 = 3'b101;
       
        reg [2:0] state;
        reg [9:0] count;

        always @ (posedge sys_clk)
        begin
                if (!wr_rst_n)
                        begin
                                wr_bus[19:16] <= `NOP;
                                wr_bus[15] <= 1;
                                wr_bus[14:0] <= 0;
                                int_dq <= 0;
                                count <= 0;
                                out_en <= 0;
                                wr_done <=0;
                                state <= s0;
                                wr_data_ok <= 0;
                        end
                else
                        case (state)
                                s0 :        begin
                                                        wr_bus[19:16] <= `ACT;                           //发送激活命令
                                                        wr_bus[14:13] <= int_addr[24:23]; //发送bank地址
                                                        wr_bus[12:0] <= int_addr[22:10];  //发送行地址
                                                        state <= s1;
                                                        wr_data_ok <= 1;
                                                end
                                               
                                s1 :  if (count < `tRCD-1)  //`tRCD-1 = 1
                                                        begin
                                                                wr_bus[19:16] <= `NOP;
                                                                count <= count + 1'b1;
                                                        end
                                                else
                                                        begin
                                                                wr_bus[19:16] <= `WR;
                                                                wr_bus[14:13] <= int_addr[24:23];
                                                                wr_bus[10] <= 1;                          //拉高a[10],自动刷新
                                                                wr_bus[9:0] <= int_addr[9:0]; //列地址
                                                                int_dq <= local_wdata;
                                                                out_en <= 1;
                                                                count <= 0;
                                                                state <= s2;
                                                        end
                               
                                s2 :                begin
                                                                if (count < `WR_SIZE)
                                                                        begin
                                                                                int_dq <= local_wdata;
                                                                                out_en <= 1;
                                                                                count <= count + 1'b1;
                                                                                wr_bus[19:16] <= `NOP;
                                                                        end
                                                                else if(count == `WR_SIZE)
                                                                        begin
                                                                                int_dq <= local_wdata;
                                                                                out_en <= 1;
                                                                                count <= count + 1'b1;
                                                                                wr_data_ok <= 0;
                                                                        end       
                                                                else
                                                                        begin
                                                                                int_dq <= local_wdata;
                                                                                out_en <= 1;
                                                                                count <= 0;
                                                                                state <= s3;
                                                                        end
                                                        end
                               
                                s3 : begin
                                                out_en <= 0;
                                                wr_bus[19:16] <= `BT;  //发出突发终止命令
                                                state <= s4;                                                                       
                                        end
                                s4 : begin                                               
                                                if (count < 2)
                                                        begin
                                                                count <= count + 1'b1;
                                                                wr_bus[19:16] <= `NOP;
                                                        end
                                                else
                                                        begin
                                                                count <= 0;
                                                                wr_bus[19:16] <= `PRECHANGE;
                                                                wr_bus[10] <= 1;
                                                                state <= s5;
                                                        end               
                                         end
                                s5 :  if (count < 2)
                                                        begin
                                                                count <= count + 1'b1;
                                                                wr_bus[19:16] <= `NOP;
                                                        end
                                                else
                                                        begin
                                                                wr_done <= 1;
                                                        end       
                       
                                default : wr_bus[19:16] <= `NOP;
                                endcase
        end
       
endmodule
zhangyukun 发表于 2019-11-26 19:33:24 | 显示全部楼层
SDRAM页写状态机设计程序——仅供参考
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-4-30 12:48 , Processed in 0.059655 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表