512X8的双端口RAM来实现FIFO
module dualRAM (
read_clk,
write_clk,
read_allow,
write_allow,
read_address,
write_address,
read_data,
write_data,
);
//这里可以定义三个常数:RAM的位宽为8,深度为512,地址位宽为9
input read_clk;
input write_clk;
input read_allow;
input write_allow;
input [8:0] read_address;
input [8:0] write_address;
input [7:0] write_data;
output [7:0] read_data;
reg [7:0] read_data;
reg [7:0] mem[511:0];
always@(posedge write_clk)
begin
if(write_allow)
mem[write_address]<=write_data;
end
always@(posedge read_clk)
begin
if(read_allow)
read_data<=mem[read_address];
end
endmodule
FIFO是什么?
First In First Out,是一种先进先出的数据缓存器,没有外部读写地址线
缺点:只能顺序写入和读出数据,数据地址由内部读写指针自动+1
用处:不同时钟域之间的数据传输;不同宽度的数据接口之间的数据传输
分类:同步FIFO(读时钟和写时钟为同一个时钟)和异步FIFO
核心问题:如何判断空或满的状态ÿ