library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use work.pack.all; entity fsm3 is port ( --global io_clk : in std_logic; rst : in std_logic; -- datapath eo : out std_logic; -- fsm 2 handshake signal output_write : in std_logic; output_write_clr : out std_logic; output_busy_clr : out std_logic; -- fifo dst_ready : in std_logic; dst_write : out std_logic ); end fsm3; architecture beh of fsm3 is signal ek, lk, zk3 : std_logic; signal kc : std_logic_vector(1 downto 0); type fsm3_state_type is (idle, write_data); signal cstate_fsm3, nstate : fsm3_state_type; begin -- fsm3 counter kcount_gen : countern generic map ( N => 2 ) port map ( clk => io_clk, load => lk, en => ek, input => "00", output => kc); zk3 <= '1' when kc = "11" else '0'; cstate_proc : process ( io_clk ) begin if rising_edge( io_clk ) then if rst = '1' then cstate_fsm3 <= idle; else cstate_fsm3 <= nstate; end if; end if; end process; nstate_proc : process ( cstate_fsm3, dst_ready, output_write, zk3) begin case cstate_fsm3 is when idle => if ( output_write = '1') then nstate <= write_data; else nstate <= idle; end if; when write_data => if ( dst_ready = '0' and zk3 = '1' ) then nstate <= idle; else nstate <= write_data; end if; end case; end process; dst_write <= '1' when (cstate_fsm3 = write_data and dst_ready = '0') else '0'; output_write_clr <= '1' when (cstate_fsm3 = idle and output_write = '1') else '0'; output_busy_clr <= '1' when (cstate_fsm3 = write_data and dst_ready = '0' and zk3 = '1') else '0'; ek <= '1' when (cstate_fsm3 = write_data and dst_ready = '0' and zk3 = '0' ) else '0'; lk <= '1' when ((cstate_fsm3 = write_data and dst_ready = '0' and zk3 = '1' ) or (cstate_fsm3 = idle and output_write = '1')) else '0'; eo <= '1' when (cstate_fsm3 = write_data and dst_ready = '0') else '0'; end beh;