From 32cfb421267f7257ea1810496dad0dfed60d61cf Mon Sep 17 00:00:00 2001 From: Simon Southwell Date: Tue, 15 Dec 2020 16:35:48 +0000 Subject: [PATCH] ELGIP-99 ELGIP-109 Added memory write interface and self-checking simulation regression tests. --- generic_ip/common/0/src/sync_pulse.vhd | 88 ++++++++++ generic_ip/xgbe_oe/0/doc/xgbe_oe_0.json | 74 +++++++- generic_ip/xgbe_oe/0/src/mem_wr_if_0.vhd | 212 +++++++++++++++++++++++ generic_ip/xgbe_oe/0/src/xgbe_oe_0.vhd | 78 ++++++++- 4 files changed, 440 insertions(+), 12 deletions(-) create mode 100644 generic_ip/common/0/src/sync_pulse.vhd create mode 100644 generic_ip/xgbe_oe/0/src/mem_wr_if_0.vhd diff --git a/generic_ip/common/0/src/sync_pulse.vhd b/generic_ip/common/0/src/sync_pulse.vhd new file mode 100644 index 0000000..c208013 --- /dev/null +++ b/generic_ip/common/0/src/sync_pulse.vhd @@ -0,0 +1,88 @@ +------------------------------------------------------------------------------- +-- Title : sync_pulse +------------------------------------------------------------------------------- +-- File : sync_pulse.vhd +-- Author : Simon Southwell +-- Company : GIS +-- Target : Generic (simulation), Generic (synthesis) +-- Dependency : none +------------------------------------------------------------------------------- +-- Description: synchronise single cycle pulse between two async clk domains +------------------------------------------------------------------------------- +-- Last update: 2020-12-14 +------------------------------------------------------------------------------- +-- Revisions : +-- Date Version Author Description +-- 2020-12-14 1.0 SDS Created +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; + +entity sync_pulse is + generic( + SYNC_STAGES : positive := 2 + ); + port + ( + clk_in : in std_logic; + rst_n : in std_logic; + pulse_in : in std_logic; + + clk_out : in std_logic; + pulse_out : out std_logic + ); +end sync_pulse; + +architecture rtl of sync_pulse is + + signal pulse_in_hold : std_logic; + signal pulse_in_sync : std_logic_vector(SYNC_STAGES-1 downto 0); + signal pulse_out_sync : std_logic_vector(SYNC_STAGES-1 downto 0); + + signal pulse_out_hold : std_logic; + signal pulse_out_hold_dly : std_logic := '0'; + +begin + + --Synchronised pulse hold + pulse_out_hold <= pulse_in_sync(0); + + -- Pulse output on rising edge of output pulse held + pulse_out <= pulse_out_hold and not pulse_out_hold_dly; + + P_SYNC_IN : process (clk_in, rst_n) + begin + if rst_n = '0' then + + pulse_in_hold <= '0'; + pulse_out_sync <= (others => '0'); + + elsif clk_in'event and clk_in = '1' then + + -- Hold input pulse until cleared by return path + pulse_in_hold <= (pulse_in_hold or pulse_in) and not pulse_out_sync(0); + + -- Synchronise output held pulse + pulse_out_sync <= pulse_out_hold & pulse_out_sync(pulse_in_sync'left downto 1); + + end if; + end process; + + P_SYNC_OUT : process (clk_out) + begin + if clk_out'event and clk_out = '1' then + + -- Synchronise held input pulse + pulse_in_sync <= pulse_in_hold & pulse_in_sync(pulse_in_sync'left downto 1); + + -- Generate delayed version of held pulse for rising edge detection. + pulse_out_hold_dly <= pulse_out_hold; + end if; + end process; + +end; + + + diff --git a/generic_ip/xgbe_oe/0/doc/xgbe_oe_0.json b/generic_ip/xgbe_oe/0/doc/xgbe_oe_0.json index 8e79a77..6d91276 100644 --- a/generic_ip/xgbe_oe/0/doc/xgbe_oe_0.json +++ b/generic_ip/xgbe_oe/0/doc/xgbe_oe_0.json @@ -40,7 +40,7 @@ "bit_len" : "8", "reset" : "0xFF", "description" : "Manufacturer number" - + }, "reserved" : { "type" : "rsv", @@ -48,7 +48,7 @@ "description" : "Reserved bits" } } - }, + }, "ip_ver" : { "address" : "1", "width" : "32", @@ -65,7 +65,7 @@ "bit_len" : "8", "reset" : "0x00", "description" : "Major number" - + }, "reserved" : { "type" : "rsv", @@ -80,7 +80,7 @@ "description" : "Main Control register", "fields": { "init" : { - "type" : "w", + "type" : "w0", "bit_len" : "1", "reset" : "0x0", "description" : "All the logic is brought back to the initial state, without loosing the existing configuration" @@ -90,7 +90,7 @@ "bit_len" : "1", "reset" : "0x0", "description" : "Start a hardware reset to the 10G-PHY" - }, + }, "mac_loopback_en" : { "type" : "w", "bit_len" : "1", @@ -133,7 +133,7 @@ "bit_len" : "1", "reset" : "0x0", "description" : "10G-PHY hardware reset completed" - }, + }, "PHY_rclk_locked" : { "type" : "r", "bit_len" : "1", @@ -368,7 +368,7 @@ "type" : "w0", "bit_len" : "1", "reset" : "0x0", - "description" : "Request to poll the error status (tpc_errors)" + "description" : "Request to poll the error status (tpc_errors)" } } }, @@ -387,7 +387,65 @@ "type" : "r", "bit_len" : "16", "reset" : "0x0", - "description" : "Number of words affected by errors" + "description" : "Number of words affected by errors" + } + } + }, + "mem_wr_if_ctrl" : { + "address" : "19", + "width" : "3", + "description" : "Memory write interface control", + "fields": { + "clr" : { + "type" : "w0", + "bit_len" : "1", + "reset" : "0", + "description" : "Clear interface" + }, + "flush" : { + "type" : "w", + "bit_len" : "1", + "reset" : "0", + "description" : "Flush" + }, + "update_addr" : { + "type" : "w0", + "bit_len" : "1", + "reset" : "0", + "description" : "Update DMA addresses" + } + } + }, + "mem_wr_if_base_addr" : { + "address" : "20", + "width" : "32", + "type" : "w", + "reset" : "0x20000000", + "description" : "Byte address of DMA circular buffer base" + }, + "mem_wr_if_end_addr" : { + "address" : "21", + "width" : "32", + "type" : "w", + "reset" : "0x20010000", + "description" : "Byte address of DMA circular buffer end" + }, + "mem_wr_if_status" : { + "address" : "22", + "width" : "2", + "description" : "Memory write interface status", + "fields": { + "flushed" : { + "type" : "r", + "bit_len" : "1", + "reset" : "0", + "description" : "Interface flushed status" + }, + "overflow" : { + "type" : "r", + "bit_len" : "1", + "reset" : "0", + "description" : "Overfow error (sticky)." } } } diff --git a/generic_ip/xgbe_oe/0/src/mem_wr_if_0.vhd b/generic_ip/xgbe_oe/0/src/mem_wr_if_0.vhd new file mode 100644 index 0000000..7f45c10 --- /dev/null +++ b/generic_ip/xgbe_oe/0/src/mem_wr_if_0.vhd @@ -0,0 +1,212 @@ +------------------------------------------------------------------------------- +-- Title : mem_wr_if_0 +-- Project : 10G +------------------------------------------------------------------------------- +-- File : mem_wr_if_0.vhd +-- Author : Simon Southwell +-- Company : Global Inkjet Systems +-- Created : 2020-12-14 +-- Last update: 2020-12-14 +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: GIS 10 Gigabit Ethernet Offload Engine memory write interface +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +use work.common_pkg.all; + +entity mem_wr_if_0 is + + generic ( + MAX_BURST_SIZE : natural range 1 to 128 := 8 + ); + port ( + clk : in std_logic; -- @156.25MHz + rst_n : in std_logic; + + -- Control and status + clr : in std_logic; + update_addr : in std_logic; + new_base_addr_bytes : in std_logic_vector(31 downto 0); + new_end_addr_bytes : in std_logic_vector(31 downto 0); + flush : in std_logic; + flushed : out std_logic; + overflow : out std_logic; + + -- TCP Server Rx interface + rx_data : in std_logic_vector(63 downto 0); + rx_data_valid : in std_logic_vector( 7 downto 0); + rx_rts : in std_logic; + rx_cts : out std_logic; + + -- Avalon Master burst write interface for FPGA configuration block + avm_tx_write : out std_logic; + avm_tx_waitrequest : in std_logic; + avm_tx_burstcount : out std_logic_vector(11 downto 0) := (others => '0'); + avm_tx_address : out std_logic_vector(31 downto 0); -- byte address + avm_tx_writedata : out std_logic_vector(63 downto 0); + avm_tx_last : out std_logic + + ); +end entity mem_wr_if_0; + +architecture rtl of mem_wr_if_0 is + + constant DEFAULT_START_QADDR : std_logic_vector(31 downto 3) := 29x"4000000"; -- 0x20000000 byte address + constant DEFAULT_END_QADDR : std_logic_vector(31 downto 3) := 29x"4001fff"; -- 0x2000fff8 byte address + constant BURST_TOP_BIT : integer := log2(MAX_BURST_SIZE); + + signal wrreq : std_logic; + signal rdreq : std_logic; + signal almost_full : std_logic; + signal full : std_logic; + signal empty : std_logic; + signal usedw : std_logic_vector(log2(MAX_BURST_SIZE*2)-1 downto 0); + signal rddata : std_logic_vector(63 downto 0); + + -- Buffer QWORD addresses + signal start_addr : std_logic_vector(31 downto 3); + signal end_addr : std_logic_vector(31 downto 3); + signal addr : std_logic_vector(31 downto 3); + + signal burstcount : std_logic_vector(BURST_TOP_BIT downto 0); + +begin + + ----------------------------------------------------------------------------- + -- Short queue to gather up words into sensible burst sizes + ----------------------------------------------------------------------------- + + ip_fifo_inst : entity work.alt_sync_fifo + generic map + ( + DATA_WIDTH => 64, + DEPTH => MAX_BURST_SIZE*2, + REGISTER_OUTPUT => "ON", + NEARLY_FULL => MAX_BURST_SIZE*2-4, + SHOWAHEAD => "ON" + ) + port map + ( + clk => clk, + rst_n => rst_n, + sclr => clr, + + wrreq => wrreq, + wrdata => rx_data, + almost_full => almost_full, + full => full, + + rdreq => rdreq, + rddata => rddata, + empty => empty, + + usedw => usedw + ); + + ----------------------------------------------------------------------------- + -- Combinatorial logic + ----------------------------------------------------------------------------- + + -- Write to the fifo when a whole word is available, or a flush request and some bytes available + wrreq <= '1' when unsigned(rx_data_valid) = 8x"ff" or (flush = '1' and unsigned(rx_data_valid) /= 0) else '0'; + + -- Read from the queue whenever a write over the bus happens (and not stalled), and input queue is not empty. + rdreq <= avm_tx_write and not avm_tx_waitrequest and not empty; + + -- Write data on Avalon bus is the registered output of the Input queue. + avm_tx_writedata <= rddata; + + ----------------------------------------------------------------------------- + -- Synchrnous process + ----------------------------------------------------------------------------- + P_SYNC : process(clk, rst_n) + begin + if rst_n = '0' then + overflow <= '0'; + burstcount <= (others => '0'); + flushed <= '0'; + addr <= DEFAULT_START_QADDR; + start_addr <= DEFAULT_START_QADDR; + end_addr <= DEFAULT_END_QADDR; + elsif clk'event and clk = '1' then + + -- Assert clear-to-send if ready-to-send unless nearly full or flushing. + rx_cts <= rx_rts and not almost_full and not flush; + + -- Default the Avalon writes to inactive + avm_tx_write <= '0'; + avm_tx_last <= '0'; + + -- Flag that we're flushed when flush asserted and input queue is empty and TCP server is not ready-to-send + flushed <= flush and empty and not rx_rts; + + -- If a write to a full queue is seen, flag an overflow. + if full = '1' and wrreq = '1' then + overflow <= '1'; + end if; + + -- If a write is not active ... + if unsigned(burstcount) = 0 then + + -- If the maximum burst size amount of data is available then send a block of data + if unsigned(usedw) >= MAX_BURST_SIZE or full = '1' then + avm_tx_burstcount(BURST_TOP_BIT downto 0) <= std_logic_vector(to_unsigned(MAX_BURST_SIZE, BURST_TOP_BIT+1)); + burstcount <= std_logic_vector(to_unsigned(MAX_BURST_SIZE, burstcount'length)); + avm_tx_write <= '1'; + avm_tx_address <= addr & "000"; + -- If flushing and and data available, and no new data arriving, send the remaining words. + elsif unsigned(usedw) /= 0 and flush = '1' and rx_rts = '0' then + avm_tx_burstcount <= std_logic_vector(resize(unsigned(usedw), avm_tx_burstcount'length)); + burstcount <= std_logic_vector(resize(unsigned(usedw), burstcount'length)); + avm_tx_write <= '1'; + avm_tx_address <= addr & "000"; + end if; + -- Else a write to memory is active ... + else + + -- Assert write and update the write data from the input queue + avm_tx_write <= '1'; + + -- If bus not stalled ... + if avm_tx_waitrequest = '0' then + -- Decrement the burst count + burstcount <= std_logic_vector(unsigned(burstcount) - 1); + + -- If address is the end addrss, wrap back to start address, else increment + if addr = end_addr then + addr <= start_addr; + else + addr <= std_logic_vector(unsigned(addr) + 1); + end if; + + -- If burst count is 2, flag next word (at count 1) as the last + if unsigned(burstcount) = 2 then + avm_tx_last <= '1'; + elsif unsigned(burstcount) = 1 then + avm_tx_write <= '0'; + end if; + end if; + end if; + + -- If requested, update the start and end addresses and reset the address counter to the new start + if update_addr = '1' then + addr <= new_base_addr_bytes(31 downto 3); + start_addr <= new_base_addr_bytes(31 downto 3); + end_addr <= new_end_addr_bytes(31 downto 3); + end if; + + -- If cleared reset internal state + if clr = '1' then + burstcount <= (others => '0'); + overflow <= '0'; + flushed <= '0'; + end if; + end if; + end process; + +end rtl; \ No newline at end of file diff --git a/generic_ip/xgbe_oe/0/src/xgbe_oe_0.vhd b/generic_ip/xgbe_oe/0/src/xgbe_oe_0.vhd index 092898d..ce15c54 100644 --- a/generic_ip/xgbe_oe/0/src/xgbe_oe_0.vhd +++ b/generic_ip/xgbe_oe/0/src/xgbe_oe_0.vhd @@ -21,7 +21,6 @@ use ieee.numeric_std.all; library transconfig; library xaui_phy_itf; -library work; use work.xgbe_oe_0_pkg.all; use work.com5502pkg.all; @@ -84,13 +83,21 @@ entity xgbe_oe_0 is hps_emac_gtx_clk : in std_logic; hps_emac_ptp_ref_clock : out std_logic; + -- Avalon Master burst write interface for FPGA configuration block + avm_tx_write : out std_logic; + avm_tx_waitrequest : in std_logic; + avm_tx_burstcount : out std_logic_vector(11 downto 0); + avm_tx_address : out std_logic_vector(31 downto 0); -- byte address + avm_tx_writedata : out std_logic_vector(63 downto 0); + avm_tx_last : out std_logic; + -- Avalon MM Slave Interface avs_address : in std_logic_vector(10 downto 0); avs_write : in std_logic; avs_writedata : in std_logic_vector(31 downto 0); avs_read : in std_logic; avs_readdata : out std_logic_vector(31 downto 0); - + debug_out : out std_logic_vector(4 downto 0) ); end entity xgbe_oe_0; @@ -285,8 +292,22 @@ architecture rtl of xgbe_oe_0 is signal reconfig_from_xcvr : std_logic_vector(229 downto 0) := (others => '0'); signal reconfig_to_xcvr : std_logic_vector(349 downto 0) := (others => '0'); - + signal xaui_rx_ch_aligned_i : std_logic := '1'; + + signal mem_wr_if_ctrl_clr : std_logic; + signal mem_wr_if_ctrl_flush : std_logic; + signal mem_wr_if_ctrl_update_addr : std_logic; + signal mem_wr_if_base_addr : std_logic_vector(31 downto 0); + signal mem_wr_if_end_addr : std_logic_vector(31 downto 0); + signal mem_wr_if_status_flushed : std_logic; + signal mem_wr_if_status_overflow : std_logic; + + signal mem_wr_if_ctrl_clr_156 : std_logic; + signal mem_wr_if_ctrl_flush_156 : std_logic; + signal mem_wr_if_ctrl_update_addr_156 : std_logic; + signal mem_wr_if_status_flushed_156 : std_logic; + signal mem_wr_if_status_overflow_156 : std_logic; begin @@ -523,7 +544,7 @@ begin rx_channelaligned => xaui_rx_ch_aligned_i, rx_ready => xaui_rx_ready_i, - tx_ready => xaui_tx_ready_i, + tx_ready => xaui_tx_ready_i, reconfig_from_xcvr => reconfig_from_xcvr, reconfig_to_xcvr => reconfig_to_xcvr, @@ -891,6 +912,47 @@ begin -- tcp_tx_data_flush_v(0) <= tcp_tx_data_flush; + ----------------------------------------------------------------------------- + -- Memory write interafce + ----------------------------------------------------------------------------- + + mem_wr_if_inst : entity work.mem_wr_if_0 + port map ( + clk => clk_156, + rst_n => reset_n_i, + + -- Control and status + clr => init, + update_addr => mem_wr_if_ctrl_update_addr_156, + new_base_addr_bytes => mem_wr_if_base_addr, + new_end_addr_bytes => mem_wr_if_end_addr, + flush => mem_wr_if_ctrl_flush_156, + flushed => mem_wr_if_status_flushed_156, + overflow => mem_wr_if_status_overflow_156, + + -- TCP Server Rx interface + rx_data => tcp_rx_data, + rx_data_valid => tcp_rx_data_valid, + rx_rts => tcp_rx_rts, + rx_cts => tcp_rx_cts, + + -- Avalon Master burst write interface for FPGA configuration block + avm_tx_write => avm_tx_write, + avm_tx_waitrequest => avm_tx_waitrequest, + avm_tx_burstcount => avm_tx_burstcount , + avm_tx_address => avm_tx_address, + avm_tx_writedata => avm_tx_writedata, + avm_tx_last => avm_tx_last + + ); + + sync_pulse_0 : entity work.sync_pulse port map(clk_in => clk_avs, rst_n=> reset_n_avs, pulse_in => mem_wr_if_ctrl_clr, clk_out => clk_156, pulse_out => mem_wr_if_ctrl_clr_156); + sync_pulse_1 : entity work.sync_pulse port map(clk_in => clk_avs, rst_n=> reset_n_avs, pulse_in => mem_wr_if_ctrl_update_addr, clk_out => clk_156, pulse_out => mem_wr_if_ctrl_update_addr_156); + sync_wire_0 : entity work.sync_wire port map(rstN => reset_n_i, clk => clk_156, async_in => mem_wr_if_ctrl_flush, sync_out => mem_wr_if_ctrl_flush_156); + + sync_wire_2 : entity work.sync_wire port map(rstN => reset_n_avs, clk => clk_avs, async_in => mem_wr_if_status_flushed_156, sync_out => mem_wr_if_status_flushed); + sync_wire_3 : entity work.sync_wire port map(rstN => reset_n_avs, clk => clk_avs, async_in => mem_wr_if_status_overflow_156, sync_out => mem_wr_if_status_overflow); + ----------------------------------------------------------------------------- -- Test Pattern Generation and Checking ----------------------------------------------------------------------------- @@ -1067,6 +1129,14 @@ begin tpc_ctrl_tpc_poll_error_req => tpc_poll_error_req_i, tpc_status_tpc_errors_is_valid => tpc_errors_is_valid_i, tpc_status_tpc_errors => tpc_errors_i, + + mem_wr_if_ctrl_clr => mem_wr_if_ctrl_clr, + mem_wr_if_ctrl_flush => mem_wr_if_ctrl_flush, + mem_wr_if_ctrl_update_addr => mem_wr_if_ctrl_update_addr, + mem_wr_if_base_addr => mem_wr_if_base_addr, + mem_wr_if_end_addr => mem_wr_if_end_addr, + mem_wr_if_status_flushed => mem_wr_if_status_flushed, + mem_wr_if_status_overflow => mem_wr_if_status_overflow, avs_address => avs_address(4 downto 0), avs_write => local_write,