LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE STD.TEXTIO.ALL;
USE IEEE.STD_LOGIC_TEXTIO.ALL;
USE IEEE.STD_LOGIC_SIGNED.ALL;
USE IEEE.NUMERIC_STD.ALL;
LIBRARY MODELSIM_LIB;
USE MODELSIM_LIB.UTIL.ALL;


package sim_pkg is

PROCEDURE print_file (FILE   file_pointer3: TEXT;text: IN string);

PROCEDURE print(text : in string);
PROCEDURE print_val(FILE   file_pointer3: TEXT;
                    text1 : in string;
                    text2 : in string;
                    text3 : in string
					);
                    
PROCEDURE print_text_val(text1 : in string;
				val   : in integer;
				text2 : in string);
                
PROCEDURE FILE_READ_1 ( SIGNAL reset_tb      : IN STD_LOGIC;
                        SIGNAL sys_clk_tb    : IN STD_LOGIC;
                        FILE   file_pointer1 : TEXT;
                        SIGNAL control_in    : IN STD_LOGIC;
                        SIGNAL out1          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0));

PROCEDURE FILE_READ_2 ( SIGNAL reset_tb      : IN STD_LOGIC;
                        SIGNAL sys_clk_tb    : IN STD_LOGIC;
                        FILE   file_pointer1 : TEXT;
                        FILE   file_pointer2 : TEXT;
                        SIGNAL control_in    : IN STD_LOGIC;
                        SIGNAL out1          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0);
                        SIGNAL out2          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0));

PROCEDURE FILE_READ_3 ( SIGNAL reset_tb      : IN STD_LOGIC;
                        SIGNAL sys_clk_tb    : IN STD_LOGIC;
                        FILE   file_pointer1 : TEXT;
                        FILE   file_pointer2 : TEXT;
                        FILE   file_pointer3 : TEXT;
                        SIGNAL control_in    : IN STD_LOGIC;
                        SIGNAL out1          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0);
                        SIGNAL out2          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0);
                        SIGNAL out3          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0));
PROCEDURE ERROR_COMPUTE_1 (   SIGNAL reset_tb      : IN STD_LOGIC;
                            SIGNAL sys_clk_tb    : IN STD_LOGIC;
                            SIGNAL control_in    : IN STD_LOGIC;
                            SIGNAL control_in_dly: IN STD_LOGIC;
                            SIGNAL in1_tb        : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in2_tb        : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out_tb : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_count_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0)
                        );

PROCEDURE ERROR_COMPUTE_2 (   SIGNAL reset_tb      : IN STD_LOGIC;
                            SIGNAL sys_clk_tb    : IN STD_LOGIC;
                            SIGNAL control_in    : IN STD_LOGIC;
                            SIGNAL control_in_dly: IN STD_LOGIC;
                            SIGNAL in1_tb        : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in2_tb        : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in3_tb        : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL in4_tb        : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out1_tb : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out2_tb : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_count1_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL error_count2_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0));

PROCEDURE ERROR_COMPUTE_3 ( SIGNAL reset_tb        : IN STD_LOGIC;
                            SIGNAL sys_clk_tb      : IN STD_LOGIC;
                            SIGNAL control_in      : IN STD_LOGIC;
                            SIGNAL control_in_dly  : IN STD_LOGIC;
                            SIGNAL in1_tb          : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in2_tb          : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in3_tb          : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in4_tb          : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL in5_tb          : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL in6_tb          : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out1_tb   : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out2_tb   : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out3_tb   : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_count1_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL error_count2_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL error_count3_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0));

                    
PROCEDURE ERROR_PRINT_1 (   SIGNAL reset_tb      : IN STD_LOGIC;
                            SIGNAL sys_clk_tb    : IN STD_LOGIC;
                            FILE   file_pointer_4 : TEXT;
                            SIGNAL control_in    : IN STD_LOGIC;
                            text1                : IN string;
                            text2                : IN string;
                            SIGNAL in1_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0)
                           );                   
                    
PROCEDURE ERROR_PRINT_2 (   SIGNAL reset_tb      : IN STD_LOGIC;
                            SIGNAL sys_clk_tb    : IN STD_LOGIC;
                            FILE   file_pointer_4 : TEXT;
                            SIGNAL control_in    : IN STD_LOGIC;
                            text1                : IN string;
                            text2                : IN string;
                            text3                : IN string;
                            SIGNAL in1_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL in2_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0)
                           );

PROCEDURE ERROR_PRINT_3 (   SIGNAL reset_tb      : IN STD_LOGIC;
                            SIGNAL sys_clk_tb    : IN STD_LOGIC;
                            FILE   file_pointer_4 : TEXT;
                            SIGNAL control_in    : IN STD_LOGIC;
                            text1                : IN string;
                            text2                : IN string;
                            text3                : IN string;
                            text4                : IN string;
                            SIGNAL in1_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL in2_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL in3_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0)
                           );
                           
                           
PROCEDURE START_GEN(  SIGNAL reset_tb      : IN STD_LOGIC;
            SIGNAL sys_clk_tb    : IN STD_LOGIC;
            SIGNAL s_start_count_tb : INOUT STD_LOGIC_VECTOR(3 DOWNTO 0);
            SIGNAL counter          : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0);
            SIGNAL s_flag_tb        : INOUT STD_LOGIC;
            SIGNAL s_start_tb        : INOUT STD_LOGIC;
            SIGNAL s_start_tb_dly        : INOUT STD_LOGIC;
            SIGNAL s_olmng_done_tb   : IN STD_LOGIC);
end sim_pkg;
package body sim_pkg is

--================================================================
-- PROCEDURE   : PRINT_FILE_PROCEDURE
-- DESCRIPTION : Procedure to print_file a message in an output file
--================================================================

PROCEDURE print_file (   FILE   file_pointer3: TEXT;
                    text: IN string
                ) IS
    VARIABLE msg_line       : LINE;
BEGIN
    write(msg_line, text);
    writeline(file_pointer3, msg_line);
END print_file;

--================================================================
-- PROCEDURE   : PRINT_PROCEDURE
-- DESCRIPTION : Procedure to print_file a message on the transcript window
--================================================================

PROCEDURE print(text : in string) is
     variable msg_line: line;
     begin
        write    (msg_line, text);
        writeline(output, msg_line);
   end print;
   
--================================================================
-- PROCEDURE   : PRINT_VAL_PROCEDURE
-- DESCRIPTION : Procedure to print_file a message and value on the transcript window
--================================================================   
procedure print_val(FILE   file_pointer3: TEXT;
                  text1 : in string;
                  text2 : in string;
                  text3 : in string
			) is
    variable msg_line: line;
    begin
        write    (msg_line, text1);
        write    (msg_line, text2);
        write    (msg_line, text3);
        writeline(file_pointer3, msg_line);
end print_val;


-- ================================================================
-- PROCEDURE   : PRINT_TEXT_VAL_PROCEDURE
-- DESCRIPTION : Procedure to print_file a message and value on the transcript window
-- ================================================================   
PROCEDURE print_text_val(text1 : in string;
				val   : in integer;
				text2 : in string) is
     variable msg_line: line;
     begin
        write    (msg_line, text1);
        write    (msg_line, val);
		write    (msg_line, text2);
        writeline(output, msg_line);
   end print_text_val;
--========================================================
-- PROCEDURE   : FILE_READ_1
-- DESCRIPTION : Procedure to read single file
--========================================================
PROCEDURE FILE_READ_1 ( SIGNAL reset_tb      : IN STD_LOGIC;
                        SIGNAL sys_clk_tb    : IN STD_LOGIC;
                        FILE   file_pointer1 : TEXT;
                        SIGNAL control_in    : IN STD_LOGIC;
                        SIGNAL out1          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0)) IS
    VARIABLE BUF1       : LINE;
    VARIABLE Input_Var1 :STD_LOGIC_VECTOR(19 DOWNTO 0);
BEGIN
    IF reset_tb = '0' THEN
        out1 <= (OTHERS =>'0');
    ELSIF RISING_EDGE (sys_clk_tb) THEN
        IF(NOT ENDFILE(file_pointer1)) THEN
            IF (control_in = '1') THEN
                READLINE(file_pointer1,BUF1);
                HREAD   (BUF1,Input_Var1);
                out1  <= Input_Var1 ;
            END IF;
        END IF;
    END IF;
END FILE_READ_1;

--========================================================
-- PROCEDURE   : FILE_READ_2
-- DESCRIPTION : Procedure to read single file
--========================================================
PROCEDURE FILE_READ_2 ( SIGNAL reset_tb      : IN STD_LOGIC;
                        SIGNAL sys_clk_tb    : IN STD_LOGIC;
                        FILE   file_pointer1 : TEXT;
                        FILE   file_pointer2 : TEXT;
                        SIGNAL control_in    : IN STD_LOGIC;
                        SIGNAL out1          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0);
                        SIGNAL out2          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0)) IS
    VARIABLE BUF1       : LINE;
    VARIABLE BUF2       : LINE;
    VARIABLE Input_Var1 :STD_LOGIC_VECTOR(19 DOWNTO 0);
    VARIABLE Input_Var2 :STD_LOGIC_VECTOR(19 DOWNTO 0);
BEGIN
    IF reset_tb = '0' THEN
        out1 <= (OTHERS =>'0');
        out2 <= (OTHERS =>'0');
    ELSIF RISING_EDGE (sys_clk_tb) THEN
        IF(NOT ENDFILE(file_pointer1)) THEN
            IF (control_in = '1') THEN
                READLINE(file_pointer1,BUF1);
                HREAD   (BUF1,Input_Var1);
                out1  <= Input_Var1 ;
            END IF;
        END IF;
        IF(NOT ENDFILE(file_pointer2)) THEN
            IF (control_in = '1') THEN
                READLINE(file_pointer2,BUF2);
                HREAD   (BUF2,Input_Var2);
                out2  <= Input_Var2 ;
            END IF;
        END IF;
    END IF;
END FILE_READ_2;

--========================================================
-- PROCEDURE   : FILE_READ_3
-- DESCRIPTION : Procedure to read three files
--========================================================
PROCEDURE FILE_READ_3 ( SIGNAL reset_tb      : IN STD_LOGIC;
                        SIGNAL sys_clk_tb    : IN STD_LOGIC;
                        FILE   file_pointer1 : TEXT;
                        FILE   file_pointer2 : TEXT;
                        FILE   file_pointer3 : TEXT;
                        SIGNAL control_in    : IN STD_LOGIC;
                        SIGNAL out1          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0);
                        SIGNAL out2          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0);
                        SIGNAL out3          : OUT STD_LOGIC_VECTOR(19 DOWNTO 0)) IS
    VARIABLE BUF1       : LINE;
    VARIABLE BUF2       : LINE;
    VARIABLE BUF3       : LINE;
    VARIABLE Input_Var1 :STD_LOGIC_VECTOR(19 DOWNTO 0);
    VARIABLE Input_Var2 :STD_LOGIC_VECTOR(19 DOWNTO 0);
    VARIABLE Input_Var3 :STD_LOGIC_VECTOR(19 DOWNTO 0);
BEGIN
    IF reset_tb = '0' THEN
        out1 <= (OTHERS =>'0');
        out2 <= (OTHERS =>'0');
        out3 <= (OTHERS =>'0');
    ELSIF RISING_EDGE (sys_clk_tb) THEN
        IF(NOT ENDFILE(file_pointer1)) THEN
            IF (control_in = '1') THEN
                READLINE(file_pointer1,BUF1);
                HREAD   (BUF1,Input_Var1);
                out1  <= Input_Var1 ;
            END IF;
        END IF;
        IF(NOT ENDFILE(file_pointer2)) THEN
            IF (control_in = '1') THEN
                READLINE(file_pointer2,BUF2);
                HREAD   (BUF2,Input_Var2);
                out2  <= Input_Var2 ;
            END IF;
        END IF;
        IF(NOT ENDFILE(file_pointer3)) THEN
            IF (control_in = '1') THEN
                READLINE(file_pointer3,BUF3);
                HREAD   (BUF3,Input_Var3);
                out3  <= Input_Var3 ;
            END IF;
        END IF;
    END IF;
END FILE_READ_3;

--========================================================
-- PROCEDURE   : ERROR_COMPUTE_2
-- DESCRIPTION :
--========================================================
PROCEDURE ERROR_COMPUTE_1 (   SIGNAL reset_tb      : IN STD_LOGIC;
                            SIGNAL sys_clk_tb    : IN STD_LOGIC;
                            SIGNAL control_in    : IN STD_LOGIC;
                            SIGNAL control_in_dly: IN STD_LOGIC;
                            SIGNAL in1_tb        : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in2_tb        : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out_tb : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_count_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0)
                        ) IS
BEGIN
        IF reset_tb = '0' THEN
            error_out_tb          <= (OTHERS => '0');
        ELSIF RISING_EDGE (sys_clk_tb) THEN
            IF(control_in = '1') THEN
                error_out_tb          <= in1_tb(17 DOWNTO 0) - in2_tb;
                ELSE
                error_out_tb          <= (OTHERS => '0');
            END IF;
        END IF;


    IF reset_tb = '0' THEN
        error_count_tb              <= (OTHERS => '0');
    ELSIF RISING_EDGE (sys_clk_tb) THEN


        IF(control_in_dly = '1') THEN
            IF((error_out_tb = x"00000") or (error_out_tb = "11"&x"FFFF") or (error_out_tb = x"00001") )THEN
                error_count_tb <= error_count_tb;
            ELSE
                error_count_tb <= error_count_tb + '1';
            END IF;
        END IF;
    END IF;
END ERROR_COMPUTE_1;
--========================================================
-- PROCEDURE   : ERROR_COMPUTE_2
-- DESCRIPTION :
--========================================================
PROCEDURE ERROR_COMPUTE_2 (   SIGNAL reset_tb      : IN STD_LOGIC;
                            SIGNAL sys_clk_tb    : IN STD_LOGIC;
                            SIGNAL control_in    : IN STD_LOGIC;
                            SIGNAL control_in_dly: IN STD_LOGIC;
                            SIGNAL in1_tb        : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in2_tb        : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in3_tb        : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL in4_tb        : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out1_tb : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out2_tb : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_count1_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL error_count2_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0)) IS
BEGIN
        IF reset_tb = '0' THEN
            error_out1_tb          <= (OTHERS => '0');
            error_out2_tb          <= (OTHERS => '0');
        ELSIF RISING_EDGE (sys_clk_tb) THEN
            IF(control_in = '1') THEN
                error_out1_tb          <= in1_tb(17 DOWNTO 0) - in3_tb;
                error_out2_tb          <= in2_tb (17 DOWNTO 0) - in4_tb;
                ELSE
                error_out1_tb          <= (OTHERS => '0');
                error_out2_tb          <= (OTHERS => '0');
            END IF;
        END IF;


    IF reset_tb = '0' THEN
        error_count1_tb              <= (OTHERS => '0');
        error_count2_tb              <= (OTHERS => '0');
    ELSIF RISING_EDGE (sys_clk_tb) THEN


        IF(control_in_dly = '1') THEN
            IF((error_out1_tb = x"00000") or (error_out1_tb = "11"&x"FFFF") or (error_out1_tb = x"00001") )THEN
                error_count1_tb <= error_count1_tb;
            ELSE
                error_count1_tb <= error_count1_tb + '1';
            END IF;
        END IF;

        IF(control_in_dly = '1') THEN
            IF((error_out2_tb = x"00000") or (error_out2_tb = "11"&x"FFFF") or (error_out2_tb = x"00001") )THEN
                error_count2_tb <= error_count2_tb;
            ELSE
                error_count2_tb <= error_count2_tb + '1';
            END IF;
        END IF;
    END IF;
END ERROR_COMPUTE_2;
--========================================================
-- PROCEDURE   : ERROR_COMPUTE_3
-- DESCRIPTION :
--========================================================
PROCEDURE ERROR_COMPUTE_3 ( SIGNAL reset_tb        : IN STD_LOGIC;
                            SIGNAL sys_clk_tb      : IN STD_LOGIC;
                            SIGNAL control_in      : IN STD_LOGIC;
                            SIGNAL control_in_dly  : IN STD_LOGIC;
                            SIGNAL in1_tb          : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in2_tb          : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in3_tb          : IN STD_LOGIC_VECTOR(19 DOWNTO 0);
                            SIGNAL in4_tb          : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL in5_tb          : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL in6_tb          : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out1_tb   : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out2_tb   : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_out3_tb   : INOUT STD_LOGIC_VECTOR(17 DOWNTO 0);
                            SIGNAL error_count1_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL error_count2_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL error_count3_tb : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0)) IS
BEGIN
        IF reset_tb = '0' THEN
            error_out1_tb              <= (OTHERS => '0');
            error_out2_tb              <= (OTHERS => '0');
            error_out3_tb              <= (OTHERS => '0');
        ELSIF RISING_EDGE (sys_clk_tb) THEN
            IF(control_in = '1') THEN
                error_out1_tb          <= in1_tb (17 DOWNTO 0) - in4_tb;
                error_out2_tb          <= in2_tb (17 DOWNTO 0) - in5_tb;
                error_out3_tb          <= in3_tb (17 DOWNTO 0) - in6_tb;
                ELSE
                error_out1_tb          <= (OTHERS => '0');
                error_out2_tb          <= (OTHERS => '0');
                error_out3_tb          <= (OTHERS => '0');
            END IF;
        END IF;


    IF reset_tb = '0' THEN
        error_count1_tb              <= (OTHERS => '0');
        error_count2_tb              <= (OTHERS => '0');
        error_count3_tb              <= (OTHERS => '0');
    ELSIF RISING_EDGE (sys_clk_tb) THEN


        IF(control_in_dly = '1') THEN
            IF((error_out1_tb = x"00000") or (error_out1_tb = "11"&x"FFFF") or (error_out1_tb = x"00001") )THEN
                error_count1_tb <= error_count1_tb;
            ELSE
                error_count1_tb <= error_count1_tb + '1';
            END IF;
        END IF;

        IF(control_in_dly = '1') THEN
            IF((error_out2_tb = x"00000") or (error_out2_tb = "11"&x"FFFF") or (error_out2_tb = x"00001") )THEN
                error_count2_tb <= error_count2_tb;
            ELSE
                error_count2_tb <= error_count2_tb + '1';
            END IF;
        END IF;

        IF(control_in_dly = '1') THEN
            IF((error_out3_tb = x"00000") or (error_out3_tb = "11"&x"FFFF") or (error_out3_tb = x"00001") )THEN
                error_count3_tb <= error_count3_tb;
            ELSE
                error_count3_tb <= error_count3_tb + '1';
            END IF;
        END IF;
    END IF;
END ERROR_COMPUTE_3;



PROCEDURE ERROR_PRINT_1 (   SIGNAL reset_tb      : IN STD_LOGIC;
                            SIGNAL sys_clk_tb    : IN STD_LOGIC;
                            FILE   file_pointer_4 : TEXT;
                            SIGNAL control_in    : IN STD_LOGIC;                            
                            text1                : IN string;
                            text2                : IN string;
                            SIGNAL in1_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0)
                           ) IS
BEGIN

        IF(control_in = '1') THEN
            IF(in1_tb >x"00000") THEN
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text1,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : FAILED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES DO NOT MATCH        <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text2,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            ELSE
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text1,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : PASSED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES MATCH               <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text2,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            END IF;
        END IF;
END ERROR_PRINT_1;

PROCEDURE ERROR_PRINT_2 (   SIGNAL reset_tb      : IN STD_LOGIC;
                            SIGNAL sys_clk_tb    : IN STD_LOGIC;
                            FILE   file_pointer_4 : TEXT;
                            SIGNAL control_in    : IN STD_LOGIC;
                            text1                : IN string;
                            text2                : IN string;
                            text3                : IN string;
                            SIGNAL in1_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL in2_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0)
                           ) IS
BEGIN

        IF(control_in = '1') THEN
            IF(in1_tb >x"00000") THEN
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text1,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : FAILED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES DO NOT MATCH        <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text3,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            ELSE
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text1,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : PASSED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES MATCH               <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text3,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            END IF;
            IF(in2_tb >x"00000") THEN
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text2,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : FAILED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES DO NOT MATCH        <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text3,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            ELSE
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text2,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : PASSED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES MATCH               <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text3,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            END IF;
        END IF;
END ERROR_PRINT_2;

PROCEDURE ERROR_PRINT_3 (   SIGNAL reset_tb      : IN STD_LOGIC;
                            SIGNAL sys_clk_tb    : IN STD_LOGIC;
                            FILE   file_pointer_4 : TEXT;
                            SIGNAL control_in    : IN STD_LOGIC;
                            text1                : IN string;
                            text2                : IN string;
                            text3                : IN string;
                            text4                : IN string;
                            SIGNAL in1_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL in2_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0);
                            SIGNAL in3_tb        : IN STD_LOGIC_VECTOR(11 DOWNTO 0)
                           ) IS
BEGIN

        IF(control_in = '1') THEN
            IF(in1_tb >x"00000") THEN
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text1,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : FAILED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES DO NOT MATCH        <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text4,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            ELSE
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text1,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : PASSED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES MATCH               <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text4,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            END IF;
            IF(in2_tb >x"00000") THEN
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text2,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : FAILED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES DO NOT MATCH        <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text4,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            ELSE
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text2,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : PASSED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES MATCH               <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text4,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            END IF;
            IF(in3_tb >x"00000") THEN
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text3,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : FAILED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES DO NOT MATCH        <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text4,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            ELSE
                print_file(file_pointer_4,"                                                                       ");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text3,"                                <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,">>>>     STATUS           : PASSED                                 <<<<");
                print_file(file_pointer_4,">>>>     DESCRIPTION      : REF AND ACT VALUES MATCH               <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_val(file_pointer_4,">>>>     TESTCASE         : ",text4,"                          <<<<");
                print_file(file_pointer_4,">>>>                                                               <<<<");
                print_file(file_pointer_4,"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            END IF;
        END IF;
END ERROR_PRINT_3;

--------------------------------------------------------------------------
-- Name       : START_GEN_PROC
-- Description: PROCESS generates the start SIGNAL for rate limiter module
--------------------------------------------------------------------------

PROCEDURE START_GEN(  SIGNAL reset_tb      : IN STD_LOGIC;
            SIGNAL sys_clk_tb    : IN STD_LOGIC;
            SIGNAL s_start_count_tb : INOUT STD_LOGIC_VECTOR(3 DOWNTO 0);
            SIGNAL counter          : INOUT STD_LOGIC_VECTOR(11 DOWNTO 0);
            SIGNAL s_flag_tb        : INOUT STD_LOGIC;
            SIGNAL s_start_tb        : INOUT STD_LOGIC;
            SIGNAL s_start_tb_dly        : INOUT STD_LOGIC;
            SIGNAL s_olmng_done_tb   : IN STD_LOGIC) IS
            
BEGIN

        IF reset_tb = '0' THEN
            s_start_count_tb            <= (OTHERS => '0');
            s_flag_tb                   <= '0';
        ELSIF RISING_EDGE(sys_clk_tb) THEN
            IF(s_flag_tb = '0') THEN
                IF(s_start_count_tb = x"3") THEN
                    s_flag_tb <= '1';
                ELSE
                    s_start_count_tb <= s_start_count_tb + '1';
                    s_flag_tb <= '0';
                END IF;
            END IF;
        END IF;


        IF reset_tb = '0' THEN
            s_start_tb                  <= '0';
            s_start_tb_dly                  <= '0';
        ELSIF RISING_EDGE(sys_clk_tb) THEN
            IF(counter < x"3E7")  THEN
                IF(s_flag_tb = '0') THEN
                    IF(s_start_count_tb = x"2") THEN
                        s_start_tb <= '1';
                    ELSE
                        s_start_tb <= '0';
                    END IF;
                ELSE
                    s_start_tb  <= s_olmng_done_tb;
                END IF;
            ELSE
                s_start_tb <= '0';
            END IF;
           s_start_tb_dly <= s_start_tb;
        END IF;
   
		IF(reset_tb = '0') THEN
			counter <= (OTHERS => '0');
		ELSIF RISING_EDGE (sys_clk_tb) THEN
            IF(counter < x"3E8") THEN
                IF(s_olmng_done_tb = '1') THEN
                    counter <= counter + '1';
                END IF;
            END IF;
        END IF;
END START_GEN;
end sim_pkg;
