---------------------------------------------------------------------------
-- File           : p_parameters_and_constants.vhd
-- Author(s)      : Nikola Avramovic
-- Created        : February 16th, 2019
---------------------------------------------------------------------------
-- Description    : Global parametrs and constants
---------------------------------------------------------------------------

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

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

package p_parameters_and_constants is

   constant C_BYTE_LENGTH                : natural  := 8;
   constant C_WORD_LENGTH                : natural  := 2*C_BYTE_LENGTH; -- in this design word is 16 bits 

   -- adddreses constants
   constant C_MAX_ADDRESS_PER_OBJECT   : natural := 8; -- words per object 

   ----------------------------------------------------------------
   -- Avalon Memory Map parameters
   ----------------------------------------------------------------
   constant C_AVALON_MM_DATA_WIDTH       : natural  := 8;
   constant C_AVALON_MM_ADDR_WIDTH       : natural  := 5;
   constant C_BYTES_PER_WORD             : natural  := C_AVALON_MM_DATA_WIDTH / 8;
   constant C_BURSTCOUNT_WIDTH           : positive := 5; -- address width is 5 max burst cound will be 2**5

   ----------------------------------------------------------------
   -- Avalon Streaming parameters
   ----------------------------------------------------------------
   constant C_AVALON_ST_DATA_WIDTH       : natural := 8;
   ----------------------------------------------------------------
   -- Avalon Streaming parameters
   ----------------------------------------------------------------
   constant C_CRC32_DATA_WIDTH           : positive := 32;
   constant C_CRC32_NO_OF_BYTS           : positive := C_CRC32_DATA_WIDTH/C_AVALON_ST_DATA_WIDTH -1;

   ----------------------------------------------------------------
   -- Etehrnet constants
   ----------------------------------------------------------------
   constant C_MIN_ETHERNET_LENGTH        : natural  := 64;
   constant C_IDLE                       : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"07";
   constant C_SFD                        : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"AB";
   constant C_PREAMBLE                   : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"AA";
   constant C_TERMINATED                 : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"FD";
   ----------------------------------------------------------------
   -- FIFO Avalon streaming parameters
   ----------------------------------------------------------------
   -- fifo depth will be 4KB
   constant C_FIFO_AVALON_ST_DEPTH       : natural  := 4096;

   ----------------------------------------------------------------
   -- Preemptable packet constants
   -- See standard 802.3br-2016, pages 42-45
   ----------------------------------------------------------------
   constant C_PREEMPTABLE_NO             : natural  := 4;
   -- frag_count
   constant C_FRAG_NO_0                  : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"E6";
   constant C_FRAG_NO_1                  : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"4C";
   constant C_FRAG_NO_2                  : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"7F";
   constant C_FRAG_NO_3                  : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"B3";
   -- preemptable packet start:
   constant C_SMD_S_0                    : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"E6";
   constant C_SMD_S_1                    : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"4C";
   constant C_SMD_S_2                    : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"7F";
   constant C_SMD_S_3                    : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"B3";
   -- continuation fragment 
   constant C_SMD_C_0                    : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"61";
   constant C_SMD_C_1                    : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"52";
   constant C_SMD_C_2                    : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"9E";
   constant C_SMD_C_3                    : std_logic_vector(C_BYTE_LENGTH-1 downto 0) := X"2A";

   ----------------------------------------------------------------
   -- Status monitor register
   ----------------------------------------------------------------
   constant C_FATAL_ERROR_PATT_1         : integer := 1;
   constant C_FATAL_ERROR_PATT_2         : integer := C_FATAL_ERROR_PATT_1 + 1;
   constant C_FATAL_ERROR_PORT           : integer := C_FATAL_ERROR_PATT_2 + 1;

   ----------------------------------------------------------------
   -- Status monitor register
   ----------------------------------------------------------------
   constant C_FATAL_ERROR                : integer := 1;
   constant C_CORRECT_CRC_PCK_COUNTER    : integer := C_FATAL_ERROR + 1;
   constant C_SMD_I_ERR_COUNT            : integer := C_CORRECT_CRC_PCK_COUNTER + 1;
   constant C_SMD_C_ERR_COUNT            : integer := C_SMD_I_ERR_COUNT + 1;
   constant C_CRC_PACKET_ERR_COUNTER     : integer := C_SMD_C_ERR_COUNT + 1;
   constant C_FRAG_NO_ERR_COUNTER        : integer := C_CRC_PACKET_ERR_COUNTER + 1;
   constant C_PREAMBLE_LEN_ERR_COUNTER   : integer := C_FRAG_NO_ERR_COUNTER + 1;
   constant C_ERROR_FRAME_COUNTER_1      : integer := C_PREAMBLE_LEN_ERR_COUNTER + 1;
   constant C_CORRECT_FRAME_COUNTER_1    : integer := C_ERROR_FRAME_COUNTER_1 + 1;
   constant C_ERROR_FRAME_COUNTER_2      : integer := C_CORRECT_FRAME_COUNTER_1 + 1;
   constant C_CORRECT_FRAME_COUNTER_2    : integer := C_ERROR_FRAME_COUNTER_2 + 1;

end package;


