|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
- module sram(clk_50,reset,sram_addr,wr_en,cs_n,oe_n,ub_n,lb_n,led,sram_data);//control the sram and test in the led
- input clk_50;
- input reset;
- output [19:0] sram_addr;
- output wr_en,cs_n,oe_n,ub_n,lb_n,led;
- inout [15:0] sram_data;
- assign cs_n=1'b0;//chip selet enable
- assign oe_n=1'b0;// output enable
- assign ub_n=1'b0;//upper byte avaliable
- assign lb_n=1'b0;//lower byte avaliable
- reg[25:0] delay;//delay 0.02us*2^26=1.34s
- clk_50 or negedge reset)
- if(!reset)
- delay<=26'b0;
- else
- delay<=delay+1'b1;
- reg[15:0] wr_data;
- reg[15:0] rd_data;
- reg[19:0] addr_r;
- wire wr_req;
- wire rd_req;
- reg led_r;
- assign wr_req=(delay==26'd9999);
- assign rd_req=(delay==26'd19999);
- always @(posedge clk_50 or negedge reset)
- if(!reset)
- wr_data<=16'd0;
- else if(delay==26'd29999)
- wr_data<=wr_data+1'b1;
- always @(posedge clk_50 or negedge reset)
- if(!reset)
- addr_r<=20'd0;
- else if(delay==26'd29999)
- addr_r<=addr_r+1'b1;
- always @(posedge clk_50 or negedge reset)
- if(!reset)
- led_r<=1'b0;
- else if(delay==26'd29999)
- begin
- if(wr_data==rd_data)
- led_r<=1'b1;
- else
- led_r<=1'b0;
- end
- assign led=led_r;
- reg[2:0]cnt;
- `define delay_80ns (cnt==3'd7) //delay 0.02us*7=140ns
- reg[3:0] state,nextstate;
- parameter idle =4'd0;
- parameter writ0 =4'd1;
- parameter writ1 =4'd2;
- parameter rea0 =4'd3;
- parameter rea1 =4'd4;
- always @(posedge clk_50 or negedge reset)
- if(!reset)
- cnt<=3'd0;
- else if(state==idle)
- cnt<=3'd0;
- else
- cnt<=cnt+1'b1;
- clk_50 or negedge reset)
- if(!reset)
- state<=idle;
- else
- state<=nextstate;
- clk_50 or negedge reset)
- case(state)
- idle: if(wr_req)
- nextstate<=writ0;
- else if(rd_req)
- nextstate<=rea0;
- else nextstate<=idle;
- writ0:if(`delay_80ns)
- nextstate<=writ1;
- else nextstate<=writ0;
- writ1: nextstate<=idle;
- rea0:if(`delay_80ns)
- nextstate<=rea1;
- else nextstate<=rea0;
- rea1:nextstate<=idle;
- endcase
- assign sram_addr=addr_r;
-
- // lock data
- reg sdlink; //SRAM address control
- clk_50 or negedge reset)
- if(!reset)
- rd_data <= 16'b0;
- else if(state == rea1)
- rd_data <= sram_data;
-
- clk_50 or negedge reset)
- if(!reset)
- sdlink <= 1'b0;
- else
- case(state)
- idle: if(wr_req)
- sdlink <= 1'b1;
- else if(rd_req)
- sdlink <= 1'b0;
- else
- sdlink <= 1'b0;
- writ0: sdlink <= 1'b1;
- default:sdlink <= 1'b0;
- endcase
-
- assign sram_data = sdlink ? wr_data:16'hzzzz;
- assign wr_en = ~sdlink;
-
- endmodule
复制代码 |
|