Code refactoring

This commit is contained in:
Greek 2021-01-11 12:12:03 +01:00
parent 35743b6f19
commit dcd0b51c83
2 changed files with 53 additions and 111 deletions

View File

@ -10,6 +10,8 @@ use work.rtps_config_package.all;
-- TODO: Initialise RAM to zeroes
-- TODO: Skip Packet while we are waiting for memory operation to complete
-- FIXME: ACNACK response does not nack, which is necessary to get the missing SNs.
-- TODO: Could we overwrite the data (pre-GUIDPrefix) while the memory is using them before the first memory guard? (Add test case)
-- TODO: Parse inlineQOS HASH_KEY.
entity rtps_builtin_endpoint is
port (
@ -125,6 +127,8 @@ architecture arch of rtps_builtin_endpoint is
-- Address pointing to the beginning of the first Participant Data Frame
constant FIRST_PARTICIPANT_ADDRESS : unsigned(BUILTIN_BUFFER_ADDR_WIDTH-1 downto 0) := (others => '0');
-- *UPDATE PARTICIPANT FLAG POSITIONS*
-- Width of the Update Participant Flag Signal
constant UPDATE_PARTICIPANT_FLAG_WIDTH : natural := 6;
-- Signifies that the main Participant Data are updated
constant PARTICIPANT_DATA_FLAG : natural := 0;
-- Signifies that the Lease Deadline of the Participant Data is updated
@ -177,19 +181,19 @@ architecture arch of rtps_builtin_endpoint is
-- Constant for zero Participant Data
constant ZERO_PARTICIPANT_DATA : PARTICIPANT_DATA_TYPE := (
meta_addr => (others => '0'),
def_addr => (others => '0'),
meta_port => (others => '0'),
def_port => (others => '0'),
meta_addr => IPv4_ADDRESS_INVALID,
def_addr => IPv4_ADDRESS_INVALID,
meta_port => UDP_PORT_INVALID,
def_port => UDP_PORT_INVALID,
extra_flags => (others => '0'),
lease_duration => (others => (others => '0')),
lease_deadline => (others => (others => '0')),
heartbeat_res_time => (others => (others => '0')),
acknack_res_time => (others => (others => '0')),
spdp_seq_nr => (others => (others => '0')),
pub_seq_nr => (others => (others => '0')),
sub_seq_nr => (others => (others => '0')),
mes_seq_nr => (others => (others => '0'))
lease_duration => DURATION_ZERO,
lease_deadline => TIME_INVALID,
heartbeat_res_time => TIME_INVALID,
acknack_res_time => TIME_INVALID,
spdp_seq_nr => SEQUENCENUMBER_UNKNOWN,
pub_seq_nr => SEQUENCENUMBER_UNKNOWN,
sub_seq_nr => SEQUENCENUMBER_UNKNOWN,
mes_seq_nr => SEQUENCENUMBER_UNKNOWN
);
@ -290,7 +294,7 @@ architecture arch of rtps_builtin_endpoint is
-- Toggle latching the "last_word_in" signal until reset
signal last_word_in_latch, last_word_in_latch_next : std_logic := '0';
-- Flags signifying which parts of the participant Data stored in memory to update
signal update_participant_flags, update_participant_flags_next : std_logic_vector(5 downto 0) := (others => '0');
signal update_participant_flags, update_participant_flags_next : std_logic_vector(UPDATE_PARTICIPANT_FLAG_WIDTH-1 downto 0) := (others => '0');
-- Latch for the Participant Data stored in memory
signal mem_participant_data, mem_participant_data_next : PARTICIPANT_DATA_TYPE := ZERO_PARTICIPANT_DATA;
-- Signifies if the marked Stale Participant had a Hertbeat Response/Suppression Delay Timeout
@ -1369,7 +1373,7 @@ begin
-- Participant Lease Expired
-- NOTE: The mem_participant_data is zero initialized on lease expiration, so we check the default address for zero
-- (since the default address should always be set)
if (mem_participant_data.def_addr = (mem_participant_data.def_addr'reverse_range => '0')) then
if (mem_participant_data.def_addr = IPv4_ADDRESS_INVALID) then
-- Remove Participant
mem_opcode <= REMOVE_PARTICIPANT;
mem_op_start <= '1';
@ -2905,12 +2909,13 @@ begin
end case;
end if;
when SKIP_PARAMETER =>
-- Consumed last word of Packet
if (last_word_in_latch = '1' and last_word_in = '0') then
-- Reset Last Word In Latch
last_word_in_latch_next <= '0';
-- Continue parsing next Packet
stage_next <= IDLE;
-- Reset Lengths
-- Reset Parameter End
parameter_end_next <= (others => '1');
-- End of Parameter
elsif ((read_cnt & "00" ) >= parameter_end) then
@ -2933,7 +2938,7 @@ begin
if (stale_check = '1') then
-- DONE
stage_next <= IDLE;
-- End of Packet
-- Consumed last word of Packet
elsif (last_word_in_latch = '1' and last_word_in = '0') then
-- Reset Last Word In Latch
last_word_in_latch_next <= '0';
@ -2957,12 +2962,12 @@ begin
-- Force rd_sig low
rd_sig <= '0';
-- Notify Endpoints of EOP
last_word_out <= '1';
last_word_out <= '1'; -- TODO: Necessary? (We do not pass through input to output, so a EOP should not leave as "stranded" during a write out)
-- Continue parsing next Packet
stage_next <= IDLE;
-- Reset Last Word In Latch
last_word_in_latch_next <= '0';
-- Reset Lengths
-- Reset Parameter End
parameter_end_next <= (others => '1');
-- Read outside of Parameter Length
-- NOTE: If the Parameter Length is smaller than expected for a particular parameter, there will be a read from input FIFO while
@ -2975,7 +2980,7 @@ begin
last_word_out <= '1';
-- Invalid Parameter Length, Skip Packet
stage_next <= SKIP_PACKET;
-- Reset Submessage End
-- Reset Parameter End
parameter_end_next <= (others => '1');
-- DEFAULT
else
@ -3128,40 +3133,25 @@ begin
when 2 =>
-- No Match
if (mem_read_data /= guid(1)) then
-- Reached End of Memory, No Match
if (mem_addr_base = max_participant_addr) then
addr_res_next <= MAX_ADDRESS; --No match
-- DONE
mem_stage_next <= IDLE;
else
-- Continue Search
mem_addr_next <= tmp;
mem_addr_base_next <= tmp;
mem_cnt_next <= 0;
end if;
end if;
-- GUID Prefix 3/3
when 3 =>
-- No Match
if (mem_read_data /= guid(2)) then
-- Reached End of Memory, No Match
if (mem_addr_base = max_participant_addr) then
addr_res_next <= MAX_ADDRESS; --No match
-- DONE
mem_stage_next <= IDLE;
else
-- Continue Search
mem_addr_next <= tmp;
mem_addr_base_next <= tmp;
mem_cnt_next <= 0;
end if;
-- Match
else
-- Fetch Participant Data
addr_res_next <= mem_addr_base;
mem_stage_next <= GET_PARTICIPANT_DATA;
-- No preload needed
mem_cnt_next <= 1;
mem_cnt_next <= 1; -- No preload needed
end if;
when others =>
null;
@ -3522,7 +3512,6 @@ begin
when others =>
null;
end case;
-- TODO: Should I set the addr_res?
when FIND_PARTICIPANT_SLOT =>
mem_rd <= '1';
mem_addr_next <= mem_addr + 1;
@ -3573,28 +3562,6 @@ begin
when 2 =>
-- Slot Occupied
if (mem_read_data /= GUIDPREFIX_UNKNOWN(1)) then
if (mem_addr_base = max_participant_addr) then
-- We are in the middle of resetting the MAX Participant Pointer
if (reset_max_pointer = '1') then
-- No Change
mem_stage_next <= IDLE;
-- MEMORY FULL
elsif (max_participant_addr = MAX_PARTICIPANT_ADDRESS) then
report "Memory Full, Ignoring Participant Data" severity NOTE;
-- Ignore Insertion
mem_stage_next <= IDLE;
addr_res_next <= MAX_ADDRESS;
else
-- Extend Participant Memory Area
-- NOTE: "max_participant_addr" points to the first address of last participant frame
max_participant_addr_next <= tmp;
-- Populate Participant Slot
mem_stage_next <= INSERT_PARTICIPANT;
mem_addr_next <= tmp;
addr_res_next <= tmp;
mem_cnt_next <= 0;
end if;
else
-- Latch last occupied Participant Slot
last_addr_next <= mem_addr_base;
-- Continue Search
@ -3602,44 +3569,20 @@ begin
mem_addr_base_next <= tmp;
mem_cnt_next <= 0;
end if;
end if;
-- GUID Prefix 3/3
when 3 =>
-- Slot Occupied
if (mem_read_data /= GUIDPREFIX_UNKNOWN(2)) then
if (mem_addr_base = max_participant_addr) then
-- We are in the middle of resetting the MAX Participant Pointer
if (reset_max_pointer = '1') then
-- No Change
mem_stage_next <= IDLE;
-- MEMORY FULL
elsif (max_participant_addr = MAX_PARTICIPANT_ADDRESS) then
report "Memory Full, Ignoring Participant Data" severity NOTE;
-- Ignore Insertion
mem_stage_next <= IDLE;
addr_res_next <= MAX_ADDRESS;
else
-- Extend Participant Memory Area
-- NOTE: "max_participant_addr" points to the first address of last participant frame
max_participant_addr_next <= tmp;
-- Populate Participant Slot
mem_stage_next <= INSERT_PARTICIPANT;
mem_addr_next <= tmp;
addr_res_next <= tmp;
mem_cnt_next <= 0;
end if;
else
-- Latch last occupied Participant Slot
last_addr_next <= mem_addr_base;
-- Continue Search
mem_addr_next <= tmp;
mem_addr_base_next <= tmp;
mem_cnt_next <= 0;
end if;
-- Slot Empty
else
if (reset_max_pointer = '1') then
-- Mak sure to iterate through complete participant area
-- Make sure to iterate through complete participant area
if (mem_addr_base = max_participant_addr) then
-- Reset Pointer to last occupied participant Slot
max_participant_addr_next <= last_addr;

View File

@ -7,8 +7,6 @@ use work.rtps_package.all;
use work.user_config.all;
use work.rtps_config_package.all;
-- Checksum has to be checked before
entity rtps_handler is
port (
clk : in std_logic; -- Input Clock
@ -857,6 +855,7 @@ begin
cnt2_next <= 0;
-- VALIDITY CHECK
-- TODO: Shouldn't that check the highest bit?
if (data_in_swapped(0) = '1' or unsigned(data_in_swapped) > 256) then
-- If numBits is negative or larger than 256, Number Set is invalid (see DDSI-RTPS 2.3 Section 9.4.2.6)
-- If gapList is invalid, skip Packet (see DDSI-RTPS 2.3 Section 8.3.7.4.3 and 8.3.4.1)