From 529b78b1ceb5ca127e382a91804e40192ea4e7a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Wed, 22 Feb 2023 19:52:51 +0100 Subject: [PATCH] fix: make buffer inside of ring buffer triple instead of twice temporarily --- src/data_link/ring_buffer.vhd | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/data_link/ring_buffer.vhd b/src/data_link/ring_buffer.vhd index ecdadb2..28ec9ee 100644 --- a/src/data_link/ring_buffer.vhd +++ b/src/data_link/ring_buffer.vhd @@ -28,7 +28,7 @@ end entity ring_buffer; architecture a1 of ring_buffer is signal buff : std_logic_vector(CHARACTER_SIZE*BUFFER_SIZE-1 downto 0); - signal buff_twice : std_logic_vector(2*CHARACTER_SIZE*BUFFER_SIZE-1 downto 0); + signal buff_triple : std_logic_vector(3*CHARACTER_SIZE*BUFFER_SIZE-1 downto 0); signal next_read : std_logic_vector(CHARACTER_SIZE*BUFFER_SIZE-1 downto 0); signal read_position : integer := 0; signal adjusted_read_position : integer := 0; @@ -47,11 +47,11 @@ begin -- architecture a1 read_position <= 0; reg_size <= 0; elsif ci_clk'event and ci_clk = '1' then -- rising clock edge - if ci_read = '1' then + if ci_read = '1' and size >= READ_SIZE + ci_adjust_position then read_position <= (read_position + ci_adjust_position + READ_SIZE) mod BUFFER_SIZE; co_read_position <= read_position + ci_adjust_position; reg_size <= size - READ_SIZE - ci_adjust_position + 1; - co_read <= buff_twice(2*CHARACTER_SIZE*BUFFER_SIZE - 1 - (read_position + ci_adjust_position)*CHARACTER_SIZE downto 2*CHARACTER_SIZE*BUFFER_SIZE - (read_position + ci_adjust_position + READ_SIZE)*CHARACTER_SIZE); + co_read <= buff_triple(2*CHARACTER_SIZE*BUFFER_SIZE - 1 - (read_position + ci_adjust_position)*CHARACTER_SIZE downto 2*CHARACTER_SIZE*BUFFER_SIZE - (read_position + ci_adjust_position + READ_SIZE)*CHARACTER_SIZE); else reg_size <= reg_size + 1; end if; @@ -66,8 +66,9 @@ begin -- architecture a1 co_size <= size; size <= BUFFER_SIZE when reg_size > BUFFER_SIZE else reg_size; - buff_twice(2*CHARACTER_SIZE*BUFFER_SIZE - 1 downto CHARACTER_SIZE*BUFFER_SIZE) <= buff; - buff_twice(CHARACTER_SIZE*BUFFER_SIZE - 1 downto 0) <= buff; + buff_triple(3*CHARACTER_SIZE*BUFFER_SIZE - 1 downto 2*CHARACTER_SIZE*BUFFER_SIZE) <= buff; + buff_triple(2*CHARACTER_SIZE*BUFFER_SIZE - 1 downto CHARACTER_SIZE*BUFFER_SIZE) <= buff; + buff_triple(CHARACTER_SIZE*BUFFER_SIZE - 1 downto 0) <= buff; co_filled <= '1' when reg_size > BUFFER_SIZE else '0'; -- 2.48.1