- refactored
git-svn-id: http://moon:8086/svn/vhdl/trunk@1525 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
## NOTE: Do not edit this file.
|
||||
##
|
||||
|
||||
vlib work
|
||||
vcom -explicit -93 "../bbfifo.vhd"
|
||||
vcom -explicit -93 "../tb_bbfifo.vhd"
|
||||
|
||||
#restart -force
|
||||
vsim -t 1ps -lib work tb_bbfifo
|
||||
do {tb_bbfifo.wdo}
|
||||
view wave
|
||||
view structure
|
||||
view signals
|
||||
run 1000 ns
|
||||
@@ -0,0 +1,33 @@
|
||||
onerror {resume}
|
||||
quietly WaveActivateNextPane {} 0
|
||||
add wave -noupdate -format Logic /tb_bbfifo/rst
|
||||
add wave -noupdate -format Logic /tb_bbfifo/clk
|
||||
add wave -noupdate -format Logic /tb_bbfifo/re
|
||||
add wave -noupdate -format Logic /tb_bbfifo/we
|
||||
add wave -noupdate -format Logic /tb_bbfifo/inst_bbfifo/full
|
||||
add wave -noupdate -format Logic /tb_bbfifo/inst_bbfifo/half_full
|
||||
add wave -noupdate -format Literal -radix hexadecimal /tb_bbfifo/din
|
||||
add wave -noupdate -format Logic /tb_bbfifo/inst_bbfifo/dout_vld
|
||||
add wave -noupdate -format Literal -radix hexadecimal /tb_bbfifo/dout
|
||||
add wave -noupdate -format Literal -radix hexadecimal /tb_bbfifo/dout_reg
|
||||
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/q
|
||||
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]
|
||||
WaveRestoreCursors {{Cursor 1} {494499 ps} 0}
|
||||
configure wave -namecolwidth 150
|
||||
configure wave -valuecolwidth 100
|
||||
configure wave -justifyvalue left
|
||||
configure wave -signalnamewidth 1
|
||||
configure wave -snapdistance 10
|
||||
configure wave -datasetprefix 0
|
||||
configure wave -rowmargin 4
|
||||
configure wave -childrowmargin 2
|
||||
configure wave -gridoffset 0
|
||||
configure wave -gridperiod 1
|
||||
configure wave -griddelta 40
|
||||
configure wave -timeline 0
|
||||
update
|
||||
WaveRestoreZoom {0 ps} {1050 ns}
|
||||
@@ -0,0 +1,131 @@
|
||||
-------------------------------------------------------------------------
|
||||
-- Project: JCPU, a portable 8-bit RISC CPU written in VHDL
|
||||
-- This file: Dual-ported register file with asynchrous read
|
||||
|
||||
-- Copyright (C) 2007 J. Ahrensfeld
|
||||
|
||||
-- This library is free software; you can redistribute it and/or
|
||||
-- modify it under the terms of the GNU Lesser General Public
|
||||
-- License as published by the Free Software Foundation; either
|
||||
-- version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
-- This library is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
-- Lesser General Public License for more details.
|
||||
|
||||
-- You should have received a copy of the GNU Lesser General Public
|
||||
-- License along with this library; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
-- For questions and ideas, please contact the author at jens@jayfield.org
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- $Header: D:\usr\cvsroot/VHDL/lib/misc/bbfifo.vhd,v 1.1 2008/10/20 19:26:01 Jens Exp $
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
library IEEE;
|
||||
use IEEE.STD_LOGIC_1164.ALL;
|
||||
use IEEE.numeric_std.ALL;
|
||||
|
||||
entity bbfifo is
|
||||
Generic
|
||||
(
|
||||
depth_bits : integer := 4;
|
||||
data_width : integer := 8
|
||||
);
|
||||
Port
|
||||
(
|
||||
rst : in STD_LOGIC;
|
||||
clk : in STD_LOGIC;
|
||||
re : in STD_LOGIC;
|
||||
we : in STD_LOGIC;
|
||||
full : out STD_LOGIC;
|
||||
half_full : out STD_LOGIC;
|
||||
dout_vld : out STD_LOGIC;
|
||||
din : in unsigned(data_width-1 downto 0);
|
||||
dout : out unsigned(data_width-1 downto 0)
|
||||
);
|
||||
end bbfifo;
|
||||
|
||||
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);
|
||||
signal bucket_array : bucket_array_t;
|
||||
signal Q : unsigned(0 to depth);
|
||||
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
|
||||
|
||||
Q(0) <= we;
|
||||
ce(depth+1) <= re;
|
||||
full <= full_s;
|
||||
dout_vld <= Q(depth);
|
||||
bucket_array(0) <= din;
|
||||
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:
|
||||
for i in 1 to depth generate
|
||||
proc_ce:
|
||||
process(Q, ce)
|
||||
begin
|
||||
ce(i) <= not Q(i) or ce(i+1);
|
||||
end process;
|
||||
|
||||
proc_q:
|
||||
process(clk)
|
||||
begin
|
||||
if rising_edge(clk) then
|
||||
if rst = '1' then
|
||||
Q(i) <= '0';
|
||||
elsif ce(i) = '1' then
|
||||
Q(i) <= Q(i-1);
|
||||
end if;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
proc_data:
|
||||
process (clk)
|
||||
begin
|
||||
if rising_edge(clk) then
|
||||
if ce(i) = '1' then
|
||||
bucket_array(i) <= bucket_array(i-1);
|
||||
end if;
|
||||
end if;
|
||||
end process;
|
||||
end generate;
|
||||
|
||||
end Behavioral;
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
-------------------------------------------------------------------------
|
||||
-- Project: JCPU, a portable 8-bit RISC CPU written in VHDL
|
||||
-- This file: cpu_embedded using cpu_core and rom
|
||||
--
|
||||
-- Copyright (C) 2007 J. Ahrensfeld
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--
|
||||
-- For questions and ideas, please contact the author at jens@jayfield.org
|
||||
--
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
library IEEE;
|
||||
use IEEE.STD_LOGIC_1164.ALL;
|
||||
use IEEE.numeric_std.ALL;
|
||||
|
||||
entity tb_bbfifo is
|
||||
end;
|
||||
|
||||
architecture behave of tb_bbfifo is
|
||||
|
||||
-- Number of user data words for simulation
|
||||
constant CLK_PERIOD : time := 10 ns;
|
||||
|
||||
signal rst : std_logic := '1';
|
||||
signal clk : std_logic := '1';
|
||||
signal re : std_logic := '0';
|
||||
signal we : std_logic := '0';
|
||||
signal dout_vld : std_logic;
|
||||
signal full : std_logic;
|
||||
signal half_full : std_logic;
|
||||
signal din : unsigned(7 downto 0) := (others => '0');
|
||||
signal dout : unsigned(7 downto 0);
|
||||
signal dout_reg : unsigned(7 downto 0);
|
||||
|
||||
|
||||
begin
|
||||
|
||||
inst_bbfifo : entity work.bbfifo
|
||||
GENERIC MAP
|
||||
(
|
||||
depth_bits => 2,
|
||||
data_width => 8
|
||||
)
|
||||
PORT MAP
|
||||
(
|
||||
rst => rst,
|
||||
clk => clk,
|
||||
re => re,
|
||||
we => we,
|
||||
full => full,
|
||||
half_full => half_full,
|
||||
dout_vld => dout_vld,
|
||||
din => din,
|
||||
dout => dout
|
||||
);
|
||||
|
||||
|
||||
CLK_GEN: process
|
||||
begin
|
||||
wait for CLK_PERIOD/2;
|
||||
clk <= not clk;
|
||||
end process;
|
||||
|
||||
RE_GEN: process
|
||||
begin
|
||||
wait for 2*CLK_PERIOD;
|
||||
wait until rising_edge(clk);
|
||||
re <= '1';
|
||||
wait until rising_edge(clk);
|
||||
re <= '0';
|
||||
end process;
|
||||
|
||||
PROC_DOUT_REG: process
|
||||
begin
|
||||
wait until rising_edge(clk);
|
||||
if re = '1' and dout_vld = '1' then
|
||||
dout_reg <= dout;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
STIMULUS: process
|
||||
|
||||
|
||||
begin
|
||||
|
||||
wait for 3*CLK_PERIOD;
|
||||
rst <= '0';
|
||||
din <= X"10";
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '0';
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '0';
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '0';
|
||||
|
||||
wait for 30*CLK_PERIOD;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '1';
|
||||
din <= din + 1;
|
||||
wait until rising_edge(clk) and full = '0';
|
||||
we <= '0';
|
||||
|
||||
wait;
|
||||
|
||||
end process;
|
||||
|
||||
end architecture behave;
|
||||
Reference in New Issue
Block a user