---------------------------------------------------------------------------
-- File           : p_patt_mon_interface.vhd
-- Author(s)      : Nikola Avramovic
-- Created        : April 30th, 2019
---------------------------------------------------------------------------
-- Description    : Port monitor internal interfaces
---------------------------------------------------------------------------

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

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

package p_port_mon_interface is

   type TYPE_CONTROL_PORT_TO_CAM is record
      ready                     : boolean;
      packet_crc_en             : boolean;
      priority_output           : natural;
      no_of_fragment            : natural;
      sfd                       : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
      terminated                : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
   end record;

   type TYPE_CAM_TO_CONTROL_PORT is record
      patt_not_ready            : boolean;
      cam_error                 : boolean;
   end record;

   type TYPE_CONTROL_PORT_TO_HEADER_CHECK is record
      ready                     : boolean;
      preamble_length           : natural;
      no_of_fragment            : natural;
      sfd                       : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
      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;

   type TYPE_HEADER_CHECK_TO_CONTROL_PORT 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);

   end record;

   type TYPE_HEADER_CHECK_TO_CAM is record
      smd_i_const         : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
      smd_c_const         : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
      frag_const          : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
   end record;

   type TYPE_CAM_TO_HEADER_CHECK is record
      crc32_en            : boolean;
      receiving           : boolean;
      preamble_receiving  : boolean;
      receiving_fragment  : boolean;
      idle                : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
      preamble            : 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);
      frag_const          : std_logic_vector(C_BYTE_LENGTH-1 downto 0);
      crc_mon_data        : std_logic_vector(C_CRC32_DATA_WIDTH-1 downto 0);
      crc_received_data   : std_logic_vector(C_CRC32_DATA_WIDTH-1 downto 0);
   end record;

end package;
