完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
框图如下:
顶层模块: module fifo1 #(parameter DSIZE=8, parameter ASIZE=4) (output [DSIZE-1:0] rdata,, output wfull, output rempty, input [DSIZE-1:0] wdata, input winc,wclk,wrst_n, input rinc,rclk,rrst_n); wire [ASIZE-1:0] waddr,raddr; wire [ASIZE:0] wptr,rptr,wq2_rptr,rq2_wptr; sync_r2w sync_r2w(.wq2_rptr(wq2_rptr), .rptr(rptr), .wclk(wclk),.wrst_n(wrst_n)); sync_w2r sync_w2r(.rq2_wptr(rq2_wptr), .wptr(wptr), .rclk(rclk),.rrst_n(rrst_n)); fifomem #(DSIZE,ASIZE) fifomem (.rdata(rdata), .wdata(wdata), .waddr(waddr), .raddr(raddr), .wclken(winc), .wfull(wfull), .wclk(wclk)); rptr_empty #(ASIZE) rptr_empty (.rempty(rempty), .raddr(raddr), .rptr(rptr), .rq2_wptr(rq2_wptr), .rinc(rinc), .rclk(rclk), .rrst_n(rrst_n)); wptr_full #(ASIZE) wptr_full (.wfull(wfull), .waddr(waddr), .wptr(wptr), .wq2_rptr(wq2_rptr), .winc(winc), .wclk(wclk), .wrst_n(wrst_n)); endmodule module fifomem #(parameter DSIZE = 8, parameter ASIZE = 4) (output [DSIZE-1:0] rdata, input [DSIZE-1:0] wdata, input [ASIZE-1:0] waddr,raddr, input wclken,wfull,wclk); localparam DEPTH = 1< assign rdata = mem[raddr]; always @(posedge wclk) if(wclken && !wfull) mem[waddr] <= wdata; endmodule module sync_r2w #(parameter ASIZE = 4) (output reg [ASIZE:0] wq2_rptr, input [ASIZE:0] rptr, input wclk,wrst_n); reg [ASIZE:0] wq1_rptr; always @(posedge wclk or negedge wrst_n) if(!wrt_n) {wq2_rptr,wq1_rptr} <= 0; else {wq2_rptr,wq1_rptr} <= {wq1_rptr,rptr}; endmodule module sync_w2r #(parameter ASIZE = 4) (output reg [ASIZE:0] rq2_wptr, input [ASIZE:0] wptr, input rclk,rrst_n); reg [ASIZE:0] rq1_wptr; always @(posedge rclk or negedge rrst_n) if(!rrst_n) {rq2_wptr,rq1_wptr} <= 0; else {rq2_wptr,rq1_wptr} <= {rq1_wptr,wptr}; endmodule module rptr_empty #(parameter ASIZE = 4) (output reg rempty, output [ASIZE-1:0] raddr, output reg [ASZIE :0] rptr, input [ASIZE :0] rq2_wptr, input rinc,rclk,rrst_n); reg [ASZIE:0] rbin; wire[ASIZE:0] rgraynext,rbinnext; always @(posedge rclk or negedge rrst_n) if(!rrst_n) {rbin,rptr} <= 0; else {rbin,rptr} <={rbinnext,rgraynext}; assign raddr = rbin[ASZIE-1:0]; assign rbinnext = rbin + (rinc & ~rempty); assign rgraynext = (rbinnext>>1) ^ rbinnext; assign remty_val = (rgarynext == rq2_wptr); always @(posedge rclk or negedge rrst_n) if (!rrst_n) rempty <= 1'b1; else rempty <= rempty_val; endmodule module wptr_full #(parameter ASIZE = 4) (output reg wfull, output [ASIZE-1:0] waddr, output reg [ASIZE:0] wptr, input [ASIZE:0] wq2_rptr, input winc,wclk,wrst_n); reg [ASIZE:0] wbin; wire [ASIZE:0] wgraynext,wbinnext; always @(posedge wclk or negedge wrst_n) if(!wrst_n) {wbin,wptr} <= 0; else {wbin,wptr} <= {wbinnext,wgraynext}; assign waddr = wbin[ASIZE-1:0]; assign wbinnext=wbin+(winc & ~wfull); assign wgraynext = (wbinnext>>1) ^ wbinnext; assign wfull_val = (wgraynext=={~wq2_rptr[ASIZE:ASIZE-1],wq2_rptr[ASIZE-2:0]}); always @(posedge wclk or negedge wrst_n) if(!wrst_n) wfull <= 1'b0; else wfull <= wfull_val; endmodule
|
|
相关推荐
|
|
1446 浏览 1 评论
助力AIoT应用:在米尔FPGA开发板上实现Tiny YOLO V4
1061 浏览 0 评论
2525 浏览 1 评论
2217 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
2486 浏览 0 评论
1956 浏览 54 评论
6032 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 22:16 , Processed in 0.736365 second(s), Total 66, Slave 47 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号