|
请问其中ASIZE为什么是4?我觉得应该是3.我在一本书上看到也是4." ~0 l6 h9 R8 b& _# g1 O3 w
module fifo1(rdata, wfull, rempty, wdata, winc, wclk, wrst_n,rinc, rclk, rrst_n); : c2 ]7 u+ u8 N2 r/ X7 `+ g2 r4 P
parameter DSIZE = 8; parameter ASIZE = 4;
- F# g2 Z( W+ c! F/ ^; Goutput [DSIZE-1:0] rdata; ; x# k# D, L, H) b: `! d4 V: C
output wfull; / j; Q: T+ v, W& S% R' b' ~4 F
output rempty;
1 l2 z8 i7 u; C) K u4 e. T _+ \input [DSIZE-1:0] wdata;
, ^4 b6 R3 V& Q$ \; ]* Vinput winc, wclk, wrst_n;
; `8 `% r0 }' [0 Y8 R, S* a! ]input rinc, rclk, rrst_n; 9 G, K) e- u1 e' t' b5 `
reg wfull,rempty; - p& d" v0 _2 T: S5 S/ T
reg [ASIZE:0] wptr, rptr, wq2_rptr, rq2_wptr, wq1_rptr,rq1_wptr;
P: }$ |4 T$ `0 ]reg [ASIZE:0] rbin, wbin;
2 b, B3 a' M1 [- O) \reg [DSIZE-1:0] mem[0: (1<<ASIZE)-1];
* V# a# H9 I# a) S3 Fwire [ASIZE-1:0] waddr, raddr; 1 I8 a2 L: t# f6 q* A( u. p5 Y
wire [ASIZE:0] rgraynext, rbinnext,wgraynext,wbinnext; 6 M$ J) m6 K# c% M5 z
wire rempty_val,wfull_val; ' V. v" {8 r: `
- G {0 d3 \# @( i- l: Tassign rdata=mem[raddr]; ; @- U2 X9 }7 e( Y" }
always@(posedge wclk) ! h1 y! S; _' g0 r' d
if (winc && !wfull) mem[waddr] <= wdata; ; g2 z4 J' @+ E# A4 U" o9 G* t
+ N$ i: P' D, z( V5 M# Ialways @(posedge wclk or negedge wrst_n) - ]$ j6 R/ p. B0 J' x5 L
if (!wrst_n) {wq2_rptr,wq1_rptr} <= 0;
: [* c0 t( h. o6 P9 Ielse {wq2_rptr,wq1_rptr} <= {wq1_rptr,rptr};
- u) X4 A3 |0 R8 L9 E% d
G& \2 B9 B {: talways @(posedge rclk or negedge rrst_n) * `2 }8 M* L: i3 r. g* D6 `
if (!rrst_n) {rq2_wptr,rq1_wptr} <= 0; # P( b8 O1 J5 d* v
else {rq2_wptr,rq1_wptr} <= {rq1_wptr,wptr};
( R( @4 M- x9 D1 {3 p6 E& }7 J
* i9 B6 ] r6 E' w0 b* Y0 `. I$ D# l
always @(posedge rclk or negedge rrst_n) // GRAYSTYLE2 pointer 6 D' w% l7 r1 X8 c& u
begin 1 f2 h8 j+ r2 {: f; N k: x5 p1 C
if (!rrst_n) {rbin, rptr} <= 0;
D4 [8 E# _1 Eelse {rbin, rptr} <= {rbinnext, rgraynext}; ! N7 h8 U9 W( W" i) g
end . u* X3 {* u: @7 |
! i) H- H' k" i$ J& d. i4 E; W% }
" _( G7 I& |# m% X' ~' Nassign raddr = rbin[ASIZE-1:0]; , ?& F3 x+ P6 H* \0 s& J& P) N
assign rbinnext = rbin + (rinc & ~rempty);
3 K9 F, R2 {! u# {. S8 y% sassign rgraynext = (rbinnext>>1) ^ rbinnext;
0 R1 |. d. N; S4 A6 [8 o2 v1 ]! c
4 Z0 C7 n, l- B6 X% G' qassign rempty_val = (rgraynext == rq2_wptr); + V8 s" V/ y& g2 f
always @(posedge rclk or negedge rrst_n) 0 L* W$ d2 r/ Z9 e/ Q- X2 S9 K
begin
* J9 h* O% [9 F: a oif (!rrst_n) rempty <= 1'b1; 5 @- ^; K* {! C7 z( a" {. @( [
else rempty <= rempty_val;
1 q/ G6 X7 R3 u. M* z+ }. m5 Z9 Uend
8 F# z7 @- }9 p v
}+ R3 a9 r, m' E: |5 y; N5 Y: }. [, f
always @(posedge wclk or negedge wrst_n) // GRAYSTYLE2 pointer . [, x& d, T3 q3 N
if (!wrst_n) {wbin, wptr} <= 0;
0 N; |! w* X; d6 O3 p* |) \else {wbin, wptr} <= {wbinnext, wgraynext};
/ @* \2 b) @8 h: r+ n9 q2 G. D5 |. G) g9 F; S1 u
# h6 R/ y, A& K" U9 a5 i; \, cassign waddr = wbin[ASIZE-1:0];
! E% ]$ t: Z. H: q" tassign wbinnext = wbin + (winc & ~wfull);
0 W6 f. L: e: M! w/ f# b6 k7 lassign wgraynext = (wbinnext>>1) ^ wbinnext;
9 E4 G5 E; n0 g! E" _" Qassign wfull_val = (wgraynext=={~wq2_rptr[ASIZE:ASIZE-1], wq2_rptr[ASIZE-2:0]}); //:ASIZE-1]- t) F ~/ y; [; r3 d' x
always @(posedge wclk or negedge wrst_n) 9 z" J5 W" J7 a! t0 Q. y) h- A
if (!wrst_n) wfull <= 1'b0; * q% Z, |* a+ ?2 ]( x7 }. i
else wfull <= wfull_val;
. ^2 N6 s; \1 [endmodule) ~! G0 e& r( S3 z! {* V' M% c
) S4 m# Z( g+ i; `( m; b0 ~
[ 本帖最後由 xuduo6845 於 2009-9-4 11:25 AM 編輯 ] |
|