---------------------------------------------------------------------------
-- File           : p_generator_interface.vhd
-- Author(s)      : Nikola Avramovic
-- Created        : March 12th, 2019
---------------------------------------------------------------------------
-- Description    : Object generator internal interfaces
---------------------------------------------------------------------------

---------------------------------------------------------------------------

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

package p_generator_interface is
   
   ----------------------------------------------------------------
   -- Command and status interfaces
   -- TODO: bist_error signal created just to set this recored, 
   -- every of these recoreds need to be updated
   ----------------------------------------------------------------
   type TYPE_PATTERN_GEN_TO_CMD_DECODER is record
      busy              : boolean;
   end record;

   type TYPE_PATTERN_GEN_TO_CMD_DECODER_ARRAY is array (natural range <>) of TYPE_PATTERN_GEN_TO_CMD_DECODER;

   type TYPE_CMD_DECODER_TO_PATTERN_GEN is record
      init_pattern      : natural;
      seed              : natural;
      seed_increment    : natural;
      frame_length      : natural;
      frame_no          : natural;
      crc_en            : boolean;
      lfsr_en           : boolean;
      linear_en         : boolean;
      start_sending     : boolean;
   end record;

   type TYPE_CMD_DECODER_TO_PATTERN_GEN_ARRAY is array (natural range <>) of TYPE_CMD_DECODER_TO_PATTERN_GEN;

   type TYPE_PORT_GEN_TO_CMD_DECODER is record
      busy              : boolean;
   end record;

   type TYPE_CMD_DECODER_TO_PORT_GEN is record
      init_port         : natural;
      start_sending     : boolean;
      set_frag          : boolean;
      priority_input    : natural;
      no_of_fragment    : natural;
      packet_crc_en     : boolean;
      frame_wait_priority : natural;
      frame_wait_frag   : natural;
      preamble_length   : natural;
      terminated        : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
      sfd               : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
      smd_i             : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
      smd_c             : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
   end record;

   type TYPE_MASTER_TO_FIFO_CMD is record
      address           : std_logic_vector (C_AVALON_MM_ADDR_WIDTH-1 downto 0);
      write_req         : std_logic;                                             -- it is same as avalon mm write
      data_in           : std_logic_vector (C_AVALON_MM_DATA_WIDTH-1 downto 0);  -- it is same as avalon mm writedata
      write_count       : std_logic_vector(C_BURSTCOUNT_WIDTH-1 downto 0);       -- it is same as avalon mm burstcount
      new_package       : std_logic;                                             -- it is same as beginbursttransfer
   end record;
   
   type TYPE_FIFO_CMD_TO_MASTER is record
      fifo_full         : std_logic;
   end record;
   
   type TYPE_CMD_DEC_TO_FIFO_CMD is record
      read_req          : boolean;
   end record;

   type TYPE_FIFO_CMD_TO_CMD_DEC is record
     data_out            : std_logic_vector (C_AVALON_MM_DATA_WIDTH-1 downto 0);
     fifo_empty          : boolean;
     valid               : boolean;
   end record;

   type TYPE_MASTER_TO_STATUS is record
      address            : std_logic_vector (C_AVALON_MM_ADDR_WIDTH-1 downto 0);
      read_req           : std_logic;
      read_count         : std_logic_vector(C_BURSTCOUNT_WIDTH-1 downto 0);       -- it is same as avalon mm burstcount
      start_reading      : std_logic;                                             -- it is same as beginbursttransfer
   end record;

   type TYPE_STATUS_TO_MASTER is record
      data_valid         : std_logic;
      read_data          : std_logic_vector (C_AVALON_MM_DATA_WIDTH-1 downto 0);
      wait_req           : std_logic;
   end record;

   type TYPE_PATTERN_GEN_TO_STATUS is record
      lfsr_error          : boolean;
      linear_error        : boolean;
      crc_error           : boolean;
      control_error       : boolean;
      mux_error           : boolean;
      fifo_avalon_error   : boolean;
   end record;

   type TYPE_PATTERN_GEN_TO_STATUS_ARRAY is array (natural range <>) of TYPE_PATTERN_GEN_TO_STATUS;

   type TYPE_PORT_GEN_TO_STATUS is record
      bridge_error        : boolean;
      output_error        : boolean;
   end record;

   type TYPE_PORT_GEN_TO_STATUS_ARRAY is array (natural range <>) of TYPE_PORT_GEN_TO_STATUS;

end package;
