Commit 3e8e8e64 authored by Martin Jeřábek's avatar Martin Jeřábek

testwf: feature tests: wip

parent e5c26452
......@@ -64,21 +64,18 @@ USE ieee.math_real.ALL;
use work.CANconstants.all;
USE work.CANtestLib.All;
USE work.randomLib.All;
use work.pkg_feature_exec_dispath.all;
use work.CAN_FD_register_map.all;
package abort_transmittion_feature is
procedure abort_transmittion_feature_exec(
variable outcome : inout boolean;
variable o : out feature_outputs_t;
signal rand_ctr : inout natural range 0 to RAND_POOL_SIZE;
signal mem_bus_1 : inout Avalon_mem_type;
signal mem_bus_2 : inout Avalon_mem_type;
signal bus_level : in std_logic;
signal drv_bus_1 : in std_logic_vector(1023 downto 0);
signal drv_bus_2 : in std_logic_vector(1023 downto 0);
signal stat_bus_1 : in std_logic_vector(511 downto 0);
signal stat_bus_2 : in std_logic_vector(511 downto 0)
signal iout : in instance_inputs_arr_t;
signal mem_bus : inout mem_bus_arr_t;
signal bus_level : in std_logic
);
end package;
......@@ -87,15 +84,11 @@ end package;
package body abort_transmittion_feature is
procedure abort_transmittion_feature_exec(
variable outcome : inout boolean;
variable o : out feature_outputs_t;
signal rand_ctr : inout natural range 0 to RAND_POOL_SIZE;
signal mem_bus_1 : inout Avalon_mem_type;
signal mem_bus_2 : inout Avalon_mem_type;
signal bus_level : in std_logic;
signal drv_bus_1 : in std_logic_vector(1023 downto 0);
signal drv_bus_2 : in std_logic_vector(1023 downto 0);
signal stat_bus_1 : in std_logic_vector(511 downto 0);
signal stat_bus_2 : in std_logic_vector(511 downto 0)
signal iout : in instance_inputs_arr_t;
signal mem_bus : inout mem_bus_arr_t;
signal bus_level : in std_logic
)is
variable r_data : std_logic_vector(31 downto 0) :=
(OTHERS => '0');
......@@ -115,7 +108,7 @@ package body abort_transmittion_feature is
variable command : SW_command := (false, false, false);
variable status : SW_status;
begin
outcome := true;
o.outcome := true;
------------------------------------------------------------------------
-- Generate CAN frame
......@@ -125,13 +118,13 @@ package body abort_transmittion_feature is
------------------------------------------------------------------------
-- Insert the frame for transmittion
------------------------------------------------------------------------
CAN_send_frame(CAN_frame, 1, ID_1, mem_bus_1, frame_sent);
CAN_send_frame(CAN_frame, 1, ID_1, mem_bus(1), frame_sent);
------------------------------------------------------------------------
-- Wait until unit turns transmitter
------------------------------------------------------------------------
loop
get_controller_status(status, ID_1, mem_bus_1);
get_controller_status(status, ID_1, mem_bus(1));
if (status.transmitter) then
exit;
end if;
......@@ -143,7 +136,7 @@ package body abort_transmittion_feature is
-- aborts immediately after the frame was commited and SOF was not
-- yet sent!
------------------------------------------------------------------------
wait_rand_cycles(rand_ctr, mem_bus_1.clk_sys, 200, 25000);
wait_rand_cycles(rand_ctr, mem_bus(1).clk_sys, 200, 25000);
------------------------------------------------------------------------
-- Check that unit is not transciever anymore, unit should be now as if
......@@ -151,7 +144,7 @@ package body abort_transmittion_feature is
-- space. So we check the PC_State from status bus explicitly.
------------------------------------------------------------------------
PC_State := protocol_type'VAL(to_integer(unsigned(
stat_bus_1(STAT_PC_STATE_HIGH downto STAT_PC_STATE_LOW))));
iout(1).stat_bus(STAT_PC_STATE_HIGH downto STAT_PC_STATE_LOW))));
report "PC State: " & protocol_type'Image(PC_State);
if (PC_State = sof or PC_State = arbitration or PC_State = control or
......@@ -169,18 +162,18 @@ package body abort_transmittion_feature is
-- Now send the command to abort the transmittion
--------------------------------------------------------------------
command.abort_transmission := true;
give_controller_command(command, ID_1, mem_bus_1);
give_controller_command(command, ID_1, mem_bus(1));
--------------------------------------------------------------------
-- Now wait for few clock cycles until Node aborts the transmittion
--------------------------------------------------------------------
for i in 0 to 5 loop
wait until rising_edge(mem_bus_1.clk_sys);
wait until rising_edge(mem_bus(1).clk_sys);
end loop;
get_controller_status(status, ID_1, mem_bus_1);
get_controller_status(status, ID_1, mem_bus(1));
if (status.transmitter) then
outcome := false;
o.outcome := false;
end if;
--------------------------------------------------------------------
......@@ -191,28 +184,28 @@ package body abort_transmittion_feature is
-- frame. It stays idle since it recieves recessive error passive
-- error frame from 2!
--------------------------------------------------------------------
CAN_wait_error_transmitted(ID_2, mem_bus_2);
CAN_wait_error_transmitted(ID_2, mem_bus(2));
--------------------------------------------------------------------
-- Now wait until bus is idle in both units
--------------------------------------------------------------------
CAN_wait_bus_idle(ID_2, mem_bus_2);
CAN_wait_bus_idle(ID_1, mem_bus_1);
CAN_wait_bus_idle(ID_2, mem_bus(2));
CAN_wait_bus_idle(ID_1, mem_bus(1));
else
--------------------------------------------------------------------
-- Now wait until bus is idle in both units
--------------------------------------------------------------------
CAN_wait_bus_idle(ID_2, mem_bus_2);
CAN_wait_bus_idle(ID_1, mem_bus_1);
CAN_wait_bus_idle(ID_2, mem_bus(2));
CAN_wait_bus_idle(ID_1, mem_bus(1));
--------------------------------------------------------------------
-- Check that unit is now idle since it is after transmittion already
--------------------------------------------------------------------
get_controller_status(status, ID_1, mem_bus_1);
get_controller_status(status, ID_1, mem_bus(1));
if (not status.bus_status) then
outcome := false;
o.outcome := false;
end if;
end if;
......@@ -228,7 +221,7 @@ package body abort_transmittion_feature is
err_counters.err_fd := 0;
err_counters.rx_counter := 0;
err_counters.tx_counter := 0;
set_error_counters(err_counters, ID_1, mem_bus_1);
set_error_counters(err_counters, ID_1, mem_bus(1));
end procedure;
......
......@@ -57,7 +57,7 @@
-- 5. Insert frames for transmission and give "set_ready" command.
-- 6. Wait until units start transmission.
-- 7. Wait until one of the units turn receiver or collision appears.
-- 8. Compare expected outcome with actual outcome.
-- 8. Compare expected o.outcome with actual o.outcome.
-- 9. Wait until bus is idle.
--
--------------------------------------------------------------------------------
......@@ -76,75 +76,64 @@ USE ieee.math_real.ALL;
use work.CANconstants.all;
USE work.CANtestLib.All;
USE work.randomLib.All;
use work.pkg_feature_exec_dispath.all;
use work.CAN_FD_register_map.all;
use work.CAN_FD_frame_format.all;
package arbitration_feature is
procedure arbitration_feature_exec(
variable outcome :inout boolean;
signal rand_ctr :inout natural range 0 to RAND_POOL_SIZE;
signal mem_bus_1 :inout Avalon_mem_type;
signal mem_bus_2 :inout Avalon_mem_type;
signal bus_level :in std_logic;
signal drv_bus_1 :in std_logic_vector(1023 downto 0);
signal drv_bus_2 :in std_logic_vector(1023 downto 0);
signal stat_bus_1 :in std_logic_vector(511 downto 0);
signal stat_bus_2 :in std_logic_vector(511 downto 0)
variable o : out feature_outputs_t;
signal rand_ctr : inout natural range 0 to RAND_POOL_SIZE;
signal iout : in instance_inputs_arr_t;
signal mem_bus : inout mem_bus_arr_t;
signal bus_level : in std_logic
);
end package;
package body Arbitration_feature is
procedure arbitration_feature_exec(
variable outcome :inout boolean;
signal rand_ctr :inout natural range 0 to RAND_POOL_SIZE;
signal mem_bus_1 :inout Avalon_mem_type;
signal mem_bus_2 :inout Avalon_mem_type;
signal bus_level :in std_logic;
signal drv_bus_1 :in std_logic_vector(1023 downto 0);
signal drv_bus_2 :in std_logic_vector(1023 downto 0);
signal stat_bus_1 :in std_logic_vector(511 downto 0);
signal stat_bus_2 :in std_logic_vector(511 downto 0)
variable o : out feature_outputs_t;
signal rand_ctr : inout natural range 0 to RAND_POOL_SIZE;
signal iout : in instance_inputs_arr_t;
signal mem_bus : inout mem_bus_arr_t;
signal bus_level : in std_logic
) is
variable rand_value : real;
variable alc : natural;
variable rand_value : real;
variable alc : natural;
-- 0-Node 1; 1-Node 2; 2-Collision
variable exp_winner : natural := 0;
variable exp_winner : natural := 0;
-- Some unit lost the arbitration...
-- 0 - initial , 1-Node 1 turned rec, 2 - Node 2 turned rec
variable unit_rec : natural := 0;
variable unit_rec : natural := 0;
variable ID_1 : natural := 1;
variable ID_2 : natural := 2;
variable r_data : std_logic_vector(31 downto 0) :=
(OTHERS => '0');
variable ID_1 : natural := 1;
variable ID_2 : natural := 2;
variable r_data : std_logic_vector(31 downto 0) :=
(OTHERS => '0');
-- Generated frames
variable frame_1 : SW_CAN_frame_type;
variable frame_2 : SW_CAN_frame_type;
variable frame_1 : SW_CAN_frame_type;
variable frame_2 : SW_CAN_frame_type;
-- Node status
variable stat_1 : SW_status;
variable stat_2 : SW_status;
variable stat_1 : SW_status;
variable stat_2 : SW_status;
-- Temporary variables for IDs recalculated to decimal value with
-- identifier type taken into account
variable ident_1 : natural;
variable ident_2 : natural;
variable ident_1 : natural;
variable ident_2 : natural;
begin
outcome := true;
o.outcome := true;
------------------------------------------------------------------------
-- Forbid retransmitt limiting!
------------------------------------------------------------------------
CAN_enable_retr_limit(false, 0, ID_1, mem_bus_1);
CAN_enable_retr_limit(false, 0, ID_2, mem_bus_2);
CAN_enable_retr_limit(false, 0, ID_1, mem_bus(1));
CAN_enable_retr_limit(false, 0, ID_2, mem_bus(2));
------------------------------------------------------------------------
-- Generate Two random CAN Frames.
......@@ -268,21 +257,21 @@ package body Arbitration_feature is
------------------------------------------------------------------------
-- Insert both frames to transmitt.
------------------------------------------------------------------------
CAN_insert_TX_frame(frame_1, 1, ID_1, mem_bus_1);
CAN_insert_TX_frame(frame_2, 1, ID_2, mem_bus_2);
CAN_insert_TX_frame(frame_1, 1, ID_1, mem_bus(1));
CAN_insert_TX_frame(frame_2, 1, ID_2, mem_bus(2));
------------------------------------------------------------------------
-- Give "set_ready" command to TXT Buffers in both CAN Nodes!
------------------------------------------------------------------------
send_TXT_buf_cmd(buf_set_ready, 1, ID_1, mem_bus_1);
send_TXT_buf_cmd(buf_set_ready, 1, ID_2, mem_bus_2);
send_TXT_buf_cmd(buf_set_ready, 1, ID_1, mem_bus(1));
send_TXT_buf_cmd(buf_set_ready, 1, ID_2, mem_bus(2));
------------------------------------------------------------------------
-- Now we have to wait until both units starts to transmitt!!!
------------------------------------------------------------------------
loop
get_controller_status(stat_1, ID_1, mem_bus_1);
get_controller_status(stat_2, ID_2, mem_bus_2);
get_controller_status(stat_1, ID_1, mem_bus(1));
get_controller_status(stat_2, ID_2, mem_bus(2));
if (stat_1.transmitter and stat_2.transmitter) then
exit;
end if;
......@@ -294,8 +283,8 @@ package body Arbitration_feature is
------------------------------------------------------------------------
while (unit_rec = 0) loop
get_controller_status(stat_1, ID_1, mem_bus_1);
get_controller_status(stat_2, ID_2, mem_bus_2);
get_controller_status(stat_1, ID_1, mem_bus(1));
get_controller_status(stat_2, ID_2, mem_bus(2));
-- Unit 1 turned reciever
if (stat_1.receiver) then
......@@ -333,25 +322,25 @@ package body Arbitration_feature is
report "Frame 2:";
CAN_print_frame(frame_2, info_l);
outcome := false;
o.outcome := false;
end if;
------------------------------------------------------------------------
-- Send abort transmission to both frames so that no unit will
-- attempt to retransmitt.
------------------------------------------------------------------------
send_TXT_buf_cmd(buf_set_abort, 1, ID_1, mem_bus_1);
send_TXT_buf_cmd(buf_set_abort, 1, ID_2, mem_bus_2);
send_TXT_buf_cmd(buf_set_abort, 1, ID_1, mem_bus(1));
send_TXT_buf_cmd(buf_set_abort, 1, ID_2, mem_bus(2));
CAN_wait_frame_sent(ID_1, mem_bus_1);
CAN_wait_frame_sent(ID_1, mem_bus(1));
------------------------------------------------------------------------
-- Check what is the value in the ALC register
------------------------------------------------------------------------
if (unit_rec = 1) then
read_alc(alc, ID_1, mem_bus_1);
read_alc(alc, ID_1, mem_bus(1));
elsif (unit_rec = 2) then
read_alc(alc, ID_2, mem_bus_2);
read_alc(alc, ID_2, mem_bus(2));
end if;
-- TODO: Compare ALC value with expected value where node should
......@@ -368,7 +357,7 @@ package body Arbitration_feature is
report "Frame 2:";
CAN_print_frame(frame_2, info_l);
outcome := false;
o.outcome := false;
end if;
wait for 100000 ns;
......
......@@ -54,39 +54,29 @@ USE ieee.math_real.ALL;
use work.CANconstants.all;
USE work.CANtestLib.All;
USE work.randomLib.All;
use work.pkg_feature_exec_dispath.all;
use work.CAN_FD_register_map.all;
package fault_confinement_feature is
procedure fault_confinement_feature_exec(
variable outcome : inout boolean;
signal rand_ctr : inout natural range 0 to RAND_POOL_SIZE;
signal mem_bus_1 : inout Avalon_mem_type;
signal mem_bus_2 : inout Avalon_mem_type;
signal bus_level : in std_logic;
signal drv_bus_1 : in std_logic_vector(1023 downto 0);
signal drv_bus_2 : in std_logic_vector(1023 downto 0);
signal stat_bus_1 : in std_logic_vector(511 downto 0);
signal stat_bus_2 : in std_logic_vector(511 downto 0)
variable o : out feature_outputs_t;
signal rand_ctr : inout natural range 0 to RAND_POOL_SIZE;
signal iout : in instance_inputs_arr_t;
signal mem_bus : inout mem_bus_arr_t;
signal bus_level : in std_logic
);
end package;
package body fault_confinement_feature is
procedure fault_confinement_feature_exec(
variable outcome : inout boolean;
signal rand_ctr : inout natural range 0 to RAND_POOL_SIZE;
signal mem_bus_1 : inout Avalon_mem_type;
signal mem_bus_2 : inout Avalon_mem_type;
signal bus_level : in std_logic;
signal drv_bus_1 : in std_logic_vector(1023 downto 0);
signal drv_bus_2 : in std_logic_vector(1023 downto 0);
signal stat_bus_1 : in std_logic_vector(511 downto 0);
signal stat_bus_2 : in std_logic_vector(511 downto 0)
)is
variable o : out feature_outputs_t;
signal rand_ctr : inout natural range 0 to RAND_POOL_SIZE;
signal iout : in instance_inputs_arr_t;
signal mem_bus : inout mem_bus_arr_t;
signal bus_level : in std_logic
) is
variable r_data : std_logic_vector(31 downto 0) :=
(OTHERS => '0');
variable CAN_frame : SW_CAN_frame_type;
......@@ -105,7 +95,7 @@ package body fault_confinement_feature is
variable fault_th_2 : SW_fault_thresholds := (0, 0);
variable fault_state : SW_fault_state;
begin
outcome := true;
o.outcome := true;
------------------------------------------------------------------------
-- Generate random setting of ERP treshold and RX counters to preset
......@@ -123,43 +113,43 @@ package body fault_confinement_feature is
------------------------------------------------------------------------
-- Set the counter and tresholds
------------------------------------------------------------------------
set_error_counters(err_counters, ID_1, mem_bus_1);
set_fault_thresholds(fault_th, ID_1, mem_bus_1);
set_error_counters(err_counters, ID_1, mem_bus(1));
set_fault_thresholds(fault_th, ID_1, mem_bus(1));
------------------------------------------------------------------------
-- Read counters back
------------------------------------------------------------------------
get_fault_thresholds(fault_th_2, ID_1, mem_bus_1);
get_fault_thresholds(fault_th_2, ID_1, mem_bus(1));
if (fault_th.ewl /= fault_th_2.ewl) then
outcome := false;
o.outcome := false;
end if;
if (fault_th.erp /= fault_th_2.erp) then
outcome := false;
o.outcome := false;
end if;
------------------------------------------------------------------------
-- Read fault confinement state
------------------------------------------------------------------------
get_fault_state(fault_state, ID_1, mem_bus_1);
get_fault_state(fault_state, ID_1, mem_bus(1));
if (err_counters.tx_counter > 255 or
err_counters.rx_counter > 255)
then
if (fault_state /= fc_bus_off) then
outcome := false;
o.outcome := false;
end if;
elsif (err_counters.tx_counter < fault_th.ewl and
err_counters.rx_counter < fault_th.ewl)
then
if (fault_state /= fc_error_active) then
outcome := false;
o.outcome := false;
end if;
else
if (fault_state /= fc_error_passive) then
outcome := false;
o.outcome := false;
end if;
end if;
......
......@@ -67,40 +67,31 @@ USE ieee.math_real.ALL;
use work.CANconstants.all;
USE work.CANtestLib.All;
USE work.randomLib.All;
use work.pkg_feature_exec_dispath.all;
use work.CAN_FD_register_map.all;
use work.CAN_FD_frame_format.all;
package forbid_fd_feature is
procedure forbid_fd_feature_exec(
variable outcome : inout boolean;
variable o : out feature_outputs_t;
signal rand_ctr : inout natural range 0 to RAND_POOL_SIZE;
signal mem_bus_1 : inout Avalon_mem_type;
signal mem_bus_2 : inout Avalon_mem_type;
signal bus_level : in std_logic;
signal drv_bus_1 : in std_logic_vector(1023 downto 0);
signal drv_bus_2 : in std_logic_vector(1023 downto 0);
signal stat_bus_1 : in std_logic_vector(511 downto 0);
signal stat_bus_2 : in std_logic_vector(511 downto 0)
signal iout : in instance_inputs_arr_t;
signal mem_bus : inout mem_bus_arr_t;
signal bus_level : in std_logic
);
end package;
package body forbid_fd_feature is
procedure forbid_fd_feature_exec(
variable outcome : inout boolean;
variable o : out feature_outputs_t;
signal rand_ctr : inout natural range 0 to RAND_POOL_SIZE;
signal mem_bus_1 : inout Avalon_mem_type;
signal mem_bus_2 : inout Avalon_mem_type;
signal bus_level : in std_logic;
signal drv_bus_1 : in std_logic_vector(1023 downto 0);
signal drv_bus_2 : in std_logic_vector(1023 downto 0);
signal stat_bus_1 : in std_logic_vector(511 downto 0);
signal stat_bus_2 : in std_logic_vector(511 downto 0)
signal iout : in instance_inputs_arr_t;
signal mem_bus : inout mem_bus_arr_t;
signal bus_level : in std_logic
) is
variable r_data : std_logic_vector(31 downto 0) :=
(OTHERS => '0');
......@@ -115,52 +106,52 @@ package body forbid_fd_feature is
variable err_counters_1 : SW_error_counters;
variable err_counters_2 : SW_error_counters;
begin
outcome := true;
o.outcome := true;
------------------------------------------------------------------------
-- First disable the FD support of both Nodes. This is done to make
-- sure that both nodes have the same ISO type set.
------------------------------------------------------------------------
mode.flexible_data_rate := true;
set_core_mode(mode, ID_2, mem_bus_2);
set_core_mode(mode, ID_2, mem_bus(2));
mode.flexible_data_rate := false;
set_core_mode(mode, ID_1, mem_bus_1);
set_core_mode(mode, ID_1, mem_bus(1));
------------------------------------------------------------------------
-- Read RX Error counter node 1
------------------------------------------------------------------------
read_error_counters(err_counters_1, ID_1, mem_bus_1);
read_error_counters(err_counters_1, ID_1, mem_bus(1));
------------------------------------------------------------------------
-- Send FD frame by node 2 and wait for error frame...
------------------------------------------------------------------------
CAN_generate_frame(rand_ctr, CAN_frame);
CAN_frame.frame_format := FD_CAN;
CAN_send_frame(CAN_frame, 1, ID_2, mem_bus_2, frame_sent);
CAN_wait_error_transmitted(ID_2, mem_bus_2);
CAN_wait_bus_idle(ID_2, mem_bus_2);
CAN_send_frame(CAN_frame, 1, ID_2, mem_bus(2), frame_sent);
CAN_wait_error_transmitted(ID_2, mem_bus(2));
CAN_wait_bus_idle(ID_2, mem_bus(2));
------------------------------------------------------------------------
-- Read RX Error counter node 1 again
------------------------------------------------------------------------
read_error_counters(err_counters_2, ID_1, mem_bus_1);
read_error_counters(err_counters_2, ID_1, mem_bus(1));
-- Counter should be increased
if ((err_counters_1.rx_counter + 1 + 8) /= err_counters_2.rx_counter) then
outcome := false;
o.outcome := false;
end if;
------------------------------------------------------------------------
-- Now send the same frame, but not the FD type. Wait until bus is idle
------------------------------------------------------------------------
CAN_frame.frame_format := NORMAL_CAN;
CAN_send_frame(CAN_frame, 1, ID_2, mem_bus_2, frame_sent);
CAN_wait_frame_sent(ID_2, mem_bus_2);
CAN_send_frame(CAN_frame, 1, ID_2, mem_bus(2), frame_sent);
CAN_wait_frame_sent(ID_2, mem_bus(2));
------------------------------------------------------------------------
-- Read RX Error counter node 1 again
------------------------------------------------------------------------
read_error_counters(err_counters_2, ID_1, mem_bus_1);
read_error_counters(err_counters_2, ID_1, mem_bus(1));
------------------------------------------------------------------------
-- Counter should be decreased by one now due to sucesfull reception.
......@@ -168,34 +159,34 @@ package body forbid_fd_feature is
-- detected the error!
------------------------------------------------------------------------
if ((err_counters_1.rx_counter + 8) /= err_counters_2.rx_counter) then
outcome := false;
o.outcome := false;
end if;
------------------------------------------------------------------------
-- Now enable the FD support of Node 1
------------------------------------------------------------------------
mode.flexible_data_rate := true;
set_core_mode(mode, ID_1, mem_bus_1);
set_core_mode(mode, ID_1, mem_bus(1));
------------------------------------------------------------------------
-- Now again send the same frame but FD type now unit should accept
-- the frame OK!
------------------------------------------------------------------------
CAN_frame.frame_format := FD_CAN;
CAN_send_frame(CAN_frame, 1, ID_2, mem_bus_2, frame_sent);
CAN_wait_frame_sent(ID_2, mem_bus_2);
CAN_send_frame(CAN_frame, 1, ID_2, mem_bus(2), frame_sent);
CAN_wait_frame_sent(ID_2, mem_bus(2));
------------------------------------------------------------------------
-- Read RX Error counter node 1 again
------------------------------------------------------------------------
read_error_counters(err_counters_2, ID_1, mem_bus_1);
read_error_counters(err_counters_2, ID_1, mem_bus(1));
------------------------------------------------------------------------
-- Counter should be less than the value read now or both should be
-- zeroes when counter cannnot already be lowered...
------------------------------------------------------------------------
if ((err_counters_1.rx_counter + 7) /= err_counters_2.rx_counter) then
outcome := false;
o.outcome := false;
end if;
------------------------------------------------------------------------
......@@ -207,8 +198,8 @@ package body forbid_fd_feature is
report "Resetting error counters";
err_counters_2.rx_counter := 0;