library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

 --TODO!!
    ---pociatok_adresovania - vyriesit nejake rozumne hodnoty, ako to funguje, atd.

    entity ent_krabica is
        generic
        (
            krabica_pociatok_adresovania           : integer := 100000
        );

        port
        (
            --riadenie hodinami
            krabica_CLK                             : in    std_logic;
            --asynchronny reset
            krabica_RESET                           : in    std_logic;

            --ROZHRANIE 0
            --vstupny FrameLink
            krabica_IF0_INPUT_SOF_N                 : in    std_logic;
            krabica_IF0_INPUT_SOP_N                 : in    std_logic;
            krabica_IF0_INPUT_EOP_N                 : in    std_logic;
            krabica_IF0_INPUT_EOF_N                 : in    std_logic;
            krabica_IF0_INPUT_SRC_RDY_N             : in    std_logic;
            krabica_IF0_INPUT_DST_RDY_N             : out   std_logic;
            krabica_IF0_INPUT_DATA                  : in    std_logic_vector ( 63 downto 0 );
            krabica_IF0_INPUT_DREM                  : in    std_logic_vector (  2 downto 0 );
            --vystupny FrameLink
            krabica_IF0_OUTPUT_SOF_N                : out   std_logic;
            krabica_IF0_OUTPUT_SOP_N                : out   std_logic;
            krabica_IF0_OUTPUT_EOP_N                : out   std_logic;
            krabica_IF0_OUTPUT_EOF_N                : out   std_logic;
            krabica_IF0_OUTPUT_SRC_RDY_N            : out   std_logic;
            krabica_IF0_OUTPUT_DST_RDY_N            : in    std_logic;
            krabica_IF0_OUTPUT_DATA                 : out   std_logic_vector ( 63 downto 0 );
            krabica_IF0_OUTPUT_DREM                 : out   std_logic_vector (  2 downto 0 );

            --ROZHRANIE 1
            --vstupny FrameLink
            krabica_IF1_INPUT_SOF_N                 : in    std_logic;
            krabica_IF1_INPUT_SOP_N                 : in    std_logic;
            krabica_IF1_INPUT_EOP_N                 : in    std_logic;
            krabica_IF1_INPUT_EOF_N                 : in    std_logic;
            krabica_IF1_INPUT_SRC_RDY_N             : in    std_logic;
            krabica_IF1_INPUT_DST_RDY_N             : out   std_logic;
            krabica_IF1_INPUT_DATA                  : in    std_logic_vector ( 63 downto 0 );
            krabica_IF1_INPUT_DREM                  : in    std_logic_vector (  2 downto 0 );
            --vystupny FrameLink
            krabica_IF1_OUTPUT_SOF_N                : out   std_logic;
            krabica_IF1_OUTPUT_SOP_N                : out   std_logic;
            krabica_IF1_OUTPUT_EOP_N                : out   std_logic;
            krabica_IF1_OUTPUT_EOF_N                : out   std_logic;
            krabica_IF1_OUTPUT_SRC_RDY_N            : out   std_logic;
            krabica_IF1_OUTPUT_DST_RDY_N            : in    std_logic;
            krabica_IF1_OUTPUT_DATA                 : out   std_logic_vector ( 63 downto 0 );
            krabica_IF1_OUTPUT_DREM                 : out   std_logic_vector (  2 downto 0 );

            --zbernica MI32 vchadzajuca do krabice
            krabica_MI32_DWR                        : in    std_logic_vector(31 downto 0);
            krabica_MI32_ADDR                       : in    std_logic_vector(31 downto 0);
            krabica_MI32_RD                         : in    std_logic;
            krabica_MI32_WR                         : in    std_logic;
            krabica_MI32_BE                         : in    std_logic_vector(3 downto 0);
            krabica_MI32_DRD                        : out   std_logic_vector(31 downto 0);
            krabica_MI32_ARDY                       : out   std_logic;
            krabica_MI32_DRDY                       : out   std_logic

        );

    end entity ent_krabica;


    architecture arch_krabica of ent_krabica is
            --zakomentovane, lebo pouzivame GENERIC
            --constant krabica_pociatok_adresovania   : integer := 10000;

            component ent_parser_krabicka is
                generic
                (
                    parser_pociatok_adresovania     : integer
                );
                port
                (
                    --riadenie hodinami
                    parser_CLK                      : in    std_logic;
                    --asynchronny reset
                    parser_RESET                    : in    std_logic;

                    --vstupny FrameLink
                    parser_INPUT_SOF_N              : in    std_logic;
                    parser_INPUT_SOP_N              : in    std_logic;
                    parser_INPUT_EOP_N              : in    std_logic;
                    parser_INPUT_EOF_N              : in    std_logic;
                    parser_INPUT_SRC_RDY_N          : in    std_logic;
                    parser_INPUT_DST_RDY_N          : out   std_logic;
                    parser_INPUT_DATA               : in    std_logic_vector ( 63 downto 0 );
                    parser_INPUT_DREM               : in    std_logic_vector (  2 downto 0 );
                    --vystupny FrameLink
                    parser_OUTPUT_SOF_N             : out   std_logic;
                    parser_OUTPUT_SOP_N             : out   std_logic;
                    parser_OUTPUT_EOP_N             : out   std_logic;
                    parser_OUTPUT_EOF_N             : out   std_logic;
                    parser_OUTPUT_SRC_RDY_N         : out   std_logic;
                    parser_OUTPUT_DST_RDY_N         : in    std_logic;
                    parser_OUTPUT_DATA              : out   std_logic_vector ( 63 downto 0 );
                    parser_OUTPUT_DREM              : out   std_logic_vector (  2 downto 0 );
                    --zbernica MI32 vchadzajuca do krabicky
                    parser_MI32_DWR                 : in    std_logic_vector(31 downto 0);
                    parser_MI32_ADDR                : in    std_logic_vector(31 downto 0);
                    parser_MI32_RD                  : in    std_logic;
                    parser_MI32_WR                  : in    std_logic;
                    parser_MI32_BE                  : in    std_logic_vector(3 downto 0);
                    parser_MI32_DRD                 : out   std_logic_vector(31 downto 0);
                    parser_MI32_ARDY                : out   std_logic;
                    parser_MI32_DRDY                : out   std_logic
						  
                );
            end component ent_parser_krabicka;
				
				signal dummy_MI32_DWR                 : std_logic_vector(31 downto 0) := X"00000000" ;
            signal dummy_MI32_ADDR                : std_logic_vector(31 downto 0) := X"00000000" ;
            signal dummy_MI32_RD                  : std_logic := '0';
            signal dummy_MI32_WR                  : std_logic := '0';
            signal dummy_MI32_BE                  : std_logic_vector(3 downto 0) := X"0";

        begin

            PARSER_KRABICKA_01: ent_parser_krabicka
                generic map
                (
                    parser_pociatok_adresovania     => krabica_pociatok_adresovania + 1000
                )
                port map
                (
                    --riadenie hodinami
                    parser_CLK                      =>  krabica_CLK,
                    --asynchronny reset
                    parser_RESET                    =>  krabica_RESET,
                    --vstupny FrameLink
                    parser_INPUT_SOF_N              =>  krabica_IF0_INPUT_SOF_N,
                    parser_INPUT_SOP_N              =>  krabica_IF0_INPUT_SOP_N,
                    parser_INPUT_EOP_N              =>  krabica_IF0_INPUT_EOP_N,
                    parser_INPUT_EOF_N              =>  krabica_IF0_INPUT_EOF_N,
                    parser_INPUT_SRC_RDY_N          =>  krabica_IF0_INPUT_SRC_RDY_N,
                    parser_INPUT_DST_RDY_N          =>  krabica_IF0_INPUT_DST_RDY_N,
                    parser_INPUT_DATA               =>  krabica_IF0_INPUT_DATA,
                    parser_INPUT_DREM               =>  krabica_IF0_INPUT_DREM,
                    --vystupny FrameLink
                    parser_OUTPUT_SOF_N             =>  krabica_IF1_OUTPUT_SOF_N,
                    parser_OUTPUT_SOP_N             =>  krabica_IF1_OUTPUT_SOP_N,
                    parser_OUTPUT_EOP_N             =>  krabica_IF1_OUTPUT_EOP_N,
                    parser_OUTPUT_EOF_N             =>  krabica_IF1_OUTPUT_EOF_N,
                    parser_OUTPUT_SRC_RDY_N         =>  krabica_IF1_OUTPUT_SRC_RDY_N,
                    parser_OUTPUT_DST_RDY_N         =>  krabica_IF1_OUTPUT_DST_RDY_N,
                    parser_OUTPUT_DATA              =>  krabica_IF1_OUTPUT_DATA,
                    parser_OUTPUT_DREM              =>  krabica_IF1_OUTPUT_DREM,
                    --zbernica MI32 vchadzajuca do krabicky
                    parser_MI32_DWR                 => krabica_MI32_DWR,
                    parser_MI32_ADDR                => krabica_MI32_ADDR,
                    parser_MI32_RD                  => krabica_MI32_RD,
                    parser_MI32_WR                  => krabica_MI32_WR,
                    parser_MI32_BE                  => krabica_MI32_BE,
                    parser_MI32_DRD                 => krabica_MI32_DRD,
                    parser_MI32_ARDY                => krabica_MI32_ARDY,
                    parser_MI32_DRDY                => krabica_MI32_DRDY
                );

            PARSER_KRABICKA_10: ent_parser_krabicka
                generic map
                (
                    parser_pociatok_adresovania => krabica_pociatok_adresovania + 2000
                )
                port map
                (
                    --riadenie hodinami
                    parser_CLK                      =>  krabica_CLK,
                    --asynchronny reset
                    parser_RESET                    =>  krabica_RESET,
                    --vstupny FrameLink
                    parser_INPUT_SOF_N              =>  krabica_IF1_INPUT_SOF_N,
                    parser_INPUT_SOP_N              =>  krabica_IF1_INPUT_SOP_N,
                    parser_INPUT_EOP_N              =>  krabica_IF1_INPUT_EOP_N,
                    parser_INPUT_EOF_N              =>  krabica_IF1_INPUT_EOF_N,
                    parser_INPUT_SRC_RDY_N          =>  krabica_IF1_INPUT_SRC_RDY_N,
                    parser_INPUT_DST_RDY_N          =>  krabica_IF1_INPUT_DST_RDY_N,
                    parser_INPUT_DATA               =>  krabica_IF1_INPUT_DATA,
                    parser_INPUT_DREM               =>  krabica_IF1_INPUT_DREM,
                    --vystupny FrameLink
                    parser_OUTPUT_SOF_N             =>  krabica_IF0_OUTPUT_SOF_N,
                    parser_OUTPUT_SOP_N             =>  krabica_IF0_OUTPUT_SOP_N,
                    parser_OUTPUT_EOP_N             =>  krabica_IF0_OUTPUT_EOP_N,
                    parser_OUTPUT_EOF_N             =>  krabica_IF0_OUTPUT_EOF_N,
                    parser_OUTPUT_SRC_RDY_N         =>  krabica_IF0_OUTPUT_SRC_RDY_N,
                    parser_OUTPUT_DST_RDY_N         =>  krabica_IF0_OUTPUT_DST_RDY_N,
                    parser_OUTPUT_DATA              =>  krabica_IF0_OUTPUT_DATA,
                    parser_OUTPUT_DREM              =>  krabica_IF0_OUTPUT_DREM,
                    --zbernica MI32 vchadzajuca do krabicky
                    parser_MI32_DWR                 => dummy_MI32_DWR,
                    parser_MI32_ADDR                => dummy_MI32_ADDR,
                    parser_MI32_RD                  => dummy_MI32_RD,
                    parser_MI32_WR                  => dummy_MI32_WR,
                    parser_MI32_BE                  => dummy_MI32_BE,
                    parser_MI32_DRD                 => open,
                    parser_MI32_ARDY                => open,
                    parser_MI32_DRDY                => open
                );

    end architecture arch_krabica;