sdram读程序实例
`include "camera_head.v"
module read (pi_clk, pi_rst_n, po_read_bus, pio_sdram_dq, pi_sdram_addr, po_sdram_rdata, po_rdfifo_wrreq,
po_read_done);
// system
input pi_clk;
input pi_rst_n;
// sdram
output po_read_bus;
inout pio_sdram_dq;
// in data
input pi_sdram_addr;
//out data
output po_sdram_rdata;
output po_rdfifo_wrreq;
output po_read_done;
reg flag;
reg dq_buf;
assign pio_sdram_dq = flag ? dq_buf : 16'hzz;
//------------------------------------------------------------
reg commands;
reg sdram_bank;
reg sdram_addr;
assign po_read_bus = commands;
assign po_read_bus = sdram_bank;
assign po_read_bus = sdram_addr;
//-----------------------------------------------------------
reg po_sdram_rdata;
reg po_rdfifo_wrreq;
reg po_read_done;
reg state;
reg cnt;
always @ (posedge pi_clk, negedge pi_rst_n)
begin
if (!pi_rst_n)
begin
commands <= `NOP;
sdram_bank <= 2'b00;
sdram_addr <= 12'd0;
flag <= 1'b0;
dq_buf <= 16'd0;
po_sdram_rdata <= 8'd0;
po_rdfifo_wrreq <= 1'b0;
po_read_done <= 1'b0;
state <= 0;
cnt <= 9'd0;
end
else
begin
case (state)
0 : begin
commands <= `ACT;
sdram_bank <= 2'b11;
sdram_addr <= pi_sdram_addr;
state <= 1;
flag <= 1'b0;
end
1 : begin
if (cnt < 1)
begin
commands <= `NOP;
cnt <= cnt + 1'b1;
end
else
begin
commands <= `RD;
sdram_addr <= 1'd1;
sdram_addr <= 8'd0;
cnt <= 9'd0;
state <= 2;
end
end
2 : begin
if (cnt < 2)
begin
commands <= `NOP;
cnt <= cnt + 1'b1;
end
else
begin
po_sdram_rdata <= pio_sdram_dq;
po_rdfifo_wrreq <= 1'b1;
cnt <= 9'd0;
state <= 3;
end
end
3 : begin
po_sdram_rdata <= pio_sdram_dq;
po_rdfifo_wrreq <= 1'b1;
if (cnt < 317)
begin
cnt <= cnt + 1'b1;
end
else
begin
cnt <= 9'd0;
commands <= `BT;
state <= 4;
end
end
4 : begin
po_sdram_rdata <= pio_sdram_dq;
po_rdfifo_wrreq <= 1'b1;
commands <= `NOP;
state <= 5;
end
5 : begin
po_rdfifo_wrreq <= 1'b0;
//po_read_done <= 1'b1;
state <= 6;
end
6 : begin
commands <= `PREC;
sdram_addr <= 1'b1;
state <= 7;
end
7 : begin
if (cnt < 2)
begin
commands <= `NOP;
cnt <= cnt + 1'b1;
end
else
begin
commands <= `NOP;
po_read_done <= 1'b1;
state <= 7;
cnt <= 0;
end
end
default : state <= 0;
endcase
end
end
endmodule sdram读程序实例 sdram读程序实例 sdram读程序实例
页:
[1]