From 8bfc9fcb4145cfe10b7c8648f2ae3917c4e03425 Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 20 Sep 2022 13:27:00 +0100 Subject: [PATCH] CORE-798 Make EL GIP Library FPGA Vendor Independent. Change to use generic FIFOs in common/1 --- .../streamer_fifo/1/src/streamer_fifo_1.vhd | 208 ++++++++++++++++++ generic_ip/streamer_fifo/versions.txt | 1 + 2 files changed, 209 insertions(+) create mode 100644 generic_ip/streamer_fifo/1/src/streamer_fifo_1.vhd create mode 100644 generic_ip/streamer_fifo/versions.txt diff --git a/generic_ip/streamer_fifo/1/src/streamer_fifo_1.vhd b/generic_ip/streamer_fifo/1/src/streamer_fifo_1.vhd new file mode 100644 index 0000000..6b96357 --- /dev/null +++ b/generic_ip/streamer_fifo/1/src/streamer_fifo_1.vhd @@ -0,0 +1,208 @@ +------------------------------------------------------------------------------- +--! @file +--! @brief Streamer FIFO queue +--! +--! @details This block is a queue of addresses and loop counts programmed by +--! the ESW so that when a companion data streamer makes a read access to +--! register space over the Avalon burst bus this can be redirected by the +--! address at the front of the queue. By default each address is popped when +--! redirected. All addresses are word aligned so that bits 0 and 1 are zero. +--! If a value at the front of the queue has bits 1:0 set to "01", then this +--! is seen as a loop count. Loop counts are immediately popped and an internal +--! loop counter updated. When an address is redirected with the loop count not +--! zero then it is not popped, but the counter decremented instead. The allows +--! the same address to be used multiple time when, say, doing a loop print. +--! The counter is 10 bits and updated with bits 11:2 when a loop count is +--! popped. +--! +--! @b Clock/resets: +--! @li clk : nominally 100MHz +--! @li rst_n : active low reset for clk (asynchronous assert) +--! +--! @b Interfaces: +--! @li fifo_* : FIFO control and status port for readng and writing to queue +--! @li avm_* : Memory master port sub-set for detecting register accesses by data streamer +--! +--! @b Clock-crossing considerations: +--! @li Module is a single clock domain synchronous block +--! +--! @b Language build standard requirements: +--! @li VHDL 2008 +--! +--! @author Simon Southwell +--! @copyright (c) 2020 Global Inkjet Systems +--! @date 2020-2-12 +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity streamer_fifo_1 is + generic ( + DEVICE_FAMILY : string := "Cyclone V" -- "Cyclone 10 LP" + ); + port( + + clk : in std_logic; + rst_n : in std_logic; + + fifo_wr_port_pulse : in std_logic; + fifo_wr_port : in std_logic_vector(31 downto 0); + fifo_wr_port_in : out std_logic_vector(31 downto 0); + fifo_rd_port : out std_logic_vector(31 downto 0); + fifo_rd_port_pulse : in std_logic; + fifo_status_empty : out std_logic; + fifo_status_full : out std_logic; + fifo_status_underrun : out std_logic; + fifo_status_overrun : out std_logic; + fifo_controls_clr_fifo : in std_logic; + fifo_controls_clr_errors : in std_logic; + fifo_controls_pop_rd_port : in std_logic; + fifo_loop_count : out std_logic_vector( 9 downto 0); + + avm_rx_address : in std_logic_vector(31 downto 28); + avm_rx_read : in std_logic; + avm_rx_waitrequest : in std_logic; + avm_rx_readdatavalid : in std_logic; + + ip_id_ip_number : out std_logic_vector( 7 downto 0); + ip_id_mfr_number : out std_logic_vector( 7 downto 0); + ip_ver_minor_number : out std_logic_vector( 7 downto 0); + ip_ver_major_number : out std_logic_vector( 7 downto 0) + + ); +end entity streamer_fifo_1; + +architecture rtl of streamer_fifo_1 is + + signal pop_fifo : std_logic; + signal ds_reg_rd_pop : std_logic; + signal reg_rd_sent : std_logic; + signal loop_count : std_logic_vector ( 9 downto 0); + signal pop_count : std_logic; + +begin + -- --------------------------------------- + -- IP INFORMATION + -- --------------------------------------- + + ip_id_ip_number <= 8x"02"; + ip_id_mfr_number <= 8x"FF"; + ip_ver_minor_number <= 8x"03"; + ip_ver_major_number <= 8x"00"; + + -- --------------------------------------- + -- ADDRESS/COUNT QUEUE + -- --------------------------------------- + + streamer_queue_inst : entity work.sync_fifo + generic map( + DATA_WIDTH => 32, + DEPTH => 32, + REGISTER_OUTPUT => "OFF", + NEARLY_FULL => 31, + NEARLY_EMPTY => 2, + DEVICE_FAMILY => DEVICE_FAMILY, + SHOWAHEAD => "ON", + CHECKING => "OFF" + ) + port map + ( + clk => clk, + rst_n => rst_n, -- added to reset Xilinx sync fifo. Altera resets itself + sclr => fifo_controls_clr_fifo, + + wrreq => fifo_wr_port_pulse, + wrdata => fifo_wr_port, + + rdreq => pop_fifo, + rddata => fifo_rd_port, + + empty => fifo_status_empty, + full => fifo_status_full, + usedw => open + ); + + -- --------------------------------------- + -- COMBINATORIAL LOGIC + -- --------------------------------------- + + -- Reading the fifo write port register returns 0 + fifo_wr_port_in <= (others => '0'); + + -- Generate a 'pop' signal to read the queue whenever a data streamer + -- register read completes, or if the CPU write the pop bit in the control + -- register. + pop_fifo <= ds_reg_rd_pop or pop_count; + + fifo_loop_count <= loop_count; + + -- --------------------------------------- + -- STATE SYNCHRONOUS PROCESS + -- --------------------------------------- + + process (clk, rst_n) + begin + if rst_n = '0' then + + fifo_status_underrun <= '0'; + fifo_status_overrun <= '0'; + ds_reg_rd_pop <= '0'; + reg_rd_sent <= '0'; + pop_count <= '0'; + loop_count <= (others => '0'); + + elsif clk'event and clk = '1' then + + -- Default popping of fifo to inactive + ds_reg_rd_pop <= '0'; + pop_count <= '0'; + + -- If the data streamer made an access to register space, flag + -- that this is outstanding + if avm_rx_read = '1' and avm_rx_waitrequest = '0' and avm_rx_address = 4x"f" then + reg_rd_sent <= '1'; + end if; + + -- If an outstanding data streamer register access and data is returned, + -- clear pending access state, and pulse the data streamer read pop signal + -- to pop the data just read if the loop count 0, else decrement the count. + if (avm_rx_readdatavalid = '1' and reg_rd_sent = '1') or fifo_controls_pop_rd_port = '1' then + reg_rd_sent <= '0'; + if unsigned(loop_count) = 0 then + ds_reg_rd_pop <= '1'; + else + loop_count <= std_logic_vector(unsigned(loop_count) - 1); + end if; + end if; + + if fifo_rd_port(1 downto 0) = "01" and fifo_status_empty = '0' then + loop_count <= fifo_rd_port(11 downto 2); + pop_count <= not pop_count; + end if; + + if fifo_controls_clr_fifo = '1' then + loop_count <= (others => '0'); + end if; + + -- Clear errors state when CPU instructs to do so + if fifo_controls_clr_errors then + fifo_status_underrun <= '0'; + fifo_status_overrun <= '0'; + end if; + + -- If a write to the FIFO occurs when full, flag overrun + if fifo_status_full and fifo_wr_port_pulse then + fifo_status_overrun <= '1'; + end if; + + -- If a read from the FIFO occurs when empty, flag underrun + if fifo_status_empty and pop_fifo then + fifo_status_underrun <= '1'; + end if; + + end if; + end process; +end rtl; diff --git a/generic_ip/streamer_fifo/versions.txt b/generic_ip/streamer_fifo/versions.txt new file mode 100644 index 0000000..fcb4993 --- /dev/null +++ b/generic_ip/streamer_fifo/versions.txt @@ -0,0 +1 @@ +v1 fpga vendor independent \ No newline at end of file