📄 fifo.txt
字号:
步FIFO( Verilog HDL )
发表时间:2007年11月21日 20时12分30秒 本文链接:http://user.qzone.qq.com/334982024/blog/1195647150评论/阅读(0/2)
同步FIFO( Verilog HDL )
module fifo (clk,rstp,din,writep,readp,dout,emptyp,fullp);
input clk;
input rstp;
input[15:0] din;
input readp;
input writep;
output[15:0] dout;
output emptyp;
output fullp;
//定义字数
parameter DEPTH=2,
MAX_COUNT=2'b11;
reg emptyp;
reg fullp;
//寄存器型输出
reg[15:0] dout;
//定义FIFO的指针
reg[(DEPTH-1):0] tail;
reg[(DEPTH-1):0] head;
//定义FIFO计数器
reg[(DEPTH-1):0] count;
//定义寄存器容量
reg [15:0] fifomem[0:MAX_COUNT];
//Dout是记录和取得指向RIGHT NOW底部的值
always @(posedge clk) begin;
if (rstp==1) begin
dout <=16'h0000;
end
else begin
dout<=fifomem[tail];
end
end
//更新FIFO寄存器
always @(posedge clk) begin
if (rstp==1'b0 && writep==1'b1 &&fullp==1'b0 )begin
fifomem [head] <=din;
end
end
//更新顶部寄存器
always @(posedge clk) begin
if (rstp==1'b1) begin
head<=2'b00;
end
else begin
if (writep==1'b1 && fullp == 1'b1) begin
//写
head<=head+1;
end
end
end
//更新底部寄存器
always @(posedge clk) begin
if (rstp==1'b1) begin
tail <=2'b00;
end
else begin
if (readp==1'b1 && emptyp == 1'b0) begin
//读
end
end
end
//更新计数寄存器
always @(posedge clk) begin
if (rstp ==1'b1) begin
count <=2'b00;
end
else begin
case ({readp,writep})
2'b00:count <=count;
2'b01:
//写
if (count!=MAX_COUNT)
count <=count+1;
2'b10:
//读
if (count !=2'b00)
count <=count-1;
2'b11:
//同时读写,在计数器方面没有改变
count <=count;
endcase
end
//更新标志
//首先更新空标志
always @(count) begin
if (count == 2'b00)
emptyp <= 1'b1;
case
emptyp <= 1'b0;
end
//更新满标志
always @(count) begin
if (count == MAX_COUNT)
fullp <= 1'b0;
end
endmodule
PIC系列单片机,最小的只有四个引脚,可以用于最简单的逻辑控制,虽然PIC系列也有高档次的单片机,但和专业从事高档次的单片机的来说就差得远了.
发表评论 共 0篇评论,第 1页/共 0页
第一页 上一页 下一页 最后页
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -