Commit a4a7ec2c authored by Evangelia Gousiou's avatar Evangelia Gousiou

test bench added check for comparison of front and rear output; fixed rs485_fs input

parent 03a4b568
...@@ -68,8 +68,8 @@ architecture behav of testbench is ...@@ -68,8 +68,8 @@ architecture behav of testbench is
signal gf_en_n_in : std_logic; signal gf_en_n_in : std_logic;
signal ttl_n_in, ttl_out : std_logic_vector(C_NR_CHANS-1 downto 0) := (others => '0'); signal ttl_n_in, ttl_out : std_logic_vector(C_NR_CHANS-1 downto 0) := (others => '1');
signal rs485_n_in, rs485_n_out : std_logic_vector(C_NR_CHANS-1 downto 0) := (others => '0'); signal rs485_n_in, rs485_fs_n_in, rs485_out : std_logic_vector(C_NR_CHANS-1 downto 0) := (others => '1');
signal sscl_out : std_logic; signal sscl_out : std_logic;
signal sscl_en_out : std_logic; signal sscl_en_out : std_logic;
...@@ -86,15 +86,7 @@ architecture behav of testbench is ...@@ -86,15 +86,7 @@ architecture behav of testbench is
signal pcbrev : std_logic_vector(5 downto 0); signal pcbrev : std_logic_vector(5 downto 0);
signal rtmm_in : std_logic_vector(2 downto 0); signal rtmm_in : std_logic_vector(2 downto 0);
signal rtmp_in : std_logic_vector(2 downto 0); signal rtmp_in : std_logic_vector(2 downto 0);
signal i2c_master_rcvd_val : std_logic_vector(31 downto 0);
signal line_front_in : std_logic_vector(C_NR_CHANS-1 downto 0);
signal line_inv_in : std_logic_vector(C_NR_INV_CHANS-1 downto 0);
signal line_rear_in : std_logic_vector(C_NR_CHANS-1 downto 0);
signal line_front_fs_in : std_logic_vector(C_NR_CHANS-1 downto 0);
signal line_inv_fs_in : std_logic_vector(C_NR_INV_CHANS-1 downto 0);
signal line_rear_fs_in : std_logic_vector(C_NR_CHANS-1 downto 0);
signal i2c_master_rcvd_val, i2c_master_rcvd_val1,i2c_master_rcvd_val2, i2c_master_rcvd_val3, i2c_master_rcvd_val4 : std_logic_vector(31 downto 0);
signal i2c_m_in : t_i2c_master_in; signal i2c_m_in : t_i2c_master_in;
signal i2c_m_out : t_i2c_master_out; signal i2c_m_out : t_i2c_master_out;
...@@ -106,6 +98,7 @@ architecture behav of testbench is ...@@ -106,6 +98,7 @@ architecture behav of testbench is
-- signal nb_pulses_to_send_slv : std_logic_vector(31 downto 0); -- signal nb_pulses_to_send_slv : std_logic_vector(31 downto 0);
signal reg_id : integer := 0; signal reg_id : integer := 0;
signal adr : std_logic_vector(31 downto 0); signal adr : std_logic_vector(31 downto 0);
signal fp_rp_same, fp_rp_oppos : unsigned(C_NR_CHANS-1 downto 0);
procedure read_i2c (signal i2c_m_in : out t_i2c_master_in; procedure read_i2c (signal i2c_m_in : out t_i2c_master_in;
...@@ -209,14 +202,14 @@ begin ...@@ -209,14 +202,14 @@ begin
inv_oen_o => open, inv_oen_o => open,
rs485_oen_o => open, rs485_oen_o => open,
-- Front panel channels -- Front panel channels
ttl_n_i => ttl_n_in, --: in std_logic_vector(5 downto 0); ttl_n_i => ttl_n_in,
ttl_o => ttl_out, --: out std_logic_vector(5 downto 0); ttl_o => ttl_out,
inv_n_i => (others => '0'), --inv_n_in, --: in std_logic_vector(3 downto 0); inv_n_i => (others => '0'),
inv_o => open, --inv_n_out, --: out std_logic_vector(3 downto 0); inv_o => open,
-- Rear panel channels -- Rear panel channels
rs485_n_i => rs485_n_in, --: in std_logic_vector(5 downto 0); rs485_n_i => rs485_n_in,
rs485_fs_n_i => (others => '0'), --: in std_logic_vector(5 downto 0); --failsafe? rs485_fs_n_i => rs485_fs_n_in,
rs485_o => rs485_n_out, --: out std_logic_vector(5 downto 0); rs485_o => rs485_out,
-- Rear input and output termination lines -- Rear input and output termination lines
iterm_en_o => open, iterm_en_o => open,
oterm_en_o => open, oterm_en_o => open,
...@@ -264,7 +257,8 @@ begin ...@@ -264,7 +257,8 @@ begin
led_gf_syspw_o => open, led_gf_syspw_o => open,
led_ttl_i2c_o => open); led_ttl_i2c_o => open);
sscl(0) <= sscl_out when (sscl_en_out = '1') else '1'; sscl(0) <= sscl_out when (sscl_en_out = '1') else '1';
ssda(0) <= ssda_out when (ssda_en_out = '1') else '1'; ssda(0) <= ssda_out when (ssda_en_out = '1') else '1';
...@@ -349,6 +343,30 @@ begin ...@@ -349,6 +343,30 @@ begin
scl_o => scl, scl_o => scl,
sda_o => sda sda_o => sda
); );
--============================================================================
-- Check if ttl_out matches rs485_out
--============================================================================
compare_front_rear_pulses: process (clk_20)
begin
if rising_edge (clk_20) then
if vme_sysreset_n = '0' then
fp_rp_same <= (others=>'0');
fp_rp_oppos <= (others=>'0');
else
for i in 0 to C_NR_CHANS-1 loop
if ttl_out(i) = rs485_out(i) then
fp_rp_same(i) <= '1';
end if;
if ttl_out(i) = not rs485_out(i) then
fp_rp_oppos(i) <= '1';
end if;
end loop;
end if;
end if;
end process;
--============================================================================ --============================================================================
-- processes to provide stimulus and checks -- processes to provide stimulus and checks
...@@ -357,16 +375,24 @@ begin ...@@ -357,16 +375,24 @@ begin
--i2c access --i2c access
p_stim_i2c : process p_stim_i2c : process
variable i : integer := 0; variable i : integer := 0;
variable nb_pulses_to_send : integer := 150; variable nb_pulses_to_send : integer := 15;
variable nb_pulses_to_send_slv : std_logic_vector(31 downto 0); variable nb_pulses_to_send_slv : std_logic_vector(31 downto 0);
variable glitch_filter_en : std_logic := '0';
variable ttl_out_bar_en : std_logic := '0';
begin begin
print("***************************************************"); print("************************************************************");
print(" Start of Tests"); print(" Start of Tests");
print("***************************************************"); print("************************************************************");
---------------------------------------------------------------------------
-- Board settings
print(" ---> Configure board settings");
settings_config (glitch_filter_en, ttl_out_bar_en, sw_gp_n_in, sw_other_in, pcbrev, rtmm_in);
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- VME reset -- VME reset
print(" ---> VME reset");
print_now("Sending VME reset"); print_now("Sending VME reset");
wait until vme_sysreset_n = '1'; wait until vme_sysreset_n = '1';
print_now("VME reset completed"); print_now("VME reset completed");
...@@ -375,56 +401,78 @@ begin ...@@ -375,56 +401,78 @@ begin
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- I2C reading of the board ID register -- I2C reading of the board ID register
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); print(" ---> I2C reading of the Board ID register");
--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);
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- I2C writing of a big value to Front Panel Counter 1 -- I2C writing of a big value to Front Panel Counter 1
print(" ---> I2C writing of a big value to the Front Panel Channel 1 Counter register");
write_i2c (i2c_m_in, i2c_m_out, "1011110", c_REG_MAP(4).reg_addr, c_REG_MAP(4).reg_name, x"FFFFFFF0"); write_i2c (i2c_m_in, i2c_m_out, "1011110", c_REG_MAP(4).reg_addr, c_REG_MAP(4).reg_name, x"FFFFFFF0");
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- Sending pulses to Front Panel Channel 1 -- Sending pulses to Front Panel Channel 1
print(" ---> Sending pulses");
nb_pulses_to_send_slv := std_logic_vector(to_unsigned(nb_pulses_to_send, nb_pulses_to_send_slv'length)); nb_pulses_to_send_slv := std_logic_vector(to_unsigned(nb_pulses_to_send, nb_pulses_to_send_slv'length));
print_now_s_i("Sending TTL pulses to Front Panel Channel 1: ", nb_pulses_to_send); print_now_s_i("Sending TTL pulses to Front Panel Channel 1: ", nb_pulses_to_send);
rs485_fs_n_in <= (others => '0');
generate_pulse (ttl_n_in(0), nb_pulses_to_send, 200ns, 200ns); generate_pulse (ttl_n_in(0), nb_pulses_to_send, 200ns, 200ns);
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- Check if TTL out and RS485 out are the same
print(" ---> Check that Rear output is the same as Front output");
if fp_rp_same(0) = '0' then
print_now("[OK] Rear Channel 1 matches Front Channel 1");
else
print_now("[ERR] Rear Channel 1 does not match Front Channel 1");
end if;
---------------------------------------------------------------------------
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- Reading from the I2C Front Panel regs; read only first 2 Channels to speed up testbench -- Reading from the I2C Front Panel regs; read only first 2 Channels to speed up testbench
while not(i = 3) loop -- print(" ---> I2C reading of the front pulse counters");
if i = 0 then -- while not(i = 3) loop
-- Front Panel Channel 1 register should roll over and read -- if i = 0 then
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, x"00000087"); -- -- Front Panel Channel 1 register should roll over and read
else -- 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, x"00000087");
-- Front Panel Channel 2 register should have not counted any pulses -- else
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')); -- -- Front Panel Channel 2 register should have not counted any pulses
end if; -- 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'));
i := i + 1; -- end if;
end loop; -- i := i + 1;
--------------------------------------------------------------------------- -- end loop;
-- Reading from the I2C Rear Panel regs; read only first Channel to speed up testbench -- ---------------------------------------------------------------------------
i := 0; -- -- Reading from the I2C Rear Panel regs; read only first Channel to speed up testbench
while not(i = 2) loop -- print(" ---> I2C reading of the rear pulse counters");
if i = 0 then -- i := 0;
-- Check Rear Panel Channel 1 counter has not counted any pulses -- while not(i = 2) loop
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')); -- if i = 0 then
else -- -- Check Rear Panel Channel 1 counter has not counted any pulses
-- Check Rear Panel Channel 1 counter 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'));
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')); -- else
end if; -- -- Check Rear Panel Channel 1 counter has not counted any pulses
i := i + 1; -- 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'));
end loop; -- end if;
-- i := i + 1;
-- end loop;
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
wait for 1000 ns;
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- Sending 150 pulses to Rear Panel Channel 2 -- Sending pulses to Rear Panel Channel 2
print(" ---> Sending pulses");
nb_pulses_to_send := 5; nb_pulses_to_send := 5;
print_now_s_i("Sending pulses to Rear Panel Channel 1: ", nb_pulses_to_send); print_now_s_i("Sending pulses to Rear Panel Channel 1: ", nb_pulses_to_send);
rs485_fs_n_in <= rs485_n_in;
generate_pulse (rs485_n_in(1), nb_pulses_to_send, 200ns, 200ns); generate_pulse (rs485_n_in(1), nb_pulses_to_send, 200ns, 200ns);
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- Reading from the I2C Front Panel regs; read one reg to speed up testbench -- Reading from the I2C Front Panel regs; read one reg to speed up testbench
print(" ---> I2C reading of the rear pulse counters");
i := 6; i := 6;
while not(i = 8) loop while not(i = 8) loop
if i = 0 then if i = 0 then
...@@ -442,7 +490,6 @@ begin ...@@ -442,7 +490,6 @@ begin
end process p_stim_i2c; end process p_stim_i2c;
end architecture behav; end architecture behav;
--============================================================================== --==============================================================================
-- architecture end -- architecture end
......
...@@ -245,22 +245,44 @@ end component conv_ttl_rs485; ...@@ -245,22 +245,44 @@ end component conv_ttl_rs485;
ns_on : in time; ns_on : in time;
ns_off : in time); ns_off : in time);
procedure settings_config (constant glitch_filter_en : in std_logic;
constant ttl_out_bar_en : in std_logic;
signal sw_gp_n : out std_logic_vector(7 downto 0);
signal sw_other : out std_logic_vector(31 downto 0);
signal pcbrev : out std_logic_vector(5 downto 0);
signal rtmm : out std_logic_vector(2 downto 0));
end testbench_pkg; end testbench_pkg;
package body testbench_pkg is package body testbench_pkg is
--================================================================================================== --==================================================================================================
-- Procedures -- Procedures
--================================================================================================== --==================================================================================================
procedure settings_config (signal sw_gp_n_in : out std_logic_vector(7 downto 0); procedure settings_config (constant glitch_filter_en : in std_logic;
signal sw_other_in : out std_logic_vector(31 downto 0); constant ttl_out_bar_en : in std_logic;
signal pcbrev : out std_logic_vector(5 downto 0); signal sw_gp_n : out std_logic_vector(7 downto 0);
signal rtmm_in : out std_logic_vector(2 downto 0)) is signal sw_other : out std_logic_vector(31 downto 0);
signal pcbrev : out std_logic_vector(5 downto 0);
signal rtmm : out std_logic_vector(2 downto 0)) is
begin begin
sw_gp_n_in(0) <= '1'; -- disable glitch filter ? sw_gp_n(7) <= glitch_filter_en;
sw_gp_n_in(1) <= '1'; -- if glitch_filter_en = '1' then
sw_gp_n_in(7 downto 2) <= (others => '0'); print_now("Glitch filter enabled");
sw_other_in <= (others => '0'); else
pcbrev <= "111100"; print_now("Glitch filter disabled");
rtmm_in <= (others => '0'); end if;
sw_gp_n(0) <= ttl_out_bar_en;
if ttl_out_bar_en = '1' then
print_now("TTL output BAR enabled");
else
print_now("TTL output BAR disabled");
end if;
sw_gp_n(6 downto 1) <= (others => '0'); -- not used
sw_other <= (others => '0'); -- not used
pcbrev <= "111100"; -- not used
rtmm <= (others => '0'); -- not used
end procedure; end procedure;
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
......
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