From cefdb2887ce4151e0fa8b219ceabaf01781acdbc Mon Sep 17 00:00:00 2001 From: Robert Ghilduta Date: Tue, 16 Apr 2024 02:29:29 -0700 Subject: [PATCH] hdl: fixup more timing issues --- hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd | 23 +++++++++++++------ hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd | 20 ++++++++++++---- .../bladerf-micro/constraints/bladerf.sdc | 2 +- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd index a525ab2b..d1d156c5 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd @@ -92,7 +92,10 @@ architecture simple of fifo_reader is meta_read : std_logic; meta_cache : std_logic_vector(META_FIFO_DATA_WIDTH-1 downto 0); meta_p_time : unsigned(63 downto 0); + meta_p_time_r : unsigned(63 downto 0); meta_time_go : std_logic; + meta_fifo_empty : std_logic; + meta_fifo_data : std_logic_vector(META_FIFO_DATA_WIDTH-1 downto 0); end record; constant META_FSM_RESET_VALUE : meta_fsm_t := ( @@ -104,7 +107,10 @@ architecture simple of fifo_reader is meta_read => '0', meta_cache => (others => '0'), meta_p_time => (others => '-'), - meta_time_go => '0' + meta_p_time_r => (others => '-'), + meta_time_go => '0', + meta_fifo_empty => '0', + meta_fifo_data => (others => '0') ); signal meta_current : meta_fsm_t := META_FSM_RESET_VALUE; @@ -193,7 +199,7 @@ begin end if; end process; - packet_empty <= '1' when ( meta_fifo_empty = '1' and meta_current.state /= META_WAIT ) else '0' ; + packet_empty <= '1' when ( meta_current.meta_fifo_empty = '1' and meta_current.state /= META_WAIT ) else '0' ; -- Meta FIFO combinatorial process meta_fsm_comb : process( all ) @@ -205,26 +211,29 @@ begin meta_future.meta_read <= '0'; meta_future.meta_pkt_sop <= '0'; meta_future.meta_pkt_eop <= '0'; + meta_future.meta_fifo_empty <= meta_fifo_empty; + meta_future.meta_fifo_data <= meta_fifo_data; + meta_time := unsigned(meta_current.meta_fifo_data(95 downto 32)) - 1; + meta_future.meta_p_time_r <= meta_time; case meta_current.state is when META_LOAD => meta_future.skip_padding <= '0'; - meta_time := unsigned(meta_fifo_data(95 downto 32)) - 1; - meta_future.meta_p_time <= meta_time; - meta_future.meta_cache <= meta_fifo_data; + meta_future.meta_p_time <= meta_current.meta_p_time_r; + meta_future.meta_cache <= meta_current.meta_fifo_data; if( meta_current.dma_downcount = NUM_STREAMS ) then meta_future.dma_downcount <= 0; end if; if( fifo_current.ch_shift = 0 ) then - if( meta_fifo_empty = '0' and (packet_en = '0' or + if( meta_current.meta_fifo_empty = '0' and (packet_en = '0' or (packet_en = '1' and packet_ready = '1') ) ) then meta_future.meta_read <= '1'; meta_future.state <= META_WAIT; - if( packet_en = '1' or meta_time /= timestamp ) then + if( packet_en = '1' or meta_current.meta_p_time_r /= timestamp ) then meta_future.meta_time_go <= '0'; else meta_future.meta_time_go <= '1'; diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd index a6cdfed9..491994e4 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd @@ -136,6 +136,9 @@ architecture simple of fifo_writer is signal sync_mini_exp: std_logic_vector(1 downto 0); + signal meta_fifo_used_v_r : unsigned(meta_fifo_usedw'length downto 0) := (others => '0'); + signal fifo_used_v_r : unsigned(fifo_usedw'length downto 0) := (others => '0'); + begin -- Throw an error if port widths don't make sense @@ -167,11 +170,21 @@ begin if( reset = '1' ) then fifo_enough <= false; fifo_used_v := (others => '0'); + meta_fifo_used_v_r <= (others => '0'); + fifo_used_v_r <= (others => '0'); elsif( rising_edge(clock) ) then + -- the outputs of the dcfifo are not registered so give the long combinatorial + -- data path, let's register the values. one extra clock cycle will not change + -- the fidelity of the result. the meta_fifo represents at minimum 204 timestamps. + -- there is no way for an off by 1 clock cycle timing to overflow the meta fifo + -- when the buffer leaves 4 full meta buffers empty fifo_used_v := unsigned(fifo_full & fifo_usedw); + fifo_used_v_r <= fifo_used_v; meta_fifo_used_v := unsigned(meta_fifo_full & meta_fifo_usedw); - if( fifo_full = '0' and ((FIFO_MAX - fifo_used_v) > ( dma_buf_size * 4 )) and - ( ( meta_en = '1' and meta_fifo_full = '0' and ( META_MAX - 4 ) > meta_fifo_used_v ) + meta_fifo_used_v_r <= meta_fifo_used_v; + + if( fifo_full = '0' and ((FIFO_MAX - fifo_used_v_r) > ( dma_buf_size * 4 )) and + ( ( meta_en = '1' and meta_fifo_full = '0' and ( META_MAX - 4 ) > meta_fifo_used_v_r ) or (meta_en = '0') ) ) then fifo_enough <= true; else @@ -263,11 +276,10 @@ begin when META_WRITE => for i in in_samples'range loop - if (meta_fifo_full = '0') and (in_samples(i).data_v = '1') then + if (meta_fifo_full = '0' and in_samples(i).data_v = '1') then meta_future.meta_write <= '1'; meta_future.meta_written <= '1'; meta_future.state <= META_DOWNCOUNT; - exit; -- Exit loop after first match end if; end loop; diff --git a/hdl/fpga/platforms/bladerf-micro/constraints/bladerf.sdc b/hdl/fpga/platforms/bladerf-micro/constraints/bladerf.sdc index d01c8a29..41b5ca59 100644 --- a/hdl/fpga/platforms/bladerf-micro/constraints/bladerf.sdc +++ b/hdl/fpga/platforms/bladerf-micro/constraints/bladerf.sdc @@ -71,7 +71,7 @@ set_false_path -from exp_present -to * set_false_path -from pwr_status -to * # JTAG settings -create_clock -name {altera_reserved_tck} -period 10 [get_ports {altera_reserved_tck}] +create_clock -name {altera_reserved_tck} -period 100 [get_ports {altera_reserved_tck}] set_clock_groups -asynchronous -group {altera_reserved_tck} set_false_path -from [get_ports {altera_reserved_tms}] set_false_path -from [get_ports {altera_reserved_tdi}]