From 0c57b70217d2cfb3157e65571ddbadc43b30412e Mon Sep 17 00:00:00 2001 From: Simon Southwell Date: Thu, 26 Nov 2020 13:19:35 +0000 Subject: [PATCH] HMBFDHV-204 Updated preslicer_0 to correct flushing on odd geometry heads --- generic_ip/preslicer/0/src/preslicer_0.vhd | 279 ++++++++------------- 1 file changed, 107 insertions(+), 172 deletions(-) diff --git a/generic_ip/preslicer/0/src/preslicer_0.vhd b/generic_ip/preslicer/0/src/preslicer_0.vhd index ce20874..1ddc00a 100644 --- a/generic_ip/preslicer/0/src/preslicer_0.vhd +++ b/generic_ip/preslicer/0/src/preslicer_0.vhd @@ -49,37 +49,37 @@ use work.common_pkg.all; entity preslicer_0 is generic( - NUM_STRIPES_DEPTH : integer range 2 to 32 := 8; -- whole 1bpp equivalent stripes must it be possible to buffer in preslicer - NUM_STRIPES_FULL_MARGIN : integer range 1 to 31 := 2; -- at least this many 1bpp equivalent stripes space must be available - SHIFT_DEPTH : integer range 1 to 2048 := 128; -- head shift buffer depth - MAX_OP_WIDTH : natural range 1 to 128 := 8; - DEVICE_FAMILY : string := "Cyclone V" -- "Cyclone 10 LP" + NUM_STRIPES_DEPTH : integer range 2 to 32 := 8; -- whole 1bpp equivalent stripes must it be possible to buffer in preslicer + NUM_STRIPES_FULL_MARGIN : integer range 1 to 31 := 2; -- at least this many 1bpp equivalent stripes space must be available + SHIFT_DEPTH : integer range 1 to 2048 := 128; -- head shift buffer depth + MAX_OP_WIDTH : natural range 1 to 128 := 8; + DEVICE_FAMILY : string := "Cyclone V" -- "Cyclone 10 LP" ); port ( - clk : in std_logic; - rst_n : in std_logic; + clk : in std_logic; + rst_n : in std_logic; - bpp_mode : in std_logic_vector(1 downto 0); - clear_buffer : in std_logic; + bpp_mode : in std_logic_vector(1 downto 0); + clear_buffer : in std_logic; -- Interface to print streamer - ps_buf_wr : in std_logic; - ps_buf_wr_data : in std_logic_vector(31 downto 0); - ps_buf_rdy : out std_logic; - ps_buf_last_word : in std_logic; + ps_buf_wr : in std_logic; + ps_buf_wr_data : in std_logic_vector(31 downto 0); + ps_buf_rdy : out std_logic; + ps_buf_last_word : in std_logic; -- Output data - pixel_buf_wr : out std_logic; - pixel_buf_wr_data : out std_logic_vector(31 downto 0); - pixel_buf_rdy : in std_logic; - pixel_buf_last_word : out std_logic; - - ip_id_ip_number : out std_logic_vector(7 downto 0) := 8x"1d"; - ip_id_mfr_number : out std_logic_vector(7 downto 0) := 8x"00"; - ip_ver_minor_number : out std_logic_vector(7 downto 0) := 8x"02"; - ip_ver_major_number : out std_logic_vector(7 downto 0) := 8x"00" + pixel_buf_wr : out std_logic; + pixel_buf_wr_data : out std_logic_vector(31 downto 0); + pixel_buf_rdy : in std_logic; + pixel_buf_last_word : out std_logic; + + ip_id_ip_number : out std_logic_vector(7 downto 0) := 8x"1d"; + ip_id_mfr_number : out std_logic_vector(7 downto 0) := 8x"00"; + ip_ver_minor_number : out std_logic_vector(7 downto 0) := 8x"03"; + ip_ver_major_number : out std_logic_vector(7 downto 0) := 8x"00" ); end preslicer_0; @@ -87,39 +87,31 @@ end preslicer_0; architecture rtl of preslicer_0 is - type exp_data_t is array (0 to 3) of std_logic_vector(32 downto 0); - type wn_data_t is array (0 to 2) of std_logic_vector(1 downto 0); + type ps_array_t is array (natural range <>) of std_logic_vector; - signal shift_reg : exp_data_t; - signal rdreq : std_logic; - signal word_num : wn_data_t; - signal empty : std_logic; - signal full : std_logic; - signal almost_full : std_logic; - signal q : std_logic_vector(32 downto 0); + constant DWORD_BITS : integer := 32; + constant STRIPE_SIZE : integer := ((SHIFT_DEPTH * MAX_OP_WIDTH) / DWORD_BITS); - constant DWORD_BITS : integer := 32; - constant STRIPE_SIZE : integer := ((SHIFT_DEPTH * MAX_OP_WIDTH) / DWORD_BITS); + constant DEPTH : natural range 1 to 8182 := STRIPE_SIZE * NUM_STRIPES_DEPTH; -- in 32bit words (+ 1 bit flag) + constant ALMOST_FULL_THRESH : natural range 1 to 1024 := STRIPE_SIZE * (NUM_STRIPES_DEPTH - NUM_STRIPES_FULL_MARGIN); - constant DEPTH : natural range 1 to 8182 := STRIPE_SIZE * NUM_STRIPES_DEPTH; -- in 32bit words (+ 1 bit flag) - constant ALMOST_FULL_THRESH : natural range 1 to 1024 := STRIPE_SIZE * (NUM_STRIPES_DEPTH - NUM_STRIPES_FULL_MARGIN); - signal usedw : std_logic_vector(log2(DEPTH) - 1 downto 0); + signal rdreq : std_logic; + signal word_num : ps_array_t(0 to 0)(1 downto 0); + signal empty : std_logic; + signal almost_full : std_logic; + signal q : std_logic_vector(32 downto 0); - signal bpp1_slice : exp_data_t; - signal bpp2_slice : exp_data_t; - signal bpp3_slice : exp_data_t; + signal bpp1_slice : ps_array_t(0 to 3)(32 downto 0); + signal bpp2_slice : ps_array_t(0 to 1)(32 downto 0); + signal bpp3_slice : ps_array_t(0 to 0)(32 downto 0); - signal expanded_slice : exp_data_t; + signal read_phase : std_logic; + signal pixel_buf_wr_data_int : std_logic_vector(32 downto 0); - signal read_phase : std_logic; - signal word_num_is_zero : std_logic; - signal px_buf_stalled : std_logic_vector(1 downto 0); - signal ok_to_rd : std_logic; - signal pixel_buf_wr_data_int : std_logic_vector(32 downto 0); + signal ps_buf_wr_data_int : std_logic_vector(32 downto 0); + signal ps_buf_wr_int : std_logic; + signal pixel_buf_rdy_int : std_logic; - signal ps_buf_wr_data_int : std_logic_vector(32 downto 0); - signal ps_buf_wr_int : std_logic; - signal pixel_buf_rdy_int : std_logic; begin -- pragma translate_off @@ -127,175 +119,118 @@ begin -- pragma translate_on - ps_buf_wr_data_int <= ps_buf_last_word & ps_buf_wr_data; + ps_buf_wr_data_int <= ps_buf_last_word & ps_buf_wr_data; - ps_buf_wr_int <= ps_buf_wr; + ps_buf_wr_int <= ps_buf_wr; - pixel_buf_rdy_int <= pixel_buf_rdy; + pixel_buf_rdy_int <= pixel_buf_rdy; -- Pull out the bits from the shift register for the 3 BPP mode - bpp3_slice(3) <= shift_reg(3); - bpp3_slice(2) <= shift_reg(2); - bpp3_slice(1) <= shift_reg(1); - bpp3_slice(0) <= shift_reg(0); + bpp3_slice(0) <= q; + -- @formatter:off -- Pull out the bits from the shift register for the 2BPP mode - bpp2_slice(3) <= shift_reg(1)(32) & - "00" & shift_reg(1)(31 downto 30) & "00" & shift_reg(1)(29 downto 28) & - "00" & shift_reg(1)(27 downto 26) & "00" & shift_reg(1)(25 downto 24) & - "00" & shift_reg(1)(23 downto 22) & "00" & shift_reg(1)(21 downto 20) & - "00" & shift_reg(1)(19 downto 18) & "00" & shift_reg(1)(17 downto 16); - - bpp2_slice(2) <= "000" & shift_reg(1)(15 downto 14) & "00" & shift_reg(1)(13 downto 12) & - "00" & shift_reg(1)(11 downto 10) & "00" & shift_reg(1)( 9 downto 8) & - "00" & shift_reg(1)( 7 downto 6) & "00" & shift_reg(1)( 5 downto 4) & - "00" & shift_reg(1)( 3 downto 2) & "00" & shift_reg(1)( 1 downto 0); + bpp2_slice(1) <= q(32) & + "00" & q(31 downto 30) & "00" & q(29 downto 28) & + "00" & q(27 downto 26) & "00" & q(25 downto 24) & + "00" & q(23 downto 22) & "00" & q(21 downto 20) & + "00" & q(19 downto 18) & "00" & q(17 downto 16); - bpp2_slice(1) <= shift_reg(0)(32) & - "00" & shift_reg(0)(31 downto 30) & "00" & shift_reg(0)(29 downto 28) & - "00" & shift_reg(0)(27 downto 26) & "00" & shift_reg(0)(25 downto 24) & - "00" & shift_reg(0)(23 downto 22) & "00" & shift_reg(0)(21 downto 20) & - "00" & shift_reg(0)(19 downto 18) & "00" & shift_reg(0)(17 downto 16); - - bpp2_slice(0) <= "000" & shift_reg(0)(15 downto 14) & "00" & shift_reg(0)(13 downto 12) & - "00" & shift_reg(0)(11 downto 10) & "00" & shift_reg(0)( 9 downto 8) & - "00" & shift_reg(0)( 7 downto 6) & "00" & shift_reg(0)( 5 downto 4) & - "00" & shift_reg(0)( 3 downto 2) & "00" & shift_reg(0)( 1 downto 0); + bpp2_slice(0) <= "000" & q(15 downto 14) & "00" & q(13 downto 12) & + "00" & q(11 downto 10) & "00" & q( 9 downto 8) & + "00" & q( 7 downto 6) & "00" & q( 5 downto 4) & + "00" & q( 3 downto 2) & "00" & q( 1 downto 0); -- Pull out the bits from the shift register for the 3BPP mode - bpp1_slice(3) <= shift_reg(0)(32) & - "000" & shift_reg(0)(31) & "000" & shift_reg(0)(30) & "000" & shift_reg(0)(29) & "000" & shift_reg(0)(28) & - "000" & shift_reg(0)(27) & "000" & shift_reg(0)(26) & "000" & shift_reg(0)(25) & "000" & shift_reg(0)(24); - bpp1_slice(2) <= "0000" & shift_reg(0)(23) & "000" & shift_reg(0)(22) & "000" & shift_reg(0)(21) & "000" & shift_reg(0)(20) & - "000" & shift_reg(0)(19) & "000" & shift_reg(0)(18) & "000" & shift_reg(0)(17) & "000" & shift_reg(0)(16); - bpp1_slice(1) <= "0000" & shift_reg(0)(15) & "000" & shift_reg(0)(14) & "000" & shift_reg(0)(13) & "000" & shift_reg(0)(12) & - "000" & shift_reg(0)(11) & "000" & shift_reg(0)(10) & "000" & shift_reg(0)( 9) & "000" & shift_reg(0)( 8); - bpp1_slice(0) <= "0000" & shift_reg(0)( 7) & "000" & shift_reg(0)( 6) & "000" & shift_reg(0)( 5) & "000" & shift_reg(0)( 4) & - "000" & shift_reg(0)( 3) & "000" & shift_reg(0)( 2) & "000" & shift_reg(0)( 1) & "000" & shift_reg(0)( 0); + bpp1_slice(3) <= q(32) & + "000" & q(31) & "000" & q(30) & "000" & q(29) & "000" & q(28) & + "000" & q(27) & "000" & q(26) & "000" & q(25) & "000" & q(24); + bpp1_slice(2) <= "0000" & q(23) & "000" & q(22) & "000" & q(21) & "000" & q(20) & + "000" & q(19) & "000" & q(18) & "000" & q(17) & "000" & q(16); + bpp1_slice(1) <= "0000" & q(15) & "000" & q(14) & "000" & q(13) & "000" & q(12) & + "000" & q(11) & "000" & q(10) & "000" & q( 9) & "000" & q( 8); + bpp1_slice(0) <= "0000" & q( 7) & "000" & q( 6) & "000" & q( 5) & "000" & q( 4) & + "000" & q( 3) & "000" & q( 2) & "000" & q( 1) & "000" & q( 0); - -- Pick out the appropriate slices, for the BPP mode, to get the 128 bit expanded vector - GEN_EXP_DATA : for i in 0 to 3 generate - expanded_slice(i) <= bpp1_slice(i) when bpp_mode = 2x"1" else - bpp2_slice(i) when bpp_mode = 2x"2" else - bpp3_slice(i); - end generate; -- Indicate the word_num phases to read the fifo for each BPP mode - read_phase <= '1' when (bpp_mode = 2x"1" and word_num (0) = 2x"2") or - (bpp_mode = 2x"2" and word_num(0)(1) = '0') or - bpp_mode = 2x"3" or bpp_mode = 2x"0" else '0'; + read_phase <= '1' when (bpp_mode = 2x"1" and word_num(0) = 2x"3") or + (bpp_mode = 2x"2" and word_num(0)(0) = '1') or + bpp_mode = 2x"3" or bpp_mode = 2x"0" else '0'; -- @formatter:on - -- Flag when the word_num index is 0- - word_num_is_zero <= '1' when word_num(0) = 2x"0" else '0'; - -- Flag, for each BPP mode, when it is okay to read from the FIFO. For 1 BPP then only a single word is needed. - -- For 2 BPP it's okay to read when at least two words are present, for 3/4 BPP it is four. - ok_to_rd <= '1' when (empty = '0' and bpp_mode = 2x"1") or - ((full = '1' or unsigned(usedw(usedw'high downto 1)) /= 0) and bpp_mode = 2x"2") or - ((full = '1' or unsigned(usedw(usedw'high downto 2)) /= 0) and (bpp_mode = 2x"3" or bpp_mode = 2x"0")) else '0'; - pixel_buf_wr_data <= pixel_buf_wr_data_int(31 downto 0); - pixel_buf_last_word <= pixel_buf_wr_data_int(32); + pixel_buf_wr_data <= pixel_buf_wr_data_int(31 downto 0); + pixel_buf_last_word <= pixel_buf_wr_data_int(32); -- Instantiate The FIFO. preslicer_fifo_inst : entity work.alt_sync_fifo generic map ( - DATA_WIDTH => 33, - DEPTH => DEPTH, - REGISTER_OUTPUT => "ON", - NEARLY_FULL => ALMOST_FULL_THRESH, - DEVICE_FAMILY => DEVICE_FAMILY, - SHOWAHEAD => "ON", - CHECKING => "ON" - + DATA_WIDTH => 33, + DEPTH => DEPTH, + REGISTER_OUTPUT => "ON", + NEARLY_FULL => ALMOST_FULL_THRESH, + DEVICE_FAMILY => DEVICE_FAMILY, + SHOWAHEAD => "ON", + CHECKING => "ON" + ) port map ( - clk => clk, - - sclr => clear_buffer, - - wrdata => ps_buf_wr_data_int, - wrreq => ps_buf_wr_int, - - almost_full => almost_full, - empty => empty, - full => full, - - usedw => usedw, - - rdreq => rdreq, - rddata => q + clk => clk, + + sclr => clear_buffer, + + wrdata => ps_buf_wr_data_int, + wrreq => ps_buf_wr_int, + + almost_full => almost_full, + empty => empty, + + rdreq => rdreq, + rddata => q ); - + -- Flag to print streamer we're ready for data until almost full - ps_buf_rdy <= not almost_full; + ps_buf_rdy <= not almost_full; + + rdreq <= pixel_buf_rdy_int and not empty and read_phase; PRESLICER_CTRL : process(rst_n, clk) is begin if rst_n = '0' then - pixel_buf_wr <= '0'; - rdreq <= '0'; - word_num(0) <= (others => '0'); - word_num(1) <= (others => '0'); - word_num(2) <= (others => '0'); - px_buf_stalled <= (others => '1'); + pixel_buf_wr <= '0'; + word_num(0) <= (others => '0'); elsif clk'event and clk = '1' then - -- By default, read request frpm FIFO is disabled - rdreq <= '0'; - -- Select, for the data output from the expanded slice, using the matching pipelined word_num value. - pixel_buf_wr_data_int <= expanded_slice(to_integer(unsigned(word_num(2))))(32 downto 0); - - -- the pixel buffer is stalled whenever the ready signal is inactive or fifo not ok to read, - -- and the the word_num is 0. Pipeline this to align with the stages. - px_buf_stalled <= px_buf_stalled(0) & ((not pixel_buf_rdy_int or not ok_to_rd) and word_num_is_zero); + if bpp_mode = 2x"1" then + pixel_buf_wr_data_int <= bpp1_slice(to_integer(unsigned(word_num(0)))); + elsif bpp_mode = 2x"2" then + pixel_buf_wr_data_int <= bpp2_slice(to_integer(unsigned(word_num(0)(0 downto 0)))); + else + pixel_buf_wr_data_int <= bpp3_slice(0); + end if; -- Start writing to the pixel buffer when word_num reaches 2. Clear if pixel buffer is stalled -- (aligned with output stage). - pixel_buf_wr <= (pixel_buf_wr or word_num(0)(1)) and not px_buf_stalled(1); + pixel_buf_wr <= not empty and pixel_buf_rdy_int; -- Read from the FIFO if the pixel buffer is ready, and okay to read, but continue -- if in the middle of a transfer. Similarly, increment the word_num index. - if (pixel_buf_rdy_int = '1' and ok_to_rd = '1') or word_num_is_zero = '0' then - rdreq <= read_phase; - word_num(0) <= std_logic_vector(unsigned(word_num(0)) + 1); - end if; - - -- Create pipeline matching versions of word_num - word_num(2) <= word_num(1); - word_num(1) <= word_num(0); - - -- Update the shift register with the FIFO data, as indicated by the word_num index and BPP mode. - if bpp_mode = 2x"1" then - if word_num(0) = 2x"1" then - shift_reg(0) <= q; - end if; - elsif bpp_mode = 2x"2" then - if word_num(0) = 2x"1" then - shift_reg(0) <= q; - elsif word_num(0) = 2x"2" then - shift_reg(1) <= q; - end if; - else - shift_reg(to_integer(unsigned(word_num(0)) - 1)) <= q; + if pixel_buf_rdy_int = '1' and empty = '0' then + word_num(0) <= std_logic_vector(unsigned(word_num(0)) + 1); end if; if clear_buffer then - pixel_buf_wr <= '0'; - rdreq <= '0'; - word_num(0) <= (others => '0'); - word_num(1) <= (others => '0'); - word_num(2) <= (others => '0'); - px_buf_stalled <= (others => '1'); + pixel_buf_wr <= '0'; + word_num(0) <= (others => '0'); end if; - end if; end process; -end rtl; \ No newline at end of file +end rtl; \ No newline at end of file