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

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

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

package p_monitor_interface is
   
   ----------------------------------------------------------------
   -- Command and status interfaces
   ----------------------------------------------------------------
   type TYPE_PATTERN_MON_TO_CMD_DECODER is record
      busy                      : boolean;
   end record;

   type TYPE_PATTERN_MON_TO_CMD_DECODER_ARRAY is array (natural range <>) of TYPE_PATTERN_MON_TO_CMD_DECODER;

   type TYPE_CMD_DECODER_TO_PATTERN_MON 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;
      scoreboard_en             : boolean;
      start_receiving           : boolean;
   end record;

   type TYPE_CMD_DECODER_TO_PATTERN_MON_ARRAY is array (natural range <>) of TYPE_CMD_DECODER_TO_PATTERN_MON;

   type TYPE_PORT_MON_TO_CMD_DECODER is record
      busy                      : boolean;
   end record;

   type TYPE_CMD_DECODER_TO_PORT_MON is record
      init_port                 : natural;
      start_receiving           : boolean;
      set_frag                  : boolean;
      priority_output           : natural;
      no_of_fragment            : natural;
      packet_crc_en             : boolean;
      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_MON_TO_STATUS is record
      one_frame_err             : boolean;
      error_frame_counter       : unsigned(C_BYTE_LENGTH-1 downto 0);
      correct_frame_counter     : unsigned(C_BYTE_LENGTH-1 downto 0);
   end record;

   type TYPE_PATTERN_MON_TO_STATUS_ARRAY is array (natural range <>) of TYPE_PATTERN_MON_TO_STATUS;

   type TYPE_PORT_MON_TO_STATUS is record
      -- fatal errors
      idle_error                : boolean;
      preamble_error            : boolean;
      sfd_error                 : boolean;
      -- errors per frame
      correct_crc_pck_counter   : unsigned(C_BYTE_LENGTH-1 downto 0);
      smd_i_err_count           : unsigned(C_BYTE_LENGTH-1 downto 0);
      smd_c_err_count           : unsigned(C_BYTE_LENGTH-1 downto 0);
      crc_packet_err_count      : unsigned(C_BYTE_LENGTH-1 downto 0);
      frag_no_err_count         : unsigned(C_BYTE_LENGTH-1 downto 0);
      preamble_length_err_count : unsigned(C_BYTE_LENGTH-1 downto 0);
      -- errors occured in cam
      patt_not_ready            : boolean;
      cam_error                 : boolean;
   end record;

   type TYPE_PORT_MON_TO_STATUS_ARRAY is array (natural range <>) of TYPE_PORT_MON_TO_STATUS;


   type TYPE_STATUS_TO_PORT_MON is record
      corr_crc_pck_read         : boolean;
      smd_i_read                : boolean;
      smd_c_read                : boolean;
      crc_packet_read           : boolean;
      frag_no_read              : boolean;
      preamble_length_read      : boolean;
   end record;


end package;
