You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
Verilog
47 lines
1.1 KiB
Verilog
// 该模块会在写满了fifo之后, 开始读, 直到读空
|
|
|
|
module fifo_rd(
|
|
input rd_clk,
|
|
input rst,
|
|
|
|
input [7:0] fifo_rd_data, // fifo 读到的数据
|
|
input is_full, // 是否写满了, 这个是 写时钟域的信号
|
|
input is_almost_empty, // 快空了
|
|
input is_rd_rst_busy, // 是否正在初始化读
|
|
output reg fifo_rd_en // 是否能够读了
|
|
);
|
|
|
|
reg is_full_0;
|
|
reg is_full_1;
|
|
always @(posedge rd_clk or negedge rst) begin
|
|
if (!rst) begin
|
|
is_full_0 <= 1'b0;
|
|
is_full_1 <= 1'b0;
|
|
end
|
|
else begin
|
|
is_full_0 <= is_full;
|
|
is_full_1 <= is_full_0;
|
|
end
|
|
end
|
|
|
|
|
|
// 控制是否可读
|
|
always @(posedge rd_clk or negedge rst) begin
|
|
if (!rst) begin
|
|
fifo_rd_en <= 1'b0;
|
|
end
|
|
else if (!is_rd_rst_busy) begin // 功能已经准备就绪
|
|
if (is_full_1) begin // 打两拍确定是满的, 在进行读取
|
|
fifo_rd_en <= 1'b1;
|
|
end
|
|
else if(is_almost_empty) begin // 上个时钟周期快空了, 其实当前时钟周期已经空了
|
|
fifo_rd_en <= 1'b0;
|
|
end
|
|
else begin
|
|
end
|
|
end
|
|
else begin
|
|
end
|
|
end
|
|
|
|
endmodule |