Commit 9c4bd1d7 authored by Evangelia Gousiou's avatar Evangelia Gousiou

testbench: added counter of the number of pulses; added counter of the number of errors

parent a4a7ec2c
......@@ -48,19 +48,8 @@ architecture behav of testbench is
-- Signal declarations
--============================================================================
type t_i2c_master_in is record
i2c_master_start : std_logic;
i2c_master_rdwr : std_logic;
i2c_master_slv_addr : std_logic_vector(6 downto 0);
i2c_master_reg_addr : std_logic_vector(31 downto 0);
i2c_master_send_val : std_logic_vector(31 downto 0);
end record;
type t_i2c_master_out is record
i2c_master_ready : std_logic;
i2c_master_finish : std_logic;
i2c_master_rcvd_val : std_logic_vector(31 downto 0);
end record;
signal i2c_m_in : t_i2c_master_in;
signal i2c_m_out : t_i2c_master_out;
signal clk_20, clk_125 : std_logic;
signal clk_125_p, clk_125_n : std_logic;
......@@ -84,12 +73,9 @@ architecture behav of testbench is
signal sw_gp_n_in : std_logic_vector(7 downto 0);
signal sw_other_in : std_logic_vector(31 downto 0);
signal pcbrev : std_logic_vector(5 downto 0);
signal rtmm_in : std_logic_vector(2 downto 0);
signal rtmp_in : std_logic_vector(2 downto 0);
signal rtm_in : std_logic_vector(5 downto 0);
signal i2c_master_rcvd_val : std_logic_vector(31 downto 0);
signal i2c_m_in : t_i2c_master_in;
signal i2c_m_out : t_i2c_master_out;
signal mscl, msda : std_logic_vector(C_NR_MASTERS-1 downto 0);
signal sscl, ssda : std_logic_vector(C_NR_SLAVES-1 downto 0);
signal scl, sda : std_logic;
......@@ -98,75 +84,13 @@ architecture behav of testbench is
-- signal nb_pulses_to_send_slv : std_logic_vector(31 downto 0);
signal reg_id : integer := 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;
signal i2c_m_out: in t_i2c_master_out;
constant slv_addr : in std_logic_vector(6 downto 0);
constant reg_addr : in std_logic_vector(31 downto 0);
constant reg_name : string(1 to 8);
signal rcvd_val : out std_logic_vector(31 downto 0);
constant exp_val : in std_logic_vector(31 downto 0)) is
begin
print_now ("-------------------------------------------------");
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_reg_addr <= (others => '0');
i2c_m_in.i2c_master_send_val <= (others => '1');
wait for 1us;
i2c_m_in.i2c_master_slv_addr <= slv_addr;
i2c_m_in.i2c_master_reg_addr <= reg_addr;
i2c_m_in.i2c_master_start <= '1';
i2c_m_in.i2c_master_rdwr <= '1'; --0: write
wait for C_CLK_20_PER;
i2c_m_in.i2c_master_start <= '0';
wait until i2c_m_out.i2c_master_finish = '1';
rcvd_val <= i2c_m_out.i2c_master_rcvd_val;
print_now_s_std_s_std("I2C value read from 0x", reg_addr(7 downto 0),
" is 0x",i2c_m_out.i2c_master_rcvd_val);
wait until i2c_m_out.i2c_master_finish = '0';
print_now("read_i2c: completed");
if i2c_m_out.i2c_master_rcvd_val = exp_val then
print_now_s_s("[OK] Correct reading from reg ", reg_name, "; expected value matches read value");
else
print_now_s_std_s_std("-------> [ERR]: Read value ", i2c_master_rcvd_val,
" expected value ",exp_val);
end if;
print_now ("-------------------------------------------------");
end procedure read_i2c;
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;
procedure write_i2c (signal i2c_m_in : out t_i2c_master_in;
signal i2c_m_out : in t_i2c_master_out;
constant slv_addr : in std_logic_vector( 6 downto 0);
constant reg_addr : in std_logic_vector(31 downto 0);
constant reg_name : string(1 to 8);
constant send_val : in std_logic_vector(31 downto 0)) is
begin
print_now ("-------------------------------------------------");
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_reg_addr <= (others => '0');
i2c_m_in.i2c_master_send_val <= (others => '1');
wait for 1us;
i2c_m_in.i2c_master_slv_addr <= slv_addr;
i2c_m_in.i2c_master_reg_addr <= reg_addr;
i2c_m_in.i2c_master_send_val <= send_val;
i2c_m_in.i2c_master_start <= '1';
i2c_m_in.i2c_master_rdwr <= '0'; --0: write
wait for C_CLK_20_PER;
i2c_m_in.i2c_master_start <= '0';
wait until i2c_m_out.i2c_master_ready = '1';
print_now_s_std_s("write_i2C: Value ", send_val, " written to reg " & reg_name);
print_now ("-------------------------------------------------");
end procedure write_i2c;
--==============================================================================
-- architecture begin
......@@ -243,8 +167,8 @@ begin
sw_gp_n_i => sw_gp_n_in,
sw_multicast_n_i => (others => '0'), -- not used
-- RTM lines
rtmm_i => rtmm_in,
rtmp_i => rtmp_in,
rtmm_i => rtm_in(5 downto 3),
rtmp_i => rtm_in(2 downto 0),
-- Front panel bicolor LEDs
led_ctrl0_o => open,
led_ctrl0_oen_o => open,
......@@ -352,47 +276,111 @@ begin
begin
if rising_edge (clk_20) then
if vme_sysreset_n = '0' then
fp_rp_same <= (others=>'0');
fp_rp_oppos <= (others=>'0');
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';
if ttl_out(i) /= rs485_out(i) then
fp_rp_same(i) <= fp_rp_same(i)+1;
end if;
if ttl_out(i) = not rs485_out(i) then
fp_rp_oppos(i) <= '1';
fp_rp_oppos(i) <= fp_rp_oppos(i)+1;
end if;
end loop;
end if;
end if;
end process;
--============================================================================
-- pulse counter
--============================================================================
pulse_counter_ttl: process (ttl_out)
begin
if vme_sysreset_n = '0' then
pulse_cnt_ttl <= (others=> (0));
end if;
--for i in 0 to C_NR_CHANS-1 loop
if rising_edge(ttl_out(0)) then
pulse_cnt_ttl(0) <= pulse_cnt_ttl(0) +1;
end if;
if rising_edge(ttl_out(1)) then
pulse_cnt_ttl(1) <= pulse_cnt_ttl(1) +1;
end if;
if rising_edge(ttl_out(2)) then
pulse_cnt_ttl(2) <= pulse_cnt_ttl(2) +1;
end if;
if rising_edge(ttl_out(3)) then
pulse_cnt_ttl(3) <= pulse_cnt_ttl(3) +1;
end if;
if rising_edge(ttl_out(4)) then
pulse_cnt_ttl(4) <= pulse_cnt_ttl(4) +1;
end if;
if rising_edge(ttl_out(5)) then
pulse_cnt_ttl(5) <= pulse_cnt_ttl(5) +1;
end if;
--end loop;
end process pulse_counter_ttl;
pulse_counter_rs485: process (rs485_out)
begin
if vme_sysreset_n = '0' then
pulse_cnt_rs485 <= (others=> (0));
end if;
--for i in 0 to C_NR_CHANS-1 loop
if rising_edge(rs485_out(0)) then
pulse_cnt_rs485(0) <= pulse_cnt_rs485(0) +1;
end if;
if rising_edge(rs485_out(1)) then
pulse_cnt_rs485(1) <= pulse_cnt_rs485(1) +1;
end if;
if rising_edge(rs485_out(2)) then
pulse_cnt_rs485(2) <= pulse_cnt_rs485(2) +1;
end if;
if rising_edge(rs485_out(3)) then
pulse_cnt_rs485(3) <= pulse_cnt_rs485(3) +1;
end if;
if rising_edge(rs485_out(4)) then
pulse_cnt_rs485(4) <= pulse_cnt_rs485(4) +1;
end if;
if rising_edge(rs485_out(5)) then
pulse_cnt_rs485(5) <= pulse_cnt_rs485(5) +1;
end if;
--end loop;
end process pulse_counter_rs485;
--============================================================================
-- processes to provide stimulus and checks
--============================================================================
--i2c access
p_stim_i2c : process
variable i : integer := 0;
variable nb_pulses_to_send : integer := 15;
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';
p_stim : process
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_slv : std_logic_vector(31 downto 0);
variable glitch_filter_en : std_logic := '0';
variable ttl_out_bar_en : std_logic := '0';
variable err_cnt, err : integer := 0;
begin
print("************************************************************");
print(" Start of Tests");
print("************************************************************");
print("*****************************************************************************");
print(" Start of Tests");
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);
print_now("----------------------------------------------------------------");
print_now("---> Configure board settings");
settings_config (glitch_filter_en, ttl_out_bar_en, sw_gp_n_in, sw_other_in, pcbrev, rtm_in);
---------------------------------------------------------------------------
-- VME reset
print(" ---> VME reset");
print_now("----------------------------------------------------------------");
print_now("---> VME reset");
print_now("Sending VME reset");
wait until vme_sysreset_n = '1';
print_now("VME reset completed");
......@@ -400,94 +388,173 @@ begin
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- I2C readings
print_now("----------------------------------------------------------------");
print_now("---> Test 01: I2C regs reading");
-- I2C reading of the board ID register
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);
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);
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);
err_cnt := err_cnt +err;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- 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");
-- I2C writing
print_now("----------------------------------------------------------------");
print_now("---> Test 02: I2C reg writing");
-- 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);
err_cnt := err_cnt +err;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- Pulses to the front TTL input
print_now("----------------------------------------------------------------");
print_now("---> Test 03: Sending TTL pulses and checking the outputs");
-- 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));
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);
---------------------------------------------------------------------------
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);
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");
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));
else
print_now_s_i("[ERR] Number of pulses measured in the TTL output Channel 1 : ",pulse_cnt_ttl(0));
err_cnt := err_cnt + 1;
end if;
---------------------------------------------------------------------------
-- 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("Check that the pulses arrived to the RS485 rear 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");
err_cnt := err_cnt + 1;
end if;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- Counters reading
print_now("----------------------------------------------------------------");
print_now("---> Test 04: Reading of the pulse counters through I2C");
-- Reading from the I2C Front Panel regs; read only two counters to speed up testbench
while not(i = 3) loop
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);
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);
err_cnt := err_cnt + err;
end if;
i := i + 1;
end loop;
print_now("Checking that the rear pulse counters have not registered any pulses");
-- Reading from the I2C Rear Panel regs; read only two counters to speed up testbench
i := 0;
while not(i = 2) loop
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);
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);
err_cnt := err_cnt + err;
end if;
i := i + 1;
end loop;
---------------------------------------------------------------------------
-- Reading from the I2C Front Panel regs; read only first 2 Channels to speed up testbench
-- print(" ---> I2C reading of the front pulse counters");
-- while not(i = 3) loop
-- if i = 0 then
-- -- Front Panel Channel 1 register should roll over and read
-- 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");
-- else
-- -- Front Panel Channel 2 register should have not counted any pulses
-- 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'));
-- end if;
-- i := i + 1;
-- end loop;
-- ---------------------------------------------------------------------------
-- -- Reading from the I2C Rear Panel regs; read only first Channel to speed up testbench
-- print(" ---> I2C reading of the rear pulse counters");
-- i := 0;
-- while not(i = 2) loop
-- if i = 0 then
-- -- 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'));
-- else
-- -- 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'));
-- end if;
-- i := i + 1;
-- end loop;
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- Pulses to the rear RS485 input
print_now("----------------------------------------------------------------");
print_now("---> Test 05: Sending pulses to the RS485 and checking the outputs");
-- 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);
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");
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));
else
print_now_s_i("[ERR] Number of pulses measured in the RS485 output Channel 1 : ",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");
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");
err_cnt := err_cnt + 1;
end if;
---------------------------------------------------------------------------
wait for 1000 ns;
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- Sending pulses to Rear Panel Channel 2
print(" ---> Sending pulses");
nb_pulses_to_send := 5;
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);
-- Counters reading
print_now("----------------------------------------------------------------");
print_now("---> Test 06: Reading of the pulse counters through I2C");
---------------------------------------------------------------------------
-- Reading from the I2C Front Panel regs; read one reg to speed up testbench
print(" ---> I2C reading of the rear pulse counters");
i := 6;
while not(i = 8) loop
-- Reading from the I2C Rear Panel regs; read two reg to speed up testbench
i := 0;
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+4).reg_addr, c_REG_MAP(i+4).reg_name , i2c_master_rcvd_val, nb_pulses_to_send_slv);
else
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);
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+4).reg_addr, c_REG_MAP(i+4).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'), err);
err_cnt := err_cnt + err;
end if;
i := i + 1;
end loop;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
wait for 1 us;
print("*****************************************************************************");
print(" Tests Summary");
print("*****************************************************************************");
print_now_s_i("Total number of errors: ", err_cnt);
print("*****************************************************************************");
end process p_stim_i2c;
end process p_stim;
end architecture behav;
......
......@@ -47,9 +47,12 @@ package testbench_pkg is
constant C_NR_MASTERS : positive := 1;
constant C_NR_SLAVES : positive := 1;
constant C_RTM : std_logic_vector(5 downto 0) := "010101";
constant C_INITIAL_TST_VALUE : std_logic_vector(31 downto 0) := x"FFFFFFF0";
-- DUT register map:
constant C_BIDR : std_logic_vector(31 downto 0) := x"00000000";
constant C_BIDR : std_logic_vector(31 downto 0) := x"00000000";
constant C_SR : std_logic_vector(31 downto 0) := x"00000004";
constant C_ERR : std_logic_vector(31 downto 0) := x"00000008";
......@@ -129,7 +132,6 @@ package testbench_pkg is
i2c_master_rcvd_val : std_logic_vector(31 downto 0);
end record;
--============================================================================
-- Components declarations
--============================================================================
......@@ -242,6 +244,8 @@ end component conv_ttl_rs485;
procedure generate_pulse (signal pulse_n_out : out std_logic;
nb_of_pulses : in natural;
fp_or_rp : in string (1 to 2);
signal rs485_fs_n : out std_logic;
ns_on : in time;
ns_off : in time);
......@@ -251,7 +255,29 @@ end component conv_ttl_rs485;
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));
signal rtm : out std_logic_vector(5 downto 0));
procedure cnt_pulses (signal pulse_train : in std_logic;
signal nb_of_pulses_cnted : out natural;
nb_pulses_expected : in integer);
procedure write_i2c (signal i2c_m_in : out t_i2c_master_in;
signal i2c_m_out : in t_i2c_master_out;
constant slv_addr : in std_logic_vector( 6 downto 0);
constant reg_addr : in std_logic_vector(31 downto 0);
constant reg_name : string(1 to 8);
constant send_val : in std_logic_vector(31 downto 0);
err : out natural);
procedure read_i2c (signal i2c_m_in : out t_i2c_master_in;
signal i2c_m_out: in t_i2c_master_out;
constant slv_addr : in std_logic_vector(6 downto 0);
constant reg_addr : in std_logic_vector(31 downto 0);
constant reg_name : string(1 to 8);
signal rcvd_val : out std_logic_vector(31 downto 0);
constant exp_val : in std_logic_vector(31 downto 0);
err : out natural);
end testbench_pkg;
package body testbench_pkg is
......@@ -263,7 +289,7 @@ package body testbench_pkg is
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)) is
signal rtm : out std_logic_vector(5 downto 0)) is
begin
sw_gp_n(7) <= glitch_filter_en;
if glitch_filter_en = '1' then
......@@ -279,34 +305,150 @@ package body testbench_pkg is
print_now("TTL output BAR disabled");
end if;
print_now_s_std("RTMP & RTMM set to x", C_RTM);
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
rtm <= C_RTM; -- not used
end procedure;
----------------------------------------------------------------------------------------------------
procedure generate_pulse (signal pulse_n_out : out std_logic;
nb_of_pulses : in natural;
ns_on : in time;
ns_off : in time) is
fp_or_rp : in string (1 to 2);
signal rs485_fs_n : out std_logic;
ns_on : in time;
ns_off : in time) is
variable numb_cnt : natural;
begin
numb_cnt := 0;
while not(numb_cnt = nb_of_pulses) loop
pulse_n_out <= '1';
wait for ns_off;
pulse_n_out <= '0';
wait for ns_on;
pulse_n_out <= '1';
if fp_or_rp = "fp" then
rs485_fs_n <= '0'; -- stays inactive
pulse_n_out <= '1';
wait for ns_off;
pulse_n_out <= '0';
wait for ns_on;
pulse_n_out <= '1';
else
pulse_n_out <= '1';
rs485_fs_n <= '0';
wait for ns_off;
pulse_n_out <= '0';
rs485_fs_n <= '1';
wait for ns_on;
pulse_n_out <= '1';
rs485_fs_n <= '0';
end if;
numb_cnt:= numb_cnt + 1;
end loop;
wait for ns_off;
end procedure generate_pulse;
----------------------------------------------------------------------------------------------------
procedure cnt_pulses (signal pulse_train : in std_logic;
signal nb_of_pulses_cnted : out integer;
nb_pulses_expected : in integer) is
variable pulse_cnt : integer :=0;
variable err_sum : integer:=0;
begin
if rising_edge(pulse_train) then
pulse_cnt := pulse_cnt +1;
end if;
nb_of_pulses_cnted <= pulse_cnt;
if pulse_cnt = nb_pulses_expected then
print_now_s_i("[OK] counted: ", pulse_cnt);
else
print_now_s_i("[ERR] counted: ", pulse_cnt);
end if;
end procedure cnt_pulses;
----------------------------------------------------------------------------------------------------
procedure read_i2c (signal i2c_m_in : out t_i2c_master_in;
signal i2c_m_out: in t_i2c_master_out;
constant slv_addr : in std_logic_vector(6 downto 0);
constant reg_addr : in std_logic_vector(31 downto 0);
constant reg_name : string(1 to 8);
signal rcvd_val : out std_logic_vector(31 downto 0);
constant exp_val : in std_logic_vector(31 downto 0);
err : out natural) is
variable err_cnt : natural := 0;
begin
print_now("---------------");
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_reg_addr <= (others => '0');
i2c_m_in.i2c_master_send_val <= (others => '1');
wait for 1us;
i2c_m_in.i2c_master_slv_addr <= slv_addr;
i2c_m_in.i2c_master_reg_addr <= reg_addr;
i2c_m_in.i2c_master_start <= '1';
i2c_m_in.i2c_master_rdwr <= '1'; --0: write
wait for C_CLK_20_PER;
i2c_m_in.i2c_master_start <= '0';
wait until i2c_m_out.i2c_master_finish = '1';
rcvd_val <= i2c_m_out.i2c_master_rcvd_val;
print_now_s_std_s_std("I2C value read from 0x", reg_addr(7 downto 0),
" is 0x",i2c_m_out.i2c_master_rcvd_val);
wait until i2c_m_out.i2c_master_finish = '0';
print_now("read_i2c: completed");
if i2c_m_out.i2c_master_rcvd_val = exp_val then
print_now_s_s("[OK] Correct reading from reg ", reg_name, "; expected value matches read value");
else
print_now_s_std_s_std("[ERR]: Read value from " & reg_name & ": ", i2c_m_out.i2c_master_rcvd_val,
"; expected value: ",exp_val);
err_cnt := err_cnt +1;
end if;
err := err_cnt;
print_now("---------------");
end procedure read_i2c;
----------------------------------------------------------------------------------------------------
procedure write_i2c (signal i2c_m_in : out t_i2c_master_in;
signal i2c_m_out : in t_i2c_master_out;
constant slv_addr : in std_logic_vector( 6 downto 0);
constant reg_addr : in std_logic_vector(31 downto 0);
constant reg_name : string(1 to 8);
constant send_val : in std_logic_vector(31 downto 0);
err : out natural) is
variable err_cnt : natural := 0;
begin
print_now("---------------");
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_reg_addr <= (others => '0');
i2c_m_in.i2c_master_send_val <= (others => '1');
wait for 1us;
i2c_m_in.i2c_master_slv_addr <= slv_addr;
i2c_m_in.i2c_master_reg_addr <= reg_addr;
i2c_m_in.i2c_master_send_val <= send_val;
i2c_m_in.i2c_master_start <= '1';
i2c_m_in.i2c_master_rdwr <= '0'; --0: write
wait for C_CLK_20_PER;
i2c_m_in.i2c_master_start <= '0';
wait until i2c_m_out.i2c_master_ready = '1';
print_now_s_std_s("write_i2C: Value ", send_val, " written to reg " & reg_name);
print_now("---------------");
err := 0;
end procedure write_i2c;
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