吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3935|回复: 10
收起左侧

[其他原创] Verilog语言实现异步FIFO

[复制链接]
UNICORNLI 发表于 2016-12-4 18:24
本帖最后由 UNICORNLI 于 2016-12-4 18:27 编辑

               这个月做项目,使用了Verilog写程序,这里分享一下异步FIFO,这是基本的,可以根据项目需要做修改。不对的地方请大家指正。
module fifo_interface(
        input  clk1,
        input  clk2,
        input  [7:0] in_data,
        input  addr,
        input  rst,
        output  [7:0] out_data,
        output  full,
        output  empty
        );

        reg  [ bite_Size-1:0]  Buff [deep_Size-1:0];//FIFO的存储空间
        reg  [deep_Size:0]  cur_Wr_Pt,next_Wr_Pt;
        reg  [deep_Size:0]  cur_Rd_Pt,next_Rd_Pt;
        reg  full_Flag,empty_Flag;
        reg  fifoWR, fifoRD;
        parameter  deep_Size = 256, addr_Size = 8, bite_Size = 8 ,couter_Size = 8;

        initial
               begin
                full = 0;
                empty = 1;
                wr_Addr_Bin = 0;
                rd_Addr_Bin = 0;
                 couter =0;
                cur_Wr_Pt = 0;
                cur_Rd_Pt = 0;
                next_Wr_Pt = 1;
                next_Rd_Pt = 1;
               end

        always @(addr)
        begin
        case (addr)
              2'b01:   fifoWR = 1;
              2'b10:   fifoRD = 1;
              default:
                begin
                      fifoWR = 0;
                      fifoRD  = 0;
                end
        endcase
        end        

        reg  [couter_Size-1:0] couter;
        always @(cur_Wr_Pt )
               begin
                if(cur_Wr_Pt>0)
                  empty_Flag = 0;
               end

        always @(posedge  clk)
            begin
                if  (full_Flag==1 ||couter_Rst==1)
                     couter <= 0 ;
                if (full_Flag!=1 &&  ??)
                    couter  <= couter+1;
             end        

        always @(posedge  clk1)
         begin
                if (rst == 1)
                    begin
                          Buff [deep_Size-1:0] <= 0;
                cur_Wr_Pt = 0;               
                next_Wr_Pt = 1;
                    end
               if ((full_Flag!=1)&&(fifoWR==1))
                      begin
                  Buff[cur_Wr_Pt] <= in_Data;
                                     if (next_Wr_Pt< deep_Size-1)
                        begin
                           cur_Wr_Pt  <= next_Wr_Pt;
                           next_Wr_Pt <=cur_Wr_Pt+1;
                        end
                   else  
                          begin
                            full_Flag  <=1;
                            cur_Wr_Pt = 0;
                            next_Wr_Pt = 1;
                         end

                      end

        always @(posedge  clk2)
        begin
             if (rst == 1)
                    begin
                          Buff [deep_Size-1:0] <= 0;               
                cur_Wr_Pt = 1;
                next_Rd_Pt = 1;
                    end
               if ((empty_Flag!=1)&&(fifoRD==1))
                     begin
                 out_data <= Buff[cur_Rd_Pt];
                 if (next_Wr_Pt< deep_Size-1)
                begin
                     cur_Wr_Pt  <= next_Wr_Pt;
                     next_Wr_Pt <=cur_Wr_Pt+1;
                end
               else  
                begin
                   empty_Flag  <=1;
                   cur_Rd_Pt = 0;
                   next_Rd_Pt = 1;
                 end
        end
endmodule


发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

深蓝浅 发表于 2016-12-4 19:41
刚学verilog,受不了begin和end
psx1lin 发表于 2016-12-4 19:52
Verilog是一種用於描述、設計電子系統(特別是數位電路)的硬體描述語言
沒聽過
 楼主| UNICORNLI 发表于 2016-12-5 09:16
 楼主| UNICORNLI 发表于 2016-12-5 09:16

谢谢回帖
 楼主| UNICORNLI 发表于 2016-12-5 09:17
psx1lin 发表于 2016-12-4 19:52
Verilog是一種用於描述、設計電子系統(特別是數位電路)的硬體描述語言
沒聽過

嗯,还有类似的语言是古老的VHDL
深蓝浅 发表于 2016-12-5 09:55
UNICORNLI 发表于 2016-12-5 09:16
把它当做其他语言中的大括号

对啊,为什么不用大括号,代码写起来和看起来都好麻烦
 楼主| UNICORNLI 发表于 2016-12-5 11:16
因为它里面的大括号有其他作用了,再用会让编译器懵逼
 楼主| UNICORNLI 发表于 2016-12-5 11:18
深蓝浅 发表于 2016-12-5 09:55
对啊,为什么不用大括号,代码写起来和看起来都好麻烦

因为大括号有其他作用了,用它做多种作用会让编译器懵逼,也许以后会改呢
深蓝浅 发表于 2016-12-5 11:47
UNICORNLI 发表于 2016-12-5 11:18
因为大括号有其他作用了,用它做多种作用会让编译器懵逼,也许以后会改呢

原来如此
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-9-23 17:20

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表