|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 IC.Michael 于 2015-3-26 22:21 编辑
Clifford E. Cummings有一篇文章【Simulation and Synthesis Techniques for Synchronous FIFO Design】提到一个FIFO设计,该设计只能用于测试不能用于综合。其中有些代码不太理解,请教一下大家。代码如下:
- `timescale 1ns/1ns
- module beh_fifo(rdata, rempty, wdata, wfull,
- rinc,rclk,rrst_n, winc,wclk,wrst_n);
-
- 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;
-
- reg [ASIZE:0] wptr, wrptr1, wrptr2, wrptr3;
- reg [ASIZE:0] rptr, rwptr1, rwptr2, rwptr3;
-
- parameter MEMDEPTH = 1<<ASIZE;
-
- reg [DSIZE-1:0] ex_mem [0:MEMDEPTH-1];
-
- always @(posedge wclk or negedge wrst_n)
- begin
- if (!wrst_n)
- wptr <= 0;
- else if (winc && !wfull)
- begin
- ex_mem[wptr[ASIZE-1:0]] <= wdata;
- wptr <= wptr+1;
- end
- end
-
- always @(posedge wclk or negedge wrst_n)
- begin
- if (!wrst_n)
- {wrptr3,wrptr2,wrptr1} <= 0;
- else
- {wrptr3,wrptr2,wrptr1} <= {wrptr2,wrptr1,rptr};
- end
-
- always @(posedge rclk or negedge rrst_n)
- begin
- if (!rrst_n)
- rptr <= 0;
- else if (rinc && !rempty)
- rptr <= rptr+1;
- end
-
- always @(posedge rclk or negedge rrst_n)
- begin
- if (!rrst_n)
- {rwptr3,rwptr2,rwptr1} <= 0;
- else
- {rwptr3,rwptr2,rwptr1} <= {rwptr2,rwptr1,wptr};
- end
-
- assign rdata = ex_mem[rptr[ASIZE-1:0]];
- assign rempty = (rptr == rwptr3);
- assign wfull = ((wptr[ASIZE-1:0] == wrptr3[ASIZE-1:0]) &&
- (wptr[ASIZE] != wrptr3[ASIZE]));
- endmodule
复制代码
代码中关于reg [ASIZE:0] wptr, wrptr1, wrptr2, wrptr3; reg [ASIZE:0] rptr, rwptr1, rwptr2, rwptr3;这两组寄存器中
wrptr1, wrptr2, wrptr3以及rwptr1, rwptr2, rwptr3的作用不甚清楚,第二个以及第四个always块,还望请教一下大家。 |
|