完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
//Asynchronic FIFO
//function description //using gray code to synchronic asynchronic signal module AsyncFIFO( wclk,rclk,wen,ren,din,dout,wrst,rrst, rempty,wfull); parameter DataWidth=8, RamDepth =16, AddrWidth=4; //port write input wclk; input wen; input [(DataWidth-1):0] din; input wrst; //port read input rclk; input ren; input rrst; //output port output [(DataWidth-1):0] dout; output rempty;//high active output wfull;//high active //reg rempty; //reg wfull; //wire [(DataWidth-1):0] dout; reg [(DataWidth-1):0] dout; wire rempty_val; wire wfull_val; /*****************************/ //FIFO MEMORY reg [(DataWidth-1):0] FIFO_RAM[(RamDepth-1):0]; //write wire [(AddrWidth-1):0] raddr;//read address wire [(AddrWidth-1):0] waddr;//write address reg [AddrWidth:0] rptr_binary;//read pointer with MSB reg [AddrWidth:0] wptr_binary;//write pointer with MSB wire [AddrWidth:0] rptr_gray;//read pointer transform to gray code wire [AddrWidth:0] wptr_gray;//write pointer transform to gray code reg [AddrWidth:0] wptr_gray1; reg [AddrWidth:0] rptr_gray1;//用寄存器输出的原因是,因为在同步到另一个时钟域的时候,必须不经过任何组合逻辑,同步器的第一级对于组合逻辑产生的毛刺很敏感, //同时同步器的两个寄存器要尽量的放的近些。防止设计者加入组合逻辑 //synchronic reg variate reg [AddrWidth:0] w_rptr_gray; reg [AddrWidth:0] w_rptr_gray1; reg [AddrWidth:0] r_wptr_gray; reg [AddrWidth:0] r_wptr_gray1; //write and read address generation assign raddr = rptr_binary[(AddrWidth-1):0]; assign waddr = wptr_binary[(AddrWidth-1):0]; /*******************the synchronization of asynchronous clock dpmains************/ //read pointer synchronize to write clock always @(posedge wclk,negedge wrst) if(!wrst) {w_rptr_gray1,w_rptr_gray} <= 0; else {w_rptr_gray1,w_rptr_gray} <= {w_rptr_gray,rptr_gray1}; //write pointer synchronize to read clock always @(posedge rclk,negedge rrst) if(!rrst) {r_wptr_gray1,r_wptr_gray} <= 0; else {r_wptr_gray1,r_wptr_gray} <= {r_wptr_gray,wptr_gray1}; /**************************write and read binary pointer generation****************/ always @(posedge wclk,negedge wrst) if(!wrst) wptr_binary <= 0; else if(wen&&!wfull) begin wptr_binary <= wptr_binary + 1; FIFO_RAM[waddr] <= din; end always @(posedge rclk,negedge rrst) if(!rrst) rptr_binary <= 0; else if(ren&&!rempty) begin rptr_binary <= rptr_binary +1; dout <= FIFO_RAM[raddr]; //dout <= FIFORAM[raddr]; end //assign dout = FIFO_RAM[raddr];//directly output dout,if using register,what will happen, /*******************binary to gray code using combination logic *************************/ assign wptr_gray = wptr_binary ^ (wptr_binary >>1); assign rptr_gray = rptr_binary ^ (rptr_binary >>1); //reg wptr_gray1; //reg rptr_gray1;//用寄存器输出的原因是,因为在同步到另一个时钟域的时候,必须不经过任何组合逻辑,同步器的第一级对于组合逻辑产生的毛刺很敏感, //同时同步器的两个寄存器要尽量的放的近些。防止设计者加入组合逻辑 always @(posedge wclk,negedge wrst) if(!wrst) wptr_gray1 <= 0; else wptr_gray1 <= wptr_gray; always @(posedge rclk,negedge rrst) if(!rrst) rptr_gray1 <= 0; else rptr_gray1 <= rptr_gray; /******************wfull flag and rempty flag generation using combination logic*********/ assign wfull_val = ({~wptr_gray[AddrWidth:AddrWidth-1],wptr_gray[AddrWidth-2:0]} //MSB and sub-MSB different is the condition of full == w_rptr_gray1); assign rempty_val = (rptr_gray == r_wptr_gray1); /*always @(posedge wclk,negedge wrst) if(!wrst) wfull <= 0; else wfull <= wfull_val; always @(posedge rclk,negedge rrst) if(!rrst) rempty <= 1; else rempty <= rempty_val;*/ wire wfull; wire rempty; assign wfull = (!wrst) ? 0 : wfull_val; assign rempty = (!rrst) ? 1 : rempty_val; endmodule |
|
相关推荐
|
|
1500 浏览 1 评论
助力AIoT应用:在米尔FPGA开发板上实现Tiny YOLO V4
1072 浏览 0 评论
2584 浏览 1 评论
2270 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
2541 浏览 0 评论
2025 浏览 55 评论
6037 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-28 10:34 , Processed in 0.573844 second(s), Total 64, Slave 47 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号