----------------------------------------------------------------
-- Project : agfo10_a.ise -- 25042008-RRI-RAL-hydrus-KPA
-- File    : usb_command1.vhd 
----------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL; 
library UNISIM;
use UNISIM.VComponents.all;
use IEEE.numeric_std.all;

entity usb_ipram_chsel is
    Port (  
    reset_in          : in std_logic;	 
	 usb_data_in   	 : in std_logic_vector(31 downto 0);
	 usb_load_in   	 : in std_logic;
	 clk_in 		       : in std_logic;
	 ch_sel_reg        : out std_logic_vector(7 downto 0);
	 ch_sel_reg1       : out std_logic_vector(7 downto 0)
   );
end usb_ipram_chsel;
-----------------------------------------------------------------
architecture Behavioral of usb_ipram_chsel is

signal usbL1 : std_logic_vector(31 downto 0);
signal check_ld_low,usb_load_int,valid_load : std_logic;
signal ch_sel_reg_int : std_logic_vector(7 downto 0);

-----------------------------------------------------------------
begin

-----------------------------------------------------------------
process(clk_in)
begin
  if clk_in'event and clk_in = '1' then 
   if(reset_in = '1') then
	  check_ld_low <= '0';
	end if;  	
   usb_load_int <= usb_load_in;
  	if usb_load_int = '1' and check_ld_low = '0' then
		  valid_load <= '1';
		  check_ld_low <= '1';
	elsif usb_load_int = '1' and check_ld_low = '1' then 	  
		  valid_load <= valid_load ;
		  check_ld_low <= check_ld_low;
	elsif usb_load_int = '0' and check_ld_low = '1' then
		  check_ld_low<= '0';
		  valid_load <= valid_load;
	elsif usb_load_int = '0' and check_ld_low = '0' then		
		  valid_load <= valid_load ;
		  check_ld_low<= '0';--check_ld_low;
	end if;	  
   if valid_load = '1' then
	    valid_load <= '0';
       usbL1 <= usb_data_in;
   end if;	
   ch_sel_reg_int <= usbL1(31 downto 24);	
	ch_sel_reg <= ch_sel_reg_int;
   ch_sel_reg1 <= ch_sel_reg_int + '1';	
  end if;
end process;

End Behavioral;
--------------- end of file : usb_command1.vhd ------------------
