-- altera vhdl_input_version vhdl_2008
-- XXX: QSYS Fix (https://www.intel.com/content/www/us/en/support/programmable/articles/000079458.html)

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

use work.math_pkg.all;
use work.rtps_package.all;
use work.user_config.all;
use work.rtps_config_package.all;

entity rtps_writer_syn is
    port (
        -- SYSTEM
        clk                     : in std_logic;
        reset                   : in std_logic;
        time                    : in TIME_TYPE;
        -- FROM RTPS HANDLER (USER TRAFFIC)
        empty_user              : in std_logic;
        rd_user                 : out std_logic;
        data_in_user            : in std_logic_vector(WORD_WIDTH-1 downto 0);
        last_word_in_user       : in std_logic;
        -- FROM RTPS BUILTIN ENDPOINT (META TRAFFIC)
        empty_meta              : in std_logic;
        rd_meta                 : out std_logic;
        data_in_meta            : in std_logic_vector(WORD_WIDTH-1 downto 0);
        last_word_in_meta       : in std_logic;
        -- TO RTPS BUILTIN ENDPOINT (META TRAFFIC)
        alive_sig               : out std_logic;
        -- RTPS OUTPUT
        full_ro                 : in std_logic;
        wr_ro                   : out std_logic;
        data_out_ro             : out std_logic_vector(WORD_WIDTH-1 downto 0);
        last_word_out_ro        : out std_logic;
        -- FROM HISTORY CACHE
        liveliness_assertion    : in std_logic;
        data_available          : in std_logic;
        start_hc                : out std_logic;
        opcode_hc               : out HISTORY_CACHE_OPCODE_TYPE;
        ack_hc                  : in std_logic;
        seq_nr_hc               : out SEQUENCENUMBER_TYPE;
        done_hc                 : in std_logic;
        ret_hc                  : in HISTORY_CACHE_RESPONSE_TYPE;
        get_data_hc             : out std_logic;
        data_in_hc              : in std_logic_vector(WORD_WIDTH-1 downto 0);
        valid_in_hc             : in std_logic;
        ready_in_hc             : out std_logic;
        last_word_in_hc         : in std_logic;
        cc_instance_handle      : in INSTANCE_HANDLE_TYPE;
        cc_kind                 : in CACHE_CHANGE_KIND_TYPE;
        cc_source_timestamp     : in TIME_TYPE;
        cc_seq_nr               : in SEQUENCENUMBER_TYPE
    );
end entity;

architecture arch of rtps_writer_syn is
begin
    
    if_gen : if (NUM_WRITERS > 0) generate
        syn_inst : entity work.rtps_writer(arch)
            generic map (
                RELIABILITY_QOS             => ENDPOINT_CONFIG(NUM_READERS).RELIABILITY_QOS,
                LIVELINESS_QOS              => ENDPOINT_CONFIG(NUM_READERS).LIVELINESS_QOS,
                DURABILITY_QOS              => ENDPOINT_CONFIG(NUM_READERS).DURABILITY_QOS,
                DESTINATION_ORDER_QOS       => ENDPOINT_CONFIG(NUM_READERS).DESTINATION_ORDER_QOS,
                ACKNACK_RESPONSE_DELAY      => ENDPOINT_CONFIG(NUM_READERS).ACKNACK_RESPONSE_DELAY,
                ACKNACK_SUPPRESSION_DELAY   => ENDPOINT_CONFIG(NUM_READERS).ACKNACK_SUPPRESSION_DELAY,
                LEASE_DURATION              => ENDPOINT_CONFIG(NUM_READERS).LEASE_DURATION,
                HEARTBEAT_PERIOD            => ENDPOINT_CONFIG(NUM_READERS).HEARTBEAT_PERIOD,
                ENTITYID                    => ENTITYID(NUM_READERS),
                WITH_KEY                    => ENDPOINT_CONFIG(NUM_READERS).WITH_KEY,
                PUSH_MODE                   => ENDPOINT_CONFIG(NUM_READERS).PUSH_MODE,
                INLINE_QOS                  => gen_inline_qos(NUM_READERS)
            )
            port map (
                -- SYSTEM
                clk                     => clk,
                reset                   => reset,
                time                    => time,
                empty_user              => empty_user,
                rd_user                 => rd_user,
                data_in_user            => data_in_user,
                last_word_in_user       => last_word_in_user,
                empty_meta              => empty_meta,
                rd_meta                 => rd_meta,
                data_in_meta            => data_in_meta,
                last_word_in_meta       => last_word_in_meta,
                alive_sig               => alive_sig,
                full_ro                 => full_ro,
                wr_ro                   => wr_ro,
                data_out_ro             => data_out_ro,
                last_word_out_ro        => last_word_out_ro,
                liveliness_assertion    => liveliness_assertion,
                data_available          => data_available,
                start_hc                => start_hc,
                opcode_hc               => opcode_hc,
                ack_hc                  => ack_hc,
                seq_nr_hc               => seq_nr_hc,
                done_hc                 => done_hc,
                ret_hc                  => ret_hc,
                get_data_hc             => get_data_hc,
                data_in_hc              => data_in_hc,
                valid_in_hc             => valid_in_hc,
                ready_in_hc             => ready_in_hc,
                last_word_in_hc         => last_word_in_hc,
                cc_instance_handle      => cc_instance_handle,
                cc_kind                 => cc_kind,
                cc_source_timestamp     => cc_source_timestamp,
                cc_seq_nr               => cc_seq_nr
            );
    end generate;

end architecture;
