Compare commits

...
Sign in to create a new pull request.

5 commits

Author SHA1 Message Date
Ryan Thompson
26beca1c72 hdl: add clock control blocks for system and fx3 plls
Resolves Nios and FX3 lockup when SI53304 clock select assignments are
made. The FX3 pclk and Nios system PLLs lose lock when the SI53304
transitions between clock sources and this prevents invalid cycles from
making it through.
2024-05-23 07:16:40 -05:00
Ryan Thompson
006f32ad52 hdl: nios: add response delay if new clock is selected 2024-05-23 07:16:40 -05:00
Ryan Thompson
3ae2a838a9 hdl: fix first sample drop in fifo_writer
This fixes the first sample being dropped in both meta and non-meta modes.
fifo_write is now asserted through procedure and executes on HOLDOFF exit.

Regression test results:

$ make test_libbladeRF
[       OK ] libbladeRF.scheduled_retune (19450 ms)
[----------] 29 tests from libbladeRF (297804 ms total)
[==========] 29 tests from 1 test suite ran. (297804 ms total)
[  PASSED  ] 29 tests.

$ make test_hdl
[----------] 31 tests from hdl (1354828 ms total)
[----------] 32 tests from hdl/verify (2319711 ms total)
[==========] 63 tests from 2 test suites ran. (3674539 ms total)
[  PASSED  ] 63 tests.
2024-05-01 16:17:31 -05:00
Ryan Thompson
14917b9f2d hdl: init meta_fifo_empty to 1
[==========] 32 tests from 1 test suite ran. (1785986 ms total)
[  PASSED  ] 20 tests.
[  FAILED  ] 12 tests, listed below:
[  FAILED  ] hdl/verify.fx3_gpif_iq_8bit_tb/16b01, where GetParam() = (false, false, true)
[  FAILED  ] hdl/verify.fx3_gpif_iq_8bit_tb/16b10, where GetParam() = (false, true, false)
[  FAILED  ] hdl/verify.fx3_gpif_iq_8bit_tb/16b11, where GetParam() = (false, true, true)
[  FAILED  ] hdl/verify.fx3_gpif_iq_8bit_tb/8b01, where GetParam() = (true, false, true)
[  FAILED  ] hdl/verify.fx3_gpif_iq_8bit_tb/8b10, where GetParam() = (true, true, false)
[  FAILED  ] hdl/verify.fx3_gpif_iq_8bit_tb/8b11, where GetParam() = (true, true, true)
[  FAILED  ] hdl/verify.rx_counter_8bit_tb/16b01, where GetParam() = (false, false, true)
[  FAILED  ] hdl/verify.rx_counter_8bit_tb/16b10, where GetParam() = (false, true, false)
[  FAILED  ] hdl/verify.rx_counter_8bit_tb/16b11, where GetParam() = (false, true, true)
[  FAILED  ] hdl/verify.rx_counter_8bit_tb/8b01, where GetParam() = (true, false, true)
[  FAILED  ] hdl/verify.rx_counter_8bit_tb/8b10, where GetParam() = (true, true, false)
[  FAILED  ] hdl/verify.rx_counter_8bit_tb/8b11, where GetParam() = (true, true, true)

12 FAILED TESTS
2024-05-01 16:17:31 -05:00
Robert Ghilduta
36f693c58e hdl: fixup more timing issues 2024-05-01 16:17:31 -05:00
8 changed files with 211 additions and 44 deletions

View file

@ -0,0 +1,61 @@
-- Copyright (c) 2024 Nuand LLC
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE.
library ieee;
use ieee.std_logic_1164.all;
use ieee.math_real.all;
entity clk_ctrl is
port (
inclk :in std_logic;
ena :in std_logic;
outclk :out std_logic
);
end entity clk_ctrl;
architecture rtl of clk_ctrl is
component altclkctrl
generic (
clock_type : string := "Auto";
ena_register_mode : string := "none";
number_of_clocks : integer := 1
);
port (
inclk : in std_logic_vector(0 downto 0);
ena : in std_logic;
outclk : out std_logic
);
end component;
signal clk_ctrl_out : std_logic;
begin
clkctrl : altclkctrl
port map (
inclk => (0 => inclk),
ena => ena,
outclk => clk_ctrl_out
);
outclk <= clk_ctrl_out;
end architecture rtl;

View file

@ -92,7 +92,10 @@ architecture simple of fifo_reader is
meta_read : std_logic; meta_read : std_logic;
meta_cache : std_logic_vector(META_FIFO_DATA_WIDTH-1 downto 0); meta_cache : std_logic_vector(META_FIFO_DATA_WIDTH-1 downto 0);
meta_p_time : unsigned(63 downto 0); meta_p_time : unsigned(63 downto 0);
meta_p_time_r : unsigned(63 downto 0);
meta_time_go : std_logic; 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; end record;
constant META_FSM_RESET_VALUE : meta_fsm_t := ( constant META_FSM_RESET_VALUE : meta_fsm_t := (
@ -104,7 +107,10 @@ architecture simple of fifo_reader is
meta_read => '0', meta_read => '0',
meta_cache => (others => '0'), meta_cache => (others => '0'),
meta_p_time => (others => '-'), meta_p_time => (others => '-'),
meta_time_go => '0' meta_p_time_r => (others => '-'),
meta_time_go => '0',
meta_fifo_empty => '1',
meta_fifo_data => (others => '0')
); );
signal meta_current : meta_fsm_t := META_FSM_RESET_VALUE; signal meta_current : meta_fsm_t := META_FSM_RESET_VALUE;
@ -193,7 +199,7 @@ begin
end if; end if;
end process; 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 FIFO combinatorial process
meta_fsm_comb : process( all ) meta_fsm_comb : process( all )
@ -205,26 +211,29 @@ begin
meta_future.meta_read <= '0'; meta_future.meta_read <= '0';
meta_future.meta_pkt_sop <= '0'; meta_future.meta_pkt_sop <= '0';
meta_future.meta_pkt_eop <= '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 case meta_current.state is
when META_LOAD => when META_LOAD =>
meta_future.skip_padding <= '0'; meta_future.skip_padding <= '0';
meta_time := unsigned(meta_fifo_data(95 downto 32)) - 1; meta_future.meta_p_time <= meta_current.meta_p_time_r;
meta_future.meta_p_time <= meta_time; meta_future.meta_cache <= meta_current.meta_fifo_data;
meta_future.meta_cache <= meta_fifo_data;
if( meta_current.dma_downcount = NUM_STREAMS ) then if( meta_current.dma_downcount = NUM_STREAMS ) then
meta_future.dma_downcount <= 0; meta_future.dma_downcount <= 0;
end if; end if;
if( fifo_current.ch_shift = 0 ) then 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 (packet_en = '1' and packet_ready = '1') ) ) then
meta_future.meta_read <= '1'; meta_future.meta_read <= '1';
meta_future.state <= META_WAIT; 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'; meta_future.meta_time_go <= '0';
else else
meta_future.meta_time_go <= '1'; meta_future.meta_time_go <= '1';

View file

@ -119,6 +119,8 @@ architecture simple of fifo_writer is
fifo_write : std_logic; fifo_write : std_logic;
fifo_data : unsigned(fifo_data'range); fifo_data : unsigned(fifo_data'range);
samples_left : natural range 0 to in_sample_controls'length; samples_left : natural range 0 to in_sample_controls'length;
in_sample_controls_r: sample_controls_t(0 to NUM_STREAMS-1);
in_samples_r : sample_streams_t(0 to NUM_STREAMS-1);
eight_bit_delay : std_logic; eight_bit_delay : std_logic;
end record; end record;
@ -128,6 +130,8 @@ architecture simple of fifo_writer is
fifo_write => '0', fifo_write => '0',
fifo_data => (others => '-'), fifo_data => (others => '-'),
samples_left => 0, samples_left => 0,
in_sample_controls_r=> (others => SAMPLE_CONTROL_DISABLE),
in_samples_r => (others => ZERO_SAMPLE),
eight_bit_delay => '0' eight_bit_delay => '0'
); );
@ -136,6 +140,9 @@ architecture simple of fifo_writer is
signal sync_mini_exp: std_logic_vector(1 downto 0); 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 begin
-- Throw an error if port widths don't make sense -- Throw an error if port widths don't make sense
@ -167,11 +174,21 @@ begin
if( reset = '1' ) then if( reset = '1' ) then
fifo_enough <= false; fifo_enough <= false;
fifo_used_v := (others => '0'); fifo_used_v := (others => '0');
meta_fifo_used_v_r <= (others => '0');
fifo_used_v_r <= (others => '0');
elsif( rising_edge(clock) ) then 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 := unsigned(fifo_full & fifo_usedw);
fifo_used_v_r <= fifo_used_v;
meta_fifo_used_v := unsigned(meta_fifo_full & meta_fifo_usedw); 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_fifo_used_v_r <= meta_fifo_used_v;
( ( meta_en = '1' and meta_fifo_full = '0' and ( META_MAX - 4 ) > 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 or (meta_en = '0') ) ) then
fifo_enough <= true; fifo_enough <= true;
else else
@ -263,11 +280,10 @@ begin
when META_WRITE => when META_WRITE =>
for i in in_samples'range loop 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_write <= '1';
meta_future.meta_written <= '1'; meta_future.meta_written <= '1';
meta_future.state <= META_DOWNCOUNT; meta_future.state <= META_DOWNCOUNT;
exit; -- Exit loop after first match
end if; end if;
end loop; end loop;
@ -414,6 +430,48 @@ begin
return rv; return rv;
end function; end function;
procedure handle_fifo_write(
signal fifo_current : in fifo_fsm_t;
signal meta_current : in meta_fsm_t;
signal meta_en : in std_logic;
signal eight_bit_mode_en : in std_logic;
variable write_req : out std_logic;
signal fifo_future : out fifo_fsm_t
) is
variable in_sample_controls : sample_controls_t(0 to NUM_STREAMS-1);
variable in_samples : sample_streams_t(0 to NUM_STREAMS-1);
begin
in_sample_controls := fifo_current.in_sample_controls_r;
in_samples := fifo_current.in_samples_r;
if( ((meta_current.meta_written = '1') or (meta_en = '0')) ) then
-- Check for valid data
write_req := '0';
for i in in_sample_controls'range loop
if( in_sample_controls(i).enable = '1' ) then
write_req := write_req or in_samples(i).data_v;
end if;
end loop;
-- Received valid data
if( write_req = '1' ) then
if( fifo_current.samples_left = 0 ) then
fifo_future.samples_left <= NUM_STREAMS - count_enabled_channels(in_sample_controls);
if( eight_bit_mode_en = '1' ) then
fifo_future.fifo_write <= write_req and fifo_current.eight_bit_delay;
fifo_future.eight_bit_delay <= not fifo_current.eight_bit_delay;
else
fifo_future.fifo_write <= write_req;
end if;
else
-- MIMO PACKER: STEP 3 of 3
fifo_future.samples_left <= fifo_current.samples_left - 1;
end if;
end if;
else
fifo_future.fifo_write <= '0';
end if;
end;
variable write_req : std_logic := '0'; variable write_req : std_logic := '0';
@ -424,12 +482,19 @@ begin
fifo_future.fifo_clear <= '0'; fifo_future.fifo_clear <= '0';
fifo_future.fifo_write <= '0'; fifo_future.fifo_write <= '0';
fifo_future.in_samples_r <= in_samples;
fifo_future.in_sample_controls_r <= in_sample_controls;
-- MIMO PACKER: STEP 1 of 3 -- MIMO PACKER: STEP 1 of 3
if( packet_en = '0' ) then if( packet_en = '0' ) then
if( eight_bit_mode_en = '1' ) then if( eight_bit_mode_en = '1' ) then
fifo_future.fifo_data <= pack_eight_bit_mode(in_sample_controls, in_samples, fifo_current.fifo_data); fifo_future.fifo_data <= pack_eight_bit_mode(fifo_current.in_sample_controls_r,
fifo_current.in_samples_r,
fifo_current.fifo_data);
else else
fifo_future.fifo_data <= pack(in_sample_controls, in_samples, fifo_current.fifo_data); fifo_future.fifo_data <= pack(fifo_current.in_sample_controls_r,
fifo_current.in_samples_r,
fifo_current.fifo_data);
end if; end if;
end if; end if;
@ -499,34 +564,14 @@ begin
when WRITE_SAMPLES => when WRITE_SAMPLES =>
if( ((meta_current.meta_written = '1') or (meta_en = '0')) ) then handle_fifo_write(
fifo_current => fifo_current,
-- Check for valid data meta_current => meta_current,
write_req := '0'; meta_en => meta_en,
for i in in_sample_controls'range loop eight_bit_mode_en => eight_bit_mode_en,
if( in_sample_controls(i).enable = '1' ) then write_req => write_req,
write_req := write_req or in_samples(i).data_v; fifo_future => fifo_future
end if; );
end loop;
-- Received valid data
if( write_req = '1' ) then
if( fifo_current.samples_left = 0 ) then
fifo_future.samples_left <= NUM_STREAMS - count_enabled_channels(in_sample_controls);
if( eight_bit_mode_en = '1' ) then
fifo_future.fifo_write <= write_req and fifo_current.eight_bit_delay;
fifo_future.eight_bit_delay <= not fifo_current.eight_bit_delay;
else
fifo_future.fifo_write <= write_req;
end if;
else
-- MIMO PACKER: STEP 3 of 3
fifo_future.samples_left <= fifo_current.samples_left - 1;
end if;
end if;
else
fifo_future.fifo_write <= '0';
end if;
if( fifo_full = '1' or ( meta_current.meta_written = '0' and meta_en = '1') ) then if( fifo_full = '1' or ( meta_current.meta_written = '0' and meta_en = '1') ) then
fifo_future.fifo_write <= '0'; fifo_future.fifo_write <= '0';
@ -537,6 +582,16 @@ begin
if( fifo_enough ) then if( fifo_enough ) then
fifo_future.state <= WRITE_SAMPLES; fifo_future.state <= WRITE_SAMPLES;
handle_fifo_write(
fifo_current => fifo_current,
meta_current => meta_current,
meta_en => meta_en,
eight_bit_mode_en => eight_bit_mode_en,
write_req => write_req,
fifo_future => fifo_future
);
end if; end if;
when others => when others =>

View file

@ -8,6 +8,7 @@ set opencores_ip [file normalize [file join $here ../../ip/opencores]]
# Altera IP # Altera IP
set_global_assignment -name VHDL_FILE [file normalize [file join $altera_ip common_dcfifo/common_dcfifo.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $altera_ip common_dcfifo/common_dcfifo.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $altera_ip clk_ctrl/clk_ctrl.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/wrappers/tx_fifo.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/wrappers/tx_fifo.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/wrappers/tx_meta_fifo.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/wrappers/tx_meta_fifo.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/wrappers/rx_fifo.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/wrappers/rx_fifo.vhd]]

View file

@ -71,7 +71,7 @@ set_false_path -from exp_present -to *
set_false_path -from pwr_status -to * set_false_path -from pwr_status -to *
# JTAG settings # 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_clock_groups -asynchronous -group {altera_reserved_tck}
set_false_path -from [get_ports {altera_reserved_tms}] set_false_path -from [get_ports {altera_reserved_tms}]
set_false_path -from [get_ports {altera_reserved_tdi}] set_false_path -from [get_ports {altera_reserved_tdi}]

View file

@ -39,10 +39,12 @@ architecture hosted_bladerf of bladerf is
signal sys_reset : std_logic; signal sys_reset : std_logic;
signal sys_clock : std_logic; signal sys_clock : std_logic;
signal sys_clock_out : std_logic;
signal sys_pll_locked : std_logic; signal sys_pll_locked : std_logic;
signal sys_pll_reset : std_logic; signal sys_pll_reset : std_logic;
signal fx3_pclk_pll : std_logic; signal fx3_pclk_pll : std_logic;
signal fx3_pclk_pll_out : std_logic;
signal fx3_pclk_pll_locked : std_logic; signal fx3_pclk_pll_locked : std_logic;
signal fx3_pclk_pll_reset : std_logic; signal fx3_pclk_pll_reset : std_logic;
@ -202,10 +204,17 @@ begin
port map ( port map (
refclk => c5_clock2, refclk => c5_clock2,
rst => sys_pll_reset, rst => sys_pll_reset,
outclk_0 => sys_clock, outclk_0 => sys_clock_out,
locked => sys_pll_locked locked => sys_pll_locked
); );
U_system_pll_ctrl : component clk_ctrl
port map (
inclk => sys_clock_out,
ena => sys_pll_locked,
outclk => sys_clock
);
U_pll_reset_pll : entity work.pll_reset U_pll_reset_pll : entity work.pll_reset
generic map ( generic map (
SYS_CLOCK_FREQ_HZ => 38_400_000, SYS_CLOCK_FREQ_HZ => 38_400_000,
@ -223,10 +232,17 @@ begin
port map ( port map (
refclk => fx3_pclk, refclk => fx3_pclk,
rst => fx3_pclk_pll_reset, rst => fx3_pclk_pll_reset,
outclk_0 => fx3_pclk_pll, outclk_0 => fx3_pclk_pll_out,
locked => fx3_pclk_pll_locked locked => fx3_pclk_pll_locked
); );
U_fx3_pll_ctrl : component clk_ctrl
port map (
inclk => fx3_pclk_pll_out,
ena => fx3_pclk_pll_locked,
outclk => fx3_pclk_pll
);
U_pll_reset_fx3_pll : entity work.pll_reset U_pll_reset_fx3_pll : entity work.pll_reset
generic map ( generic map (
SYS_CLOCK_FREQ_HZ => 100_000_000, SYS_CLOCK_FREQ_HZ => 100_000_000,

View file

@ -50,6 +50,14 @@ package bladerf_p is
); );
end component; end component;
component clk_ctrl
port (
inclk :in std_logic;
ena :in std_logic;
outclk :out std_logic
);
end component;
component nios_system is component nios_system is
port ( port (
clk_clk : in std_logic := 'X'; clk_clk : in std_logic := 'X';

View file

@ -27,6 +27,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h>
#include "system.h" #include "system.h"
#include "altera_avalon_spi.h" #include "altera_avalon_spi.h"
@ -41,7 +42,23 @@ static inline uint32_t control_reg_read(void)
static inline void control_reg_write(uint32_t value) static inline void control_reg_write(uint32_t value)
{ {
const size_t CFG_GPIO_CLOCK_SELECT = 18; // Refer to bladerf2_common.h
const uint32_t CLK_SEL_MASK = (1 << CFG_GPIO_CLOCK_SELECT);
uint32_t current_clock_select, requested_clock_select;
bool delay_nios_response = false;
current_clock_select = control_reg_read() & CLK_SEL_MASK;
requested_clock_select = value & CLK_SEL_MASK;
delay_nios_response = current_clock_select != requested_clock_select;
IOWR_ALTERA_AVALON_PIO_DATA(CONTROL_BASE, value); IOWR_ALTERA_AVALON_PIO_DATA(CONTROL_BASE, value);
// Adding a delay to allow the Nios and FX3 Plls
// to stabilize before we send back the Nios response.
if (delay_nios_response) {
DBG("__resp_delay__");
usleep(5);
}
} }
static inline uint32_t rffe_csr_read(void) static inline uint32_t rffe_csr_read(void)