Skip to content

Commit

Permalink
More test benches, signaling STOP to the outside, added missing flags.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://netzhansa.com/home/hans/cadr2-svn/trunk/secd@861 09d5f3f9-6417-0410-bd0c-e187ee50e7ab
  • Loading branch information
hans committed Jul 11, 2006
1 parent f139458 commit df86250
Show file tree
Hide file tree
Showing 9 changed files with 392 additions and 112 deletions.
121 changes: 63 additions & 58 deletions vhdl/clock_gen.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -21,70 +21,75 @@ end;

architecture my_clock_gen of clock_gen is

type state is (s_idle, s_read, s_alu, s_write, s_wait, s_next);
type state_type is (s_idle, s_read, s_alu, s_write, s_wait, s_next);

signal current_state : state := s_idle;
signal next_state : state := s_idle;
signal state : state_type := s_idle;

begin
clock_gen : process(clk, reset, state, ram_busy, alu_ins)
begin
clock_gen : process(current_state, ram_busy, alu_ins)
begin
if reset = '1' then

phi_read <= '0';
phi_alu <= '0';
phi_write <= '0';
phi_next <= '0';
state <= s_idle;

case current_state is

when s_idle =>
next_state <= s_read;

when s_read =>
phi_read <= '1';
if alu_ins = '0' then
next_state <= s_write;
else
next_state <= s_alu;
end if;

when s_alu =>
phi_alu <= '1';
next_state <= s_write;

when s_write =>
phi_write <= '1';
next_state <= s_next;

when s_next =>
phi_next <= '1';
if ram_busy = '1' then
next_state <= s_wait;
else
next_state <= s_read;
end if;

when s_wait =>
if ram_busy = '0' then
next_state <= s_read;
else
next_state <= s_wait;
end if;
end case;
end process;

set_next_state : process(clk, next_state, reset)
begin
if reset = '1' then
current_state <= s_idle;
elsif rising_edge(clk) then
if stop = '1' then
stopped <= '1';
current_state <= current_state;
else
stopped <= '0';
current_state <= next_state;
end if;
end if;
end process;
elsif rising_edge(clk) then

if stop = '1' then

stopped <= '1';

else

stopped <= '0';

phi_read <= '0';
phi_alu <= '0';
phi_write <= '0';
phi_next <= '0';

case state is

end;
when s_idle =>
state <= s_read;

when s_read =>
phi_read <= '1';
if ram_busy = '0' then
if alu_ins = '0' then
state <= s_write;
else
state <= s_alu;
end if;
end if;

when s_alu =>
phi_alu <= '1';
state <= s_write;

when s_write =>
phi_write <= '1';
state <= s_next;

when s_next =>
phi_next <= '1';
if ram_busy = '1' then
state <= s_wait;
else
state <= s_read;
end if;

when s_wait =>
if ram_busy = '0' then
state <= s_read;
else
state <= s_wait;
end if;
end case;
end if;
end if;
end process;
end;
121 changes: 121 additions & 0 deletions vhdl/clock_gen_TB.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
-------------------------------------------------------------------------------
--
-- Title : Test Bench for clock_gen
-- Design : secd
-- Author : Hans Hübner
-- Company : .
--
-------------------------------------------------------------------------------
--
-- File : H:\fpga\secd\vhdl\clock_gen_TB.vhd
-- Generated : 05.07.2006, 13:59
-- From : h:\fpga\secd\vhdl\clock_gen.vhd
-- By : Active-HDL Built-in Test Bench Generator ver. 1.2s
--
-------------------------------------------------------------------------------
--
-- Description : Automatically generated Test Bench for clock_gen_tb
--
-------------------------------------------------------------------------------

library ieee;
use work.secd_defs.all;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;

-- Add your library and packages declaration here ...

entity clock_gen_tb is
end clock_gen_tb;

architecture TB_ARCHITECTURE of clock_gen_tb is
-- Component declaration of the tested unit
component clock_gen
port(
reset : in std_logic;
clk : in std_logic;
alu_ins : in std_logic;
ram_busy : in std_logic;
phi_read : out std_logic;
phi_alu : out std_logic;
phi_write : out std_logic;
phi_next : out std_logic;
stop : in std_logic;
stopped : out std_logic );
end component;

-- Stimulus signals - signals mapped to the input and inout ports of tested entity
signal reset : std_logic;
signal clk : std_logic;
signal alu_ins : std_logic;
signal ram_busy : std_logic;
signal stop : std_logic;
-- Observed signals - signals mapped to the output ports of tested entity
signal phi_read : std_logic;
signal phi_alu : std_logic;
signal phi_write : std_logic;
signal phi_next : std_logic;
signal stopped : std_logic;

-- Add your code here ...

begin

-- Unit Under Test port map
UUT : clock_gen
port map (
reset => reset,
clk => clk,
alu_ins => alu_ins,
ram_busy => ram_busy,
phi_read => phi_read,
phi_alu => phi_alu,
phi_write => phi_write,
phi_next => phi_next,
stop => stop,
stopped => stopped
);

-- Add your stimulus here ...

clock_stimulus : process
begin
clk <= '1';
wait for 40 ns;
clk <= '0';
wait for 40 ns;
end process;

reset <= '0';
stop <= '0';

ram_is_busy : process
begin
loop
ram_busy <= '0';
wait for 900 ns;
ram_busy <= '1';
wait for 420 ns;
end loop;
end process;

has_alu_instruction : process
begin
loop
alu_ins <= '0';
wait for 500 ns;
alu_ins <= '1';
wait for 300 ns;
end loop;
end process;

end TB_ARCHITECTURE;

configuration TESTBENCH_FOR_clock_gen of clock_gen_tb is
for TB_ARCHITECTURE
for UUT : clock_gen
use entity work.clock_gen(my_clock_gen);
end for;
end for;
end TESTBENCH_FOR_clock_gen;

19 changes: 19 additions & 0 deletions vhdl/clock_gen_TB_runtest.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SetActiveLib -work
comp -include "h:\fpga\secd\vhdl\clock_gen.vhd"
comp -include "H:\fpga\secd\vhdl\clock_gen_TB.vhd"
asim TESTBENCH_FOR_clock_gen
wave
wave -noreg reset
wave -noreg clk
wave -noreg alu_ins
wave -noreg ram_busy
wave -noreg phi_read
wave -noreg phi_alu
wave -noreg phi_write
wave -noreg phi_next
wave -noreg stop
wave -noreg stopped
# The following lines can be used for timing simulation
# acom <backannotated_vhdl_file_name>
# comp -include "H:\fpga\secd\vhdl\clock_gen_TB_tim_cfg.vhd"
# asim TIMING_FOR_clock_gen
22 changes: 14 additions & 8 deletions vhdl/control_unit.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,29 @@ architecture my_control_unit of control_unit is
opcode, button, stack, next_mpc, sp)
begin
if reset = '1' then
mpc <= (others => '0');
push_stack <= '0';
pop_stack <= '0';
mpc <= (others => '0');
push_stack <= '0';
pop_stack <= '0';
stop_instruction <= '0';
elsif rising_edge(phi_next) then
push_stack <= '0';
pop_stack <= '0';
push_stack <= '0';
pop_stack <= '0';
stop_instruction <= '0';
if mi_test = jump then
mpc <= mi_a;
elsif mi_test = dispatch then
report "executing instruction " & integer'image(to_integer(unsigned(opcode))) & " " & secd_ins_name(to_integer(unsigned(opcode)));
-- report "executing instruction " & integer'image(to_integer(unsigned(opcode))) & " " & secd_ins_name(to_integer(unsigned(opcode)));
mpc <= opcode;
elsif mi_test = markp and flags(mark) = '1' then
mpc <= mi_a;
elsif mi_test = fieldp and flags(field) = '1' then
mpc <= mi_a;
elsif mi_test = eqp and flags(eq) = '1' then
mpc <= mi_a;
elsif mi_test = leqp and flags(leq) = '1' then
mpc <= mi_a;
elsif mi_test = zerop and flags(zero) = '1' then
mpc <= mi_a;
elsif mi_test = nump and flags(num) = '1' then
mpc <= mi_a;
elsif mi_test = atomp and flags(atom) = '1' then
Expand All @@ -85,10 +91,10 @@ architecture my_control_unit of control_unit is
mpc <= mi_a;
elsif mi_test = call then
mpc <= mi_a;
stack(sp + 1) <= next_mpc;
stack(sp) <= next_mpc;
push_stack <= '1';
elsif mi_test = returnx then
mpc <= stack(sp);
mpc <= stack(sp - 1);
pop_stack <= '1';
elsif mi_test = stop then
stop_instruction <= '1';
Expand Down
Loading

0 comments on commit df86250

Please sign in to comment.