From ca7d6f92d86657ff5a7c5372065d10885d59042e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Sun, 26 Feb 2023 08:13:38 +0100 Subject: [PATCH] feat: remove unnecessary big buffer (3 * buffer_size) from ring_buffer --- src/data_link/ring_buffer.vhd | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/data_link/ring_buffer.vhd b/src/data_link/ring_buffer.vhd index 7eef4e5..c0cc765 100644 --- a/src/data_link/ring_buffer.vhd +++ b/src/data_link/ring_buffer.vhd @@ -41,6 +41,8 @@ begin -- architecture a1 -- inputs : ci_clk, ci_reset -- outputs: read_position, write_position, buff read: process (ci_clk, ci_reset) is + variable read_from_position : integer; + variable read_to_position : integer; begin -- process read if ci_reset = '0' then -- asynchronous reset (active low) buff <= (others => '0'); @@ -51,9 +53,16 @@ begin -- architecture a1 elsif ci_clk'event and ci_clk = '1' then -- rising clock edge 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; + co_read_position <= (read_position + ci_adjust_position) mod BUFFER_SIZE; reg_size <= size - READ_SIZE - ci_adjust_position + 1; - 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); + + read_from_position := (CHARACTER_SIZE*BUFFER_SIZE - 1 - (read_position + ci_adjust_position)*CHARACTER_SIZE) mod (CHARACTER_SIZE*BUFFER_SIZE); + read_to_position := (CHARACTER_SIZE*BUFFER_SIZE - (read_position + ci_adjust_position + READ_SIZE)*CHARACTER_SIZE) mod (CHARACTER_SIZE*BUFFER_SIZE); + if read_from_position >= read_to_position then + co_read <= buff(read_from_position downto read_to_position); + else + co_read <= buff(read_from_position downto 0) & buff(CHARACTER_SIZE*BUFFER_SIZE - 1 downto read_to_position); + end if; else reg_size <= reg_size + 1; end if; @@ -68,9 +77,6 @@ begin -- architecture a1 co_size <= size; size <= BUFFER_SIZE when reg_size > BUFFER_SIZE else reg_size; - 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