From 36e37dfd11dbf66093c357f4dede324e8fe82970 Mon Sep 17 00:00:00 2001 From: Brian Padalino Date: Sun, 19 Oct 2014 17:29:00 -0400 Subject: [PATCH] hdl: Keeping contnuity of RX samples. During an RX sample overflow, keeping the metadata timestamp and the sample stream in-sync with each other. --- hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd | 17 ++++++++++++++--- hdl/fpga/platforms/bladerf/vhdl/fx3_gpif.vhd | 6 +++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd index 3134d889..6001ab96 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd @@ -40,6 +40,8 @@ architecture simple of fifo_writer is signal dma_downcount : signed(12 downto 0); signal overflow_recovering : std_logic ; signal overflow_detected : std_logic ; + signal meta_written : std_logic ; + signal meta_written_reg : std_logic ; begin @@ -48,6 +50,7 @@ begin begin if( reset = '1') then dma_downcount <= dma_buf_sz; + meta_written <= '0' ; elsif( rising_edge( clock ) ) then if (enable = '1' and meta_en = '1') then if( dma_downcount > 0 ) then @@ -55,10 +58,16 @@ begin elsif ( to_signed(2**fifo_usedw'length,fifo_usedw'length+2) - (signed('0'&fifo_full&fifo_usedw)) > dma_buf_sz ) then -- Guaranteed to be done downcounting here .. so only reset the downcount -- if we are able to store that amount of samples in the downstream FIFO - dma_downcount <= dma_buf_sz; + if( meta_written = '1' or in_valid = '1' ) then + dma_downcount <= dma_buf_sz; + meta_written <= '1' ; + end if ; + else + meta_written <= '0' ; end if; else - dma_downcount <= dma_buf_sz; + dma_downcount <= (others =>'0') ; + meta_written <= '0' ; end if; end if; end process; @@ -68,9 +77,11 @@ begin meta_fifo_write <= '1' when (enable = '1' and meta_en = '1' and buf_enough = '1') else '0'; meta_fifo_data <= x"FFFFFFFF" & std_logic_vector(timestamp) & x"12344321"; + meta_written_reg <= '0' when reset = '1' else meta_written when rising_edge(clock) ; + -- Simple concatenation of samples fifo_data <= std_logic_vector(in_q & in_i) ; - fifo_write <= in_valid when overflow_recovering = '0' and fifo_full = '0' else '0' ; + fifo_write <= in_valid when overflow_recovering = '0' and fifo_full = '0' and (meta_en = '0' or meta_written_reg = '1') else '0' ; -- Clear out the contents when RX is disabled clear_fifo : process( clock, reset ) diff --git a/hdl/fpga/platforms/bladerf/vhdl/fx3_gpif.vhd b/hdl/fpga/platforms/bladerf/vhdl/fx3_gpif.vhd index 86d0ad3e..e29118ef 100644 --- a/hdl/fpga/platforms/bladerf/vhdl/fx3_gpif.vhd +++ b/hdl/fpga/platforms/bladerf/vhdl/fx3_gpif.vhd @@ -341,11 +341,11 @@ begin meta_downcount <= meta_downcount - 1; else dma_downcount <= dma_downcount - 1; - if (unsigned(meta_buffer(31 downto 0) & meta_buffer(63 downto 32)) < (tx_timestamp + 32)) then - state <= SAMPLE_WRITE_IGNORE; - else + if (unsigned(meta_buffer(63 downto 0)) = 0 or unsigned(meta_buffer(31 downto 0) & meta_buffer(63 downto 32)) > (tx_timestamp + 32)) then meta_downcount <= to_signed(3, 13); state <= SAMPLE_WRITE; + else + state <= SAMPLE_WRITE_IGNORE; end if; end if; when SAMPLE_WRITE_IGNORE =>