[BB-FIFO]
- fixed full and half full git-svn-id: http://moon:8086/svn/vhdl/trunk@1350 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
+36
-5
@@ -31,7 +31,7 @@ use IEEE.numeric_std.ALL;
|
|||||||
entity bbfifo is
|
entity bbfifo is
|
||||||
Generic
|
Generic
|
||||||
(
|
(
|
||||||
depth : integer := 2;
|
depth_bits : integer := 4;
|
||||||
data_width : integer := 8
|
data_width : integer := 8
|
||||||
);
|
);
|
||||||
Port
|
Port
|
||||||
@@ -50,21 +50,52 @@ end bbfifo;
|
|||||||
|
|
||||||
architecture Behavioral of bbfifo is
|
architecture Behavioral of bbfifo is
|
||||||
|
|
||||||
|
constant depth : natural := 2**depth_bits;
|
||||||
type bucket_array_t is array (0 to depth) of unsigned(data_width-1 downto 0);
|
type bucket_array_t is array (0 to depth) of unsigned(data_width-1 downto 0);
|
||||||
signal bucket_array : bucket_array_t;
|
signal bucket_array : bucket_array_t;
|
||||||
signal Q : unsigned(0 to depth) := (others => '0');
|
signal Q : unsigned(0 to depth);
|
||||||
signal ce : unsigned(1 to depth+1) := (others => '0');
|
signal ce : unsigned(1 to depth+1);
|
||||||
|
signal up : std_logic;
|
||||||
|
signal down : std_logic;
|
||||||
|
signal fill : unsigned(depth_bits downto 0);
|
||||||
|
signal full_s : std_logic;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
Q(0) <= we;
|
Q(0) <= we;
|
||||||
ce(depth+1) <= re;
|
ce(depth+1) <= re;
|
||||||
full <= not ce(1);
|
full <= full_s;
|
||||||
half_full <= not ce(1+depth/2);
|
|
||||||
dout_vld <= Q(depth);
|
dout_vld <= Q(depth);
|
||||||
bucket_array(0) <= din;
|
bucket_array(0) <= din;
|
||||||
dout <= bucket_array(depth);
|
dout <= bucket_array(depth);
|
||||||
|
|
||||||
|
up <= we and not full_s;
|
||||||
|
down <= re and Q(depth);
|
||||||
|
|
||||||
|
proc_fill:
|
||||||
|
process(clk)
|
||||||
|
variable fill_next : unsigned(depth_bits downto 0);
|
||||||
|
begin
|
||||||
|
if rising_edge(clk) then
|
||||||
|
if rst = '1' then
|
||||||
|
fill_next := (others => '0');
|
||||||
|
elsif up = '1' and down = '0' then
|
||||||
|
fill_next := fill + 1;
|
||||||
|
elsif up = '0' and down = '1' then
|
||||||
|
fill_next := fill - 1;
|
||||||
|
end if;
|
||||||
|
full_s <= '0';
|
||||||
|
half_full <= '0';
|
||||||
|
fill <= fill_next;
|
||||||
|
if fill_next > depth/2-1 then
|
||||||
|
half_full <= '1';
|
||||||
|
end if;
|
||||||
|
if fill_next > depth-1 then
|
||||||
|
full_s <= '1';
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
end process;
|
||||||
|
|
||||||
gen_bb:
|
gen_bb:
|
||||||
for i in 1 to depth generate
|
for i in 1 to depth generate
|
||||||
proc_ce:
|
proc_ce:
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ add wave -noupdate -divider BB-FIFO
|
|||||||
add wave -noupdate -format Literal /tb_bbfifo/inst_bbfifo/ce
|
add wave -noupdate -format Literal /tb_bbfifo/inst_bbfifo/ce
|
||||||
add wave -noupdate -format Literal /tb_bbfifo/inst_bbfifo/q
|
add wave -noupdate -format Literal /tb_bbfifo/inst_bbfifo/q
|
||||||
add wave -noupdate -format Literal -radix hexadecimal /tb_bbfifo/inst_bbfifo/bucket_array
|
add wave -noupdate -format Literal -radix hexadecimal /tb_bbfifo/inst_bbfifo/bucket_array
|
||||||
|
add wave -noupdate -format Literal -radix unsigned /tb_bbfifo/inst_bbfifo/fill
|
||||||
TreeUpdate [SetDefaultTree]
|
TreeUpdate [SetDefaultTree]
|
||||||
WaveRestoreCursors {{Cursor 1} {70000 ps} 0}
|
WaveRestoreCursors {{Cursor 1} {77874 ps} 0}
|
||||||
configure wave -namecolwidth 150
|
configure wave -namecolwidth 150
|
||||||
configure wave -valuecolwidth 100
|
configure wave -valuecolwidth 100
|
||||||
configure wave -justifyvalue left
|
configure wave -justifyvalue left
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ begin
|
|||||||
inst_bbfifo : entity work.bbfifo
|
inst_bbfifo : entity work.bbfifo
|
||||||
GENERIC MAP
|
GENERIC MAP
|
||||||
(
|
(
|
||||||
depth => 4,
|
depth_bits => 2,
|
||||||
data_width => 8
|
data_width => 8
|
||||||
)
|
)
|
||||||
PORT MAP
|
PORT MAP
|
||||||
|
|||||||
Reference in New Issue
Block a user