aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/synth/fsm01/fsm_5s.vhdl
blob: 8e7b387c75e6c20773cbd1b09121e029f9364924 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
library ieee;
use ieee.std_logic_1164.all;

entity fsm_5s is
  port (clk : std_logic;
        rst : std_logic;
        d : std_logic;
        done : out std_logic);
end fsm_5s;

architecture behav of fsm_5s is
  type state_t is (S0_1, S1_0, S2_0, S3_1, S4_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
              s <= S2_0;
            end if;
          when S2_0 =>
            if d = '0' then
              s <= S3_1;
            end if;
          when S3_1 =>
            if d = '1' then
              s <= S4_0;
            end if;
          when S4_0 =>
            if d = '0' then
              done <= '1';
            end if;
        end case;
      end if;
    end if;
  end process;
end behav;