-- 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;
use work.Type1_package.all;

entity dds_writer_syn is
    port (
        -- SYSTEM
        clk                     : in std_logic;
        reset                   : in std_logic;
        time                    : in TIME_TYPE;
        -- TO/FROM RTPS ENDPOINT
        start_rtps              : in std_logic_vector(0 to 0);
        opcode_rtps             : in HISTORY_CACHE_OPCODE_ARRAY_TYPE(0 to 0);
        ack_rtps                : out std_logic_vector(0 to 0);
        done_rtps               : out std_logic_vector(0 to 0);
        ret_rtps                : out HISTORY_CACHE_RESPONSE_ARRAY_TYPE(0 to 0);
        seq_nr_rtps             : in SEQUENCENUMBER_ARRAY_TYPE(0 to 0);
        get_data_rtps           : in std_logic_vector(0 to 0);
        data_out_rtps           : out WORD_ARRAY_TYPE(0 to 0);
        valid_out_rtps          : out std_logic_vector(0 to 0);
        ready_out_rtps          : in std_logic_vector(0 to 0);
        last_word_out_rtps      : out std_logic_vector(0 to 0); 
        liveliness_assertion    : out std_logic_vector(0 to 0);
        data_available          : out std_logic_vector(0 to 0);
        -- Cache Change
        cc_instance_handle      : out INSTANCE_HANDLE_ARRAY_TYPE(0 to 0);
        cc_kind                 : out CACHE_CHANGE_KIND_ARRAY_TYPE(0 to 0);
        cc_source_timestamp     : out TIME_ARRAY_TYPE(0 to 0);
        cc_seq_nr               : out SEQUENCENUMBER_ARRAY_TYPE(0 to 0);
        -- TO/FROM USER ENTITY
        start_dds               : in std_logic_vector(0 to 0);
        ack_dds                 : out std_logic_vector(0 to 0);
        opcode_dds              : in DDS_WRITER_OPCODE_ARRAY_TYPE(0 to 0);
        instance_handle_in_dds  : in INSTANCE_HANDLE_ARRAY_TYPE(0 to 0);
        source_ts_dds           : in TIME_ARRAY_TYPE(0 to 0);
        max_wait_dds            : in DURATION_ARRAY_TYPE(0 to 0);
        done_dds                : out std_logic_vector(0 to 0);
        return_code_dds         : out RETURN_CODE_ARRAY_TYPE(0 to 0);
        instance_handle_out_dds : out INSTANCE_HANDLE_ARRAY_TYPE(0 to 0);
        valid_in_dds            : in std_logic_vector(0 to 0);
        ready_in_dds            : out std_logic_vector(0 to 0);
        data_in_dds             : in WORD_ARRAY_TYPE(0 to 0);
        last_word_in_dds        : in std_logic_vector(0 to 0);
        valid_out_dds           : out std_logic_vector(0 to 0);
        ready_out_dds           : in std_logic_vector(0 to 0);
        data_out_dds            : out WORD_ARRAY_TYPE(0 to 0);
        last_word_out_dds       : out std_logic_vector(0 to 0);
        -- Communication Status
        status                  : out STATUS_KIND_ARRAY_TYPE(0 to 0)
    );
end entity;

architecture arch of dds_writer_syn is
begin
    
    if_gen : if (NUM_WRITERS > 0) generate
        syn_inst : entity work.dds_writer(arch)
            generic map (
                NUM_WRITERS     => 1,
                CONFIG_ARRAY    => to_QUARTUS_CONFIG_ARRAY_TYPE(ENDPOINT_CONFIG(NUM_READERS to NUM_READERS))
            )
            port map (
                clk                     => clk,
                reset                   => reset,
                time                    => time,
                start_rtps              => start_rtps,
                opcode_rtps             => opcode_rtps,
                ack_rtps                => ack_rtps,
                done_rtps               => done_rtps,
                ret_rtps                => ret_rtps,
                seq_nr_rtps             => seq_nr_rtps,
                get_data_rtps           => get_data_rtps,
                data_out_rtps           => data_out_rtps,
                valid_out_rtps          => valid_out_rtps,
                ready_out_rtps          => ready_out_rtps,
                last_word_out_rtps      => last_word_out_rtps,
                liveliness_assertion    => liveliness_assertion,
                data_available          => data_available,
                cc_instance_handle      => cc_instance_handle,
                cc_kind                 => cc_kind,
                cc_source_timestamp     => cc_source_timestamp,
                cc_seq_nr               => cc_seq_nr,
                start_dds               => start_dds,
                ack_dds                 => ack_dds,
                opcode_dds              => opcode_dds,
                instance_handle_in_dds  => instance_handle_in_dds,
                source_ts_dds           => source_ts_dds,
                max_wait_dds            => max_wait_dds,
                done_dds                => done_dds,
                return_code_dds         => return_code_dds,
                instance_handle_out_dds => instance_handle_out_dds,
                ready_in_dds            => ready_in_dds,
                valid_in_dds            => valid_in_dds,
                data_in_dds             => data_in_dds,
                last_word_in_dds        => last_word_in_dds,
                ready_out_dds           => ready_out_dds,
                valid_out_dds           => valid_out_dds,
                data_out_dds            => data_out_dds,
                last_word_out_dds       => last_word_out_dds,
                status                  => status
            );
    end generate;

end architecture;
