aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/gna/issue1935/bwc.vhdl
blob: 86b6d2948fd78ffcf76fcf4662588fe162f1c460 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
library IEEE;
use IEEE.std_logic_1164.all;

entity bwc is
	port
	(
		enable, clock, reset : in std_logic;
		button_pressed       : in std_logic;
		open_window, close_window    : out std_logic
	);
end bwc;

architecture behave of bwc is

-- User defined type
type SM_State is (w_closed, w_open);
signal current_state, next_state: SM_State;


begin
	-- State memory process
	State_memory: process (clock)
	begin
		if    (reset  = '0') then current_state <= w_closed;
		
		elsif (enable = '1' and rising_edge(clock)) then 
			current_state <= next_state;
		
		end if;
	end process;
	
	-- Next state logic
	Next_state_logic: process (clock)
	begin
		case (current_state) is
			when w_open =>  if (button_pressed = '1') 
							then next_state <= w_closed;
							else next_state <= w_open;
							end if;

			when w_closed =>if (button_pressed = '1') 
							then next_state <= w_open;
							else next_state <= w_closed;
							end if;
		end case;
	end process;
	
	-- Output logic
	Output_logic: process(clock)
	begin
		case (current_state) is
			when w_open =>  if (button_pressed = '1') 
							then open_window <= '0'; close_window <= '1';
							else open_window <= '0'; close_window <= '0';
							end if;

			when w_closed =>if (button_pressed = '1') 
							then open_window <= '1'; close_window <= '0';
							else open_window <= '0'; close_window <= '0';
							end if;
			when others => open_window <= '0'; close_window <= '0';
		end case;
	end process;
end architecture;