aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/gna/issue736/simple_fsm.vhdl
blob: dfc871ba9fee974cada4993f328ca5f15861c6b3 (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
--Standard Library
library ieee;
--Standard Packages
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity simple_fsm is
  port (
    clk : in  std_logic;
    rst : in  std_logic;

    valid : in std_logic;
    invalid : in std_logic
    );
end simple_fsm;

architecture rtl of simple_fsm is

  type t_states is (e_IDLE, e_S1);
  signal p_state : t_states := e_IDLE;
  signal n_state : t_states;
  
begin
  
  p_sync_fsm : process(clk)
  begin
    if rising_edge(clk) then
      if (rst = '1') then
        p_state <= e_IDLE;
      else
        p_state <= n_state;
      end if;
    end if;
  end process;

  p_comb_fsm : process (all)
  begin
    case p_state is
      when e_IDLE =>
        n_state <= e_S1 when valid = '1' else e_IDLE;
      when e_S1 =>
        n_state <= e_IDLE when (valid = '0' and invalid = '1') else e_S1;
    end case;
  end process;

end rtl;