Add code to handle unaligned Payloads

If the payload is not directly aligned with the Payload slots, it has
to be ensured that the rest of the payload slot is zeroed.
If we ran out of payload slots during the write process (Which can
happen since we don't know the size of the payload beforehand), we have
to abort the Key Hash Generation before parsing the next sample.
This commit is contained in:
Greek 2021-01-26 23:37:24 +01:00
parent 8433006fb8
commit 607273e1c4

View File

@ -272,6 +272,7 @@ architecture arch of history_cache is
signal unmark_instances, unmark_instances_next : std_logic := '0';
signal dynamic_next_instance, dynamic_next_instance_next : std_logic := '0';
signal inst_data_variant : std_logic := '0';
signal abort_khg : std_logic := '0';
--*****ALIAS DECLARATION*****
alias prev_sample : unsigned(SAMPLE_MEMORY_ADDR_WIDTH-1 downto 0) is sample_addr_latch_1;
@ -353,7 +354,7 @@ begin
key_hash_generator_inst : entity work.key_hash_generator(arch)
port (
clk => clk,
reset => reset,
reset => reset or abort_khg,
data_in => khg_data_in,
valid_in => khg_valid_in,
ready_in => khg_ready_in,
@ -443,6 +444,7 @@ begin
ack_dds <= '0';
inst_data_variant <= '0';
done_dds <= '0';
abort_khg <= '0';
return_code_dds <= RETCODE_UNSUPPORTED;
case (stage) is
@ -702,7 +704,7 @@ begin
sample_wen <= '1';
sample_write_data <= empty_payload_list_head;
payload_addr_next <= empty_payload_list_head + PMF_NEXT_ADDR_OFFSET;
payload_addr_next <= empty_payload_list_head + PMF_PAYLOAD_OFFSET;
cur_payload_next <= empty_payload_list_head;
else
-- Mark Sample with no Payload
@ -734,9 +736,9 @@ begin
end if;
-- Flow Control Guard
if ((valid_in_rtps = '1' and has_key_hash = '0') or (valid_in_rtps = '1' and has_key_hash = '0' and khg_ready_in = '1')) then
if ((valid_in_rtps = '1' and has_key_hash = '1') or (valid_in_rtps = '1' and has_key_hash = '0' and khg_ready_in = '1')) then
cnt_next <= cnt + 1;
payload_addr_next <= payload_addr + PMF_NEXT_ADDR_OFFSET;
payload_addr_next <= payload_addr + 1;
-- Payload Write
if (has_data = '1') then
@ -752,22 +754,30 @@ begin
-- End of Payload
if (last_word_in_rtps = '1') then
if (has_key_hash = '0') then
khg_last_word_in <= '1';
stage_next <= GET_KEY_HASH;
cnt_next <= 0;
khg_last_word_in <= '1';
-- Payload Slot not full
if (has_data = '1' and cnt /= PAYLOAD_FRAME_SIZE-2) then
-- Zero Rest of Payload Slot
stage_next <= ZERO_PAYLOAD;
else
stage_next <= FILTER_STAGE;
if (has_key_hash = '0') then
-- Fetch the Key Hash
stage_next <= GET_KEY_HASH;
cnt_next <= 0;
else
stage_next <= FILTER_STAGE;
end if;
end if;
-- End of Payload Slot
elsif (has_data = '1' and cnt = PAYLOAD_FRAME_SIZE-2) then
stage_next <= NEXT_PAYLOAD_SLOT;
payload_addr_next <= cur_payload;
payload_addr_next <= cur_payload + PMF_NEXT_ADDR_OFFSET;
cnt_next <= 0;
end if;
end if;
when NEXT_PAYLOAD_SLOT =>
-- Precondition: payload_addr (Beginning of current Slot)
-- Precondition: payload_addr (Next Pointer of cur_payload)
cnt_next <= cnt + 1;
@ -780,15 +790,34 @@ begin
if (payload_read_data = PAYLOAD_MEMORY_MAX_ADDRESS) then
-- Reject Change
stage_next <= SKIP_ADD_REJECT;
-- Abort Key Hash Generation
abort_khg <= '1';
else
-- Latch next Payload Slot and Continue
cur_payload_next <= payload_read_data;
payload_addr_next <= payload_read_data + PMF_NEXT_ADDR_OFFSET;
payload_addr_next <= payload_read_data + PMF_PAYLOAD_OFFSET;
stage_next <= ADD_PAYLOAD;
end if;
when others =>
null;
end case;
when ZERO_PAYLOAD =>
cnt_next <= cnt + 1;
payload_addr_next <= payload_addr + 1;
-- Zero Payload
payload_write_data <= (others => '0');
payload_wen <= '1';
-- Exit Condition
if (cnt = PAYLOAD_FRAME_SIZE-2) then
if (has_key_hash = '0') then
stage_next <= GET_KEY_HASH;
cnt_next <= 0;
else
stage_next <= FILTER_STAGE;
end if;
end if;
when GET_KEY_HASH =>
khg_ready_out <= '1';