Commit 8478cf37 authored by Ille, Ondrej, Ing.'s avatar Ille, Ondrej, Ing.

Brought up retransmitt limit bench.

Removed obsolete type from Testlib.
parent 3470b74c
......@@ -43,6 +43,8 @@
-- Revision History:
-- 30.6.2016 Created file
-- 06.02.2018 Modified to work with the IP-XACT generated memory map
-- 12.06.2018 Modified to use CAN Test lib instead of direct register
-- access functions.
--------------------------------------------------------------------------------
Library ieee;
......@@ -54,108 +56,126 @@ USE work.CANtestLib.All;
USE work.randomLib.All;
use work.CAN_FD_register_map.all;
use work.CAN_FD_frame_format.all;
package retr_limit_feature is
procedure retr_limit_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;
--Additional signals for tests
--Pretty much everything can be read out of stat bus...
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)
);
procedure retr_limit_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)
);
end package;
package body retr_limit_feature is
procedure retr_limit_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;
--Additional signals for tests
--Pretty much everything can be read out of stat bus...
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 r_data : std_logic_vector(31 downto 0):=(OTHERS => '0');
variable CAN_frame : SW_CAN_frame_type;
variable frame_sent : boolean:=false;
variable ctr_1 : natural;
variable ctr_2 : natural;
variable ID_1 : natural:=1;
variable ID_2 : natural:=2;
variable rand_val : real;
variable retr_th : natural;
variable mode_backup : std_logic_vector(31 downto 0):=(OTHERS => '0');
begin
outcome:=true;
-----------------------------------------------
--Set node 2 to forbid acknowledge
-----------------------------------------------
CAN_read(r_data,MODE_ADR,ID_2,mem_bus_2);
r_data(ACF_IND) := '1';
CAN_write(r_data,MODE_ADR,ID_2,mem_bus_2);
-----------------------------------------------
-- Erase error counters node 1
-----------------------------------------------
r_data :=(OTHERS => '0');
r_data(9):='1';
CAN_write(r_data,CTR_PRES_ADR,ID_1,mem_bus_1);
-----------------------------------------------
--Set node 1 retransmitt limit
-----------------------------------------------
CAN_read(r_data,MODE_ADR,ID_1,mem_bus_1);
mode_backup:=r_data;
r_data(24):='1';
rand_real_v(rand_ctr,rand_val);
retr_th:=integer(15.0*rand_val);
r_data(28 downto 25):= std_logic_vector(to_unsigned(retr_th,4));
CAN_write(r_data,MODE_ADR,ID_1,mem_bus_1);
CAN_generate_frame(rand_ctr,CAN_frame);
CAN_send_frame(CAN_frame,1,ID_1,mem_bus_1,frame_sent);
for i in 0 to retr_th loop
CAN_wait_frame_sent(ID_1,mem_bus_1);
end loop;
-----------------------------------------------
--Read TX Counter, it should be equal to
-- 8 times number of retransmitts plus one
-- original transmittion does not count
-- as retransmittion
-----------------------------------------------
CAN_read(r_data,RXC_ADR,ID_1,mem_bus_1);
if(to_integer(unsigned(r_data(31 downto 16))) /= 8*(retr_th+1))then
outcome:=false;
end if;
-----------------------------------------------
--Set node 2 to allow acknowledge again
-----------------------------------------------
CAN_read(r_data,MODE_ADR,ID_2,mem_bus_2);
r_data(7) := '0';
CAN_write(r_data,MODE_ADR,ID_2,mem_bus_2);
CAN_write(mode_backup,MODE_ADR,ID_1,mem_bus_1);
procedure retr_limit_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 r_data : std_logic_vector(31 downto 0) :=
(OTHERS => '0');
variable CAN_frame : SW_CAN_frame_type;
variable frame_sent : boolean := false;
variable ctr_1 : natural;
variable ctr_2 : natural;
variable ID_1 : natural := 1;
variable ID_2 : natural := 2;
variable rand_val : real;
variable retr_th : natural;
variable mode_backup : std_logic_vector(31 downto 0) :=
(OTHERS => '0');
variable mode : SW_mode := (false, false, false,
false, true, false, false,
false, false, false);
variable err_counters : SW_error_counters := (0, 0, 0, 0);
variable buf_state : SW_TXT_Buffer_state_type;
begin
outcome := true;
------------------------------------------------------------------------
-- Set both nodes to forbid acknowledge
------------------------------------------------------------------------
mode.acknowledge_forbidden := true;
set_core_mode(mode, ID_2, mem_bus_2);
set_core_mode(mode, ID_1, mem_bus_1);
mode.acknowledge_forbidden := false;
------------------------------------------------------------------------
-- Erase error counters node 1
------------------------------------------------------------------------
set_error_counters(err_counters, ID_1, mem_bus_1);
------------------------------------------------------------------------
-- Set Node 1 retransmitt limit
------------------------------------------------------------------------
rand_int_v(rand_ctr, 15, retr_th);
report "Retransmitt threshold: " & Integer'image(retr_th);
CAN_enable_retr_limit(true, retr_th, ID_1, mem_bus_1);
------------------------------------------------------------------------
-- Generate and send frame by Node 1
------------------------------------------------------------------------
CAN_generate_frame(rand_ctr, CAN_frame);
CAN_frame.rtr := RTR_FRAME;
CAN_frame.frame_format := NORMAL_CAN;
CAN_send_frame(CAN_frame, 1, ID_1, mem_bus_1, frame_sent);
------------------------------------------------------------------------
-- Wait number of retransmissions. After each one, TXT Buffer should
-- be back in ready. After last one, it should be in failed.
------------------------------------------------------------------------
for i in 0 to retr_th loop
CAN_wait_frame_sent(ID_1, mem_bus_1);
get_tx_buf_state(1, buf_state, ID_1, mem_bus_1);
if (i /= retr_th) then
if (buf_state /= buf_ready) then
report "Buffer not ready";
outcome := false;
exit;
end if;
else
if (buf_state /= buf_failed) then
report "Buffer not failed";
outcome := false;
end if;
end if;
end loop;
------------------------------------------------------------------------
-- Read TX Counter, it should be equal to 8 times number of retransmitts
-- plus one original transmittion does not count as retransmittion.
------------------------------------------------------------------------
read_error_counters(err_counters, ID_1, mem_bus_1);
if (err_counters.tx_counter /= 8 * (retr_th + 1)) then
report "Counters exp: " & Integer'Image(err_counters.tx_counter) &
" coutners real: " & Integer'image(8 * (retr_th + 1));
outcome := false;
end if;
------------------------------------------------------------------------
-- Set node 2 to allow acknowledge again
------------------------------------------------------------------------
set_core_mode(mode, ID_2, mem_bus_2);
set_core_mode(mode, ID_1, mem_bus_1);
wait for 40000 ns;
end procedure;
end package body;
......@@ -180,15 +180,7 @@ package CANtestLib is
bit_rate_shift_int : boolean;
rx_buffer_not_empty_int : boolean;
tx_buffer_hw_cmd : boolean;
end record;
-- Error limits (Normal and special)
type SW_err_counters is record
error_warning_limit : natural range 0 to 255;
error_passive_limit : natural range 0 to 255;
end record;
end record;
-- Fault confinement states
type SW_fault_state is (
......
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