FIFO (two): FIFO works

 

                                            FIFO works

     The work is divided into the clock domain FIFO synchronous / asynchronous FIFO. Synchronous FIFO means a read clock and write clock with a clock in the clock edge comes simultaneous read and write. Inconsistent asynchronous FIFO read and write clocks, independent read and write.

1. read and write pointers works

Read pointer: always points to the next cell to be read, to the first element (numbered 0) reset;

Write pointer: always points to the current data to be read out, reset, to the first element (numbered 0);

2. FIFO "empty / full" detection

  FIFO key design : FIFO read and write pointers to produce reliable and generate FIFO "empty / full" status identified.

      Obviously, when the FIFO is full, you can not write new data, and otherwise cause an overflow of data; and the data that is written in the empty state before've read, you can not read, or read data It is invalid data.

2.1 Read null signal (rd_empty)

      Generally when the write pointer are equal, indicating that the FIFO is empty, this occurs when the reset operation , or when the read pointer is read FIFO last word , the write pointer on the catch, when the read valid null signal.

It occurs as shown below:

2.2 filled signal (wr_full)

     When the read pointer is again equal, indicates that the FIFO is full, this situation occurs, when the write pointer in a circle folded back (wrapped around) and catch up with the read pointer, as shown below:

 

以上FIFO的读写状态是基于读写指针的比较,而问题是两者的判断条件都是读写指针相等,区别在于写满状态是在写指针写满一圈后重新追上读指针,这该如何取表示呢???

如何区分到底是满状态还是空状态呢??

2.3 FIFO读写状态的判断方法

可以采用以下两种方法:

1extra bit

一般情况下深度为N=2^n的FIFO其地址的位宽为n,其读写地址的位宽也为n。共有N个存储单元,若数据位宽为W则该FIFO的容量即为N*W bit。

现在在指针中添加额外的位(extra bit,即地址的MSB)变为n+1bit,该extra bit用于指示写指针是否递增并越过最后一个FIFO地址,若越过则将该MSB加1,其它位清零。对读指针也进行同样的操作。如对于深度为8的FIFO,需要采用3+1bit是计数器:0000-1000、1001-1111,MSB作为折回标志,而低3位作为地址指针。

那么判断机制为:

   *如果两个指针的MSB不同,就说明写指针比读指针多折回一次:如r_addr=0000,且w_addr=1000,为满;

   *如果两个指针的MSB相同,就说明两个指针折回次数相等。再者其余位相等(则说明FIFO为空。

2)设置数据计数器

设置一个data_counter, 当写使能有效时每写入一个data计数器同时加1;读操作时,每读出一个data时该计数器减1。如此,当data_counter为0时FIFO空,当data_counter计数至FIFO深度deep时,表示FIFO写满。

由于计数器会占用额外的资源,当FIFO较大时,可能会降低FIFO的读写速度。

3 读写指针的表示

读写指针的编码有多种,上述提到的指针采用二进制码形式表示。

3.1二进制FIFO指针

将一个二进制的计数值从一个时钟域同步到另一个时钟域的时候很容易出现问题,因为采用二进制计数器时所有位都可能同时变化,在同一个时钟沿同步多个信号的变化会产生亚稳态问题。而使用格雷码只有一位变化,因此在两个时钟域间同步多个位不会产生问题。所以需要一个 二进制到gray码的转换电路  ,将地址值转换为相应的gray码,然后将该gray码同步到另一个时钟域进行对比,作为空满状态的检测。

3.2 gray码表示指针

使用gray码解决了一个问题,同时也带来另一个问题,即格雷码如何判断空与满?

空的判断

依然依据二者完全相等(包括MSB);

满的判断

如下图,由于gray码除了MSB外具有镜像对称的特点,当读指针指向7,写指针指向8时,除了MSB其余位都相同,不能说它为满。因此不能单纯地检测最高位了,在gray码上判断为满必须同时满足以下3条:

wptr 和同步过来的rptr的MSB不相等,因为wptr必须比rptr多折回一次;

wptr与rptr的次高位不相等;如上图位置7和和位置15,转化为2进制:0111和1111. 。MSB不同说明多折回一次,111相同代表同一个位置。 

 

Guess you like

Origin blog.csdn.net/qq_26652069/article/details/90765269