shaiko
Advanced Member level 5
- Joined
- Aug 20, 2011
- Messages
- 2,644
- Helped
- 303
- Reputation
- 608
- Reaction score
- 297
- Trophy points
- 1,363
- Activity points
- 18,302
While designing a synchronous FIFO, I'm evaluating the pros and cons of 2 methods for generating the full and empty flags:
1. First method - use read and write pointers that are one bit larger than the address. For example:
2. Second method - I call it: "remember who got you there". for example:
Which method would you suggest? And why?
1. First method - use read and write pointers that are one bit larger than the address. For example:
Code:
signal full , empty : std_logic ;
signal write_address , read_addres : unsigned ( 2 downto 0 ) ;
signal write_pointer , read_pointer : unsigned ( 3 downto 0 ) ;
write_address <= write_pointer ( 2 downto 0 ) ;
read_address <= read_pointer ( 2 downto 0 ) ;
if write_pointer ( 2 downto 0 ) = read_pointer ( 2 downto 0 ) then
if ( write_pointer ( 3 ) = read_pointer ( 3 ) ) then
full <= '0' ;
empty <= '1' ;
else
full < = '1' ;
empty < = '0' ;
end if ;
end if ;
2. Second method - I call it: "remember who got you there". for example:
Code:
-- The red equations are evaluated only under the read or write operations.
-- The logic "knows" the state it was at prior to the read or write operation - therefore it can assert the correct flag afterwards...
if rising_edge ( clock ) then
if read_operation = '1' and empty = '0' then
read_address <= read_address + 1 ;
full <= '0' ;
if [COLOR="#FF0000"]write_address - read_address = 1[/COLOR] then
empty <= '1' ;
end if ;
end if ;
if write_operation = '1' and full = '0' then
write_address <= write_address + 1 ;
empty <= '1' ;
if [COLOR="#FF0000"]read_address - write_address = 1[/COLOR] then
full <= '1' ;
end if ;
end if ;
end if ;
Which method would you suggest? And why?