Commit 1351d6b2 authored by Evangelia Gousiou's avatar Evangelia Gousiou

added test for timetag reg and test for INV channels

parent 9c4bd1d7
......@@ -58,7 +58,9 @@ architecture behav of testbench is
signal gf_en_n_in : std_logic;
signal ttl_n_in, ttl_out : std_logic_vector(C_NR_CHANS-1 downto 0) := (others => '1');
signal rs485_n_in, rs485_fs_n_in, rs485_out : std_logic_vector(C_NR_CHANS-1 downto 0) := (others => '1');
signal rs485_n_in, rs485_fs_n_in : std_logic_vector(C_NR_CHANS-1 downto 0) := (others => '1');
signal rs485_out : std_logic_vector(C_NR_CHANS-1 downto 0) := (others => '1');
signal inv_n_in, inv_out : std_logic_vector(C_NR_INV_CHANS-1 downto 0) := (others => '0');
signal sscl_out : std_logic;
signal sscl_en_out : std_logic;
......@@ -85,10 +87,12 @@ architecture behav of testbench is
signal reg_id : integer := 0;
signal adr : std_logic_vector(31 downto 0);
signal nb_of_pulses_rcved : integer := 0;
type cnt_array is array (C_NR_CHANS-1 downto 0) of integer;
signal fp_rp_same, fp_rp_oppos : cnt_array;
signal pulse_cnt_ttl : cnt_array;
signal pulse_cnt_rs485 : cnt_array;
type cnt_ch_array is array (C_NR_CHANS-1 downto 0) of integer;
signal fp_rp_same, fp_rp_oppos, pulse_cnt_ttl, pulse_cnt_rs485 : cnt_ch_array;
type cnt_inv_ch_array is array (C_NR_INV_CHANS-1 downto 0) of integer;
signal inv_err: cnt_ch_array;
......@@ -128,8 +132,8 @@ begin
-- Front panel channels
ttl_n_i => ttl_n_in,
ttl_o => ttl_out,
inv_n_i => (others => '0'),
inv_o => open,
inv_n_i => inv_n_in,
inv_o => inv_out,
-- Rear panel channels
rs485_n_i => rs485_n_in,
rs485_fs_n_i => rs485_fs_n_in,
......@@ -293,6 +297,24 @@ begin
end if;
end process;
--============================================================================
-- Check INV channels
--============================================================================
compare_inv_i_inv_o: process (clk_125)
begin
if rising_edge (clk_125) then
if vme_sysreset_n = '0' then
inv_err <= (others=> (0));
else
for i in 0 to C_NR_INV_CHANS-1 loop
if inv_n_in(i) /= inv_out(i) then
inv_err(i) <= inv_err(i)+1;
end if;
end loop;
end if;
end if;
end process;
--============================================================================
-- pulse counter
......@@ -360,7 +382,8 @@ begin
variable i : integer := 0;
variable nb_pulses_to_send_fp : integer := 150;
variable nb_pulses_to_send_fp_slv : std_logic_vector(31 downto 0);
variable nb_pulses_to_send_rp : integer :=5;
variable nb_pulses_to_send_rp : integer := 5;
variable nb_pulses_to_send_inv : integer := 5;
variable nb_pulses_to_send_rp_slv : std_logic_vector(31 downto 0);
variable glitch_filter_en : std_logic := '0';
variable ttl_out_bar_en : std_logic := '0';
......@@ -394,15 +417,15 @@ begin
-- I2C reading of the board ID register
print_now_s("I2C reading of the register ", c_REG_MAP(0).reg_name);
read_i2c (i2c_m_in, i2c_m_out, "1011110", c_REG_MAP(0).reg_addr, c_REG_MAP(0).reg_name, i2c_master_rcvd_val, C_BOARD_ID, err);
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, c_REG_MAP(0).reg_addr, c_REG_MAP(0).reg_name, i2c_master_rcvd_val, C_BOARD_ID, err);
err_cnt := err_cnt +err;
-- I2C reading of the board ID register
print_now_s("I2C reading of the register ", c_REG_MAP(1).reg_name);
read_i2c (i2c_m_in, i2c_m_out, "1011110", c_REG_MAP(1).reg_addr, c_REG_MAP(1).reg_name, i2c_master_rcvd_val, x"EF2AFF10", err);
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, c_REG_MAP(1).reg_addr, c_REG_MAP(1).reg_name, i2c_master_rcvd_val, x"EF2AFF10", err);
err_cnt := err_cnt +err;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- I2C writing
......@@ -411,11 +434,11 @@ begin
-- I2C writing of a big value to Front Panel Counter 1
print_now_s("I2C writing to the register ", c_REG_MAP(4).reg_name);
write_i2c (i2c_m_in, i2c_m_out, "1011110", c_REG_MAP(4).reg_addr, c_REG_MAP(4).reg_name, C_INITIAL_TST_VALUE, err);
write_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, c_REG_MAP(4).reg_addr, c_REG_MAP(4).reg_name, C_INITIAL_TST_VALUE, err);
err_cnt := err_cnt +err;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- Pulses to the front TTL input
......@@ -424,29 +447,29 @@ begin
-- Sending pulses to Front Panel Channel 1
nb_pulses_to_send_fp_slv := std_logic_vector(to_unsigned(nb_pulses_to_send_fp, nb_pulses_to_send_fp_slv'length));
print_now_s_i("Sending TTL pulses to Front Panel Channel 1: ", nb_pulses_to_send_fp);
print_now_s_i("Sending TTL pulses to TTL_N_I(0)", nb_pulses_to_send_fp);
generate_pulse (ttl_n_in(0), nb_pulses_to_send_fp, "fp", rs485_fs_n_in(0), 200ns, 200ns);
-- Checking if the number of TTL output pulses matches the sent ones
print_now("Check that the pulses arrived to the TTL front output");
print_now("Check that the pulses arrived to the TTL_O(0)");
if pulse_cnt_ttl(0) = nb_pulses_to_send_fp then
print_now_s_i("[OK] Number of pulses measured in the TTL output Channel 1 :",pulse_cnt_ttl(0));
print_now_s_i("[OK] Number of pulses measured at TTL_O(0): ",pulse_cnt_ttl(0));
else
print_now_s_i("[ERR] Number of pulses measured in the TTL output Channel 1 : ",pulse_cnt_ttl(0));
print_now_s_i("[ERR] Number of pulses measured at TTL_O(0): ",pulse_cnt_ttl(0));
err_cnt := err_cnt + 1;
end if;
-- Check if TTL out and RS485 out are the same
print_now("Check that the pulses arrived to the RS485 rear output");
print_now("Check that the pulses arrived to the RS485_O(0)");
if fp_rp_same(0) = 0 then
print_now("[OK] Rear Channel 1 matches Front Channel 1");
print_now("[OK] RS485_O(0) matches TTL_O(0)");
else
print_now("[ERR] Rear Channel 1 does not match Front Channel 1");
print_now("[ERR] RS485_O(0) does not match TTL_O(0)");
err_cnt := err_cnt + 1;
end if;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- Counters reading
......@@ -458,12 +481,12 @@ begin
if i = 0 then
-- Front Panel Channel 1 register should roll over and read
print_now_s("I2C reading of the register ", c_REG_MAP(i+4).reg_name);
read_i2c (i2c_m_in, i2c_m_out, "1011110", c_REG_MAP(i+4).reg_addr, c_REG_MAP(i+4).reg_name , i2c_master_rcvd_val, std_logic_vector(unsigned(C_INITIAL_TST_VALUE)+unsigned(nb_pulses_to_send_fp_slv)), err);
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, c_REG_MAP(i+4).reg_addr, c_REG_MAP(i+4).reg_name , i2c_master_rcvd_val, std_logic_vector(unsigned(C_INITIAL_TST_VALUE)+unsigned(nb_pulses_to_send_fp_slv)), err);
err_cnt := err_cnt + err;
elsif i = 1 then
-- Front Panel Channel 2 register should have not counted any pulses
print_now_s("I2C reading of the register ", c_REG_MAP(i+4).reg_name);
read_i2c (i2c_m_in, i2c_m_out, "1011110", c_REG_MAP(i+4).reg_addr, c_REG_MAP(i+4).reg_name, i2c_master_rcvd_val, (others =>'0'), err);
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, c_REG_MAP(i+4).reg_addr, c_REG_MAP(i+4).reg_name, i2c_master_rcvd_val, (others =>'0'), err);
err_cnt := err_cnt + err;
end if;
i := i + 1;
......@@ -477,19 +500,19 @@ begin
if i = 0 then
-- Check Rear Panel Channel 1 counter has not counted any pulses
print_now_s("I2C reading of the register ", c_REG_MAP(i+10).reg_name);
read_i2c (i2c_m_in, i2c_m_out, "1011110", c_REG_MAP(i+10).reg_addr, c_REG_MAP(i+10).reg_name , i2c_master_rcvd_val, (others =>'0'), err);
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, c_REG_MAP(i+10).reg_addr, c_REG_MAP(i+10).reg_name , i2c_master_rcvd_val, (others =>'0'), err);
err_cnt := err_cnt + err;
elsif i = 1 then
-- Check Rear Panel Channel 1 counter has not counted any pulses
print_now_s("I2C reading of the register ", c_REG_MAP(i+10).reg_name);
read_i2c (i2c_m_in, i2c_m_out, "1011110", c_REG_MAP(i+10).reg_addr, c_REG_MAP(i+10).reg_name, i2c_master_rcvd_val, (others =>'0'), err);
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, c_REG_MAP(i+10).reg_addr, c_REG_MAP(i+10).reg_name, i2c_master_rcvd_val, (others =>'0'), err);
err_cnt := err_cnt + err;
end if;
i := i + 1;
end loop;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- Pulses to the rear RS485 input
......@@ -499,29 +522,29 @@ begin
-- Sending pulses to Rear Panel Channel 1
nb_pulses_to_send_rp := 5;
nb_pulses_to_send_rp_slv := std_logic_vector(to_unsigned(nb_pulses_to_send_rp, nb_pulses_to_send_rp_slv'length));
print_now_s_i("Sending pulses to Rear Panel Channel 1: ", nb_pulses_to_send_rp);
print_now_s_i("Sending pulses to RS485_N_I(0): ", nb_pulses_to_send_rp);
generate_pulse (rs485_n_in(0), nb_pulses_to_send_rp, "rp", rs485_fs_n_in(0), 200ns, 200ns);
-- Checking if the number of RS485 output pulses matches the sent ones
print_now("Check that the pulses arrived to the RS485 rear output");
print_now("Check that the pulses arrived to the RS485_O(0)");
if pulse_cnt_rs485(0) = nb_pulses_to_send_rp+nb_pulses_to_send_fp then
print_now_s_i("[OK] Number of pulses measured in the RS485 output Channel 1 :",pulse_cnt_rs485(0));
print_now_s_i("[OK] Number of pulses measured at RS485_O(0) :",pulse_cnt_rs485(0));
else
print_now_s_i("[ERR] Number of pulses measured in the RS485 output Channel 1 : ",pulse_cnt_rs485(0));
print_now_s_i("[ERR] Number of pulses measured in the RS485_O(0) : ",pulse_cnt_rs485(0));
err_cnt := err_cnt + 1;
end if;
-- Check if TTL out and RS485 out are the same
print_now("Check that the pulses arrived to the TTL front output");
print_now("Check that the pulses arrived to the TTL_O(0)");
if fp_rp_same(0) = 0 then
print_now("[OK] Rear Channel 1 matches Front Channel 1");
print_now("[OK] RS485_O(0) matches TTL_O(0)");
else
print_now("[ERR] Rear Channel 1 does not match Front Channel 1");
print_now("[ERR] RS485_O(0) does not match TTL_O(0)");
err_cnt := err_cnt + 1;
end if;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- Counters reading
......@@ -534,18 +557,63 @@ begin
while not(i = 2) loop
if i = 0 then
-- Check Rear Panel Channel 1 counter has correctly counted the pulses
read_i2c (i2c_m_in, i2c_m_out, "1011110", c_REG_MAP(i+10).reg_addr, c_REG_MAP(i+10).reg_name , i2c_master_rcvd_val, nb_pulses_to_send_rp_slv, err);
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, c_REG_MAP(i+10).reg_addr, c_REG_MAP(i+10).reg_name , i2c_master_rcvd_val, nb_pulses_to_send_rp_slv, err);
err_cnt := err_cnt + err;
elsif i = 1 then
-- Check Rear Panel Channel 2 has not counted any pulses
read_i2c (i2c_m_in, i2c_m_out, "1011110", c_REG_MAP(i+10).reg_addr, c_REG_MAP(i+10).reg_name, i2c_master_rcvd_val, (others =>'0'), err);
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, c_REG_MAP(i+10).reg_addr, c_REG_MAP(i+10).reg_name, i2c_master_rcvd_val, (others =>'0'), err);
err_cnt := err_cnt + err;
end if;
i := i + 1;
end loop;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- Timetag reading
print_now("----------------------------------------------------------------");
print_now("---> Test 07: Reading of the timetag register through I2C");
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, CH1LTSCYR, "CH1LTSCY", i2c_master_rcvd_val, x"F001F177", err);
err_cnt := err_cnt + err;
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, CH1LTSTLR, "CH1LTSTL", i2c_master_rcvd_val, (others =>'0'), err);
err_cnt := err_cnt + err;
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, CH1LTSCYR, "CH1LTSCY", i2c_master_rcvd_val, x"F001F177", err);
err_cnt := err_cnt + err;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- INV channels
print_now("----------------------------------------------------------------");
print_now("---> Test 08: INV channel check");
-- Note INV channels just take INV_N_I and output the same signal to INV_O;
-- inversion happens through inv buffers; there is no associated counter, timetag, rear channel
print_now_s_i("Sending pulses to INV_N_I(3): ", nb_pulses_to_send_inv);
generate_pulse (inv_n_in(3), nb_pulses_to_send_inv, "fp", rs485_fs_n_in(3), 40ns, 20ns);
print_now("Check INV_O(3) output");
if inv_err(3) = 0 then
print_now("[OK] INV_O(3) matches INV_N_I(3) OK");
else
print_now("[ERR] INV_O(3) does not match INV_N_I(3)");
err_cnt := err_cnt + 1;
end if;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- I2C ERR
print_now("----------------------------------------------------------------");
print_now("---> Test 09: Access non existent I2C address");
read_i2c_err(i2c_m_in, i2c_m_out);
wait for 1 us;
read_i2c (i2c_m_in, i2c_m_out, C_I2C_MASTER_SLV_ADDR, c_REG_MAP(2).reg_addr, c_REG_MAP(2).reg_name, i2c_master_rcvd_val, x"F001F177", err);
err_cnt := err_cnt + err;
---------------------------------------------------------------------------
wait for 1 us;
print("*****************************************************************************");
......
......@@ -50,6 +50,8 @@ package testbench_pkg is
constant C_RTM : std_logic_vector(5 downto 0) := "010101";
constant C_INITIAL_TST_VALUE : std_logic_vector(31 downto 0) := x"FFFFFFF0";
constant C_I2C_MASTER_SLV_ADDR: std_logic_vector(6 downto 0) := "1011110";
-- DUT register map:
constant C_BIDR : std_logic_vector(31 downto 0) := x"00000000";
......@@ -72,6 +74,10 @@ package testbench_pkg is
constant C_CH5RPPCR : std_logic_vector(31 downto 0) := x"00000038";
constant C_CH6RPPCR : std_logic_vector(31 downto 0) := x"0000003C";
constant CH1LTSCYR : std_logic_vector(31 downto 0) := x"0000005C";
constant CH1LTSTLR : std_logic_vector(31 downto 0) := x"00000060";
type t_reg is
record
reg_addr : std_logic_vector(31 downto 0);
......@@ -279,6 +285,9 @@ end component conv_ttl_rs485;
constant exp_val : in std_logic_vector(31 downto 0);
err : out natural);
procedure read_i2c_err (signal i2c_m_in : out t_i2c_master_in;
signal i2c_m_out : in t_i2c_master_out);
end testbench_pkg;
package body testbench_pkg is
--==================================================================================================
......@@ -388,7 +397,7 @@ package body testbench_pkg is
print_now("read_i2c: start");
i2c_m_in.i2c_master_start <= '0';
i2c_m_in.i2c_master_rdwr <= '0'; --mst_fsm_op
i2c_m_in.i2c_master_slv_addr <= "1011110";
i2c_m_in.i2c_master_slv_addr <= C_I2C_MASTER_SLV_ADDR;
i2c_m_in.i2c_master_reg_addr <= (others => '0');
i2c_m_in.i2c_master_send_val <= (others => '1');
wait for 1us;
......@@ -429,7 +438,7 @@ package body testbench_pkg is
print_now("write_i2c: start");
i2c_m_in.i2c_master_start <= '0';
i2c_m_in.i2c_master_rdwr <= '0'; --mst_fsm_op
i2c_m_in.i2c_master_slv_addr <= "1011110";
i2c_m_in.i2c_master_slv_addr <= C_I2C_MASTER_SLV_ADDR;
i2c_m_in.i2c_master_reg_addr <= (others => '0');
i2c_m_in.i2c_master_send_val <= (others => '1');
wait for 1us;
......@@ -448,6 +457,30 @@ package body testbench_pkg is
end procedure write_i2c;
----------------------------------------------------------------------------------------------------
procedure read_i2c_err (signal i2c_m_in : out t_i2c_master_in;
signal i2c_m_out : in t_i2c_master_out) is
variable err_cnt : natural := 0;
begin
print_now("---------------");
print_now("read_i2c_err: start");
i2c_m_in.i2c_master_start <= '0';
i2c_m_in.i2c_master_rdwr <= '0'; --mst_fsm_op
i2c_m_in.i2c_master_slv_addr <= "1011111";
i2c_m_in.i2c_master_reg_addr <= (others => '0');
i2c_m_in.i2c_master_send_val <= (others => '1');
wait for 1us;
i2c_m_in.i2c_master_slv_addr <= "1011111";
i2c_m_in.i2c_master_reg_addr <= x"F1F1F1F1";
i2c_m_in.i2c_master_start <= '1';
i2c_m_in.i2c_master_rdwr <= '1'; --read
wait for C_CLK_20_PER;
i2c_m_in.i2c_master_start <= '0';
wait until i2c_m_out.i2c_master_ready = '1';
print_now("---------------");
end procedure read_i2c_err;
end;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment