126 lines
6.4 KiB
VHDL
126 lines
6.4 KiB
VHDL
--------------------------------------------------------------------------------
|
|
-- Paul Scherrer Institute (PSI)
|
|
--------------------------------------------------------------------------------
|
|
-- Unit : evr320_pkg.vhd
|
|
-- Author : Waldemar Koprek, Section Diagnostic
|
|
-- Goran Marinkovic, Section Diagnostic
|
|
-- Patric Bucher, Section DSV
|
|
--------------------------------------------------------------------------------
|
|
-- Copyright© PSI, Section Diagnostic
|
|
--------------------------------------------------------------------------------
|
|
-- Comment : Definitions and Types used for the evr320 library component.
|
|
--------------------------------------------------------------------------------
|
|
library ieee;
|
|
use ieee.std_logic_1164.all;
|
|
use ieee.numeric_std.all;
|
|
use work.psi_common_math_pkg.all;
|
|
|
|
package evr320_pkg is
|
|
|
|
-- --------------------------------------------------------------------------
|
|
-- Constants
|
|
-- --------------------------------------------------------------------------
|
|
constant c_CHECKSUM_MIN_EVT : std_logic_vector(31 downto 0) := X"00000064"; -- Check sum min count for events 100
|
|
constant c_CHECKSUM_MIN_TIME : std_logic_vector(31 downto 0) := X"0015CA20"; -- Check sum min time for events 10 ms
|
|
constant c_SOS_EVENT_DEFAULT : std_logic_vector( 7 downto 0) := X"26"; -- default start-of-sequence (SOS) event
|
|
|
|
|
|
-- --------------------------------------------------------------------------
|
|
-- Type Definitions
|
|
-- --------------------------------------------------------------------------
|
|
type typ_arr8 is array (natural range <>) of std_logic_vector(7 downto 0);
|
|
|
|
type typ_evr320_params is record
|
|
event_numbers : typ_arr8( 3 downto 0);
|
|
event_enable : std_logic_vector( 3 downto 0);
|
|
cs_min_cnt : std_logic_vector(31 downto 0);
|
|
cs_min_time : std_logic_vector(31 downto 0);
|
|
end record typ_evr320_params;
|
|
|
|
type typ_evr320_status is record
|
|
mgt_status : std_logic_vector(31 downto 0);
|
|
end record typ_evr320_status;
|
|
|
|
type typ_evt_rec_status is record
|
|
data_valid : std_logic;
|
|
data_error : std_logic;
|
|
usr_events_counter : std_logic_vector(31 downto 0);
|
|
end record typ_evt_rec_status;
|
|
|
|
type typ_evt_rec_ctrl is record
|
|
event_number : std_logic_vector( 7 downto 0);
|
|
event_enable : std_logic;
|
|
data_ack : std_logic;
|
|
error_ack : std_logic;
|
|
end record typ_evt_rec_ctrl;
|
|
|
|
type typ_rec_latency_measure_ctrl is record
|
|
event_nr : std_logic_vector(7 downto 0);
|
|
counter_arm : std_logic;
|
|
end record;
|
|
|
|
type typ_rec_latency_measure_stat is record
|
|
counter_val : std_logic_vector(31 downto 0);
|
|
event_detected : std_logic;
|
|
end record;
|
|
|
|
--*** Type record and constant for new feature pulse width & delay ***
|
|
constant MaxDuration_c : positive := 2**16-1; -- defines maximum pulse width to add on user events pulse output, in recovery clock cycles
|
|
constant MaxDelay_c : positive := 2**16-1; -- defines maximum delay to add on user events pulse output, in recovery clock cycles
|
|
constant UsrEventWidthDefault_c : std_logic_vector(log2ceil(MaxDuration_c)-1 downto 0) := std_logic_vector(to_unsigned(4, log2ceil(MaxDuration_c))); -- default pulse width of usr_events_adj_o
|
|
type typ_arr_width is array (4 downto 0) of std_logic_vector(log2ceil(MaxDuration_c)-1 downto 0);
|
|
type typ_arr_delay is array (4 downto 0) of std_logic_vector(log2ceil(MaxDelay_c)-1 downto 0);
|
|
|
|
|
|
-- --------------------------------------------------------------------------
|
|
-- Type Initialisation
|
|
-- --------------------------------------------------------------------------
|
|
constant c_INIT_EVT_REC_STATUS : typ_evt_rec_status := ( data_valid => '0',
|
|
data_error => '0',
|
|
usr_events_counter => (others =>'0'));
|
|
|
|
constant c_INIT_EVT_REC_CTRL : typ_evt_rec_ctrl := ( event_number => (others=>'0'),
|
|
event_enable => '0',
|
|
data_ack => '0',
|
|
error_ack => '0');
|
|
|
|
constant c_INIT_REC_LATENCY_MEASURE_CTRL : typ_rec_latency_measure_ctrl := (event_nr => (others =>'0'),
|
|
counter_arm => '1');
|
|
constant c_INIT_REC_LATENCY_MEASURE_STAT : typ_rec_latency_measure_stat := (counter_val => (others =>'0'),
|
|
event_detected => '0');
|
|
-- --------------------------------------------------------------------------
|
|
-- Function Prototypes
|
|
-- --------------------------------------------------------------------------
|
|
function bit2byte(bit_zero : std_logic) return std_logic_vector;
|
|
function bit2byte(bit_zero_vec : std_logic_vector) return std_logic_vector;
|
|
|
|
|
|
end package evr320_pkg;
|
|
--------------------------------------------------------------------------------
|
|
package body evr320_pkg is
|
|
|
|
-- ------------------------------------------------------------------------
|
|
-- Functions
|
|
-- ------------------------------------------------------------------------
|
|
-- Bit Zero to Byte Conversion (concat with zeros)
|
|
function bit2byte(bit_zero : std_logic) return std_logic_vector is
|
|
begin
|
|
return B"0000_000" & bit_zero;
|
|
end function;
|
|
|
|
function bit2byte(bit_zero_vec : std_logic_vector) return std_logic_vector is
|
|
variable converted_byte_vec : std_logic_vector(8*bit_zero_vec'length-1 downto 0);
|
|
begin
|
|
for i in 0 to bit_zero_vec'length-1 loop
|
|
converted_byte_vec(i*8+7 downto i*8) := B"0000_000" & bit_zero_vec(bit_zero_vec'low + i);
|
|
end loop;
|
|
return converted_byte_vec;
|
|
end function;
|
|
|
|
|
|
|
|
end package body evr320_pkg;
|
|
--------------------------------------------------------------------------------
|
|
-- End of file
|
|
--------------------------------------------------------------------------------
|