--------------------------------------------------------------------------------
-- Company: 
-- Engineer:
--
-- Create Date:   14:35:19 10/27/2016
-- Design Name:   
-- Module Name:   C:/Users/admin/Desktop/Xilinx/Eight_Bit_RGB/test.vhd
-- Project Name:  Eight_Bit_RGB
-- Target Device:  
-- Tool versions:  
-- Description:   
-- 
-- VHDL Test Bench Created by ISE for module: RGB_modul
-- 
-- Dependencies:
-- 
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
-- Notes: 
-- This testbench has been automatically generated using types std_logic and
-- std_logic_vector for the ports of the unit under test.  Xilinx recommends
-- that these types always be used for the top-level I/O of a design in order
-- to guarantee that the testbench will bind correctly to the post-implementation 
-- simulation model.
--------------------------------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
USE ieee.numeric_std.ALL;

ENTITY test_micomp IS
END test_micomp;

ARCHITECTURE behavior OF test_micomp IS

	-- Component Declaration for the Unit Under Test (UUT)

	COMPONENT Micomp is
		Generic(
			UART_DIV   : integer := (40000000/9600); -- vstup. frekvence, pozadovana frekvence
			UART_CNT_B : integer := 12  -- pocet potrebnych bitu na citac zmenseny o 1: 13b= (12 downto 0)
		);
		Port(
			ARST      : in  STD_LOGIC;
			CLK       : in  std_logic;
			RX        : in  std_logic;
			CHAIN_END : out std_logic;
			CNT_BYT   : out std_logic_vector(7 downto 0);
			DAT_O     : out std_logic_vector(7 downto 0);
			DAT_O_EN  : out std_logic;
			RIGHT_WR  : out std_logic;
			TX        : out std_logic
		);
	END COMPONENT;

	COMPONENT ROM is
		Port(CLK      :     std_logic;
		     ADDRES   : in  STD_LOGIC_VECTOR(10 DOWNTO 0);
		     CNT      : in  integer;
		     DATA_OUT : out std_logic_vector(7 downto 0)
		);
	END COMPONENT;

	-- Inputs
	signal arst    : std_logic := '0';
	signal clk_i   : std_logic := '0';
	signal Rx      : std_logic := '1';
	
	
	signal Cnt_byT  : std_logic_vector(7 downto 0);
	signal Dat_O    : std_logic_vector(7 downto 0);
	signal Dat_o_eN : std_logic;
	signal Right_wR : std_logic;
	-- Outputs
	signal ram_adr : std_logic_vector(8 downto 0);
	signal Tx      : std_logic;
	signal ram_en  : std_logic;
	signal img_end : std_logic;

	-- ROM

	signal addres  : STD_LOGIC_VECTOR (10 DOWNTO 0) := (others => '0');
	signal dat_ram : std_logic_vector ( 7 downto 0);

	-- help

	signal k, l : integer := 0;
	signal n    : integer := 0;

	-- Clock period definitions
	constant clk_in_period : time := 25 ns;

BEGIN

	-- Instantiate the Unit Under Test (UUT)
	uut : Micomp
		generic map(
			UART_DIV   => 40000000/9600,
			UART_CNT_B => 12
		)
		port map(
			ARST      => ArsT,
			CLK       => ClK_i,
			RX        => RX,
			CHAIN_END => img_end,
			CNT_BYT   => Cnt_byT,
			DAT_O     => Dat_O,
			DAT_O_EN  => Dat_o_eN,
			RIGHT_WR  => Right_wR,
			TX        => TX
		);

	ut1 : ROM
		Port map(
			CLK      => clk_i,
			ADDRES   => addres,
			CNT      => n,
			DATA_OUT => dat_ram
		);

	-- Clock process definitions
	clk_in_process : process
	begin
		clk_i <= '0';
		wait for clk_in_period / 2;
		clk_i <= '1';
		wait for clk_in_period / 2;
	end process;

	-- Stimulus process
	stim_proc : process
	begin
		addres <= (others => '0');
		wait for 50 ns;
		wait for 50 us;

		loop_2 : for l in 1 downto 0 loop
			n      <= 0;
			addres <= (others => '0');
			loop_1 : for k in 120 downto 0 loop

				Rx <= '0';
				-- velikost 1 ( 254 datovych byte)
				wait for 104 us;
				Rx <= dat_ram(0);
				wait for 104 us;
				Rx <= dat_ram(1);
				wait for 104 us;
				Rx <= dat_ram(2);
				wait for 104 us;
				Rx <= dat_ram(3);
				wait for 104 us;
				Rx <= dat_ram(4);
				wait for 104 us;
				Rx <= dat_ram(5);
				wait for 104 us;
				Rx <= dat_ram(6);
				wait for 104 us;
				Rx <= dat_ram(7);
				wait for 104 us;
				Rx <= '1';
				wait for 104 us;
				n  <= n + 1;
				wait for 20 ns;
				if n <= 120 then
					addres <= std_logic_vector(to_unsigned(n, 11));
				end if;
				wait for 20 ns;

			end loop loop_1;
		end loop loop_2;
		wait for 2 ms;

		Rx <= '0';
		-- velikost 1 ( 254 datovych byte)
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;

		Rx <= '0';
		-- velikost 1 ( 254 datovych byte)
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;

		Rx <= '0';
		-- velikost 1 ( 254 datovych byte)
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;

		Rx <= '0';
		-- velikost 1 ( 254 datovych byte)
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '0';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;
		Rx <= '1';
		wait for 104 us;

		-- loop_2: for k in 256 downto 0 loop
		--	
		--		
		--		Rx <= '0';
		--		  
		--		wait for 104 us;
		--		Rx <=   dat_ram(0);
		--		wait for 104 us;
		--		Rx <=   dat_ram(1);
		--		wait for 104 us;
		--		Rx <=   dat_ram(2);
		--		wait for 104 us;
		--		Rx <=   dat_ram(3);
		--		wait for 104 us;
		--		Rx <=   dat_ram(4);
		--		wait for 104 us;
		--		Rx <=   dat_ram(5);
		--		wait for 104 us;
		--		Rx <=   dat_ram(6);
		--		wait for 104 us;
		--		Rx <=   dat_ram(7);
		--		wait for 104 us;
		--		Rx <= '1';
		--		wait for 104 us;
		--		n<=n+1;
		--		wait for 20 ns;
		--		addres<= std_logic_vector(to_unsigned(n,11));		
		--		wait for 20 ns;
		--		
		--  end loop loop_2;
		--  		wait for 2 ms;		
		-- 
		--  loop_3: for k in 256 downto 0 loop
		--	
		--		
		--		Rx <= '0';
		--		--velikost 1 ( 254 datovych byte)
		--		  
		--		wait for 104 us;
		--		Rx <=   dat_ram(0);
		--		wait for 104 us;
		--		Rx <=   dat_ram(1);
		--		wait for 104 us;
		--		Rx <=   dat_ram(2);
		--		wait for 104 us;
		--		Rx <=   dat_ram(3);
		--		wait for 104 us;
		--		Rx <=   dat_ram(4);
		--		wait for 104 us;
		--		Rx <=   dat_ram(5);
		--		wait for 104 us;
		--		Rx <=   dat_ram(6);
		--		wait for 104 us;
		--		Rx <=   dat_ram(7);
		--		wait for 104 us;
		--		Rx <= '1';
		--		wait for 104 us;
		--		n<=n+1;
		--		wait for 20 ns;
		--		addres<= std_logic_vector(to_unsigned(n,11));	
		--		wait for 20 ns;
		--		
		--  end loop loop_3;
		--  		wait for 2 ms;	
		--  		
		--  	loop_4: for k in 256 downto 0 loop
		--	
		--		
		--		Rx <= '0';
		--		--velikost 1 ( 254 datovych byte)
		--		  
		--		wait for 104 us;
		--		Rx <=   dat_ram(0);
		--		wait for 104 us;
		--		Rx <=   dat_ram(1);
		--		wait for 104 us;
		--		Rx <=   dat_ram(2);
		--		wait for 104 us;
		--		Rx <=   dat_ram(3);
		--		wait for 104 us;
		--		Rx <=   dat_ram(4);
		--		wait for 104 us;
		--		Rx <=   dat_ram(5);
		--		wait for 104 us;
		--		Rx <=   dat_ram(6);
		--		wait for 104 us;
		--		Rx <=   dat_ram(7);
		--		wait for 104 us;
		--		Rx <= '1';
		--		wait for 104 us;
		--		n<=n+1;
		--		wait for 20 ns;
		--		addres<= std_logic_vector(to_unsigned(n,11));	
		--		wait for 20 ns;
		--		
		--  end loop loop_4;
		--  		wait for 2 ms;	
		--  		
		--  		loop_5: for k in 72 downto 0 loop
		--	
		--		Rx <= '0';
		--		--velikost 1 ( 254 datovych byte)
		--		  
		--		wait for 104 us;
		--		Rx <=   dat_ram(0);
		--		wait for 104 us;
		--		Rx <=   dat_ram(1);
		--		wait for 104 us;
		--		Rx <=   dat_ram(2);
		--		wait for 104 us;
		--		Rx <=   dat_ram(3);
		--		wait for 104 us;
		--		Rx <=   dat_ram(4);
		--		wait for 104 us;
		--		Rx <=   dat_ram(5);
		--		wait for 104 us;
		--		Rx <=   dat_ram(6);
		--		wait for 104 us;
		--		Rx <=   dat_ram(7);
		--		wait for 104 us;
		--		Rx <= '1';
		--		wait for 104 us;
		--		n<=n+1;
		--		wait for 20 ns;
		--		addres<= std_logic_vector(to_unsigned(n,11));	
		--		wait for 20 ns;
		--		
		--  end loop loop_5;

		Rx <= '1';
		wait;
	end process;

END;
