Commit 886f1bf3 authored by Ing. Viktor Fúra's avatar Ing. Viktor Fúra

TXT buffer priority test: code cleanup

parent f579df1a
Pipeline #6846 failed with stage
in 9 seconds
......@@ -80,60 +80,37 @@ package body txt_buffer_priority_feature is
signal mem_bus : inout mem_bus_arr_t;
signal bus_level : in std_logic
) is
type CAN_frame_array_type is array (1 to 4) of SW_CAN_frame_type;
type priority_array_type is array (1 to 4) of natural range 0 to 8;
variable data : std_logic_vector(31 downto 0) :=
(OTHERS => '0');
variable address : std_logic_vector(11 downto 0) :=
(OTHERS => '0');
variable ID_1 : natural := 1; -- Transmiter
variable ID_2 : natural := 2; -- Receiver
variable CAN_frame : SW_CAN_frame_type;
type CAN_frame_array_type is array (1 to 4) of SW_CAN_frame_type;
variable ID_2 : natural := 2; -- Receiver
variable CAN_frame_array_tx : CAN_frame_array_type;
variable CAN_frame_array_rx : CAN_frame_array_type;
type priority_array_type is array (1 to 4) of natural range 0 to 8;
variable CAN_frame_array_rx : CAN_frame_array_type;
variable priority_array : priority_array_type;
variable priority_array_bckp : priority_array_type;
variable priority_value_tmp : natural range 0 to 8;
variable priority_value_max : natural range 0 to 8;
variable priority_index_max : natural range 0 to 8;
variable frame_equal : boolean := false;
variable frame_length : natural;
variable rand_value : real;
variable wt : time;
variable bus_config : bit_time_config_type;
variable still_tx : boolean := false;
variable PC_State : protocol_type;
variable err_counters : SW_error_counters;
variable command : SW_command := (false, false, false);
variable status : SW_status;
variable txt_buf_state : SW_TXT_Buffer_state_type;
-- Node status
variable stat_1 : SW_status;
variable stat_2 : SW_status;
-- Some unit lost the arbitration...
-- 0 - initial , 1-Node 1 turned rec, 2 - Node 2 turned rec
variable unit_rec : natural := 0;
variable priority_value_tmp : natural range 0 to 8;
variable priority_value_max : natural range 0 to 8;
variable priority_index_max : natural range 0 to 8;
variable frame_equal : boolean := false;
begin
o.outcome := true;
o.outcome := true;
-- TODO Generate priorities
priority_array(1) := 6; -- Priority of TXT Buffer 1
priority_array(2) := 1; -- Priority of TXT Buffer 2
priority_array(3) := 2; -- Priority of TXT Buffer 3
priority_array(4) := 3; -- Priority of TXT Buffer 4
priority_array(1) := 3; -- Priority of TXT Buffer 1
priority_array(2) := 2; -- Priority of TXT Buffer 2
priority_array(3) := 3; -- Priority of TXT Buffer 3
priority_array(4) := 5; -- Priority of TXT Buffer 4
for i in 1 to 4 loop
priority_array_bckp(i) := priority_array(i);
end loop;
--for i in 1 to 4 loop
---- priority_array_bckp(i) := priority_array(i);
--end loop;
-- Convert priorities to vector
data := std_logic_vector(to_unsigned(0, 16)) &
......@@ -143,7 +120,6 @@ package body txt_buffer_priority_feature is
std_logic_vector(to_unsigned(priority_array(1), 4)); -- Priority of TXT Buffer 1
-- Set tx buffer priorities
--data := std_logic_vector(to_unsigned(17185, data'length)); -- 17185: B4 1st, B3 2nd, B2 3rd, B1 last.
address := TX_PRIORITY_ADR;
CAN_write(data, address, ID_1, mem_bus(1), BIT_16);
......@@ -158,20 +134,22 @@ package body txt_buffer_priority_feature is
-- Find unused buffer with the highest priority (used buffer = priority 8)
for i in 1 to 4 loop
if((priority_array_bckp(i) > priority_value_max) AND
(priority_array_bckp(i) /= 8)) then
priority_value_max := priority_array_bckp(i); -- The highest priority found
-- Use only ">" in this statement because documenntion says
-- "If two buffers have equal priorities, the one with lower index is selected"
if((priority_array(i) > priority_value_max) AND
(priority_array(i) /= 8)) then
priority_value_max := priority_array(i); -- The highest priority found
priority_index_max := i; -- Index of buffer with the highest priority
end if;
end loop;
-- Print buffer number with its priority value.
info("[" & Integer'image(j) & "] Priority " &
Integer'image(priority_array_bckp(priority_index_max)) & " in buffer " &
Integer'image(priority_array(priority_index_max)) & " in buffer " &
Integer'image(priority_index_max) & ".");
-- Mark buffer as used
priority_array_bckp(priority_index_max) := 8;
priority_array(priority_index_max) := 8;
-- Generate CAN frame -
CAN_generate_frame(rand_ctr, CAN_frame_array_tx(j));
......@@ -236,70 +214,6 @@ package body txt_buffer_priority_feature is
end loop;
-- Repeat test several times
--for i in 1 to 150 loop
-- Give "Set ready" command to the buffer
-- send_TXT_buf_cmd(buf_set_ready, 1, ID_1, mem_bus(1));
-- Wait for some clock cycles before sending abort command.
--for j in 0 to i loop
-- wait until rising_edge(mem_bus(1).clk_sys);
-- end loop;
-- Give "Set abort" command to the buffer
-- send_TXT_buf_cmd(buf_set_abort, 1, ID_1, mem_bus(1));
-- Wait for some clock cycles before reading buffer and controller state
-- for i in 0 to 20 loop
-- wait until rising_edge(mem_bus(1).clk_sys);
-- end loop;
-- Read "TXT Buffer state"
-- get_tx_buf_state(1, txt_buf_state, ID_1, mem_bus(1));
-- Read status of CTU CAN FD controller.
-- get_controller_status(status, ID_1, mem_bus(1));
-- Is controller transmitting?
-- if (status.transmitter) then
-- Is also TXT buffer in transmitting state? Or if set_abort command
-- comes just at the time when the core LOCKs the buffer, it goes to
-- "Abort in Progress".
-- if (txt_buf_state = buf_tx_progress) or
-- (txt_buf_state = buf_ab_progress) then
-- Everything is ok
-- info("Transmitting: Both TXT buffer and controller " &
-- "in consistence state." & " [" & to_string(i) & "]");
-- Wait until bus is idle
------------------------------------------------------------------
-- CAN_wait_bus_idle(ID_1, mem_bus(1));
-- Is the unit now in idle since it is after transmittion already?
-- get_controller_status(status, ID_1, mem_bus(1));
-- check(status.bus_status, "Unit is not Idle!");
-- else
-- Inconsistency happened
-- check_failed("Inconsistence: CAN controller transmitter=TRUE, TXT " &
-- "buffer=" & to_string(txt_buf_state) &
-- " [" & to_string(i) & "]");
-- end if;
-- else
-- Is also TXT buffer in aborted state?
-- if (txt_buf_state = buf_aborted) then
-- Everything is ok
-- info("Both TXT buffer and controller in aborted state" &
-- " [" & to_string(i) & "]");
-- else
-- Inconsistency happened
-- check_failed("Inconsistence: CAN controller transmitter=FALSE, TXT " &
-- "buffer=" & to_string(txt_buf_state) &
-- " [" & to_string(i) & "]");
-- end if;
-- end if;
--end loop;
end procedure;
end package body;
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