aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/synth/fsm01
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-06-30 13:46:08 +0200
committerTristan Gingold <tgingold@free.fr>2019-06-30 13:46:08 +0200
commit181165f90d7ab05cff1c2bc5894d0143f03d3634 (patch)
treebb27972df2886504ba7b9d426b39c4840c2a077a /testsuite/synth/fsm01
parent10b2f5a4012ae368dfcf49628281e34674f913d7 (diff)
downloadghdl-181165f90d7ab05cff1c2bc5894d0143f03d3634.tar.gz
ghdl-181165f90d7ab05cff1c2bc5894d0143f03d3634.tar.bz2
ghdl-181165f90d7ab05cff1c2bc5894d0143f03d3634.zip
testsuite/synth: add a test for previous commit.
Diffstat (limited to 'testsuite/synth/fsm01')
-rw-r--r--testsuite/synth/fsm01/fsm_2s.vhdl38
-rw-r--r--testsuite/synth/fsm01/tb_fsm_2s.vhdl44
-rwxr-xr-xtestsuite/synth/fsm01/testsuite.sh2
3 files changed, 83 insertions, 1 deletions
diff --git a/testsuite/synth/fsm01/fsm_2s.vhdl b/testsuite/synth/fsm01/fsm_2s.vhdl
new file mode 100644
index 000000000..a951721c0
--- /dev/null
+++ b/testsuite/synth/fsm01/fsm_2s.vhdl
@@ -0,0 +1,38 @@
+library ieee;
+use ieee.std_logic_1164.all;
+
+entity fsm_2s is
+ port (clk : std_logic;
+ rst : std_logic;
+ d : std_logic;
+ done : out std_logic);
+end fsm_2s;
+
+architecture behav of fsm_2s is
+ type state_t is (S0_1, S1_0);
+ signal s : state_t;
+begin
+ process (clk)
+ begin
+ if rising_edge(clk) then
+ if rst = '1' then
+ s <= S0_1;
+ done <= '0';
+ else
+ -- Reset by default
+ s <= S0_1;
+ done <= '0';
+ case s is
+ when S0_1 =>
+ if d = '1' then
+ s <= S1_0;
+ end if;
+ when S1_0 =>
+ if d = '0' then
+ done <= '1';
+ end if;
+ end case;
+ end if;
+ end if;
+ end process;
+end behav;
diff --git a/testsuite/synth/fsm01/tb_fsm_2s.vhdl b/testsuite/synth/fsm01/tb_fsm_2s.vhdl
new file mode 100644
index 000000000..d647db5c9
--- /dev/null
+++ b/testsuite/synth/fsm01/tb_fsm_2s.vhdl
@@ -0,0 +1,44 @@
+entity tb_fsm_2s is
+end tb_fsm_2s;
+
+library ieee;
+use ieee.std_logic_1164.all;
+
+architecture behav of tb_fsm_2s is
+ signal clk : std_logic;
+ signal rst : std_logic;
+ signal din : std_logic;
+ signal done : std_logic;
+begin
+ dut: entity work.fsm_2s
+ port map (
+ done => done,
+ d => din,
+ clk => clk,
+ rst => rst);
+
+ process
+ constant dat : std_logic_vector := b"10010";
+ constant res : std_logic_vector := b"01001";
+ procedure pulse is
+ begin
+ clk <= '0';
+ wait for 1 ns;
+ clk <= '1';
+ wait for 1 ns;
+ end pulse;
+ begin
+ rst <= '1';
+ din <= '0';
+ pulse;
+ assert done = '0' severity failure;
+ -- Test the whole sequence.
+ rst <= '0';
+ for i in dat'range loop
+ din <= dat (i);
+ pulse;
+ assert done = res(i) severity failure;
+ end loop;
+ wait;
+ end process;
+end behav;
diff --git a/testsuite/synth/fsm01/testsuite.sh b/testsuite/synth/fsm01/testsuite.sh
index b9a451fa2..08d7ff60f 100755
--- a/testsuite/synth/fsm01/testsuite.sh
+++ b/testsuite/synth/fsm01/testsuite.sh
@@ -2,7 +2,7 @@
. ../../testenv.sh
-for t in fsm_4s; do
+for t in fsm_2s fsm_4s; do
analyze $t.vhdl tb_$t.vhdl
elab_simulate tb_$t
clean