Compare commits

..

4 commits

Author SHA1 Message Date
Ryan Thompson
86ef50e210 nios: added support for more fastlock profiles
Only supported by the xA9 FPGA given the addition M10K blocks required.
2024-12-06 08:20:21 -06:00
Ryan Thompson
42cda64a98 nios: added quick tune debug print for late timestamps
In the case the fastlock AD9361 SPI writes are too slow, we make sure
the requested timestamp is in the future before assigning the next
fastlock profile.
2024-12-06 08:20:21 -06:00
Ryan Thompson
2a109c9af2 nios: fixed num profile mask to support uint16_t
This relieves the silent 256 profile limit.
2024-12-06 08:20:21 -06:00
Ryan Thompson
979c175891 test: added scheduled ahead test
This test schedules N retunes ahead. This will test the max number
of profiles that the nios core can hold.
2024-12-06 08:20:21 -06:00
293 changed files with 11242 additions and 8606 deletions

3
.gitignore vendored
View file

@ -57,8 +57,5 @@ host/misc/windows/scripts/work
env/
venv/
ENV/
__pycache__/
*.py[cod]
*$py.class
.vscode/

3
.gitmodules vendored
View file

@ -1,6 +1,3 @@
[submodule "thirdparty/analogdevicesinc/no-OS"]
path = thirdparty/analogdevicesinc/no-OS
url = https://github.com/analogdevicesinc/no-OS/
[submodule "host/utilities/bladeRF-fsk"]
path = host/utilities/bladeRF-fsk
url = https://github.com/Nuand/bladeRF-fsk

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10...3.27)
cmake_minimum_required(VERSION 3.5)
project(bladeRF CXX C)
# Indicate that this is a top-level build
set(BLADERF_TOP_LEVEL_BUILD ON)

View file

@ -1,7 +1,7 @@
#!/bin/sh -e
UPSTREAM='https://www.nuand.com/fx3/bladeRF_fw_v2.6.0.img'
CHECKSUM='7cc51b4eedebf54dd01be83745d1c59f'
UPSTREAM='https://www.nuand.com/fx3/bladeRF_fw_v2.4.0.img'
CHECKSUM='337f570f2e3fdb26abde0f0765196d92'
DATAFILE='/usr/share/Nuand/bladeRF/bladeRF_fw.img'
DESCRIPT='firmware'
MYNAMEIS='bladerf-firmware-fx3'

View file

@ -1,7 +1,7 @@
#!/bin/sh -e
UPSTREAM='https://www.nuand.com/fpga/v0.16.0/hostedx115.rbf'
CHECKSUM='a7f25be8abdab3835e734599eb846ea4'
UPSTREAM='https://www.nuand.com/fpga/v0.14.0/hostedx115.rbf'
CHECKSUM='94ee5c7f68abe5c3392202246789fedd'
DATAFILE='/usr/share/Nuand/bladeRF/hostedx115.rbf'
DESCRIPT='FPGA bitstream'
MYNAMEIS='bladerf-fpga-hostedx115'

View file

@ -1,7 +1,7 @@
#!/bin/sh -e
UPSTREAM='https://www.nuand.com/fpga/v0.16.0/hostedx40.rbf'
CHECKSUM='f3d0e55aa4cae485df6d3c20004b7742'
UPSTREAM='https://www.nuand.com/fpga/v0.14.0/hostedx40.rbf'
CHECKSUM='25f402b3734c9aa0d37db9531f93335c'
DATAFILE='/usr/share/Nuand/bladeRF/hostedx40.rbf'
DESCRIPT='FPGA bitstream'
MYNAMEIS='bladerf-fpga-hostedx40'

View file

@ -1,7 +1,7 @@
#!/bin/sh -e
UPSTREAM='https://www.nuand.com/fpga/v0.16.0/hostedxA4.rbf'
CHECKSUM='276a74b748d699a9fc348babd34af19c'
UPSTREAM='https://www.nuand.com/fpga/v0.14.0/hostedxA4.rbf'
CHECKSUM='c24af70cf56b13123295125a22d5e921'
DATAFILE='/usr/share/Nuand/bladeRF/hostedxA4.rbf'
DESCRIPT='FPGA bitstream'
MYNAMEIS='bladerf-fpga-hostedxa4'

View file

@ -1,7 +1,7 @@
#!/bin/sh -e
UPSTREAM='https://www.nuand.com/fpga/v0.16.0/hostedxA5.rbf'
CHECKSUM='be0909dc27b48a08c54db33675130f27'
UPSTREAM='https://www.nuand.com/fpga/v0.14.0/hostedxA5.rbf'
CHECKSUM='ae6391cc3fd467bbb07868450612ce17'
DATAFILE='/usr/share/Nuand/bladeRF/hostedxA5.rbf'
DESCRIPT='FPGA bitstream'
MYNAMEIS='bladerf-fpga-hostedxa5'

View file

@ -1,7 +1,7 @@
#!/bin/sh -e
UPSTREAM='https://www.nuand.com/fpga/v0.16.0/hostedxA9.rbf'
CHECKSUM='1ab3bc8bdcf16a5f0ddf3fcdbaa6556b'
UPSTREAM='https://www.nuand.com/fpga/v0.14.0/hostedxA9.rbf'
CHECKSUM='7dfe8c32f260d43a14b9583375a1a6eb'
DATAFILE='/usr/share/Nuand/bladeRF/hostedxA9.rbf'
DESCRIPT='FPGA bitstream'
MYNAMEIS='bladerf-fpga-hostedxa9'

4
debian/control vendored
View file

@ -2,8 +2,8 @@ Source: bladerf
Priority: optional
Maintainer: Nuand LLC <bladeRF@nuand.com>
Build-Depends: debhelper (>=9), cmake (>= 2.8.5), pkg-config, doxygen,
libusb-1.0-0-dev (>= 1.0.12), libedit-dev, libncurses5-dev,
git, help2man, pandoc, libcurl4-openssl-dev
libusb-1.0-0-dev (>= 1.0.12), libtecla-dev | libtecla1-dev, libncurses5-dev,
git, help2man, pandoc
Standards-Version: 4.1.4
Section: comm
Homepage: https://www.nuand.com/bladeRF

11
debian/copyright vendored
View file

@ -60,6 +60,17 @@ License: OpenCores-I2C
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Files: host/cmake/modules/FindLibPThreadsWin32.cmake
Copyright: 2008-2009 Hendrik Sattler
2013-2018 Nuand LLC
License: GPL-2+
Comment: This is file is based off of the FindLibUSB.cmake file written by
Hendrik Sattler, from the OpenOBEX project (licensed GPLv2/LGPL). (If
this is not correct, please contact us so we can attribute the author
appropriately.)
https://github.com/zuckschwerdt/openobex/blob/master/CMakeModules/FindLibUSB.cmake
http://dev.zuckschwerdt.org/openobex/
Files: host/cmake/modules/FindLibUSB.cmake
Copyright: 2008-2009 Hendrik Sattler
2013-2018 Nuand LLC

View file

@ -29,8 +29,6 @@
#include <inttypes.h>
#include <stdbool.h>
#include <ad9361_api.h>
/**
* The purpose of this header file is to allow the use of libad9361 without
* including all of the unnecessary defines, etc, used during compilation.
@ -48,6 +46,15 @@
* From common.h
******************************************************************************/
struct clk_onecell_data {
struct clk **clks;
uint32_t clk_num;
};
/******************************************************************************
* From ad9361.h
******************************************************************************/
#define AD936X_REG_TX1_OUT_1_PHASE_CORR 0x08E
#define AD936X_REG_TX1_OUT_1_GAIN_CORR 0x08F
#define AD936X_REG_TX2_OUT_1_PHASE_CORR 0x090
@ -91,6 +98,681 @@
#define AD936X_CNT(x) ((((x)-1) & 0x7) << 12)
#define AD936X_ADDR(x) ((x)&0x3FF)
enum dev_id { ID_AD9361, ID_AD9364, ID_AD9363A };
enum ad9361_clocks {
BB_REFCLK,
RX_REFCLK,
TX_REFCLK,
BBPLL_CLK,
ADC_CLK,
R2_CLK,
R1_CLK,
CLKRF_CLK,
RX_SAMPL_CLK,
DAC_CLK,
T2_CLK,
T1_CLK,
CLKTF_CLK,
TX_SAMPL_CLK,
RX_RFPLL_INT,
TX_RFPLL_INT,
RX_RFPLL_DUMMY,
TX_RFPLL_DUMMY,
RX_RFPLL,
TX_RFPLL,
NUM_AD9361_CLKS,
EXT_REF_CLK,
};
enum rx_gain_table_name {
TBL_200_1300_MHZ,
TBL_1300_4000_MHZ,
TBL_4000_6000_MHZ,
RXGAIN_TBLS_END,
};
enum rx_gain_table_type {
RXGAIN_FULL_TBL,
RXGAIN_SPLIT_TBL,
};
struct rx_gain_info {
enum rx_gain_table_type tbl_type;
int32_t starting_gain_db;
int32_t max_gain_db;
int32_t gain_step_db;
int32_t max_idx;
int32_t idx_step_offset;
};
enum ad9361_pdata_rx_freq {
BBPLL_FREQ,
ADC_FREQ,
R2_FREQ,
R1_FREQ,
CLKRF_FREQ,
RX_SAMPL_FREQ,
NUM_RX_CLOCKS,
};
enum ad9361_pdata_tx_freq {
IGNORE_FREQ,
DAC_FREQ,
T2_FREQ,
T1_FREQ,
CLKTF_FREQ,
TX_SAMPL_FREQ,
NUM_TX_CLOCKS,
};
struct ad9361_fastlock_entry {
//#define FASTLOOK_INIT 1
uint8_t flags;
uint8_t alc_orig;
uint8_t alc_written;
};
struct ad9361_fastlock {
uint8_t save_profile;
uint8_t current_profile[2];
struct ad9361_fastlock_entry entry[2][8];
};
enum ad9361_bist_mode {
BIST_DISABLE,
BIST_INJ_TX,
BIST_INJ_RX,
};
enum ad9361_clkout {
CLKOUT_DISABLE,
BUFFERED_XTALN_DCXO,
ADC_CLK_DIV_2,
ADC_CLK_DIV_3,
ADC_CLK_DIV_4,
ADC_CLK_DIV_8,
ADC_CLK_DIV_16,
};
enum rf_gain_ctrl_mode {
RF_GAIN_MGC,
RF_GAIN_FASTATTACK_AGC,
RF_GAIN_SLOWATTACK_AGC,
RF_GAIN_HYBRID_AGC
};
enum f_agc_target_gain_index_type {
MAX_GAIN,
SET_GAIN,
OPTIMIZED_GAIN,
NO_GAIN_CHANGE,
};
enum rssi_restart_mode {
AGC_IN_FAST_ATTACK_MODE_LOCKS_THE_GAIN,
EN_AGC_PIN_IS_PULLED_HIGH,
ENTERS_RX_MODE,
GAIN_CHANGE_OCCURS,
SPI_WRITE_TO_REGISTER,
GAIN_CHANGE_OCCURS_OR_EN_AGC_PIN_PULLED_HIGH,
};
struct rssi_control {
enum rssi_restart_mode restart_mode;
bool rssi_unit_is_rx_samples;
uint32_t rssi_delay;
uint32_t rssi_wait;
uint32_t rssi_duration;
};
struct port_control {
uint8_t pp_conf[3];
uint8_t rx_clk_data_delay;
uint8_t tx_clk_data_delay;
uint8_t digital_io_ctrl;
uint8_t lvds_bias_ctrl;
uint8_t lvds_invert[2];
uint8_t clk_out_drive;
uint8_t dataclk_drive;
uint8_t data_port_drive;
uint8_t clk_out_slew;
uint8_t dataclk_slew;
uint8_t data_port_slew;
};
struct ctrl_outs_control {
uint8_t index;
uint8_t en_mask;
};
struct elna_control {
uint16_t gain_mdB;
uint16_t bypass_loss_mdB;
uint32_t settling_delay_ns;
bool elna_1_control_en;
bool elna_2_control_en;
bool elna_in_gaintable_all_index_en;
};
struct auxadc_control {
int8_t offset;
uint32_t temp_time_inteval_ms;
uint32_t temp_sensor_decimation;
bool periodic_temp_measuremnt;
uint32_t auxadc_clock_rate;
uint32_t auxadc_decimation;
};
struct auxdac_control {
uint16_t dac1_default_value;
uint16_t dac2_default_value;
bool auxdac_manual_mode_en;
bool dac1_in_rx_en;
bool dac1_in_tx_en;
bool dac1_in_alert_en;
bool dac2_in_rx_en;
bool dac2_in_tx_en;
bool dac2_in_alert_en;
uint8_t dac1_rx_delay_us;
uint8_t dac1_tx_delay_us;
uint8_t dac2_rx_delay_us;
uint8_t dac2_tx_delay_us;
};
struct gpo_control {
bool gpo0_inactive_state_high_en;
bool gpo1_inactive_state_high_en;
bool gpo2_inactive_state_high_en;
bool gpo3_inactive_state_high_en;
bool gpo0_slave_rx_en;
bool gpo0_slave_tx_en;
bool gpo1_slave_rx_en;
bool gpo1_slave_tx_en;
bool gpo2_slave_rx_en;
bool gpo2_slave_tx_en;
bool gpo3_slave_rx_en;
bool gpo3_slave_tx_en;
uint8_t gpo0_rx_delay_us;
uint8_t gpo0_tx_delay_us;
uint8_t gpo1_rx_delay_us;
uint8_t gpo1_tx_delay_us;
uint8_t gpo2_rx_delay_us;
uint8_t gpo2_tx_delay_us;
uint8_t gpo3_rx_delay_us;
uint8_t gpo3_tx_delay_us;
};
struct tx_monitor_control {
bool tx_mon_track_en;
bool one_shot_mode_en;
uint32_t low_high_gain_threshold_mdB;
uint8_t low_gain_dB;
uint8_t high_gain_dB;
uint16_t tx_mon_delay;
uint16_t tx_mon_duration;
uint8_t tx1_mon_front_end_gain;
uint8_t tx2_mon_front_end_gain;
uint8_t tx1_mon_lo_cm;
uint8_t tx2_mon_lo_cm;
};
struct gain_control {
enum rf_gain_ctrl_mode rx1_mode;
enum rf_gain_ctrl_mode rx2_mode;
uint8_t adc_ovr_sample_size;
uint8_t adc_small_overload_thresh;
uint8_t adc_large_overload_thresh;
uint16_t lmt_overload_high_thresh;
uint16_t lmt_overload_low_thresh;
uint16_t dec_pow_measuremnt_duration;
uint8_t low_power_thresh;
bool dig_gain_en;
uint8_t max_dig_gain;
bool mgc_rx1_ctrl_inp_en;
bool mgc_rx2_ctrl_inp_en;
uint8_t mgc_inc_gain_step;
uint8_t mgc_dec_gain_step;
uint8_t mgc_split_table_ctrl_inp_gain_mode;
uint8_t agc_attack_delay_extra_margin_us;
uint8_t agc_outer_thresh_high;
uint8_t agc_outer_thresh_high_dec_steps;
uint8_t agc_inner_thresh_high;
uint8_t agc_inner_thresh_high_dec_steps;
uint8_t agc_inner_thresh_low;
uint8_t agc_inner_thresh_low_inc_steps;
uint8_t agc_outer_thresh_low;
uint8_t agc_outer_thresh_low_inc_steps;
uint8_t adc_small_overload_exceed_counter;
uint8_t adc_large_overload_exceed_counter;
uint8_t adc_large_overload_inc_steps;
bool adc_lmt_small_overload_prevent_gain_inc;
uint8_t lmt_overload_large_exceed_counter;
uint8_t lmt_overload_small_exceed_counter;
uint8_t lmt_overload_large_inc_steps;
uint8_t dig_saturation_exceed_counter;
uint8_t dig_gain_step_size;
bool sync_for_gain_counter_en;
uint32_t gain_update_interval_us;
bool immed_gain_change_if_large_adc_overload;
bool immed_gain_change_if_large_lmt_overload;
uint32_t f_agc_dec_pow_measuremnt_duration;
uint32_t f_agc_state_wait_time_ns;
bool f_agc_allow_agc_gain_increase;
uint8_t f_agc_lp_thresh_increment_time;
uint8_t f_agc_lp_thresh_increment_steps;
uint8_t f_agc_lock_level;
bool f_agc_lock_level_lmt_gain_increase_en;
uint8_t f_agc_lock_level_gain_increase_upper_limit;
uint8_t f_agc_lpf_final_settling_steps;
uint8_t f_agc_lmt_final_settling_steps;
uint8_t f_agc_final_overrange_count;
bool f_agc_gain_increase_after_gain_lock_en;
enum f_agc_target_gain_index_type f_agc_gain_index_type_after_exit_rx_mode;
bool f_agc_use_last_lock_level_for_set_gain_en;
uint8_t f_agc_optimized_gain_offset;
bool f_agc_rst_gla_stronger_sig_thresh_exceeded_en;
uint8_t f_agc_rst_gla_stronger_sig_thresh_above_ll;
bool f_agc_rst_gla_engergy_lost_sig_thresh_exceeded_en;
bool f_agc_rst_gla_engergy_lost_goto_optim_gain_en;
uint8_t f_agc_rst_gla_engergy_lost_sig_thresh_below_ll;
uint8_t f_agc_energy_lost_stronger_sig_gain_lock_exit_cnt;
bool f_agc_rst_gla_large_adc_overload_en;
bool f_agc_rst_gla_large_lmt_overload_en;
bool f_agc_rst_gla_en_agc_pulled_high_en;
enum f_agc_target_gain_index_type f_agc_rst_gla_if_en_agc_pulled_high_mode;
uint8_t f_agc_power_measurement_duration_in_state5;
};
struct ad9361_phy_platform_data {
bool rx2tx2;
bool fdd;
bool fdd_independent_mode;
bool split_gt;
bool use_extclk;
bool ensm_pin_pulse_mode;
bool ensm_pin_ctrl;
bool debug_mode;
bool tdd_use_dual_synth;
bool tdd_skip_vco_cal;
bool use_ext_rx_lo;
bool use_ext_tx_lo;
bool rx1rx2_phase_inversion_en;
bool qec_tracking_slow_mode_en;
uint8_t dc_offset_update_events;
uint8_t dc_offset_attenuation_high;
uint8_t dc_offset_attenuation_low;
uint8_t rf_dc_offset_count_high;
uint8_t rf_dc_offset_count_low;
uint8_t dig_interface_tune_skipmode;
uint8_t dig_interface_tune_fir_disable;
uint32_t dcxo_coarse;
uint32_t dcxo_fine;
uint32_t rf_rx_input_sel;
uint32_t rf_tx_output_sel;
uint32_t rx1tx1_mode_use_rx_num;
uint32_t rx1tx1_mode_use_tx_num;
uint32_t rx_path_clks[NUM_RX_CLOCKS];
uint32_t tx_path_clks[NUM_TX_CLOCKS];
uint32_t trx_synth_max_fref;
uint64_t rx_synth_freq;
uint64_t tx_synth_freq;
uint32_t rf_rx_bandwidth_Hz;
uint32_t rf_tx_bandwidth_Hz;
int32_t tx_atten;
bool update_tx_gain_via_alert;
uint32_t rx_fastlock_delay_ns;
uint32_t tx_fastlock_delay_ns;
bool trx_fastlock_pinctrl_en[2];
enum ad9361_clkout ad9361_clkout_mode;
struct gain_control gain_ctrl;
struct rssi_control rssi_ctrl;
struct port_control port_ctrl;
struct ctrl_outs_control ctrl_outs_ctrl;
struct elna_control elna_ctrl;
struct auxadc_control auxadc_ctrl;
struct auxdac_control auxdac_ctrl;
struct gpo_control gpo_ctrl;
struct tx_monitor_control txmon_ctrl;
int32_t gpio_resetb;
int32_t gpio_sync;
int32_t gpio_cal_sw1;
int32_t gpio_cal_sw2;
};
struct ad9361_rf_phy {
enum dev_id dev_sel;
uint8_t id_no;
struct spi_device *spi;
struct gpio_device *gpio;
struct clk *clk_refin;
struct clk *clks[NUM_AD9361_CLKS];
struct refclk_scale *ref_clk_scale[NUM_AD9361_CLKS];
struct clk_onecell_data clk_data;
uint32_t (*ad9361_rfpll_ext_recalc_rate)(struct refclk_scale *clk_priv);
int32_t (*ad9361_rfpll_ext_round_rate)(struct refclk_scale *clk_priv,
uint32_t rate);
int32_t (*ad9361_rfpll_ext_set_rate)(struct refclk_scale *clk_priv,
uint32_t rate);
struct ad9361_phy_platform_data *pdata;
uint8_t prev_ensm_state;
uint8_t curr_ensm_state;
uint8_t cached_rx_rfpll_div;
uint8_t cached_tx_rfpll_div;
struct rx_gain_info rx_gain[RXGAIN_TBLS_END];
enum rx_gain_table_name current_table;
bool ensm_pin_ctl_en;
bool auto_cal_en;
uint64_t last_tx_quad_cal_freq;
uint32_t last_tx_quad_cal_phase;
uint64_t current_tx_lo_freq;
uint64_t current_rx_lo_freq;
bool current_tx_use_tdd_table;
bool current_rx_use_tdd_table;
uint32_t flags;
uint32_t cal_threshold_freq;
uint32_t current_rx_bw_Hz;
uint32_t current_tx_bw_Hz;
uint32_t rxbbf_div;
uint32_t rate_governor;
bool bypass_rx_fir;
bool bypass_tx_fir;
bool rx_eq_2tx;
bool filt_valid;
uint32_t filt_rx_path_clks[NUM_RX_CLOCKS];
uint32_t filt_tx_path_clks[NUM_TX_CLOCKS];
uint32_t filt_rx_bw_Hz;
uint32_t filt_tx_bw_Hz;
uint8_t tx_fir_int;
uint8_t tx_fir_ntaps;
uint8_t rx_fir_dec;
uint8_t rx_fir_ntaps;
uint8_t agc_mode[2];
bool rfdc_track_en;
bool bbdc_track_en;
bool quad_track_en;
bool txmon_tdd_en;
uint16_t auxdac1_value;
uint16_t auxdac2_value;
uint32_t tx1_atten_cached;
uint32_t tx2_atten_cached;
struct ad9361_fastlock fastlock;
struct axiadc_converter *adc_conv;
struct axiadc_state *adc_state;
int32_t bist_loopback_mode;
enum ad9361_bist_mode bist_prbs_mode;
enum ad9361_bist_mode bist_tone_mode;
uint32_t bist_tone_freq_Hz;
uint32_t bist_tone_level_dB;
uint32_t bist_tone_mask;
bool bbpll_initialized;
};
struct rf_rx_gain {
uint32_t ant;
int32_t gain_db;
uint32_t fgt_lmt_index;
uint32_t lmt_gain;
uint32_t lpf_gain;
uint32_t digital_gain;
uint32_t lna_index;
uint32_t tia_index;
uint32_t mixer_index;
};
struct rf_rssi {
uint32_t ant;
uint32_t symbol;
uint32_t preamble;
int32_t multiplier;
uint8_t duration;
};
int32_t ad9361_get_rx_gain(struct ad9361_rf_phy *phy,
uint32_t rx_id,
struct rf_rx_gain *rx_gain);
int32_t ad9361_spi_read(struct spi_device *spi, uint32_t reg);
int32_t ad9361_spi_write(struct spi_device *spi, uint32_t reg, uint32_t val);
void ad9361_get_bist_loopback(struct ad9361_rf_phy *phy, int32_t *mode);
int32_t ad9361_bist_loopback(struct ad9361_rf_phy *phy, int32_t mode);
/******************************************************************************
* From ad9361_api.h
******************************************************************************/
typedef struct {
enum dev_id dev_sel;
uint8_t id_no;
uint32_t reference_clk_rate;
uint8_t two_rx_two_tx_mode_enable;
uint8_t one_rx_one_tx_mode_use_rx_num;
uint8_t one_rx_one_tx_mode_use_tx_num;
uint8_t frequency_division_duplex_mode_enable;
uint8_t frequency_division_duplex_independent_mode_enable;
uint8_t tdd_use_dual_synth_mode_enable;
uint8_t tdd_skip_vco_cal_enable;
uint32_t tx_fastlock_delay_ns;
uint32_t rx_fastlock_delay_ns;
uint8_t rx_fastlock_pincontrol_enable;
uint8_t tx_fastlock_pincontrol_enable;
uint8_t external_rx_lo_enable;
uint8_t external_tx_lo_enable;
uint8_t dc_offset_tracking_update_event_mask;
uint8_t dc_offset_attenuation_high_range;
uint8_t dc_offset_attenuation_low_range;
uint8_t dc_offset_count_high_range;
uint8_t dc_offset_count_low_range;
uint8_t split_gain_table_mode_enable;
uint32_t trx_synthesizer_target_fref_overwrite_hz;
uint8_t qec_tracking_slow_mode_enable;
uint8_t ensm_enable_pin_pulse_mode_enable;
uint8_t ensm_enable_txnrx_control_enable;
uint64_t rx_synthesizer_frequency_hz;
uint64_t tx_synthesizer_frequency_hz;
uint32_t rx_path_clock_frequencies[6];
uint32_t tx_path_clock_frequencies[6];
uint32_t rf_rx_bandwidth_hz;
uint32_t rf_tx_bandwidth_hz;
uint32_t rx_rf_port_input_select;
uint32_t tx_rf_port_input_select;
int32_t tx_attenuation_mdB;
uint8_t update_tx_gain_in_alert_enable;
uint8_t xo_disable_use_ext_refclk_enable;
uint32_t dcxo_coarse_and_fine_tune[2];
uint32_t clk_output_mode_select;
uint8_t gc_rx1_mode;
uint8_t gc_rx2_mode;
uint8_t gc_adc_large_overload_thresh;
uint8_t gc_adc_ovr_sample_size;
uint8_t gc_adc_small_overload_thresh;
uint16_t gc_dec_pow_measurement_duration;
uint8_t gc_dig_gain_enable;
uint16_t gc_lmt_overload_high_thresh;
uint16_t gc_lmt_overload_low_thresh;
uint8_t gc_low_power_thresh;
uint8_t gc_max_dig_gain;
uint8_t mgc_dec_gain_step;
uint8_t mgc_inc_gain_step;
uint8_t mgc_rx1_ctrl_inp_enable;
uint8_t mgc_rx2_ctrl_inp_enable;
uint8_t mgc_split_table_ctrl_inp_gain_mode;
uint8_t agc_adc_large_overload_exceed_counter;
uint8_t agc_adc_large_overload_inc_steps;
uint8_t agc_adc_lmt_small_overload_prevent_gain_inc_enable;
uint8_t agc_adc_small_overload_exceed_counter;
uint8_t agc_dig_gain_step_size;
uint8_t agc_dig_saturation_exceed_counter;
uint32_t agc_gain_update_interval_us;
uint8_t agc_immed_gain_change_if_large_adc_overload_enable;
uint8_t agc_immed_gain_change_if_large_lmt_overload_enable;
uint8_t agc_inner_thresh_high;
uint8_t agc_inner_thresh_high_dec_steps;
uint8_t agc_inner_thresh_low;
uint8_t agc_inner_thresh_low_inc_steps;
uint8_t agc_lmt_overload_large_exceed_counter;
uint8_t agc_lmt_overload_large_inc_steps;
uint8_t agc_lmt_overload_small_exceed_counter;
uint8_t agc_outer_thresh_high;
uint8_t agc_outer_thresh_high_dec_steps;
uint8_t agc_outer_thresh_low;
uint8_t agc_outer_thresh_low_inc_steps;
uint32_t agc_attack_delay_extra_margin_us;
uint8_t agc_sync_for_gain_counter_enable;
uint32_t fagc_dec_pow_measuremnt_duration;
uint32_t fagc_state_wait_time_ns;
uint8_t fagc_allow_agc_gain_increase;
uint32_t fagc_lp_thresh_increment_time;
uint32_t fagc_lp_thresh_increment_steps;
uint8_t fagc_lock_level_lmt_gain_increase_en;
uint32_t fagc_lock_level_gain_increase_upper_limit;
uint32_t fagc_lpf_final_settling_steps;
uint32_t fagc_lmt_final_settling_steps;
uint32_t fagc_final_overrange_count;
uint8_t fagc_gain_increase_after_gain_lock_en;
uint32_t fagc_gain_index_type_after_exit_rx_mode;
uint8_t fagc_use_last_lock_level_for_set_gain_en;
uint8_t fagc_rst_gla_stronger_sig_thresh_exceeded_en;
uint32_t fagc_optimized_gain_offset;
uint32_t fagc_rst_gla_stronger_sig_thresh_above_ll;
uint8_t fagc_rst_gla_engergy_lost_sig_thresh_exceeded_en;
uint8_t fagc_rst_gla_engergy_lost_goto_optim_gain_en;
uint32_t fagc_rst_gla_engergy_lost_sig_thresh_below_ll;
uint32_t fagc_energy_lost_stronger_sig_gain_lock_exit_cnt;
uint8_t fagc_rst_gla_large_adc_overload_en;
uint8_t fagc_rst_gla_large_lmt_overload_en;
uint8_t fagc_rst_gla_en_agc_pulled_high_en;
uint32_t fagc_rst_gla_if_en_agc_pulled_high_mode;
uint32_t fagc_power_measurement_duration_in_state5;
uint32_t rssi_delay;
uint32_t rssi_duration;
uint8_t rssi_restart_mode;
uint8_t rssi_unit_is_rx_samples_enable;
uint32_t rssi_wait;
uint32_t aux_adc_decimation;
uint32_t aux_adc_rate;
uint8_t aux_dac_manual_mode_enable;
uint32_t aux_dac1_default_value_mV;
uint8_t aux_dac1_active_in_rx_enable;
uint8_t aux_dac1_active_in_tx_enable;
uint8_t aux_dac1_active_in_alert_enable;
uint32_t aux_dac1_rx_delay_us;
uint32_t aux_dac1_tx_delay_us;
uint32_t aux_dac2_default_value_mV;
uint8_t aux_dac2_active_in_rx_enable;
uint8_t aux_dac2_active_in_tx_enable;
uint8_t aux_dac2_active_in_alert_enable;
uint32_t aux_dac2_rx_delay_us;
uint32_t aux_dac2_tx_delay_us;
uint32_t temp_sense_decimation;
uint16_t temp_sense_measurement_interval_ms;
int8_t temp_sense_offset_signed;
uint8_t temp_sense_periodic_measurement_enable;
uint8_t ctrl_outs_enable_mask;
uint8_t ctrl_outs_index;
uint32_t elna_settling_delay_ns;
uint32_t elna_gain_mdB;
uint32_t elna_bypass_loss_mdB;
uint8_t elna_rx1_gpo0_control_enable;
uint8_t elna_rx2_gpo1_control_enable;
uint8_t elna_gaintable_all_index_enable;
uint8_t digital_interface_tune_skip_mode;
uint8_t digital_interface_tune_fir_disable;
uint8_t pp_tx_swap_enable;
uint8_t pp_rx_swap_enable;
uint8_t tx_channel_swap_enable;
uint8_t rx_channel_swap_enable;
uint8_t rx_frame_pulse_mode_enable;
uint8_t two_t_two_r_timing_enable;
uint8_t invert_data_bus_enable;
uint8_t invert_data_clk_enable;
uint8_t fdd_alt_word_order_enable;
uint8_t invert_rx_frame_enable;
uint8_t fdd_rx_rate_2tx_enable;
uint8_t swap_ports_enable;
uint8_t single_data_rate_enable;
uint8_t lvds_mode_enable;
uint8_t half_duplex_mode_enable;
uint8_t single_port_mode_enable;
uint8_t full_port_enable;
uint8_t full_duplex_swap_bits_enable;
uint32_t delay_rx_data;
uint32_t rx_data_clock_delay;
uint32_t rx_data_delay;
uint32_t tx_fb_clock_delay;
uint32_t tx_data_delay;
uint32_t lvds_bias_mV;
uint8_t lvds_rx_onchip_termination_enable;
uint8_t rx1rx2_phase_inversion_en;
uint8_t lvds_invert1_control;
uint8_t lvds_invert2_control;
uint8_t clk_out_drive;
uint8_t dataclk_drive;
uint8_t data_port_drive;
uint8_t clk_out_slew;
uint8_t dataclk_slew;
uint8_t data_port_slew;
uint8_t gpo0_inactive_state_high_enable;
uint8_t gpo1_inactive_state_high_enable;
uint8_t gpo2_inactive_state_high_enable;
uint8_t gpo3_inactive_state_high_enable;
uint8_t gpo0_slave_rx_enable;
uint8_t gpo0_slave_tx_enable;
uint8_t gpo1_slave_rx_enable;
uint8_t gpo1_slave_tx_enable;
uint8_t gpo2_slave_rx_enable;
uint8_t gpo2_slave_tx_enable;
uint8_t gpo3_slave_rx_enable;
uint8_t gpo3_slave_tx_enable;
uint8_t gpo0_rx_delay_us;
uint8_t gpo0_tx_delay_us;
uint8_t gpo1_rx_delay_us;
uint8_t gpo1_tx_delay_us;
uint8_t gpo2_rx_delay_us;
uint8_t gpo2_tx_delay_us;
uint8_t gpo3_rx_delay_us;
uint8_t gpo3_tx_delay_us;
uint32_t low_high_gain_threshold_mdB;
uint32_t low_gain_dB;
uint32_t high_gain_dB;
uint8_t tx_mon_track_en;
uint8_t one_shot_mode_en;
uint32_t tx_mon_delay;
uint32_t tx_mon_duration;
uint32_t tx1_mon_front_end_gain;
uint32_t tx2_mon_front_end_gain;
uint32_t tx1_mon_lo_cm;
uint32_t tx2_mon_lo_cm;
int32_t gpio_resetb;
int32_t gpio_sync;
int32_t gpio_cal_sw1;
int32_t gpio_cal_sw2;
uint32_t (*ad9361_rfpll_ext_recalc_rate)(struct refclk_scale *clk_priv);
int32_t (*ad9361_rfpll_ext_round_rate)(struct refclk_scale *clk_priv,
uint32_t rate);
int32_t (*ad9361_rfpll_ext_set_rate)(struct refclk_scale *clk_priv,
uint32_t rate);
} AD9361_InitParam;
typedef struct {
uint32_t rx; /* 1, 2, 3(both) */
int32_t rx_gain; /* -12, -6, 0, 6 */
uint32_t rx_dec; /* 1, 2, 4 */
int16_t rx_coef[128];
uint8_t rx_coef_size;
uint32_t rx_path_clks[6];
uint32_t rx_bandwidth;
} AD9361_RXFIRConfig;
typedef struct {
uint32_t tx; /* 1, 2, 3(both) */
int32_t tx_gain; /* -6, 0 */
uint32_t tx_int; /* 1, 2, 4 */
int16_t tx_coef[128];
uint8_t tx_coef_size;
uint32_t tx_path_clks[6];
uint32_t tx_bandwidth;
} AD9361_TXFIRConfig;
#define AD936X_A_BALANCED 0
#define AD936X_B_BALANCED 1
#define AD936X_C_BALANCED 2
@ -107,5 +789,70 @@
#define AD936X_TXA 0
#define AD936X_TXB 1
int32_t ad9361_init(struct ad9361_rf_phy **ad9361_phy,
AD9361_InitParam *init_param,
void *userdata);
int32_t ad9361_deinit(struct ad9361_rf_phy *phy);
int32_t ad9361_set_rx_rf_gain(struct ad9361_rf_phy *phy,
uint8_t ch,
int32_t gain_db);
int32_t ad9361_set_rx_rf_bandwidth(struct ad9361_rf_phy *phy,
uint32_t bandwidth_hz);
int32_t ad9361_get_rx_rf_bandwidth(struct ad9361_rf_phy *phy,
uint32_t *bandwidth_hz);
int32_t ad9361_set_rx_sampling_freq(struct ad9361_rf_phy *phy,
uint32_t sampling_freq_hz);
int32_t ad9361_get_rx_sampling_freq(struct ad9361_rf_phy *phy,
uint32_t *sampling_freq_hz);
int32_t ad9361_set_rx_lo_freq(struct ad9361_rf_phy *phy, uint64_t lo_freq_hz);
int32_t ad9361_get_rx_lo_freq(struct ad9361_rf_phy *phy, uint64_t *lo_freq_hz);
int32_t ad9361_get_rx_rssi(struct ad9361_rf_phy *phy,
uint8_t ch,
struct rf_rssi *rssi);
int32_t ad9361_set_rx_gain_control_mode(struct ad9361_rf_phy *phy,
uint8_t ch,
uint8_t gc_mode);
int32_t ad9361_get_rx_gain_control_mode(struct ad9361_rf_phy *phy,
uint8_t ch,
uint8_t *gc_mode);
int32_t ad9361_set_rx_fir_config(struct ad9361_rf_phy *phy,
AD9361_RXFIRConfig fir_cfg);
int32_t ad9361_set_rx_fir_en_dis(struct ad9361_rf_phy *phy, uint8_t en_dis);
int32_t ad9361_set_rx_rf_port_input(struct ad9361_rf_phy *phy, uint32_t mode);
int32_t ad9361_get_rx_rf_port_input(struct ad9361_rf_phy *phy, uint32_t *mode);
int32_t ad9361_set_tx_attenuation(struct ad9361_rf_phy *phy,
uint8_t ch,
uint32_t attenuation_mdb);
int32_t ad9361_get_tx_attenuation(struct ad9361_rf_phy *phy,
uint8_t ch,
uint32_t *attenuation_mdb);
int32_t ad9361_set_tx_rf_bandwidth(struct ad9361_rf_phy *phy,
uint32_t bandwidth_hz);
int32_t ad9361_get_tx_rf_bandwidth(struct ad9361_rf_phy *phy,
uint32_t *bandwidth_hz);
int32_t ad9361_set_tx_sampling_freq(struct ad9361_rf_phy *phy,
uint32_t sampling_freq_hz);
int32_t ad9361_get_tx_sampling_freq(struct ad9361_rf_phy *phy,
uint32_t *sampling_freq_hz);
int32_t ad9361_set_tx_lo_freq(struct ad9361_rf_phy *phy, uint64_t lo_freq_hz);
int32_t ad9361_get_tx_lo_freq(struct ad9361_rf_phy *phy, uint64_t *lo_freq_hz);
int32_t ad9361_set_tx_fir_config(struct ad9361_rf_phy *phy,
AD9361_TXFIRConfig fir_cfg);
int32_t ad9361_set_tx_fir_en_dis(struct ad9361_rf_phy *phy, uint8_t en_dis);
int32_t ad9361_get_tx_rssi(struct ad9361_rf_phy *phy,
uint8_t ch,
uint32_t *rssi_db_x_1000);
int32_t ad9361_set_tx_rf_port_output(struct ad9361_rf_phy *phy, uint32_t mode);
int32_t ad9361_get_tx_rf_port_output(struct ad9361_rf_phy *phy, uint32_t *mode);
int32_t ad9361_get_temp(struct ad9361_rf_phy *phy);
int32_t ad9361_rx_fastlock_store(struct ad9361_rf_phy *phy, uint32_t profile);
int32_t ad9361_rx_fastlock_save(struct ad9361_rf_phy *phy,
uint32_t profile,
uint8_t *values);
int32_t ad9361_tx_fastlock_store(struct ad9361_rf_phy *phy, uint32_t profile);
int32_t ad9361_tx_fastlock_save(struct ad9361_rf_phy *phy,
uint32_t profile,
uint8_t *values);
int32_t ad9361_set_no_ch_mode(struct ad9361_rf_phy *phy, uint8_t no_ch_mode);
#endif // AD936X_H_

View file

@ -97,7 +97,7 @@ static bladerf_frequency const RESET_FREQUENCY = 70000000;
/* Number of fast lock profiles that can be stored in the Nios
* Make sure this number matches that of the Nios' devices.h */
#define NUM_BBP_FASTLOCK_PROFILES 256
#define NUM_BBP_FASTLOCK_PROFILES 2048
/* Number of fast lock profiles that can be stored in the RFFE
* Make sure this number matches that of the Nios' devices.h */

View file

@ -5,16 +5,6 @@ For more detailed information, please see the git change log and issue tracker
hosted on GitHub: https://github.com/nuand/bladeRF
================================================================================
v2.6.0 (2025-05-06)
--------------------------------
* Increase GPIF buffer size for increase performance
* Fixed missing break in BLADE_USB_CMD_QUERY_FPGA_SOURCE command handling
* Improved FX3 SDK setup instructions in README
v2.5.0 (2024-07-30)
--------------------------------
* Bumped GPIF DMA buffer size to 8192 bytes
* Reduced the number of GPIF DMA buffers to 11 per channel
v2.4.0 (2020-08-01)
--------------------------------

View file

@ -33,7 +33,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../host/cmake/modules)
# Update these definitions when updating the firmware version
set(VERSION_INFO_MAJOR 2)
set(VERSION_INFO_MINOR 6)
set(VERSION_INFO_MINOR 4)
set(VERSION_INFO_PATCH 0)
if(NOT DEFINED VERSION_INFO_EXTRA)

View file

@ -18,7 +18,7 @@ Building the FX3 firmware first requires the download of the [Cypress FX3 SDK][c
**This firmware build requires FX3 SDK version 1.3.3 or later**
[cypress_sdk]: http://www.cypress.com/?rID=57990 (Cypress FX3 SDK) (downloaded file is `ezusbfx3sdk_1.3.5_Linux_x32-x64.tar.gz`)
[cypress_sdk]: http://www.cypress.com/?rID=57990 (Cypress FX3 SDK)
[CMake](https://cmake.org) is used to configure the build. There are two locations that we must provide to CMake when configuring the build:
@ -27,24 +27,6 @@ Building the FX3 firmware first requires the download of the [Cypress FX3 SDK][c
### Command Line-Based Build (Recommended for Linux Users) ###
#### Setting up the FX3 SDK on Linux ####
1. Extract the contents of `ezusbfx3sdk_1.3.5_Linux_x32-x64.tar.gz` (the contents are 5 .tar.gz files)
2. Extract and arrange two of them such that these folders exist:
- `/opt/cypress/ARM_GCC/arm-2013.11/`
- `/opt/cypress/fx3_firmware_linux/cyfx3sdk/`
##### Ubuntu 20.04 Dependencies #####
On Ubuntu 20.04, you'll need to install 32-bit libraries:
```
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install libc6:i386 libstdc++6:i386 libncurses5:i386
```
#### Building the Firmware ####
Below are instructions for building the FX3 firmware from the command-line. This assumes that `cmake` and `make`
are in your `PATH`, and is best suited for Linux developers.
@ -56,7 +38,7 @@ Adjust the paths as necessary on your system, depending where you installed the
```
$ mkdir build
$ cd build
$ cmake -DFX3_INSTALL_PATH=/opt/cypress/fx3_firmware_linux -DCMAKE_TOOLCHAIN_FILE=../cmake/fx3-toolchain.cmake ../
$ cmake -DFX3_INSTALL_PATH=/opt/cypress/fx3_sdk -DCMAKE_TOOLCHAIN_FILE=../cmake/fx3-toolchain.cmake ../
$ make
```

View file

@ -468,7 +468,6 @@ CyBool_t NuandHandleVendorRequest(
case BLADE_USB_CMD_QUERY_FPGA_SOURCE:
ret = (unsigned int)NuandGetFpgaConfigSource();
CyU3PUsbSendRetCode(ret);
break;
case BLADE_USB_CMD_SET_LOOPBACK:
NuandRFLinkLoopBack(wValue);

View file

@ -290,8 +290,8 @@ static void NuandRFLinkStart(void)
}
CyU3PMemSet((uint8_t *)&dmaCfg, 0, sizeof(dmaCfg));
dmaCfg.size = size * 8;
dmaCfg.count = 11;
dmaCfg.size = size * 2;
dmaCfg.count = 22;
dmaCfg.prodSckId = BLADE_RF_SAMPLE_EP_PRODUCER_USB_SOCKET;
dmaCfg.consSckId = CY_U3P_PIB_SOCKET_3;
dmaCfg.dmaMode = CY_U3P_DMA_MODE_BYTE;

View file

@ -5,30 +5,6 @@ For more detailed information, please see the git change log and issue tracker
hosted on GitHub: https://github.com/nuand/bladeRF
================================================================================
--------------------------------
v0.16.0 (2025-05-06)
--------------------------------
This version brings significant FPGA improvements including sc16q11 packed mode
support and optimized USB throughput, along with important bug fixes for bladeRF
1.0 and 2.0 micro devices.
Features:
* hdl: Added sc16q11 packed mode for improved sample efficiency
* hdl: Increased FX3 GPIF buffer sizes, boosting USB throughput (~356MB/s)
* hdl: Implemented dynamic Nios base address assignment based on RAM size
* hdl: Added parallel build support for hosted FPGA variants (40, 115, A4, A5, A9)
* nios: Enabled elf-gdb and gdb-server support for improved debugging capability
* hdl: Added git revision information to FPGA build outputs
Fixes:
* hdl: Fixed delayed sample and off-by-one timestamp bugs on bladeRF 1.0
* hdl: Corrected TX meta sample gap issue when timestamp set to META NOW
* hdl: Fixed corrupted UART buffer in command_uart component
* hdl: Resolved TX deadlock scenarios by refactoring RX/TX DMA prioritization
* hdl: Improved FPGA simulation accuracy for bladeRF 1 and 2 micro models
* hdl: Fixed false timing paths and resolved multiple timing violations
--------------------------------
v0.15.3 (2023-08-09)
--------------------------------

View file

@ -1,5 +1,5 @@
# bladeRF HDL Source #
The Cyclone FPGA is at the heart of the bladeRF. It interfaces to the Cypress FX3, Analog Devices AD9361 (bladeRF 2.0 micro) or Lime Micro LMS6002D (bladeRF 1) RF transceiver, Silicon Labs clock generator chip, and VCTCXO trim DAC. It has an input to read NMEA from a GPS as well as a 1pps input for time synchronization of signals and has a reference input for a reference clock to tame the VCTCXO. Lastly, it connects directly to the expansion header for controlling GPIO or any other interfaces that may reside on the expansion board.
The Cyclone IV FPGA is at the heart of the bladeRF. It interfaces to the Cypress FX3, Lime Micro LMS6002D RF transceiver, Si5338 clock generator chip, and VCTCXO trim DAC. It has an input to read NMEA from a GPS as well as a 1pps input for time synchronization of signals and has a reference input for a reference clock to tame the VCTCXO. Lastly, it connects directly to the expansion header for controlling GPIO or any other interfaces that may reside on the expansion board.
The HDL is separated out into two different sections:
@ -18,14 +18,13 @@ Some FPGA binaries are available for [download][download]. Please note the md5
[download]: https://www.nuand.com/fpga/ (nuand/FPGA Images)
## Required Software ##
We use an [Intel (Altera)][intel] [Cyclone V E FPGA][cve] for bladeRF 2.0 micro and a [Cyclone IV E FPGA][cive] for bladeRF 1 (classic). The size of the FPGA is the only difference between different bladeRF models of the same generation (x40 vs x115, xA4 vs xA9). Intel provides their [Quartus Prime][quartus] software for synthesizing designs for their FPGAs. The Lite Edition is free of charge, but not open source, and may require registering on their site to download the software.
We use an [Intel (Altera)][intel] [Cyclone IV E FPGA][cive]. The size of the FPGA is the only difference between the x40 and x115 models. Intel provides their [Quartus Prime][quartus] software for synthesizing designs for their FPGAs. The Lite Edition is free of charge, but not open source, and may require registering on their site to download the software.
**Important Note:** Be sure to download and install [Quartus Prime version 20.1.1][quartus], which the bladeRF project files are based upon. Updates to Quartus Prime are not guaranteed to be reverse-compatible with earlier Quartus versions, nor will future versions necessarily be reverse-compatible. Particularly, newer versions of Quartus may not support older generation bladeRF 1 devices or the Nios II processor used on all bladeRF devices.
**Important Note:** Be sure to download and install [Quartus Prime version 17.1][quartus], which the bladeRF project files are based upon. Updates to Quartus Prime are not guaranteed to be reverse-compatible with earlier Quartus versions, nor will future versions necessarily be reverse-compatible.
[intel]: https://www.altera.com/ (Altera, part of the Intel Programmable Solutions Group)
[quartus]: https://www.intel.com/content/www/us/en/software-kit/660904/intel-quartus-prime-lite-edition-design-software-version-20-1-1-for-linux.html (Quartus Prime Lite Edition v20.1.1)
[cve]: https://www.intel.com/content/www/us/en/products/details/fpga/cyclone/v.html
[cive]: https://www.intel.com/content/www/us/en/products/details/fpga/cyclone/iv.html
[quartus]: https://dl.altera.com/17.1/?edition=lite (Quartus Prime Lite Edition v17.1)
[cive]: https://www.altera.com/products/fpga/cyclone-series/cyclone-iv/overview.html
## HDL Structure ##
Since the FPGA is connected and soldered down to the board, it makes sense to have a single top level which defines where the pins go, their IO levels and their general directionality. We use a single `bladerf.vhd` top level to define a VHDL entity called `bladerf` that defines these pins.
@ -42,25 +41,21 @@ This technique can be seen with the currently supported architectures:
## Building the Project ##
The Quartus Prime build tools supports TCL as a scripting language which we utilize to not only create the project file, but build the system without requiring the need of the GUI. Currently, the `build_bladerf.sh` performs some environment checks, builds the NIOS BSP and software, and then kicks off TCL scripts to build the FPGA image.
To support multiple versions of Quartus Prime on the same machine and to ensure the environment is appropriately setup, please run the `nios2_command_shell.sh` script to get into an appropriate Quartus Prime environment. Note that this shell script is usually located in the `nios2eds` directory of your Quartus Prime install directory (e.g. `~/intelFPGA_lite/20.1/nios2eds/nios2_command_shell.sh`). Also note that this is the preferred method regardless of using Windows or Linux to build. If you're using pybombs, make sure you haven't run `setup_env.sh`, as it prevents `nios2_command_shell.sh` from working properly.
To support multiple versions of Quartus Prime on the same machine and to ensure the environment is appropriately setup, please use the `nios2_command_shell.sh` script to get into an appropriate Quartus Prime environment. Note that this shell script is usually located in the `nios2eds` directory of your Quartus Prime install directory. Also note that this is the preferred method regardless of using Windows or Linux to build. If you're using pybombs, make sure you haven't run `setup_env.sh`, as it prevents `nios2_command_shell.sh` from working properly.
1. Take note of your bladeRF model (bladeRF micro, bladeRF classic) and its corresponding FPGA size (x40, xA9, etc). You'll need this info below.
1. Take note of which Cyclone device you have. (The EP4CE40 is 40 kLE, and the EP4CE115 is 115 kLE.) You'll need this size below.
2. Enter the `quartus` directory
3. Execute, from inside an appropriate NIOS II command shell, `./build_bladerf.sh -h` to view the usage for the build script. Note the board, size, and revision options. Also note any items you'll need to add to your PATH before continuing.
4. Execute, from inside an appropriate NIOS II command shell, `./build_bladerf.sh -b <board> -s <size> -r <revision>`, with your bladeRF board model, the relevant size for your bladeRF, and the desired revision. This will create the NIOS system and software associated with the FPGA build needed by the internal RAM for execution.
3. Execute, from inside an appropriate NIOS II command shell, `./build_bladerf.sh -h` to view the usage for the build script. Note the size and revision options. Also note any items you'll need to add to your PATH before continuing.
4. Execute, from inside an appropriate NIOS II command shell, `./build_bladerf.sh -s <size> -r <revision>`, with the relevant size for your bladeRF, and the desired revision. This will create the NIOS system and software associated with the FPGA build needed by the internal RAM for execution.
5. The output of the build will be stored in a directory named in the form, `<revision>x<size>-<build time>`. This directory will contain the bitstream, summaries, and reports.
Note that there will be a _lot_ of information displayed from notes to critical warnings. Some of these are benign and others are, in fact, critical.
Ex: Build the bladeRF 2.0 micro xA4 with the default `hosted` architecture
```
./build_bladerf.sh -b bladeRF-micro -s A4 -r hosted
```
## Adding Signal Tap ##
For advanced users who want to use Signal Tap internal logic analyzer in their design, use the `-a` flag to add the Signal Tap file to the project before building it:
For advanced users who want to use Signal Tap internal logic analyzer in their design, the `build.tcl` file can be passed a `-stp` flag which will add the Signal Tap file to the project before building it:
```
./build_bladerf.sh -b bladeRF-micro -s A4 -r hosted -a ../signaltap/debug_rx.stp
quartus_sh -t ../build.tcl -rev hosted -size 115 -stp ../signaltap/debug_rx.stp
```
Note that to use Signal Tap with the Quartus Prime Lite Edition software, the TalkBack feature must be enabled. The build script tries to 'fake' this out by setting the TalkBack feature to be on, compiling the project, then turning it off immediately afterward. If this behavior is not desired, don't try to add a Signal Tap file to the project.

View file

@ -184,7 +184,7 @@ begin
count := 0 ;
irq <= '0' ;
elsif( rising_edge(clock) ) then
if( sin_we = '1' and state /= WAIT_FOR_READ ) then
if( sin_we = '1' ) then
reg_request(count*8+7 downto count*8) <= sin_data ;
end if ;
case state is

View file

@ -4,7 +4,6 @@ proc compile_fx3_gpif { root } {
vlib work
vcom -2008 -work work [file join $root ./synthesis/set_clear_ff.vhd]
vcom -2008 -work work [file join $root ../../platforms/common/bladerf/vhdl/fx3_gpif_p.vhd]
vcom -2008 -work work [file join $root ../../platforms/common/bladerf/vhdl/fx3_gpif.vhd]
vcom -2008 -work work [file join $root ./simulation/util.vhd]
vcom -2008 -work work [file join $root ./simulation/fx3_model.vhd]

View file

@ -42,7 +42,6 @@ proc compile_nuand { root platform } {
vcom -work nuand -2008 [file join $root ./synthesis/tb/atsc_tx_tb.vhd]
vcom -work nuand -2008 [file join $root ../../platforms/common/bladerf/vhdl/fx3_gpif_p.vhd]
vcom -work nuand -2008 [file join $root ./simulation/fx3_model.vhd]
vcom -work nuand -2008 [file join $root ./simulation/lms6002d_model.vhd]

View file

@ -26,8 +26,6 @@ library ieee;
library work;
use work.util.all;
use work.fx3_gpif_p.all;
entity fx3_model is
port (
@ -42,7 +40,6 @@ entity fx3_model is
fx3_tx_en : in std_logic;
fx3_tx_meta_en : in std_logic;
eight_bit_mode_en : in std_logic := '0';
packed_mode_en : in std_logic := '0';
done : out boolean
);
end entity ; -- fx3_model
@ -105,7 +102,7 @@ begin
done <= rx_done and tx_done;
rx_sample_stream : process
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
constant BLOCK_SIZE : natural := 512;
variable count : natural := START_COUNT;
variable req_time : time;
begin
@ -158,7 +155,7 @@ begin
end process;
tx_sample_stream : process
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
constant BLOCK_SIZE : natural := 512;
variable count : natural := START_COUNT;
variable timestamp_cntr : natural := 80;
variable header_len : natural := 0;
@ -204,7 +201,7 @@ begin
data_out := x"12341234";
when 2 =>
data_out(31 downto 0) := std_logic_vector(to_signed(timestamp_cntr, 32));
timestamp_cntr := timestamp_cntr + (GPIF_BUF_SIZE_SS-4) * 2;
timestamp_cntr := timestamp_cntr + 508 * 2;
when 3 =>
data_out := (others => '0');
when 4 =>

View file

@ -28,7 +28,6 @@ library nuand ;
use nuand.fifo_readwrite_p.all;
use nuand.common_dcfifo_p.all;
use nuand.bladerf_p.all;
use nuand.fx3_gpif_p.all;
library std ;
use std.env.all ;
@ -436,8 +435,8 @@ begin
wait until reset = '0' ;
end if ;
while true loop
wait until rising_edge(fx3_clock) and unsigned(rx_sample_fifo.rused) > GPIF_BUF_SIZE_SS;
for i in 1 to GPIF_BUF_SIZE_SS loop
wait until rising_edge(fx3_clock) and unsigned(rx_sample_fifo.rused) > 512 ;
for i in 1 to 512 loop
rx_sample_fifo.rreq <= '1' ;
nop( fx3_clock, 1 ) ;
if( CHECK_OVERFLOW ) then

View file

@ -24,7 +24,6 @@ library ieee;
library work;
use work.fifo_readwrite_p.all;
use work.fx3_gpif_p.all;
entity fifo_reader is
generic (
@ -44,7 +43,6 @@ entity fifo_reader is
meta_en : in std_logic;
packet_en : in std_logic;
eight_bit_mode_en : in std_logic;
highly_packed_mode_en : in std_logic;
timestamp : in unsigned(63 downto 0);
fifo_usedw : in std_logic_vector(FIFO_USEDW_WIDTH-1 downto 0);
@ -73,9 +71,8 @@ end entity;
architecture simple of fifo_reader is
constant DMA_BUF_SIZE_SS : natural := GPIF_BUF_SIZE_SS;
constant DMA_BUF_SIZE_HS : natural := GPIF_BUF_SIZE_HS;
constant MAX_TIMESTAMP : unsigned(timestamp'high downto timestamp'low) := (others => '1');
constant DMA_BUF_SIZE_SS : natural := 512;
constant DMA_BUF_SIZE_HS : natural := 256;
signal dma_buf_size : natural range DMA_BUF_SIZE_HS to DMA_BUF_SIZE_SS := DMA_BUF_SIZE_SS;
signal underflow_detected : std_logic := '0';
@ -144,10 +141,6 @@ architecture simple of fifo_reader is
fifo_read : std_logic;
out_samples : sample_streams_t(out_samples'range);
eight_bit_sample_sel: std_logic;
-- Highly packed mode signals
packed_buffer : std_logic_vector(47 downto 0);
packed_cycle : integer range 0 to 4;
end record;
constant FIFO_FSM_RESET_VALUE : fifo_fsm_t := (
@ -163,9 +156,7 @@ architecture simple of fifo_reader is
packet_data_cache => (others => '0'),
fifo_read => '0',
out_samples => (others => ZERO_SAMPLE),
eight_bit_sample_sel => '0',
packed_buffer => (others => '0'),
packed_cycle => 0
eight_bit_sample_sel => '0'
);
signal fifo_current : fifo_fsm_t := FIFO_FSM_RESET_VALUE;
@ -212,9 +203,7 @@ begin
-- Meta FIFO combinatorial process
meta_fsm_comb : process( all )
constant META_NOW : unsigned(63 downto 0) := (others => '1');
variable meta_time : unsigned(63 downto 0);
variable packet_len : integer;
variable meta_time : unsigned(63 downto 0);
begin
meta_future <= meta_current;
@ -244,7 +233,7 @@ begin
(packet_en = '1' and packet_ready = '1') ) ) then
meta_future.meta_read <= '1';
meta_future.state <= META_WAIT;
if( packet_en = '1' or (meta_current.meta_p_time_r > timestamp and meta_current.meta_p_time_r /= META_NOW) ) 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';
@ -257,13 +246,12 @@ begin
when META_WAIT =>
if( packet_en = '1' ) then
packet_len := to_integer(unsigned(meta_current.meta_cache(15 downto 0)));
meta_future.dma_downcount <= packet_len - 1;
meta_future.dma_downcount <= to_integer(unsigned(meta_current.meta_cache(15 downto 0)));
else
meta_future.dma_downcount <= dma_buf_size - 4;
end if;
if( (timestamp >= meta_current.meta_p_time or meta_current.meta_p_time = MAX_TIMESTAMP)
if( (timestamp >= meta_current.meta_p_time or meta_current.meta_p_time + 1 = 0)
and ( packet_en = '0' or ( packet_en = '1' and packet_ready = '1' ) ) ) then
meta_future.meta_time_go <= '1';
meta_future.state <= META_DOWNCOUNT;
@ -278,11 +266,11 @@ begin
if( packet_en = '0' ) then
if( fifo_current.fifo_read = '1') then
meta_future.dma_downcount <= meta_current.dma_downcount - NUM_STREAMS;
if( meta_current.dma_downcount <= 2 ) then
-- Look for 2 because of the 2 cycles passing
-- through META_LOAD and META_WAIT after this.
meta_future.state <= META_LOAD;
end if;
end if;
if( meta_current.dma_downcount <= NUM_STREAMS ) then
-- Look for 2 because of the 2 cycles passing
-- through META_LOAD and META_WAIT after this.
meta_future.state <= META_LOAD;
end if;
else
if( fifo_current.packet_control.data_valid = '1') then
@ -430,67 +418,6 @@ begin
return rv;
end function;
-- --------------------------------------------------------------------
-- MIMO UNPACKER: STEP 1 of 5 (SC12Q11 Highly Packed Mode)
-- --------------------------------------------------------------------
-- The sample FIFO output is a wide data bus that contains multiple
-- 12-bit I/Q samples packed across multiple cycles. This procedure unpacks
-- data from a 64-bit wide bus across three cycles to extract eight 12-bit I/Q pairs.
--
-- The packing scheme for 12-bit samples across three 64-bit cycles:
-- Cycle 1: | 63:60 | 59:48 | 47:36 | 35:24 | 23:12 | 11:0 | Bit indices
-- | Q0' | I0 | Q1 | I1 | Q0 | I0 | Samples
-- [-----][--------full 12-bit samples-----------]
-- 4-bit
-- overlap
--
-- Cycle 2: | 63:56 | 55:44 | 43:32 | 31:20 | 19:8 | 7:0 | Bit indices
-- | I1' | Q0 | I0 | Q1 | I1 | Q0' | Samples
-- [-----][--------full 12-bit samples--------][---]
-- 8-bit 8-bit
-- overlap overlap
--
-- Cycle 3: | 63:52 | 51:40 | 39:28 | 27:16 | 15:4 | 3:0 | Bit indices
-- | Q1 | I1 | Q0 | I0 | Q1 | I1' | Samples
-- [--------full 12-bit samples-----------][-----]
-- 4-bit
-- overlap
--
-- Note: Samples with apostrophes (') indicate partial samples that span
-- across cycle boundaries. The complete samples are reconstructed by
-- combining these partial segments from different cycles.
procedure unpack_sc12q11(
signal data : in std_logic_vector(63 downto 0);
signal previous_data : in std_logic_vector(47 downto 0);
signal cycle : in integer;
variable rv : out sample_streams_t
) is
constant OFFSET_UNIT : natural := 24;
begin
for i in rv'range loop
rv(i).data_i := resize(signed(shift_right(unsigned(data),i*OFFSET_UNIT)(11 downto 0)),rv(i).data_i'length);
rv(i).data_q := resize(signed(shift_right(unsigned(data),i*OFFSET_UNIT)(23 downto 12)),rv(i).data_q'length);
rv(i).data_v := '0';
end loop;
if (cycle = 1) then
rv(0).data_i := resize(signed(previous_data(43 downto 32)),rv(0).data_i'length);
rv(0).data_q := resize(signed(data(7 downto 0) & previous_data(47 downto 44)),rv(0).data_q'length);
rv(1).data_i := resize(signed(shift_right(unsigned(data),8)(11 downto 0)),rv(1).data_i'length);
rv(1).data_q := resize(signed(shift_right(unsigned(data),8)(23 downto 12)),rv(1).data_q'length);
elsif (cycle = 2) then
rv(0).data_i := resize(signed(previous_data(27 downto 16)),rv(0).data_i'length);
rv(0).data_q := resize(signed(previous_data(39 downto 28)),rv(0).data_q'length);
rv(1).data_i := resize(signed(fifo_data(3 downto 0) & previous_data(47 downto 40)), rv(1).data_i'length);
rv(1).data_q := resize(signed(fifo_data(15 downto 4)), rv(1).data_q'length);
elsif (cycle = 3) then
rv(0).data_i := resize(signed(previous_data(11 downto 0)),rv(0).data_i'length);
rv(0).data_q := resize(signed(previous_data(23 downto 12)),rv(0).data_q'length);
rv(1).data_i := resize(signed(previous_data(35 downto 24)),rv(0).data_i'length);
rv(1).data_q := resize(signed(previous_data(47 downto 36)),rv(0).data_q'length);
end if;
end procedure;
-- --------------------------------------------------------------------
-- MIMO UNPACKER: STEP 3 of 5
-- --------------------------------------------------------------------
@ -531,14 +458,7 @@ begin
fifo_future.packet_control.data_valid <= '0';
-- MIMO UNPACKER: STEP 1 of 5
if (highly_packed_mode_en = '1' and NUM_STREAMS = 2) then
unpack_sc12q11(
data => fifo_data,
previous_data => fifo_current.packed_buffer,
cycle => fifo_current.packed_cycle,
rv => unpacked
);
elsif (eight_bit_mode_en = '1') then
if( eight_bit_mode_en = '1') then
unpacked := unpack_eight_bit_mode(fifo_current.sample_controls_reg, fifo_data, fifo_current.eight_bit_sample_sel);
else
unpacked := unpack(fifo_current.sample_controls_reg, fifo_data);
@ -573,11 +493,7 @@ begin
-- still need to be processed (not including the first). This becomes the number of clock
-- cycles to wait before asserting the FIFO read request to get a new batch of samples.
fifo_future.samples_left_init <= NUM_STREAMS - fifo_current.enabled_channels;
if (fifo_current.samples_left = FIFO_FSM_RESET_VALUE.samples_left) then
fifo_future.samples_left <= NUM_STREAMS - fifo_current.enabled_channels;
fifo_future.ch_shift <= 0;
end if;
fifo_future.samples_left <= NUM_STREAMS - fifo_current.enabled_channels;
if( packet_en = '1' ) then
fifo_future.state <= READ_PACKET;
@ -645,17 +561,11 @@ begin
if( fifo_current.samples_left = 0 ) then
fifo_future.samples_left <= fifo_current.samples_left_init;
fifo_future.ch_shift <= 0;
fifo_future.fifo_read <= read_req;
if( eight_bit_mode_en = '1' ) then
fifo_future.fifo_read <= read_req and fifo_current.eight_bit_sample_sel;
fifo_future.eight_bit_sample_sel <= not fifo_current.eight_bit_sample_sel;
elsif (highly_packed_mode_en = '1' and NUM_STREAMS = 2) then
fifo_future.packed_cycle <= (fifo_current.packed_cycle + 1);
fifo_future.packed_buffer <= fifo_data(fifo_data'high downto fifo_data'high-47);
if fifo_current.packed_cycle = 3 then
fifo_future.packed_cycle <= 0;
fifo_future.fifo_read <= '0';
end if;
else
fifo_future.fifo_read <= read_req;
end if;
else
-- MIMO UNPACKER: STEP 5 of 5

View file

@ -24,7 +24,6 @@ library ieee;
library work;
use work.fifo_readwrite_p.all;
use work.fx3_gpif_p.all;
entity fifo_writer is
generic (
@ -43,7 +42,6 @@ entity fifo_writer is
meta_en : in std_logic;
packet_en : in std_logic;
eight_bit_mode_en : in std_logic := '0';
highly_packed_mode_en : in std_logic;
timestamp : in unsigned(63 downto 0);
mini_exp : in std_logic_vector(1 downto 0);
@ -72,8 +70,8 @@ end entity;
architecture simple of fifo_writer is
constant DMA_BUF_SIZE_SS : natural := GPIF_BUF_SIZE_SS;
constant DMA_BUF_SIZE_HS : natural := GPIF_BUF_SIZE_HS;
constant DMA_BUF_SIZE_SS : natural := 512;
constant DMA_BUF_SIZE_HS : natural := 256;
signal dma_buf_size : natural range DMA_BUF_SIZE_HS to DMA_BUF_SIZE_SS := DMA_BUF_SIZE_SS;
@ -120,8 +118,6 @@ architecture simple of fifo_writer is
fifo_clear : std_logic;
fifo_write : std_logic;
fifo_data : unsigned(fifo_data'range);
fifo_12b_buf : unsigned(95 downto 0);
write_cycle : natural range 0 to 3;
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);
@ -133,8 +129,6 @@ architecture simple of fifo_writer is
fifo_clear => '1',
fifo_write => '0',
fifo_data => (others => '-'),
fifo_12b_buf => (others => '-'),
write_cycle => 0,
samples_left => 0,
in_sample_controls_r=> (others => SAMPLE_CONTROL_DISABLE),
in_samples_r => (others => ZERO_SAMPLE),
@ -193,7 +187,7 @@ begin
meta_fifo_used_v := unsigned(meta_fifo_full & meta_fifo_usedw);
meta_fifo_used_v_r <= meta_fifo_used_v;
if( fifo_full = '0' and ((FIFO_MAX - fifo_used_v_r) > ( dma_buf_size )) and
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;
@ -299,7 +293,7 @@ begin
meta_future.dma_downcount <= meta_current.dma_downcount - NUM_STREAMS;
end if;
if( meta_current.dma_downcount <= 2 ) then
if( meta_current.dma_downcount <= NUM_STREAMS ) then
-- Look for 2 because of the 2 cycles passing
-- through IDLE and META_WRITE after this.
-- 8bit format requires an additional 2 cycle delay.
@ -436,57 +430,6 @@ begin
return rv;
end function;
-- --------------------------------------------------------------------
-- MIMO PACKER: STEP 1 of 3 (SC12Q11 Highly Packed Mode)
-- --------------------------------------------------------------------
-- This block receives samples as an array of sample streams, one
-- element per channel. These streams need to be packed into a single,
-- wide bus that is written to a FIFO and delivered to the host.
-- For SC12Q11 (SC16_Q11_PACKED) format, each I and Q sample is 12 bits wide.
--
-- This packing scheme efficiently utilizes the available bandwidth
-- for the SC12Q11 format, allowing for 8 complete IQ pairs every 3 cycles.
--
-- The packing process fills 3 cycles of a 64-bit buffer with 8 24b IQ pairs:
-- Cycle 1: | 63:60 | 59:48 | 47:36 | 35:24 | 23:12 | 11:0 | Bit indices
-- | Q0' | I0 | Q1 | I1 | Q0 | I0 | Samples
-- [-----][--------full 12-bit samples-----------]
-- 4-bit
-- overlap
--
-- Cycle 2: | 63:56 | 55:44 | 43:32 | 31:20 | 19:8 | 7:0 | Bit indices
-- | I1' | Q0 | I0 | Q1 | I1 | Q0' | Samples
-- [-----][--------full 12-bit samples--------][---]
-- 8-bit 8-bit
-- overlap overlap
--
-- Cycle 3: | 63:52 | 51:40 | 39:28 | 27:16 | 15:4 | 3:0 | Bit indices
-- | Q1 | I1 | Q0 | I0 | Q1 | I1' | Samples
-- [--------full 12-bit samples-----------][-----]
-- 4-bit
-- overlap
--
-- Note: Samples with apostrophes (') indicate partial samples that span
-- across cycle boundaries. The complete samples are reconstructed by
-- combining these partial segments from different cycles.
function pack_sc12q11( sc : sample_controls_t;
ss : sample_streams_t;
d : unsigned ) return unsigned is
constant IQ_PAIR_LEN : positive := 24;
variable rv : unsigned(d'range) := (others => '0');
begin
rv := d;
for i in sc'range loop
if( (sc(i).enable = '1') and (ss(i).data_v = '1') ) then
rv := unsigned(ss(i).data_q(11 downto 0)) &
unsigned(ss(i).data_i(11 downto 0)) &
rv(rv'high downto rv'low+IQ_PAIR_LEN);
end if;
end loop;
return rv;
end function;
procedure handle_fifo_write(
signal fifo_current : in fifo_fsm_t;
signal meta_current : in meta_fsm_t;
@ -514,18 +457,11 @@ begin
if( write_req = '1' ) then
if( fifo_current.samples_left = 0 ) then
fifo_future.samples_left <= NUM_STREAMS - count_enabled_channels(in_sample_controls);
fifo_future.fifo_write <= write_req;
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;
end if;
if( highly_packed_mode_en = '1' ) then
fifo_future.write_cycle <= (fifo_current.write_cycle + 1) mod 4;
if fifo_current.write_cycle = 0 then
fifo_future.fifo_write <= '0';
end if;
else
fifo_future.fifo_write <= write_req;
end if;
else
-- MIMO PACKER: STEP 3 of 3
@ -551,33 +487,14 @@ begin
-- MIMO PACKER: STEP 1 of 3
if( packet_en = '0' ) then
fifo_future.fifo_data <= pack(fifo_current.in_sample_controls_r,
fifo_current.in_samples_r,
fifo_current.fifo_data);
if( highly_packed_mode_en = '1' ) then
fifo_future.fifo_12b_buf <= pack_sc12q11(
sc => in_sample_controls,
ss => in_samples,
d => fifo_current.fifo_12b_buf
);
if fifo_current.write_cycle = 1 then
fifo_future.fifo_data <= fifo_current.fifo_12b_buf(
fifo_data'length-1 downto fifo_current.fifo_12b_buf'low);
elsif fifo_current.write_cycle = 2 then
fifo_future.fifo_data <= fifo_current.fifo_12b_buf(
fifo_data'length-1+16 downto fifo_current.fifo_12b_buf'low+16);
elsif fifo_current.write_cycle = 3 then
fifo_future.fifo_data <= fifo_current.fifo_12b_buf(
fifo_data'length-1+32 downto fifo_current.fifo_12b_buf'low+32);
end if;
end if;
if( eight_bit_mode_en = '1' ) then
fifo_future.fifo_data <= pack_eight_bit_mode(fifo_current.in_sample_controls_r,
fifo_current.in_samples_r,
fifo_current.fifo_data);
else
fifo_future.fifo_data <= pack(fifo_current.in_sample_controls_r,
fifo_current.in_samples_r,
fifo_current.fifo_data);
end if;
end if;
@ -659,13 +576,10 @@ begin
if( fifo_full = '1' or ( meta_current.meta_written = '0' and meta_en = '1') ) then
fifo_future.fifo_write <= '0';
fifo_future.state <= HOLDOFF;
fifo_future.write_cycle <= fifo_current.write_cycle;
fifo_future.fifo_12b_buf <= fifo_current.fifo_12b_buf;
end if;
when HOLDOFF =>
fifo_future.write_cycle <= fifo_current.write_cycle;
fifo_future.fifo_12b_buf <= fifo_current.fifo_12b_buf;
if( fifo_enough ) then
fifo_future.state <= WRITE_SAMPLES;

View file

@ -36,7 +36,6 @@ set_global_assignment -name QIP_FILE [file normalize [file join $nuand_ip pll_r
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip ps_sync/vhdl/ps_sync.vhd]]
# Implementation Details
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx-adsb.vhd]]

View file

@ -33,7 +33,6 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip ps_sy
set_global_assignment -name QIP_FILE [file normalize [file join $nuand_ip tone_generator/tone_generator.qip]]
# Implementation Details
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx.vhd]]

View file

@ -34,7 +34,6 @@ set_global_assignment -name QIP_FILE [file normalize [file join $nuand_ip pll_r
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip ps_sync/vhdl/ps_sync.vhd]]
# Implementation Details
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx.vhd]]

View file

@ -36,7 +36,6 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synth
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip rfic_spi_controller/vhdl/rfic_spi_controller.vhd]]
# Implementation Details
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx.vhd]]

View file

@ -33,10 +33,6 @@ if { [info exists platform_revision] == 0 } {
puts "platform revision: ${platform_revision}"
}
# RAM base address is equal to the RAM size
set ram_base_addr "0x[format %08x $ram_size]"
puts "RAM size: ${ram_size}, base address: ${ram_base_addr}"
# Instances and instance parameters
# (disabled instances are intentionally culled)
add_instance axi_ad9361_0 axi_ad9361 1.0
@ -500,7 +496,7 @@ set_connection_parameter_value nios2.data_master/peripheral_spi.spi_control_port
add_connection nios2.data_master ram.s1
set_connection_parameter_value nios2.data_master/ram.s1 arbitrationPriority {1}
set_connection_parameter_value nios2.data_master/ram.s1 baseAddress ${ram_base_addr}
set_connection_parameter_value nios2.data_master/ram.s1 baseAddress {0x00040000}
set_connection_parameter_value nios2.data_master/ram.s1 defaultConnection {0}
add_connection nios2.data_master rffe_spi.spi_control_port
@ -560,7 +556,7 @@ set_connection_parameter_value nios2.instruction_master/nios2.debug_mem_slave de
add_connection nios2.instruction_master ram.s1
set_connection_parameter_value nios2.instruction_master/ram.s1 arbitrationPriority {1}
set_connection_parameter_value nios2.instruction_master/ram.s1 baseAddress ${ram_base_addr}
set_connection_parameter_value nios2.instruction_master/ram.s1 baseAddress {0x00040000}
set_connection_parameter_value nios2.instruction_master/ram.s1 defaultConnection {0}
add_connection nios2.irq command_uart.interrupt

View file

@ -38,7 +38,7 @@ function get_device_family() {
# RAM during Qsys generation
function get_qsys_ram() {
if [ "${1}" == "A4" ] || [ "${1}" == "A5" ] || [ "${1}" == "A9" ]; then
rams=131072
rams=262144
else
rams=32768
fi

View file

@ -71,10 +71,11 @@ set_false_path -from exp_present -to *
set_false_path -from pwr_status -to *
# JTAG settings
set_clock_groups -exclusive -group [get_clocks altera_reserved_tck]
set_input_delay -clock [get_clocks altera_reserved_tck] 2.0 [get_ports altera_reserved_tdi]
set_input_delay -clock [get_clocks altera_reserved_tck] 2.0 [get_ports altera_reserved_tms]
set_output_delay -clock [get_clocks altera_reserved_tck] 2.0 [get_ports altera_reserved_tdo]
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}]
set_false_path -to [get_ports {altera_reserved_tdo}]
# Exceptions

View file

@ -3,7 +3,6 @@ compile_nuand ../../../ip/nuand bladerf-micro
vcom -work nuand -2008 ../vhdl/tb/nios_system.vhd
vcom -work nuand -2008 ../../../platforms/common/bladerf/vhdl/fx3_gpif_p.vhd
vcom -work nuand -2008 ../../../platforms/common/bladerf/vhdl/fx3_gpif.vhd
vcom -work nuand -2008 ../vhdl/bladerf_p.vhd

View file

@ -1,12 +0,0 @@
source ../../../ip/nuand/nuand.do
vcom -work nuand -2008 ../vhdl/rx.vhd
vcom -work nuand -2008 ../vhdl/tx.vhd
vlib rtl_work
vcom -work rtl_work -2008 ../../../ip/altera/fx3_pll/fx3_pll.vhd
compile_nuand ../../../ip/nuand bladerf-micro
vcom -work nuand -2008 ../vhdl/tb/fx3_model_fifo_stress.vhd
vcom -work nuand -2008 ../vhdl/tb/fx3_gpif_iq_8bit_fifo_stress_tb.vhd

View file

@ -1,13 +0,0 @@
source ../../../ip/nuand/nuand.do
# vcom -work nuand -2008 ../vhdl/rx.vhd
# vcom -work nuand -2008 ../vhdl/tx.vhd
# vlib rtl_work
# vcom -work rtl_work -2008 ../../../ip/altera/fx3_pll/fx3_pll.vhd
# compile_nuand ../../../ip/nuand bladerf-micro
vcom -work nuand -2008 ../../../ip/nuand/simulation/fx3_model.vhd
vcom -work nuand -2008 ../vhdl/tb/fx3_model.vhd
vcom -work nuand -2008 ../vhdl/tb/fx3_gpif_iq_packed_tb.vhd

View file

@ -36,9 +36,7 @@ LIBAD936X_DIR := ../../../../fpga/ip/analogdevicesinc/no_OS
INC_DIRS += $(LIBAD936X_BUILDDIR) \
../$(LIBAD936X_DIR)/include \
../../../../../../host/common/include \
../../../../../../host/build/common/thirdparty/ad936x/ \
../../../../../../thirdparty/analogdevicesinc/no-OS_local/platform_bladerf2/
../../../../../../host/common/include
LIB_DIRS += $(LIBAD936X_BUILDDIR)
LDDEPS += $(LIBAD936X_BUILDDIR)/libad936x.a
@ -82,6 +80,3 @@ $(LIBAD936X_BUILDDIR)/Makefile: $(LIBAD936X_MAKE_DEP)
$(LIBAD936X_BUILDDIR)/libad936x.a: $(LIBAD936X_BUILD_DEP)
@$(ECHO) Info: Building libad936x
@$(MAKE) --no-print-directory -C $(LIBAD936X_BUILDDIR) ad936x
# Ensure libad936x is built before the application objects that depend on its headers
$(APP_OBJS): $(LIBAD936X_BUILDDIR)/libad936x.a

View file

@ -7,8 +7,8 @@
#define FPGA_VERSION_ID 0x7777
#define FPGA_VERSION_MAJOR 0
#define FPGA_VERSION_MINOR 16
#define FPGA_VERSION_PATCH 0
#define FPGA_VERSION_MINOR 15
#define FPGA_VERSION_PATCH 3
#define FPGA_VERSION ((uint32_t)( FPGA_VERSION_MAJOR | \
(FPGA_VERSION_MINOR << 8) | \
(FPGA_VERSION_PATCH << 16) ) )

View file

@ -38,8 +38,7 @@ LIBAD936X_DIR := ../../../../fpga/ip/analogdevicesinc/no_OS
INC_DIRS += $(LIBAD936X_BUILDDIR) \
../$(LIBAD936X_DIR)/include \
../../../../../../host/common/include \
../../../../../../thirdparty/analogdevicesinc/no-OS_local/platform_bladerf2/
../../../../../../host/common/include
LIB_DIRS += $(LIBAD936X_BUILDDIR)
LDDEPS += $(LIBAD936X_BUILDDIR)/libad936x.a

View file

@ -93,8 +93,6 @@ architecture hosted_bladerf of bladerf is
signal eightbit_en_tx : std_logic;
signal eightbit_en_rx : std_logic;
signal highly_packed_en_txrx : std_logic;
signal packet_en_pclk : std_logic;
signal packet_en_tx : std_logic;
signal packet_en_rx : std_logic;
@ -569,7 +567,6 @@ begin
-- Eightbit mode
eight_bit_mode_en => eightbit_en_tx,
highly_packed_mode_en => highly_packed_en_txrx,
-- Packet FIFO
packet_en => packet_en_tx,
@ -644,9 +641,8 @@ begin
trigger_master => rx_trigger_ctl.master,
trigger_line => rx_trigger_line,
-- Packed modes
-- Eightbit mode
eight_bit_mode_en => eightbit_en_rx,
highly_packed_mode_en => highly_packed_en_txrx,
-- Packet FIFO
packet_en => packet_en_rx,
@ -863,17 +859,6 @@ begin
sync => eightbit_en_tx
);
U_sync_highly_packed_en_txrx : entity work.synchronizer
generic map (
RESET_LEVEL => '0'
)
port map (
reset => '0',
clock => ad9361.clock,
async => nios_gpio.o.highly_packed_en,
sync => highly_packed_en_txrx
);
U_sync_packet_en_pclk : entity work.synchronizer
generic map (
RESET_LEVEL => '0'

View file

@ -168,11 +168,11 @@ package bladerf_p is
constant TX_FIFO_WWIDTH : natural := 32; -- write side data width
constant TX_FIFO_RWIDTH : natural := 64; -- read side data width
constant TX_FIFO_LENGTH : natural := 8192; -- samples
constant TX_FIFO_LENGTH : natural := 16384; -- samples
constant RX_FIFO_WWIDTH : natural := 64; -- write side data width
constant RX_FIFO_RWIDTH : natural := 32; -- read side data width
constant RX_FIFO_LENGTH : natural := 8192; -- samples
constant RX_FIFO_LENGTH : natural := 4096; -- samples
constant ADSB_FIFO_WWIDTH : natural := 128; -- write side data width
constant ADSB_FIFO_RWIDTH : natural := 32; -- read side data width
@ -184,11 +184,11 @@ package bladerf_p is
constant META_FIFO_TX_WWIDTH : natural := 32; -- write side data width
constant META_FIFO_TX_RWIDTH : natural := 128; -- read side data width
constant META_FIFO_TX_LENGTH : natural := 2048; -- 32-bit words
constant META_FIFO_TX_LENGTH : natural := 512; -- 32-bit words
constant META_FIFO_RX_WWIDTH : natural := 128; -- write side data width
constant META_FIFO_RX_RWIDTH : natural := 32; -- read side data width
constant META_FIFO_RX_LENGTH : natural := 2048; -- 32-bit words
constant META_FIFO_RX_LENGTH : natural := 512; -- 32-bit words
type tx_fifo_t is record
aclr : std_logic;
@ -307,7 +307,6 @@ package bladerf_p is
type nios_gpo_t is record
xb_mode : std_logic_vector(1 downto 0);
eightbit_en : std_logic;
highly_packed_en: std_logic;
packet_en : std_logic;
si_clock_sel : std_logic;
ufl_clock_oe : std_logic;
@ -519,7 +518,6 @@ package body bladerf_p is
variable rv : std_logic_vector(31 downto 0) := (others => 'U');
begin
rv(31 downto 30) := x.xb_mode;
rv(21) := x.highly_packed_en;
rv(20) := x.eightbit_en;
rv(19) := x.packet_en;
rv(18) := x.si_clock_sel;
@ -599,7 +597,6 @@ package body bladerf_p is
variable rv : nios_gpo_t;
begin
rv.xb_mode := x(31 downto 30);
rv.highly_packed_en:= x(21);
rv.eightbit_en := x(20);
rv.packet_en := x(19);
rv.si_clock_sel := x(18);

View file

@ -51,7 +51,6 @@ entity rx is
-- 8-bit mode
eight_bit_mode_en : in std_logic := '0';
highly_packed_mode_en : in std_logic := '0';
-- Packet to host via FX3
packet_en : in std_logic;
@ -252,7 +251,6 @@ begin
packet_ready => packet_ready,
eight_bit_mode_en => eight_bit_mode_en,
highly_packed_mode_en => highly_packed_mode_en,
meta_fifo_full => meta_fifo.wfull,
meta_fifo_usedw => meta_fifo.wused,

View file

@ -1,840 +0,0 @@
-- 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.numeric_std.all;
library rtl_work;
library altera_lnsim;
use altera_lnsim.altera_pll;
library nuand;
use nuand.util.all ;
use nuand.fifo_readwrite_p.all;
use nuand.common_dcfifo_p.all;
use nuand.bladerf_p.all;
entity fx3_gpif_iq_8bit_fifo_stress is
generic (
-- For bladeRF2 (2x2 MIMO):
NUM_MIMO_STREAMS : natural := 2;
FIFO_READER_READ_THROTTLE : natural := 0;
ENABLE_CHANNEL_0 : std_logic := '1';
ENABLE_CHANNEL_1 : std_logic := '0';
EIGHT_BIT_MODE_EN : std_logic := '1'
);
end entity;
architecture arch of fx3_gpif_iq_8bit_fifo_stress is
-- bladerf-hosted uses ad9361.clock (125 MHz) for rx_clock and tx_clock
constant SYSCLK_HALF_PERIOD : time := 1 sec * (1.0/125.0e6/2.0);
-- For reasons unknown, simulation of this system in ModelSim requires that
-- wrreq and data be asserted shortly before the rising clock edge. Sigh...
constant FIFO_WORKAROUND : time := 1 ps;
type fx3_control_t is record
usb_speed : std_logic;
tx_enable : std_logic;
rx_enable : std_logic;
meta_enable : std_logic;
packet : std_logic;
end record;
type fx3_gpif_t is record
gpif_in : std_logic_vector(31 downto 0);
gpif_out : std_logic_vector(31 downto 0);
gpif_oe : std_logic;
ctl_in : std_logic_vector(12 downto 0);
ctl_out : std_logic_vector(12 downto 0);
ctl_oe : std_logic_vector(12 downto 0);
end record;
signal sys_rst : std_logic := '1';
signal done : boolean := false;
signal fx3_pclk : std_logic := '1';
signal fx3_pclk_pll : std_logic := '1';
signal sys_clk : std_logic := '1';
signal pll_reset : std_logic := '0';
signal pll_locked : std_logic := '0';
signal fx3_control : fx3_control_t;
signal fx3_gpif : fx3_gpif_t;
signal fx3_gpif_i : std_logic_vector(31 downto 0);
signal fx3_ctl_i : std_logic_vector(12 downto 0);
-- Control mapping
alias dma0_rx_ack is fx3_ctl_i( 0);
alias dma1_rx_ack is fx3_ctl_i( 1);
alias dma2_tx_ack is fx3_ctl_i( 2);
alias dma3_tx_ack is fx3_ctl_i( 3);
alias dma_rx_enable is fx3_ctl_i( 4);
alias dma_tx_enable is fx3_ctl_i( 5);
alias dma_idle is fx3_ctl_i( 6);
alias system_reset is fx3_ctl_i( 7);
alias dma0_rx_reqx is fx3_ctl_i( 8);
alias dma1_rx_reqx is fx3_ctl_i(12); -- due to 9 being connected to dclk
alias dma2_tx_reqx is fx3_ctl_i(10);
alias dma3_tx_reqx is fx3_ctl_i(11);
signal loopback_i : signed(15 downto 0) := (others =>'0');
signal loopback_q : signed(15 downto 0) := (others =>'0');
signal loopback_valid : std_logic := '0';
signal loopback_enabled : std_logic := '0';
signal tx_clock : std_logic := '1' ;
signal rx_clock : std_logic := '1' ;
signal rx_sample_fifo : rx_fifo_t := RX_FIFO_T_DEFAULT;
signal tx_sample_fifo : tx_fifo_t := TX_FIFO_T_DEFAULT;
signal loopback_fifo : loopback_fifo_t := LOOPBACK_FIFO_T_DEFAULT;
signal rx_meta_fifo : meta_fifo_rx_t := META_FIFO_RX_T_DEFAULT;
signal tx_meta_fifo : meta_fifo_tx_t := META_FIFO_TX_T_DEFAULT;
signal rx_mux_i : signed(15 downto 0);
signal rx_mux_q : signed(15 downto 0);
signal rx_mux_valid : std_logic;
signal tx_timestamp : unsigned(63 downto 0) := ( others => '0' );
signal rx_timestamp : unsigned(63 downto 0) := ( others => '0' );
constant FX3_HALF_PERIOD : time := 1.0/(100.0e6)/2.0*1 sec ;
constant TX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
constant RX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
signal dac_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
signal dac_streams : sample_streams_t(dac_controls'range) := (others => ZERO_SAMPLE);
signal adc_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
signal adc_streams : sample_streams_t(adc_controls'range) := (others => ZERO_SAMPLE);
signal tx_reset : std_logic := '0';
signal tx_ts_reset : std_logic := '0';
signal rx_reset : std_logic := '0';
signal rx_ts_reset : std_logic := '0';
signal meta_en_tx : std_logic := '0';
signal meta_en_rx : std_logic := '0';
signal rx_packet_control : packet_control_t := PACKET_CONTROL_DEFAULT;
signal tx_packet_control : packet_control_t;
signal trigger_signal_sync_tb : std_logic;
signal adc_stream_val_at_rx_enable : signed(15 downto 0) := ( others => '0' );
function data_gen (count : natural) return std_logic_vector is
variable msw, lsw : std_logic_vector(15 downto 0);
begin
msw := std_logic_vector(to_signed(count, 16));
lsw := std_logic_vector(to_signed(-count, 16));
return (msw & lsw);
end function data_gen;
signal rx_packet_ready : std_logic;
begin
-- ========================================================================
-- Brief summary of data flow
-- ========================================================================
--
-- Simulated samples flow from fx3_model's TX side to its RX side. The
-- validity of the data is checked there.
--
-- entity U_fx3_model FX3 model, TX process
-- signal fx3_gpif_i fx3_gpif.gpif_oe is '0'
-- process register_gpif
-- signal fx3_gpif.gpif_in Demuxed GPIF interface (FX3 -> FPGA)
-- entity U_fx3_gpif GPIF implementation, write side
-- signal tx_sample_fifo.w* TX fifo, write side
-- entity U_tx_sample_fifo
-- signal tx_sample_fifo.r* TX fifo, read side
-- process tx_mux
-- signal loopback_fifo.w* Loopback fifo, write side
-- entity U_rx_loopback_fifo
-- signal loopback_fifo.r* Loopback fifo, read side
-- process loopback_fifo_control
-- signal loopback_{i,q,valid}
-- process rx_mux
-- signal rx_mux_{i,q,valid}
-- entity U_fifo_writer
-- signal rx_sample_fifo.w* RX fifo, write side
-- entity U_rx_sample_fifo
-- signal rx_sample_fifo.r* RX fifo, read side
-- entity U_fx3_gpif GPIF implementation, read side
-- signal fx3_gpif.gpif_out Demuxed GPIF interface (FPGA -> FX3)
-- process register_gpif
-- signal fx3_gpif_i fx3_gpif.gpif_oe is '1'
-- entity U_fx3_model FX3 model, RX process
-- ========================================================================
-- Instantiations
-- ========================================================================
-- Unit under test
-- Clock domain: fx3_pclk_pll
U_fx3_gpif : entity nuand.fx3_gpif
port map (
pclk => fx3_pclk_pll,
reset => sys_rst,
usb_speed => fx3_control.usb_speed,
gpif_in => fx3_gpif.gpif_in,
gpif_out => fx3_gpif.gpif_out,
gpif_oe => fx3_gpif.gpif_oe,
ctl_in => fx3_gpif.ctl_in,
ctl_out => fx3_gpif.ctl_out,
ctl_oe => fx3_gpif.ctl_oe,
tx_enable => fx3_control.tx_enable,
rx_enable => fx3_control.rx_enable,
meta_enable => fx3_control.meta_enable,
packet_enable => fx3_control.packet,
tx_fifo_write => tx_sample_fifo.wreq,
tx_fifo_full => tx_sample_fifo.wfull,
tx_fifo_empty => tx_sample_fifo.wempty,
tx_fifo_usedw => tx_sample_fifo.wused,
tx_fifo_data => tx_sample_fifo.wdata,
tx_timestamp => tx_timestamp,
tx_meta_fifo_write => tx_meta_fifo.wreq,
tx_meta_fifo_full => tx_meta_fifo.wfull,
tx_meta_fifo_empty => tx_meta_fifo.wempty,
tx_meta_fifo_usedw => tx_meta_fifo.wused,
tx_meta_fifo_data => tx_meta_fifo.wdata,
rx_fifo_read => rx_sample_fifo.rreq,
rx_fifo_full => rx_sample_fifo.rfull,
rx_fifo_empty => rx_sample_fifo.rempty,
rx_fifo_usedw => rx_sample_fifo.rused,
rx_fifo_data => rx_sample_fifo.rdata,
rx_meta_fifo_read => rx_meta_fifo.rreq,
rx_meta_fifo_full => rx_meta_fifo.rfull,
rx_meta_fifo_empty => rx_meta_fifo.rempty,
rx_meta_fifo_usedr => rx_meta_fifo.rused,
rx_meta_fifo_data => rx_meta_fifo.rdata
);
-- Discrete control signals for fx3_gpif
fx3_control.usb_speed <= '0';
fx3_control.meta_enable <= '0';
fx3_control.packet <= '0';
U_pkt_gen : entity nuand.rx_packet_generator
port map(
rx_clock => rx_clock,
rx_reset => rx_reset,
rx_enable => fx3_control.rx_enable,
rx_packet_enable => fx3_control.packet,
rx_packet_ready => rx_packet_ready,
rx_packet_control => rx_packet_control
);
meta_en_tx <= fx3_control.meta_enable;
meta_en_rx <= fx3_control.meta_enable;
increment_tx_ts : process(tx_clock)
variable ping : boolean := true ;
begin
if( rising_edge(tx_clock) ) then
ping := not ping ;
if( ping = true ) then
tx_timestamp <= tx_timestamp + 1 ;
end if ;
end if ;
end process ;
increment_rx_ts : process(rx_clock)
variable ping : boolean := true ;
begin
if( rising_edge(rx_clock) ) then
ping := not ping ;
if( ping = true ) then
rx_timestamp <= rx_timestamp + 1 ;
end if ;
end if ;
end process ;
-- Model of FX3's GPIF interface
-- Clock domain: fx3_pclk (source)
U_fx3_model : entity nuand.fx3_model(micro_dma_fifo_stress)
port map (
fx3_pclk => fx3_pclk,
fx3_gpif => fx3_gpif_i,
fx3_ctl => fx3_ctl_i,
fx3_uart_rxd => '0',
fx3_uart_txd => open,
fx3_uart_cts => open,
fx3_rx_en => '1',
fx3_rx_meta_en => meta_en_rx,
fx3_tx_en => '1',
fx3_tx_meta_en => meta_en_tx,
eight_bit_mode_en => EIGHT_BIT_MODE_EN,
done => done
);
-- Generate phase-shifted PLL clock
U_fx3_pll : entity rtl_work.fx3_pll
port map (
inclk0 => fx3_pclk,
areset => pll_reset,
c0 => fx3_pclk_pll,
locked => pll_locked
);
tx_clock <= not tx_clock after TX_HALF_PERIOD ;
rx_clock <= not rx_clock after RX_HALF_PERIOD ;
-- Reset handler
sys_rst <= '0' after 100 ns;
-- Generate system clock
sys_clk <= not sys_clk after SYSCLK_HALF_PERIOD when not done else '0';
tx_reset <= sys_rst;
tx_ts_reset <= sys_rst;
rx_reset <= sys_rst;
rx_ts_reset <= sys_rst;
meta_en_tx <= fx3_control.meta_enable;
meta_en_rx <= fx3_control.meta_enable;
-- TX Submodule
U_tx : entity work.tx
generic map (
NUM_STREAMS => dac_controls'length
)
port map (
tx_reset => tx_reset,
tx_clock => tx_clock,
tx_enable => fx3_control.tx_enable,
meta_en => meta_en_tx,
timestamp_reset => tx_ts_reset,
usb_speed => fx3_control.usb_speed,
tx_underflow_led => open,
tx_timestamp => tx_timestamp,
-- Triggering
trigger_arm => '0',
trigger_fire => '0',
trigger_master => '0',
trigger_line => open,
-- Packet FIFO
packet_en => fx3_control.packet,
packet_empty => open,
packet_control => tx_packet_control,
packet_ready => '1',
-- 8-bit mode
eight_bit_mode_en => EIGHT_BIT_MODE_EN,
-- Samples from host via FX3
sample_fifo_wclock => fx3_pclk_pll,
sample_fifo_wreq => tx_sample_fifo.wreq,
sample_fifo_wdata => tx_sample_fifo.wdata,
sample_fifo_wempty => tx_sample_fifo.wempty,
sample_fifo_wfull => tx_sample_fifo.wfull,
sample_fifo_wused => tx_sample_fifo.wused,
-- Metadata from host via FX3
meta_fifo_wclock => fx3_pclk_pll,
meta_fifo_wreq => tx_meta_fifo.wreq,
meta_fifo_wdata => tx_meta_fifo.wdata,
meta_fifo_wempty => tx_meta_fifo.wempty,
meta_fifo_wfull => tx_meta_fifo.wfull,
meta_fifo_wused => tx_meta_fifo.wused,
-- Digital Loopback Interface
loopback_enabled => '0',
loopback_fifo_wdata => loopback_fifo.wdata,
loopback_fifo_wreq => loopback_fifo.wreq,
loopback_fifo_wfull => loopback_fifo.wfull,
loopback_fifo_wused => loopback_fifo.wused,
-- RFFE Interface
dac_controls => dac_controls,
dac_streams => dac_streams
);
-- RX Submodule
U_rx : entity work.rx
generic map (
NUM_STREAMS => adc_controls'length
)
port map (
rx_reset => rx_reset,
rx_clock => rx_clock,
rx_enable => fx3_control.rx_enable,
meta_en => meta_en_rx,
timestamp_reset => rx_ts_reset,
usb_speed => fx3_control.usb_speed,
rx_mux_sel => to_unsigned(0, 3),
rx_overflow_led => open,
rx_timestamp => rx_timestamp,
-- Triggering
trigger_arm => '0',
trigger_fire => '0',
trigger_master => '0',
trigger_line => open,
trigger_signal_sync_tb => trigger_signal_sync_tb,
-- Packet FIFO
packet_en => fx3_control.packet,
packet_control => rx_packet_control,
packet_ready => rx_packet_ready,
-- 8-bit mode
eight_bit_mode_en => EIGHT_BIT_MODE_EN,
-- Samples to host via FX3
sample_fifo_rclock => fx3_pclk_pll,
sample_fifo_raclr => not fx3_control.rx_enable,
sample_fifo_rreq => rx_sample_fifo.rreq,
sample_fifo_rdata => rx_sample_fifo.rdata,
sample_fifo_rempty => rx_sample_fifo.rempty,
sample_fifo_rfull => rx_sample_fifo.rfull,
sample_fifo_rused => rx_sample_fifo.rused,
-- Mini expansion signals
mini_exp => "00",
-- Metadata to host via FX3
meta_fifo_rclock => fx3_pclk_pll,
meta_fifo_raclr => not fx3_control.rx_enable,
meta_fifo_rreq => rx_meta_fifo.rreq,
meta_fifo_rdata => rx_meta_fifo.rdata,
meta_fifo_rempty => rx_meta_fifo.rempty,
meta_fifo_rfull => rx_meta_fifo.rfull,
meta_fifo_rused => rx_meta_fifo.rused,
-- Digital Loopback Interface
loopback_fifo_wenabled => open,
loopback_fifo_wreset => tx_reset,
loopback_fifo_wclock => tx_clock,
loopback_fifo_wdata => loopback_fifo.wdata,
loopback_fifo_wreq => loopback_fifo.wreq,
loopback_fifo_wfull => loopback_fifo.wfull,
loopback_fifo_wused => loopback_fifo.wused,
-- RFFE Interface
adc_controls => adc_controls,
adc_streams => adc_streams
);
-- ========================================================================
-- Data converters
-- ========================================================================
gen_dac_controls : if( NUM_MIMO_STREAMS > 1 ) generate
-- The TX side of the AD9361 HDL is a FIFO pull interface
-- that expects a readahead FIFO. It toggles the data request
-- signal every other cycle. This behavior is mimicked here.
process( tx_clock, sys_rst )
begin
if( sys_rst = '1' ) then
dac_controls <= (
0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
);
elsif( rising_edge(tx_clock) ) then
for i in dac_controls'range loop
dac_controls(i) <= (
enable => dac_controls(i).enable,
data_req => not dac_controls(i).data_req );
end loop;
end if;
end process;
else generate
dac_controls <= (others => SAMPLE_CONTROL_ENABLE);
end generate;
gen_adc_controls : if( NUM_MIMO_STREAMS > 1 ) generate
process( rx_clock, sys_rst )
constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000";
constant COUNT_RESET : integer := 0;
variable count : integer range -2047 to 2047 := COUNT_RESET;
begin
if( sys_rst = '1' ) then
count := COUNT_RESET;
adc_controls <= (
0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
);
elsif( rising_edge(rx_clock) ) then
for i in adc_controls'range loop
adc_controls(i) <= (
enable => adc_controls(i).enable,
data_req => not adc_controls(i).data_req );
if( adc_controls(i).enable = '1') then
if( adc_streams(i).data_v = '1' ) then
if( EIGHT_BIT_MODE_EN = '1' ) then
adc_streams(i).data_i <= "0000" & to_signed(count, 8) & SIGMA_DELTA_BITS;
adc_streams(i).data_q <= "0000" & to_signed(-count, 8) & SIGMA_DELTA_BITS;
count := (count + 1) mod 128;
else
adc_streams(i).data_i <= to_signed(count, 16);
adc_streams(i).data_q <= to_signed(-count, 16);
count := (count + 1) mod 2048;
end if;
end if;
adc_streams(i).data_v <= not adc_streams(i).data_v;
end if;
end loop;
end if;
end process;
else generate
adc_controls <= (others => SAMPLE_CONTROL_ENABLE);
end generate;
-- ========================================================================
-- Processes
-- ========================================================================
-- FX3 GPIF bidirectional signal control
-- Adapted from same process in bladerf-hosted.vhd
register_gpif : process(sys_rst, fx3_pclk_pll)
begin
if( sys_rst = '1' ) then
fx3_gpif_i <= (others => 'Z');
fx3_gpif.gpif_in <= (others => 'Z');
elsif( rising_edge(fx3_pclk_pll) ) then
fx3_gpif.gpif_in <= fx3_gpif_i;
if( fx3_gpif.gpif_oe = '1' ) then
fx3_gpif_i <= fx3_gpif.gpif_out;
else
fx3_gpif_i <= (others =>'Z');
end if;
end if;
end process;
-- FX3 CTL bidirectional signals
-- Adapted from same generator in bladerf-hosted.vhd
generate_ctl : for i in fx3_ctl_i'range generate
fx3_ctl_i(i) <= fx3_gpif.ctl_out(i) when fx3_gpif.ctl_oe(i) = '1' else 'Z';
end generate;
fx3_gpif.ctl_in <= fx3_ctl_i;
-- Controller for loopback FIFO
-- Stripped-down version of same process from rx.vhd
loopback_fifo_control : process( sys_rst, loopback_fifo.rclock )
begin
if( sys_rst = '1' ) then
loopback_enabled <= '0';
loopback_fifo.rreq <= '0';
loopback_i <= (others => '0');
loopback_q <= (others => '0');
loopback_valid <= '0';
elsif( rising_edge(loopback_fifo.rclock) ) then
loopback_enabled <= '0';
loopback_fifo.rreq <= '0';
loopback_i <= loopback_i;
loopback_q <= loopback_q;
loopback_valid <= '0';
-- Is loopback enabled?
loopback_enabled <= fx3_control.rx_enable;
-- Do the loopback
loopback_i <= resize(signed(loopback_fifo.rdata(15 downto 0)), loopback_i'length);
loopback_q <= resize(signed(loopback_fifo.rdata(31 downto 16)), loopback_q'length);
loopback_valid <= loopback_fifo.rreq and not loopback_fifo.rempty;
-- Read from the FIFO if req'd
loopback_fifo.rreq <= loopback_enabled and (not loopback_fifo.rempty);
end if;
end process;
-- RX multiplexer
-- Stripped-down version of same process from rx.vhd
rx_mux : process(sys_rst, sys_clk)
begin
if( sys_rst = '1' ) then
rx_mux_i <= (others =>'0');
rx_mux_q <= (others =>'0');
rx_mux_valid <= '0';
elsif( rising_edge(sys_clk) ) then
rx_mux_i <= loopback_i;
rx_mux_q <= loopback_q;
rx_mux_valid <= loopback_valid;
end if;
end process;
-- TX multiplexer
-- Stripped-down version of mimo_channel_sel_mux from tx.vhd
--tx_mux : process( sys_clk )
--begin
-- if( rising_edge(sys_clk) ) then
-- tx_sample_fifo.rreq <= not tx_sample_fifo.rempty;
-- loopback_fifo.wdata <= tx_sample_fifo.rdata;
-- loopback_fifo.wreq <= tx_sample_fifo.rreq and not tx_sample_fifo.rempty;
-- end if;
--end process;
-- ========================================================================
-- Verification
-- ========================================================================
print_config: process
begin
wait until rising_edge(fx3_control.tx_enable);
report lf&
"[CONFIG] EIGHT_BIT_MODE_EN: " & std_logic'image(EIGHT_BIT_MODE_EN) &lf&
"[CONFIG] ENABLE_CHANNEL_0: " & std_logic'image(ENABLE_CHANNEL_0) &lf&
"[CONFIG] ENABLE_CHANNEL_1: " & std_logic'image(ENABLE_CHANNEL_1);
end process print_config;
--
-- Check for metavalues
-- We should never see metavalues written to the FIFOs
--
check_fifo_write : process(fx3_pclk_pll) is
begin
if( rising_edge(fx3_pclk_pll) ) then
if( tx_sample_fifo.wreq = '1' and fx3_control.meta_enable = '0' ) then
for i in tx_sample_fifo.wdata'range loop
assert tx_sample_fifo.wdata(i) = '0' or tx_sample_fifo.wdata(i) = '1'
severity failure;
end loop;
end if;
end if;
end process;
check_fifo_read : process(fx3_pclk_pll) is
begin
if( rising_edge(fx3_pclk_pll) ) then
if( rx_sample_fifo.rreq = '1' ) then
for i in rx_sample_fifo.rdata'range loop
assert rx_sample_fifo.rdata(i) = '0' or rx_sample_fifo.rdata(i) = '1'
severity failure;
end loop;
end if;
end if;
end process check_fifo_read;
--
-- Check for fullness on FIFOs
--
assert(rx_sample_fifo.wfull = '0') report "rx_sample_fifo full (write)" severity warning;
assert(tx_sample_fifo.wfull = '0') report "tx_sample_fifo full (write)" severity warning;
assert(loopback_fifo.wfull = '0') report "loopback_fifo full (write)" severity warning;
--
-- Tx Sample Check
--
look_for_dropped_tx_samples : process(tx_clock) is
constant MESSAGES_PER_ITERATION : natural := 7; --Provided in fx3_model
constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000";
variable current_message_count : natural := 1;
variable iq_value : signed (15 downto 0) := x"0000";
variable expected_sample_i : signed (15 downto 0);
variable expected_sample_q : signed (15 downto 0);
variable failure_count : natural := 0;
begin
for i in dac_controls'range loop
if( rising_edge(tx_clock)
and dac_controls(i).enable = '1'
and dac_streams(i).data_v = '1'
and fx3_control.tx_enable = '1' )
then
if( EIGHT_BIT_MODE_EN = '1' ) then
expected_sample_i := iq_value (11 downto 0) & SIGMA_DELTA_BITS;
expected_sample_q := iq_value (11 downto 0) + 1 & SIGMA_DELTA_BITS;
assert ( dac_streams(i).data_i = expected_sample_i )
report "dac_streams("&to_string(i)&").data_i: " & to_hstring(dac_streams(i).data_i) & " | " &
"expected_sample_i: " & to_hstring(expected_sample_i)
severity warning;
assert ( dac_streams(i).data_q = expected_sample_q )
report "dac_streams("&to_string(i)&").data_q: " & to_hstring(dac_streams(i).data_q) & " | " &
"expected_sample_q: " & to_hstring(expected_sample_q)
severity warning;
if ( dac_streams(i).data_i /= expected_sample_i or dac_streams(i).data_q /= expected_sample_q ) then
failure_count := failure_count + 1;
if ( failure_count >= 6 ) then
report "tx fail count tolerance exceeded" severity failure;
end if;
end if;
iq_value := (iq_value + 2) mod 128;
else
expected_sample_i := iq_value;
expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1);
assert(dac_streams(i).data_i = expected_sample_i)
report "dac_streams("&to_string(i)&").data_i: " & to_hstring(dac_streams(i).data_i) & " | " &
"expected_sample_i: " & to_hstring(expected_sample_i)
severity failure;
assert(dac_streams(i).data_q = expected_sample_q)
report "dac_streams("&to_string(i)&").data_q: " & to_hstring(dac_streams(i).data_q) & " | " &
"expected_sample_q: " & to_hstring(expected_sample_q)
severity failure;
-- Set iq values based on blocks received
-- See tx_sample_stream's encoding scheme in fx3_model.vhd
if( iq_value = x"03FE" ) then
iq_value := x"0000";
if( current_message_count < MESSAGES_PER_ITERATION ) then
current_message_count := current_message_count + 1;
else
current_message_count := 1;
end if;
else
iq_value := (iq_value + 2) mod 2048;
end if;
end if;
end if;
end loop;
end process look_for_dropped_tx_samples;
--
-- Rx Sample Check
--
first_rx_val_at_mux: process
-- Catches and saves the first sample of
-- each rx enabled burst seen by the mux
begin
for i in adc_controls'range loop
if( adc_controls(i).enable = '1') then
if( ENABLE_CHANNEL_0 = '1' and ENABLE_CHANNEL_1 = '1' ) then
adc_stream_val_at_rx_enable <= adc_streams(i).data_i - 1;
else
adc_stream_val_at_rx_enable <= adc_streams(i).data_i;
end if;
end if;
end loop;
wait until rising_edge(trigger_signal_sync_tb);
end process first_rx_val_at_mux;
look_for_dropped_rx_samples: process(fx3_pclk_pll)
variable rx_val : integer := 0;
variable q_expected : std_logic_vector (15 downto 0);
variable i_expected : std_logic_vector (15 downto 0);
variable q_out : std_logic_vector (15 downto 0);
variable i_out : std_logic_vector (15 downto 0);
variable q0_expected_eight_bit_mode : std_logic_vector (7 downto 0);
variable i0_expected_eight_bit_mode : std_logic_vector (7 downto 0);
variable q1_expected_eight_bit_mode : std_logic_vector (7 downto 0);
variable i1_expected_eight_bit_mode : std_logic_vector (7 downto 0);
variable q0_out_eight_bit_mode : std_logic_vector (7 downto 0);
variable i0_out_eight_bit_mode : std_logic_vector (7 downto 0);
variable q1_out_eight_bit_mode : std_logic_vector (7 downto 0);
variable i1_out_eight_bit_mode : std_logic_vector (7 downto 0);
variable previous_adc_stream_val_at_rx_enable : signed (15 downto 0) := ( others => '0');
variable fail_count: natural := 0;
variable both_channels_en : std_logic;
begin
if( previous_adc_stream_val_at_rx_enable /= adc_stream_val_at_rx_enable ) then
rx_val := to_integer(adc_stream_val_at_rx_enable (15 downto 4)) when EIGHT_BIT_MODE_EN else
to_integer(adc_stream_val_at_rx_enable);
previous_adc_stream_val_at_rx_enable := adc_stream_val_at_rx_enable;
end if;
if( rising_edge(fx3_pclk_pll)
and fx3_gpif.gpif_oe = '1'
and fx3_control.rx_enable = '1' ) then
if( EIGHT_BIT_MODE_EN = '1') then
-- The +-1 ch1 offset in SISO mode will not reach 128
both_channels_en := ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1;
q1_expected_eight_bit_mode := std_logic_vector(to_signed(-rx_val - 1, 8)) when both_channels_en else
std_logic_vector(to_signed(-((rx_val + 1) mod 128), 8));
i1_expected_eight_bit_mode := std_logic_vector(to_signed(rx_val + 1, 8)) when both_channels_en else
std_logic_vector(to_signed((rx_val + 1) mod 128, 8));
q0_expected_eight_bit_mode := std_logic_vector(to_signed(-rx_val, 8));
i0_expected_eight_bit_mode := std_logic_vector(to_signed(rx_val, 8));
q1_out_eight_bit_mode := fx3_gpif.gpif_out(31 downto 24);
i1_out_eight_bit_mode := fx3_gpif.gpif_out(23 downto 16);
q0_out_eight_bit_mode := fx3_gpif.gpif_out(15 downto 8);
i0_out_eight_bit_mode := fx3_gpif.gpif_out(7 downto 0);
if( q1_out_eight_bit_mode /= q1_expected_eight_bit_mode or
i1_out_eight_bit_mode /= i1_expected_eight_bit_mode or
q0_out_eight_bit_mode /= q0_expected_eight_bit_mode or
i0_out_eight_bit_mode /= i0_expected_eight_bit_mode) then
fail_count := fail_count + 1;
report "-----------------------------";
if( fail_count > 3 ) then
report "rx fail count tolerance exceeded" severity failure;
end if;
end if;
assert ( q1_out_eight_bit_mode = q1_expected_eight_bit_mode )
report "data_q1: " & to_hstring(q1_out_eight_bit_mode) & " | " &
"expected: " & to_hstring(q1_expected_eight_bit_mode)
severity warning;
assert ( i1_out_eight_bit_mode = i1_expected_eight_bit_mode )
report "data_i1: " & to_hstring(i1_out_eight_bit_mode) & " | " &
"expected: " & to_hstring(i1_expected_eight_bit_mode)
severity warning;
assert ( q0_out_eight_bit_mode = q0_expected_eight_bit_mode )
report "data_q0: " & to_hstring(q0_out_eight_bit_mode) & " | " &
"expected: " & to_hstring(q0_expected_eight_bit_mode)
severity warning;
assert ( i0_out_eight_bit_mode = i0_expected_eight_bit_mode )
report "data_i0: " & to_hstring(i0_out_eight_bit_mode) & " | " &
"expected: " & to_hstring(i0_expected_eight_bit_mode)
severity warning;
-- 128 limit set by gen_adc_controls above
rx_val := (rx_val + 2) mod 128;
else
q_expected := std_logic_vector(to_signed(-rx_val, 16));
i_expected := std_logic_vector(to_signed(rx_val, 16));
q_out := fx3_gpif.gpif_out(31 downto 16);
i_out := fx3_gpif.gpif_out(15 downto 0);
assert(q_out = q_expected)
report "data_q: " & to_hstring(q_out) & " | " &
"expected: " & to_hstring(q_expected)
severity failure;
assert(i_out = i_expected)
report "data_i: " & to_hstring(i_out) & " | " &
"expected: " & to_hstring(i_expected)
severity failure;
-- 2047 limit set by gen_adc_controls above
rx_val := (rx_val + 1) mod 2048;
end if;
end if;
end process look_for_dropped_rx_samples;
end architecture;

View file

@ -32,7 +32,6 @@ library nuand;
use nuand.fifo_readwrite_p.all;
use nuand.common_dcfifo_p.all;
use nuand.bladerf_p.all;
use nuand.fx3_gpif_p.all;
entity fx3_gpif_iq_8bit_tb is
generic (
@ -660,7 +659,6 @@ begin
constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model
constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000";
variable current_message_count : natural := 1;
variable valid_sample_count : natural := 0;
variable iq_value : signed (15 downto 0) := x"0000";
variable expected_sample_i : signed (15 downto 0);
variable expected_sample_q : signed (15 downto 0);
@ -672,7 +670,6 @@ begin
and dac_streams(i).data_v = '1'
and fx3_control.tx_enable = '1' )
then
valid_sample_count := valid_sample_count + 1;
if( EIGHT_BIT_MODE_EN = '1' ) then
expected_sample_i := iq_value (11 downto 0) & SIGMA_DELTA_BITS;
expected_sample_q := iq_value (11 downto 0) + 1 & SIGMA_DELTA_BITS;
@ -709,7 +706,7 @@ begin
-- Set iq values based on blocks received
-- See tx_sample_stream's encoding scheme in fx3_model.vhd
if( valid_sample_count mod GPIF_BUF_SIZE_SS = 0 ) then
if( iq_value = x"03FE" ) then
iq_value := x"0000";
if( current_message_count < MESSAGES_PER_ITERATION ) then
current_message_count := current_message_count + 1;

View file

@ -1,681 +0,0 @@
-- 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.numeric_std.all;
library rtl_work;
library altera_lnsim;
use altera_lnsim.altera_pll;
library nuand;
use nuand.util.all ;
use nuand.fifo_readwrite_p.all;
use nuand.common_dcfifo_p.all;
use nuand.bladerf_p.all;
use nuand.fx3_gpif_p.all;
entity fx3_gpif_iq_packed_tb is
generic (
-- For bladeRF2 (2x2 MIMO):
NUM_MIMO_STREAMS : natural := 2;
FIFO_READER_READ_THROTTLE : natural := 0;
ENABLE_CHANNEL_0 : std_logic := '1';
ENABLE_CHANNEL_1 : std_logic := '1'
);
end entity;
architecture arch of fx3_gpif_iq_packed_tb is
-- bladerf-hosted uses ad9361.clock (125 MHz) for rx_clock and tx_clock
constant SYSCLK_HALF_PERIOD : time := 1 sec * (1.0/125.0e6/2.0);
-- For reasons unknown, simulation of this system in ModelSim requires that
-- wrreq and data be asserted shortly before the rising clock edge. Sigh...
constant FIFO_WORKAROUND : time := 1 ps;
type fx3_control_t is record
usb_speed : std_logic;
tx_enable : std_logic;
rx_enable : std_logic;
meta_enable : std_logic;
packet : std_logic;
highly_packed_mode : std_logic;
end record;
type fx3_gpif_t is record
gpif_in : std_logic_vector(31 downto 0);
gpif_out : std_logic_vector(31 downto 0);
gpif_oe : std_logic;
ctl_in : std_logic_vector(12 downto 0);
ctl_out : std_logic_vector(12 downto 0);
ctl_oe : std_logic_vector(12 downto 0);
end record;
signal sys_rst : std_logic := '1';
signal done : boolean := false;
signal fx3_pclk : std_logic := '1';
signal fx3_pclk_pll : std_logic := '1';
signal sys_clk : std_logic := '1';
signal pll_reset : std_logic := '0';
signal pll_locked : std_logic := '0';
signal fx3_control : fx3_control_t;
signal fx3_gpif : fx3_gpif_t;
signal fx3_gpif_i : std_logic_vector(31 downto 0);
signal fx3_ctl_i : std_logic_vector(12 downto 0);
-- Control mapping
alias dma0_rx_ack is fx3_ctl_i( 0);
alias dma1_rx_ack is fx3_ctl_i( 1);
alias dma2_tx_ack is fx3_ctl_i( 2);
alias dma3_tx_ack is fx3_ctl_i( 3);
alias dma_rx_enable is fx3_ctl_i( 4);
alias dma_tx_enable is fx3_ctl_i( 5);
alias dma_idle is fx3_ctl_i( 6);
alias system_reset is fx3_ctl_i( 7);
alias dma0_rx_reqx is fx3_ctl_i( 8);
alias dma1_rx_reqx is fx3_ctl_i(12); -- due to 9 being connected to dclk
alias dma2_tx_reqx is fx3_ctl_i(10);
alias dma3_tx_reqx is fx3_ctl_i(11);
signal loopback_i : signed(15 downto 0) := (others =>'0');
signal loopback_q : signed(15 downto 0) := (others =>'0');
signal loopback_valid : std_logic := '0';
signal loopback_enabled : std_logic := '0';
signal tx_clock : std_logic := '1' ;
signal rx_clock : std_logic := '1' ;
signal rx_sample_fifo : rx_fifo_t := RX_FIFO_T_DEFAULT;
signal tx_sample_fifo : tx_fifo_t := TX_FIFO_T_DEFAULT;
signal loopback_fifo : loopback_fifo_t := LOOPBACK_FIFO_T_DEFAULT;
signal rx_meta_fifo : meta_fifo_rx_t := META_FIFO_RX_T_DEFAULT;
signal tx_meta_fifo : meta_fifo_tx_t := META_FIFO_TX_T_DEFAULT;
signal rx_mux_i : signed(15 downto 0);
signal rx_mux_q : signed(15 downto 0);
signal rx_mux_valid : std_logic;
signal tx_timestamp : unsigned(63 downto 0) := ( others => '0' );
signal rx_timestamp : unsigned(63 downto 0) := ( others => '0' );
constant FX3_HALF_PERIOD : time := 1.0/(100.0e6)/2.0*1 sec ;
constant TX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
constant RX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
signal dac_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
signal dac_streams : sample_streams_t(dac_controls'range) := (others => ZERO_SAMPLE);
signal adc_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
signal adc_streams : sample_streams_t(adc_controls'range) := (others => ZERO_SAMPLE);
signal tx_reset : std_logic := '0';
signal tx_ts_reset : std_logic := '0';
signal rx_reset : std_logic := '0';
signal rx_ts_reset : std_logic := '0';
signal meta_en_tx : std_logic := '0';
signal meta_en_rx : std_logic := '0';
signal rx_packet_control : packet_control_t := PACKET_CONTROL_DEFAULT;
signal tx_packet_control : packet_control_t;
signal trigger_signal_sync_tb : std_logic;
signal dac_stream_val_at_rx_enable : signed(15 downto 0) := ( others => '0' );
function data_gen (count : natural) return std_logic_vector is
variable msw, lsw : std_logic_vector(15 downto 0);
begin
msw := std_logic_vector(to_signed(count, 16));
lsw := std_logic_vector(to_signed(-count, 16));
return (msw & lsw);
end function data_gen;
signal rx_packet_ready : std_logic;
begin
-- ========================================================================
-- Brief summary of data flow
-- ========================================================================
--
-- Simulated samples flow from fx3_model's TX side to its RX side. The
-- validity of the data is checked there.
--
-- entity U_fx3_model FX3 model, TX process
-- signal fx3_gpif_i fx3_gpif.gpif_oe is '0'
-- process register_gpif
-- signal fx3_gpif.gpif_in Demuxed GPIF interface (FX3 -> FPGA)
-- entity U_fx3_gpif GPIF implementation, write side
-- signal tx_sample_fifo.w* TX fifo, write side
-- entity U_tx_sample_fifo
-- signal tx_sample_fifo.r* TX fifo, read side
-- process tx_mux
-- signal loopback_fifo.w* Loopback fifo, write side
-- entity U_rx_loopback_fifo
-- signal loopback_fifo.r* Loopback fifo, read side
-- process loopback_fifo_control
-- signal loopback_{i,q,valid}
-- process rx_mux
-- signal rx_mux_{i,q,valid}
-- entity U_fifo_writer
-- signal rx_sample_fifo.w* RX fifo, write side
-- entity U_rx_sample_fifo
-- signal rx_sample_fifo.r* RX fifo, read side
-- entity U_fx3_gpif GPIF implementation, read side
-- signal fx3_gpif.gpif_out Demuxed GPIF interface (FPGA -> FX3)
-- process register_gpif
-- signal fx3_gpif_i fx3_gpif.gpif_oe is '1'
-- entity U_fx3_model FX3 model, RX process
-- ========================================================================
-- Instantiations
-- ========================================================================
-- Unit under test
-- Clock domain: fx3_pclk_pll
U_fx3_gpif : entity nuand.fx3_gpif
port map (
pclk => fx3_pclk_pll,
reset => sys_rst,
usb_speed => fx3_control.usb_speed,
gpif_in => fx3_gpif.gpif_in,
gpif_out => fx3_gpif.gpif_out,
gpif_oe => fx3_gpif.gpif_oe,
ctl_in => fx3_gpif.ctl_in,
ctl_out => fx3_gpif.ctl_out,
ctl_oe => fx3_gpif.ctl_oe,
tx_enable => fx3_control.tx_enable,
rx_enable => fx3_control.rx_enable,
meta_enable => fx3_control.meta_enable,
packet_enable => fx3_control.packet,
tx_fifo_write => tx_sample_fifo.wreq,
tx_fifo_full => tx_sample_fifo.wfull,
tx_fifo_empty => tx_sample_fifo.wempty,
tx_fifo_usedw => tx_sample_fifo.wused,
tx_fifo_data => tx_sample_fifo.wdata,
tx_timestamp => tx_timestamp,
tx_meta_fifo_write => tx_meta_fifo.wreq,
tx_meta_fifo_full => tx_meta_fifo.wfull,
tx_meta_fifo_empty => tx_meta_fifo.wempty,
tx_meta_fifo_usedw => tx_meta_fifo.wused,
tx_meta_fifo_data => tx_meta_fifo.wdata,
rx_fifo_read => rx_sample_fifo.rreq,
rx_fifo_full => rx_sample_fifo.rfull,
rx_fifo_empty => rx_sample_fifo.rempty,
rx_fifo_usedw => rx_sample_fifo.rused,
rx_fifo_data => rx_sample_fifo.rdata,
rx_meta_fifo_read => rx_meta_fifo.rreq,
rx_meta_fifo_full => rx_meta_fifo.rfull,
rx_meta_fifo_empty => rx_meta_fifo.rempty,
rx_meta_fifo_usedr => rx_meta_fifo.rused,
rx_meta_fifo_data => rx_meta_fifo.rdata
);
-- Discrete control signals for fx3_gpif
fx3_control.usb_speed <= '0';
fx3_control.meta_enable <= '0';
fx3_control.packet <= '0';
fx3_control.highly_packed_mode <= '1';
U_pkt_gen : entity nuand.rx_packet_generator
port map(
rx_clock => rx_clock,
rx_reset => rx_reset,
rx_enable => fx3_control.rx_enable,
rx_packet_enable => fx3_control.packet,
rx_packet_ready => rx_packet_ready,
rx_packet_control => rx_packet_control
);
meta_en_tx <= fx3_control.meta_enable;
meta_en_rx <= fx3_control.meta_enable;
increment_tx_ts : process(tx_clock)
variable ping : boolean := true ;
begin
if( rising_edge(tx_clock) ) then
ping := not ping ;
if( ping = true ) then
tx_timestamp <= tx_timestamp + 1 ;
end if ;
end if ;
end process ;
increment_rx_ts : process(rx_clock)
variable ping : boolean := true ;
begin
if( rising_edge(rx_clock) ) then
ping := not ping ;
if( ping = true ) then
rx_timestamp <= rx_timestamp + 1 ;
end if ;
end if ;
end process ;
-- Model of FX3's GPIF interface
-- Clock domain: fx3_pclk (source)
U_fx3_model : entity nuand.fx3_model(micro_dma)
port map (
fx3_pclk => fx3_pclk,
fx3_gpif => fx3_gpif_i,
fx3_ctl => fx3_ctl_i,
fx3_uart_rxd => '0',
fx3_uart_txd => open,
fx3_uart_cts => open,
fx3_rx_en => '1',
fx3_rx_meta_en => meta_en_rx,
fx3_tx_en => '1',
fx3_tx_meta_en => meta_en_tx,
packed_mode_en => fx3_control.highly_packed_mode,
done => done
);
-- Generate phase-shifted PLL clock
U_fx3_pll : entity rtl_work.fx3_pll
port map (
inclk0 => fx3_pclk,
areset => pll_reset,
c0 => fx3_pclk_pll,
locked => pll_locked
);
tx_clock <= not tx_clock after TX_HALF_PERIOD ;
rx_clock <= not rx_clock after RX_HALF_PERIOD ;
-- Reset handler
sys_rst <= '0' after 100 ns;
-- Generate system clock
sys_clk <= not sys_clk after SYSCLK_HALF_PERIOD when not done else '0';
tx_reset <= sys_rst;
tx_ts_reset <= sys_rst;
rx_reset <= sys_rst;
rx_ts_reset <= sys_rst;
meta_en_tx <= fx3_control.meta_enable;
meta_en_rx <= fx3_control.meta_enable;
-- TX Submodule
U_tx : entity work.tx
generic map (
NUM_STREAMS => dac_controls'length
)
port map (
tx_reset => tx_reset,
tx_clock => tx_clock,
tx_enable => fx3_control.tx_enable,
meta_en => meta_en_tx,
timestamp_reset => tx_ts_reset,
usb_speed => fx3_control.usb_speed,
tx_underflow_led => open,
tx_timestamp => tx_timestamp,
-- Packing modes
highly_packed_mode_en => fx3_control.highly_packed_mode,
-- Triggering
trigger_arm => '0',
trigger_fire => '0',
trigger_master => '0',
trigger_line => open,
-- Packet FIFO
packet_en => fx3_control.packet,
packet_empty => open,
packet_control => tx_packet_control,
packet_ready => '1',
-- Samples from host via FX3
sample_fifo_wclock => fx3_pclk_pll,
sample_fifo_wreq => tx_sample_fifo.wreq,
sample_fifo_wdata => tx_sample_fifo.wdata,
sample_fifo_wempty => tx_sample_fifo.wempty,
sample_fifo_wfull => tx_sample_fifo.wfull,
sample_fifo_wused => tx_sample_fifo.wused,
-- Metadata from host via FX3
meta_fifo_wclock => fx3_pclk_pll,
meta_fifo_wreq => tx_meta_fifo.wreq,
meta_fifo_wdata => tx_meta_fifo.wdata,
meta_fifo_wempty => tx_meta_fifo.wempty,
meta_fifo_wfull => tx_meta_fifo.wfull,
meta_fifo_wused => tx_meta_fifo.wused,
-- Digital Loopback Interface
loopback_enabled => '0',
loopback_fifo_wdata => loopback_fifo.wdata,
loopback_fifo_wreq => loopback_fifo.wreq,
loopback_fifo_wfull => loopback_fifo.wfull,
loopback_fifo_wused => loopback_fifo.wused,
-- RFFE Interface
dac_controls => dac_controls,
dac_streams => dac_streams
);
-- RX Submodule
U_rx : entity work.rx
generic map (
NUM_STREAMS => adc_controls'length
)
port map (
highly_packed_mode_en => fx3_control.highly_packed_mode,
rx_reset => rx_reset,
rx_clock => rx_clock,
rx_enable => fx3_control.rx_enable,
meta_en => meta_en_rx,
timestamp_reset => rx_ts_reset,
usb_speed => fx3_control.usb_speed,
rx_mux_sel => to_unsigned(0, 3),
rx_overflow_led => open,
rx_timestamp => rx_timestamp,
-- Triggering
trigger_arm => '0',
trigger_fire => '0',
trigger_master => '0',
trigger_line => open,
trigger_signal_sync_tb => trigger_signal_sync_tb,
-- Packet FIFO
packet_en => fx3_control.packet,
packet_control => rx_packet_control,
packet_ready => rx_packet_ready,
-- Samples to host via FX3
sample_fifo_rclock => fx3_pclk_pll,
sample_fifo_raclr => not fx3_control.rx_enable,
sample_fifo_rreq => rx_sample_fifo.rreq,
sample_fifo_rdata => rx_sample_fifo.rdata,
sample_fifo_rempty => rx_sample_fifo.rempty,
sample_fifo_rfull => rx_sample_fifo.rfull,
sample_fifo_rused => rx_sample_fifo.rused,
-- Mini expansion signals
mini_exp => "00",
-- Metadata to host via FX3
meta_fifo_rclock => fx3_pclk_pll,
meta_fifo_raclr => not fx3_control.rx_enable,
meta_fifo_rreq => rx_meta_fifo.rreq,
meta_fifo_rdata => rx_meta_fifo.rdata,
meta_fifo_rempty => rx_meta_fifo.rempty,
meta_fifo_rfull => rx_meta_fifo.rfull,
meta_fifo_rused => rx_meta_fifo.rused,
-- Digital Loopback Interface
loopback_fifo_wenabled => open,
loopback_fifo_wreset => tx_reset,
loopback_fifo_wclock => tx_clock,
loopback_fifo_wdata => loopback_fifo.wdata,
loopback_fifo_wreq => loopback_fifo.wreq,
loopback_fifo_wfull => loopback_fifo.wfull,
loopback_fifo_wused => loopback_fifo.wused,
-- RFFE Interface
adc_controls => adc_controls,
adc_streams => adc_streams
);
-- ========================================================================
-- Data converters
-- ========================================================================
gen_dac_controls : if( NUM_MIMO_STREAMS > 1 ) generate
-- The TX side of the AD9361 HDL is a FIFO pull interface
-- that expects a readahead FIFO. It toggles the data request
-- signal every other cycle. This behavior is mimicked here.
process( tx_clock, sys_rst )
begin
if( sys_rst = '1' ) then
dac_controls <= (
0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
);
elsif( rising_edge(tx_clock) ) then
for i in dac_controls'range loop
dac_controls(i) <= (
enable => dac_controls(i).enable,
data_req => not dac_controls(i).data_req );
end loop;
end if;
end process;
else generate
dac_controls <= (others => SAMPLE_CONTROL_ENABLE);
end generate;
gen_adc_controls : if( NUM_MIMO_STREAMS > 1 ) generate
process( rx_clock, sys_rst )
constant COUNT_RESET : integer := 0;
variable count : integer range -2047 to 2047 := COUNT_RESET;
begin
if( sys_rst = '1' ) then
count := COUNT_RESET;
adc_controls <= (
0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
);
elsif( rising_edge(rx_clock) ) then
for i in adc_controls'range loop
adc_controls(i) <= (
enable => adc_controls(i).enable,
data_req => not adc_controls(i).data_req );
if( adc_controls(i).enable = '1') then
if( adc_streams(i).data_v = '1' ) then
adc_streams(i).data_i <= to_signed(count, 16);
adc_streams(i).data_q <= to_signed(-count, 16);
if( count < 2047 ) then
count := count + 1;
else
count := COUNT_RESET;
end if;
end if;
adc_streams(i).data_v <= not adc_streams(i).data_v;
end if;
end loop;
end if;
end process;
else generate
adc_controls <= (others => SAMPLE_CONTROL_ENABLE);
end generate;
-- ========================================================================
-- Processes
-- ========================================================================
-- FX3 GPIF bidirectional signal control
-- Adapted from same process in bladerf-hosted.vhd
register_gpif : process(sys_rst, fx3_pclk_pll)
begin
if( sys_rst = '1' ) then
fx3_gpif_i <= (others => 'Z');
fx3_gpif.gpif_in <= (others => 'Z');
elsif( rising_edge(fx3_pclk_pll) ) then
fx3_gpif.gpif_in <= fx3_gpif_i;
if( fx3_gpif.gpif_oe = '1' ) then
fx3_gpif_i <= fx3_gpif.gpif_out;
else
fx3_gpif_i <= (others =>'Z');
end if;
end if;
end process;
-- FX3 CTL bidirectional signals
-- Adapted from same generator in bladerf-hosted.vhd
generate_ctl : for i in fx3_ctl_i'range generate
fx3_ctl_i(i) <= fx3_gpif.ctl_out(i) when fx3_gpif.ctl_oe(i) = '1' else 'Z';
end generate;
fx3_gpif.ctl_in <= fx3_ctl_i;
-- Controller for loopback FIFO
-- Stripped-down version of same process from rx.vhd
loopback_fifo_control : process( sys_rst, loopback_fifo.rclock )
begin
if( sys_rst = '1' ) then
loopback_enabled <= '0';
loopback_fifo.rreq <= '0';
loopback_i <= (others => '0');
loopback_q <= (others => '0');
loopback_valid <= '0';
elsif( rising_edge(loopback_fifo.rclock) ) then
loopback_enabled <= '0';
loopback_fifo.rreq <= '0';
loopback_i <= loopback_i;
loopback_q <= loopback_q;
loopback_valid <= '0';
-- Is loopback enabled?
loopback_enabled <= fx3_control.rx_enable;
-- Do the loopback
loopback_i <= resize(signed(loopback_fifo.rdata(15 downto 0)), loopback_i'length);
loopback_q <= resize(signed(loopback_fifo.rdata(31 downto 16)), loopback_q'length);
loopback_valid <= loopback_fifo.rreq and not loopback_fifo.rempty;
-- Read from the FIFO if req'd
loopback_fifo.rreq <= loopback_enabled and (not loopback_fifo.rempty);
end if;
end process;
-- RX multiplexer
-- Stripped-down version of same process from rx.vhd
rx_mux : process(sys_rst, sys_clk)
begin
if( sys_rst = '1' ) then
rx_mux_i <= (others =>'0');
rx_mux_q <= (others =>'0');
rx_mux_valid <= '0';
elsif( rising_edge(sys_clk) ) then
rx_mux_i <= loopback_i;
rx_mux_q <= loopback_q;
rx_mux_valid <= loopback_valid;
end if;
end process;
-- TX multiplexer
-- Stripped-down version of mimo_channel_sel_mux from tx.vhd
--tx_mux : process( sys_clk )
--begin
-- if( rising_edge(sys_clk) ) then
-- tx_sample_fifo.rreq <= not tx_sample_fifo.rempty;
-- loopback_fifo.wdata <= tx_sample_fifo.rdata;
-- loopback_fifo.wreq <= tx_sample_fifo.rreq and not tx_sample_fifo.rempty;
-- end if;
--end process;
-- ========================================================================
-- Verification
-- ========================================================================
--
-- Check for fullness on FIFOs
--
assert (rx_sample_fifo.wfull = '0') report "rx_sample_fifo full (write)" severity warning;
assert (tx_sample_fifo.wfull = '0') report "tx_sample_fifo full (write)" severity warning;
assert (loopback_fifo.wfull = '0') report "loopback_fifo full (write)" severity warning;
-- Every three gpif transfers will contain 4 samples.
-- Let's fill and check a 4 sample buffer every 3 pclk cycles.
--
-- Note: Failure expected after each fx3_model iteration since we lose
-- sample continuity when fifo writer is disabled.
look_for_dropped_rx_samples: process(fx3_pclk_pll)
variable rx_val : integer;
variable gpif_buffer_idx : integer range 0 to 2 := 0;
variable buf_sc12q11 : std_logic_vector(3*fx3_gpif.gpif_out'length-1 downto 0) := (others => '0');
begin
-- Init rx_val
if sys_rst = '1' then
rx_val := 16#172# when ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1 else 16#B9#;
end if;
if (rising_edge(fx3_pclk_pll)
and fx3_gpif.gpif_oe = '1'
and fx3_control.rx_enable = '1') then
-- Shift in the new samples
buf_sc12q11 := fx3_gpif.gpif_out & buf_sc12q11(buf_sc12q11'length-1 downto fx3_gpif.gpif_out'length);
-- Checks the 4 sample buffer every 3 pclk cycles
if gpif_buffer_idx = 2 then
for i in 0 to 3 loop
assert(signed(buf_sc12q11(11+24*i downto 24*i))) = to_signed(rx_val, 12)
report "I expected: " & integer'image(rx_val) & ", Actual: " & integer'image(to_integer(signed(buf_sc12q11(11+24*i downto 24*i))))
severity failure;
assert(signed(buf_sc12q11(23+24*i downto 12+24*i))) = to_signed(-1*rx_val, 12)
report "Q expected: " & integer'image(-1*rx_val) & ", Actual: " & integer'image(to_integer(signed(buf_sc12q11(23+24*i downto 12+24*i))))
severity failure;
rx_val := (rx_val + 1) mod 2048;
end loop;
end if;
gpif_buffer_idx := (gpif_buffer_idx + 1) mod 3;
end if;
end process look_for_dropped_rx_samples;
look_for_dropped_tx_samples: process(tx_clock)
variable tx_val : integer := 0;
variable message_count : integer := 1;
variable q_expected : integer := 0;
variable valid_tx_count : integer := 0;
begin
if rising_edge(tx_clock) then
for i in dac_controls'range loop
if dac_streams(i).data_v = '1' then
q_expected := tx_val+1 when fx3_control.highly_packed_mode = '1'
else to_integer(to_signed(message_count,8) & to_signed(tx_val+1, 8));
assert(dac_streams(i).data_i = to_signed(tx_val, 16))
report "TX("&integer'image(i)&") I expected: " & integer'image(tx_val) & ", Actual: " & integer'image(to_integer(signed(dac_streams(i).data_i)))
severity failure;
assert(dac_streams(i).data_q = q_expected)
report "TX("&integer'image(i)&") Q expected: " & integer'image(q_expected) & ", Actual: " & integer'image(to_integer(signed(dac_streams(i).data_q)))
severity failure;
-- A new message is received every 2048 samples
valid_tx_count := valid_tx_count + 1;
if valid_tx_count mod 2048 = 0 then
message_count := message_count + 1;
end if;
tx_val := (tx_val + 2) when tx_val < 2046 else -2048;
end if;
end loop;
end if;
end process look_for_dropped_tx_samples;
end architecture;

View file

@ -32,7 +32,6 @@ library nuand;
use nuand.fifo_readwrite_p.all;
use nuand.common_dcfifo_p.all;
use nuand.bladerf_p.all;
use nuand.fx3_gpif_p.all;
entity fx3_gpif_iq_tb is
generic (
@ -639,7 +638,6 @@ begin
look_for_dropped_tx_samples : process(tx_clock) is
constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model
variable current_message_count : natural := 1;
variable valid_sample_count : natural := 0;
variable iq_value : signed (15 downto 0) := x"0000";
variable expected_sample_q : signed (15 downto 0);
variable expected_sample_i : signed (15 downto 0);
@ -650,7 +648,6 @@ begin
and dac_streams(i).data_v = '1'
and fx3_control.tx_enable = '1' )
then
valid_sample_count := valid_sample_count + 1;
expected_sample_i := iq_value;
expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1);
@ -665,7 +662,7 @@ begin
-- Set iq values based on blocks received
-- See tx_sample_stream's encoding scheme in fx3_model.vhd
if( valid_sample_count mod GPIF_BUF_SIZE_SS = 0 ) then
if( iq_value = x"03FE" ) then
iq_value := x"0000";
if( current_message_count < MESSAGES_PER_ITERATION ) then
current_message_count := current_message_count + 1;

View file

@ -32,7 +32,6 @@ library nuand;
use nuand.fifo_readwrite_p.all;
use nuand.common_dcfifo_p.all;
use nuand.bladerf_p.all;
use nuand.fx3_gpif_p.all;
entity fx3_gpif_meta_8bit_tb is
generic (
@ -697,8 +696,7 @@ begin
look_for_dropped_tx_samples : process(tx_clock) is
constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model
constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000";
constant HEADER_LEN : natural := 4; -- In clk cycles
variable valid_sample_count : natural := 0;
variable dac_stream_back_to_0 : natural := 0;
variable current_message_count : natural := 1;
variable iq_value : signed (15 downto 0) := x"0000";
variable expected_sample_i : signed (15 downto 0);
@ -711,7 +709,6 @@ begin
and dac_streams(i).data_v = '1'
and fx3_control.tx_enable = '1' )
then
valid_sample_count := valid_sample_count + 1;
if( EIGHT_BIT_MODE_EN = '1' ) then
expected_sample_i := iq_value (11 downto 0) & SIGMA_DELTA_BITS;
expected_sample_q := iq_value (11 downto 0) + 1 & SIGMA_DELTA_BITS;
@ -732,16 +729,9 @@ begin
end if;
end if;
if( valid_sample_count mod (2*GPIF_BUF_SIZE_SS - 8) = 0 ) then
iq_value := x"0000";
if( current_message_count < MESSAGES_PER_ITERATION ) then
current_message_count := current_message_count + 1;
else
current_message_count := 1;
end if;
else
iq_value := (iq_value + 2) mod 128;
end if;
dac_stream_back_to_0 := dac_stream_back_to_0 + 1 when iq_value = 0;
iq_value := (iq_value + 2) mod 128 when dac_stream_back_to_0 mod 16 /= 0 else
(iq_value + 2) mod 112;
else
expected_sample_i := iq_value;
expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1);
@ -757,7 +747,7 @@ begin
-- Set iq values based on blocks received
-- See tx_sample_stream's encoding scheme in fx3_model.vhd
if( valid_sample_count mod (GPIF_BUF_SIZE_SS - HEADER_LEN) = 0 ) then
if( iq_value = x"03F6" ) then
iq_value := x"0000";
if( current_message_count < MESSAGES_PER_ITERATION ) then
current_message_count := current_message_count + 1;
@ -920,11 +910,11 @@ begin
-- Allows a 0 increment for the first ts assertion
if( ENABLE_CHANNEL_0 = '1' and ENABLE_CHANNEL_1 = '1') then
ts_increment := (GPIF_BUF_SIZE_SS-4)/2 when EIGHT_BIT_MODE_EN = '0'
else (GPIF_BUF_SIZE_SS-4);
ts_increment := 254 when EIGHT_BIT_MODE_EN = '0'
else 508;
else
ts_increment := (GPIF_BUF_SIZE_SS -4) when EIGHT_BIT_MODE_EN = '0'
else 2*(GPIF_BUF_SIZE_SS -4);
ts_increment := 508 when EIGHT_BIT_MODE_EN = '0'
else 1016;
end if;
iteration := iteration + 1;

View file

@ -32,7 +32,6 @@ library nuand;
use nuand.fifo_readwrite_p.all;
use nuand.common_dcfifo_p.all;
use nuand.bladerf_p.all;
use nuand.fx3_gpif_p.all;
entity fx3_gpif_meta_tb is
generic (
@ -684,10 +683,8 @@ begin
end process tx_sample_start_check;
look_for_dropped_tx_samples : process(tx_clock) is
constant HEADER_LEN : integer := 4; -- In clk cycles
constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model
variable current_message_count : natural := 1;
variable valid_sample_count : natural := 0;
variable iq_value : signed (15 downto 0) := x"0000";
variable expected_sample_q : signed (15 downto 0);
variable expected_sample_i : signed (15 downto 0);
@ -698,7 +695,6 @@ begin
and dac_streams(i).data_v = '1'
and fx3_control.tx_enable = '1' )
then
valid_sample_count := valid_sample_count + 1;
expected_sample_i := iq_value;
expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1);
@ -713,7 +709,7 @@ begin
-- Set iq values based on blocks received
-- See tx_sample_stream's encoding scheme in fx3_model.vhd
if( valid_sample_count mod (GPIF_BUF_SIZE_SS-HEADER_LEN) = 0 ) then
if( iq_value = x"03F6" ) then
iq_value := x"0000";
if( current_message_count < MESSAGES_PER_ITERATION ) then
current_message_count := current_message_count + 1;

View file

@ -700,7 +700,7 @@ begin
-- Change the iq values based on blocks received
-- See tx_sample_stream's encoding scheme in fx3_model.vhd
if( iq_value(7 downto 0) = tx_packet_len - 1 ) then
if( iq_value(7 downto 0) = tx_packet_len ) then
iq_value := x"0000";
if( current_block_count <= BLOCKS_PER_ITERATION ) then
current_block_count := current_block_count + 1;

View file

@ -26,7 +26,6 @@ library ieee;
library work;
use work.util.all;
use work.fx3_gpif_p.all;
architecture micro_dma of fx3_model is
@ -58,32 +57,6 @@ architecture micro_dma of fx3_model is
signal rx_data : std_logic_vector(31 downto 0);
signal tx_data : std_logic_vector(31 downto 0);
-- Generates packed samples
-- The host will pack SC16Q11 samples into an SC12Q11 format. Every 3 gpif_in
-- cycles contain 4 SC12Q11 IQ pairs.
--
-- Packing order:
-- Buffer 1: [--Sample1(8)--|----------Sample0(24)----------]
-- Buffer 2: [------Sample2(16)------|------Sample1(16)-----]
-- Buffer 3: [----------Sample3(24)----------|--Sample2(8)--]
function data_gen_packed(cycle : natural) return std_logic_vector is
variable four_sample_buffer : std_logic_vector(95 downto 0) := (others => '0');
variable buffer_offset : integer := 0;
variable sample_value_ref : integer := 0;
variable I : std_logic_vector(11 downto 0) := (others => '0');
variable Q : std_logic_vector(11 downto 0) := (others => '0');
begin
sample_value_ref := cycle / 3;
for j in 0 to 3 loop
Q := std_logic_vector(to_signed(8*sample_value_ref+2*j+1, 12));
I := std_logic_vector(to_signed(8*sample_value_ref+2*j, 12));
four_sample_buffer := Q & I & four_sample_buffer(95 downto 24);
end loop;
buffer_offset := (cycle mod 3) * 32;
return four_sample_buffer(31+buffer_offset downto buffer_offset);
end function data_gen_packed;
impure function data_gen (count : natural) return std_logic_vector is
variable eight_bit_msw_i : std_logic_vector(7 downto 0);
variable eight_bit_msw_q : std_logic_vector(7 downto 0);
@ -125,7 +98,7 @@ begin
done <= rx_done and tx_done;
rx_sample_stream : process
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
constant BLOCK_SIZE : natural := 512;
variable count : natural := START_COUNT;
variable req_time : time;
begin
@ -178,10 +151,9 @@ begin
end process;
tx_sample_stream : process
constant TIME_BETWEEN_ITERATIONS : natural := 7000;
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
constant TIME_BETWEEN_ITERATIONS : natural := 4593;
constant BLOCK_SIZE : natural := 512;
variable count : natural := START_COUNT;
variable cycle : natural := 0;
variable timestamp_cntr : natural := 400;
variable header_len : natural := 0;
variable data_out : std_logic_vector(31 downto 0);
@ -251,11 +223,7 @@ begin
for i in 1 to (BLOCK_SIZE - header_len) loop
gpif_state_tx <= TX_SAMPLES;
data_out := data_gen(count);
if packed_mode_en = '1' then
data_out := data_gen_packed(cycle);
end if;
if( eight_bit_mode_en = '1' or packed_mode_en = '1' ) then
if( eight_bit_mode_en = '1' ) then
fx3_gpif <= data_out;
tx_data <= data_out;
else
@ -264,7 +232,6 @@ begin
end if;
wait until rising_edge( fx3_pclk );
cycle := cycle + 1;
count := (count + 4) mod 128 when eight_bit_mode_en = '1' else
(count + 2) mod 2048;
gpif_state_tx <= IDLE;
@ -275,7 +242,7 @@ begin
nop(fx3_pclk, 10);
end loop;
wait for 1.5 ms;
wait for 1 ms;
dma_tx_enable <= '0';
wait for 10 us;
end loop;
@ -366,7 +333,7 @@ begin
done <= rx_done and tx_done;
rx_sample_stream : process
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
constant BLOCK_SIZE : natural := 512;
variable count : natural := START_COUNT;
variable req_time : time;
begin
@ -420,7 +387,7 @@ begin
tx_sample_stream : process
constant TIME_BETWEEN_ITERATIONS : natural := 4556;
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
constant BLOCK_SIZE : natural := 512;
variable count : natural := START_COUNT;
variable timestamp_cntr : natural := 250;
variable header_len : natural := 0;

View file

@ -1,280 +0,0 @@
-- 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.numeric_std.all;
use ieee.math_real.all;
use ieee.math_complex.all;
library work;
use work.util.all;
use work.fx3_gpif_p.all;
architecture micro_dma_fifo_stress of fx3_model is
constant PCLK_HALF_PERIOD : time := 1 sec * (1.0/100.0e6/2.0);
constant START_COUNT : natural := 32;
constant BLOCKS_PER_ITERATION : natural := 7;
constant ITERATIONS : natural := 4;
-- Control mapping
alias dma0_rx_ack is fx3_ctl( 0);
alias dma1_rx_ack is fx3_ctl( 1);
alias dma2_tx_ack is fx3_ctl( 2);
alias dma3_tx_ack is fx3_ctl( 3);
alias dma_rx_enable is fx3_ctl( 4);
alias dma_tx_enable is fx3_ctl( 5);
alias dma_idle is fx3_ctl( 6);
alias system_reset is fx3_ctl( 7);
alias dma0_rx_reqx is fx3_ctl( 8);
alias dma1_rx_reqx is fx3_ctl(12); -- due to 9 being connected to dclk
alias dma2_tx_reqx is fx3_ctl(10);
alias dma3_tx_reqx is fx3_ctl(11);
type gpif_state_t is (IDLE, TX_META, TX_SAMPLES, RX_SAMPLES);
signal gpif_state_rx, gpif_state_tx : gpif_state_t;
signal rx_done : boolean := false;
signal tx_done : boolean := false;
signal rx_data : std_logic_vector(31 downto 0);
signal tx_data : std_logic_vector(31 downto 0);
impure function data_gen (count : natural) return std_logic_vector is
variable eight_bit_msw_i : std_logic_vector(7 downto 0);
variable eight_bit_msw_q : std_logic_vector(7 downto 0);
variable eight_bit_lsw_i : std_logic_vector(7 downto 0);
variable eight_bit_lsw_q : std_logic_vector(7 downto 0);
variable msw, lsw : std_logic_vector(15 downto 0);
begin
if( eight_bit_mode_en = '1' ) then
eight_bit_lsw_i := std_logic_vector(to_unsigned(count, 8));
eight_bit_lsw_q := std_logic_vector(to_unsigned(count+1, 8));
eight_bit_msw_i := std_logic_vector(to_unsigned(count+2, 8));
eight_bit_msw_q := std_logic_vector(to_unsigned(count+3, 8));
lsw := eight_bit_lsw_q & eight_bit_lsw_i;
msw := eight_bit_msw_q & eight_bit_msw_i;
else
msw := std_logic_vector(to_signed(count+1, 16));
lsw := std_logic_vector(to_signed(count, 16));
end if;
return (msw & lsw);
end function data_gen;
impure function data_check (count : natural ; rxdata : std_logic_vector(31 downto 0)) return boolean is
begin
return (rxdata = data_gen(count));
end function data_check;
begin
-- DCLK which isn't used
fx3_ctl(9) <= '0';
fx3_ctl(3 downto 0) <= (others => 'Z');
-- Create a 100MHz clock output
fx3_pclk <= not fx3_pclk after PCLK_HALF_PERIOD when (not rx_done or not tx_done) else '0';
-- Doneness
done <= rx_done and tx_done;
rx_sample_stream : process
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
variable count : natural := START_COUNT;
variable req_time : time;
begin
gpif_state_rx <= IDLE;
dma0_rx_reqx <= '1';
dma1_rx_reqx <= '1';
dma_rx_enable <= '0';
rx_data <= (others => 'U');
wait until rising_edge(fx3_pclk) and system_reset = '0';
nop(fx3_pclk, 1000);
wait until rising_edge(fx3_pclk) and fx3_rx_en = '1';
wait for 30 us;
for j in 1 to ITERATIONS loop
dma_rx_enable <= '1';
for i in 1 to BLOCKS_PER_ITERATION loop
dma0_rx_reqx <= '0';
req_time := now;
wait until rising_edge( fx3_pclk ) and dma0_rx_ack = '1';
wait until rising_edge( fx3_pclk );
dma0_rx_reqx <= '1';
report "RX iteration " & to_string(j) & " block " & to_string(i) & " delay " & to_string(now - req_time);
for i in 1 to BLOCK_SIZE loop
gpif_state_rx <= RX_SAMPLES;
rx_data <= fx3_gpif;
wait until rising_edge( fx3_pclk );
--assert data_check(count, rx_data) severity failure;
count := (count + 1) mod 2048;
gpif_state_rx <= IDLE;
rx_data <= (others => 'X');
end loop;
end loop;
dma_rx_enable <= '0';
wait for 10 us;
end loop;
report "Done with RX sample stream";
rx_done <= true;
wait;
end process;
tx_sample_stream : process
constant TIME_BETWEEN_ITERATIONS : natural := 4593;
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
variable count : natural := START_COUNT;
variable timestamp_cntr : natural := 400;
variable header_len : natural := 0;
variable data_out : std_logic_vector(31 downto 0);
variable req_time : time;
begin
gpif_state_tx <= IDLE;
dma2_tx_reqx <= '1';
dma3_tx_reqx <= '1';
dma_tx_enable <= '0';
fx3_gpif <= (others =>'Z');
wait until rising_edge(fx3_pclk) and system_reset = '0';
nop(fx3_pclk, 1000);
wait until rising_edge(fx3_pclk) and fx3_tx_en = '1';
wait for 30 us;
for k in 1 to ITERATIONS loop
dma_tx_enable <= '1';
for fifo_stress_idx in 1 to 3 loop
for j in 1 to BLOCKS_PER_ITERATION loop
header_len := 0;
dma3_tx_reqx <= '0';
req_time := now;
wait until rising_edge( fx3_pclk ) and dma3_tx_ack = '1';
wait until rising_edge( fx3_pclk );
wait until rising_edge( fx3_pclk );
wait until rising_edge( fx3_pclk );
dma3_tx_reqx <= '1';
report "TX iteration " & to_string(k) & " block " & to_string(j) & " delay " & to_string(now - req_time);
if( fx3_tx_meta_en = '1') then
header_len := 4;
for i in 1 to 4 loop
case (i) is
when 1 =>
data_out := x"00000000";
when 2 =>
data_out(31 downto 0) := std_logic_vector(to_signed(timestamp_cntr, 32));
if (j = BLOCKS_PER_ITERATION) then
timestamp_cntr := timestamp_cntr + TIME_BETWEEN_ITERATIONS;
else
timestamp_cntr := timestamp_cntr + 254;
end if;
when 3 =>
data_out := (others => '0');
when 4 =>
data_out := (others => '1');
end case;
gpif_state_tx <= TX_META;
fx3_gpif <= data_out;
tx_data <= data_out;
wait until rising_edge( fx3_pclk );
gpif_state_tx <= IDLE;
tx_data <= (others => 'X');
end loop;
end if;
count := 0;
for i in 1 to (BLOCK_SIZE - header_len) loop
gpif_state_tx <= TX_SAMPLES;
data_out := data_gen(count);
if( eight_bit_mode_en = '1' ) then
fx3_gpif <= data_out;
tx_data <= data_out;
else
fx3_gpif <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0);
tx_data <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0);
end if;
wait until rising_edge( fx3_pclk );
count := (count + 4) mod 128 when eight_bit_mode_en = '1' else
(count + 2) mod 2048;
gpif_state_tx <= IDLE;
tx_data <= (others => 'X');
end loop;
fx3_gpif <= (others =>'Z');
nop(fx3_pclk, 10);
end loop;
wait for 10 us;
end loop;
wait for 2 ms;
dma_tx_enable <= '0';
wait for 10 us;
end loop;
report "Done with TX sample stream";
tx_done <= true;
wait;
end process;
reset_system : process
begin
system_reset <= '1';
dma_idle <= '0';
nop( fx3_pclk, 100 );
system_reset <= '0';
nop( fx3_pclk, 10 );
dma_idle <= '1';
wait;
end process;
-- TODO: UART Interface
fx3_uart_txd <= '1';
fx3_uart_cts <= '1';
assert (gpif_state_tx = IDLE and gpif_state_rx /= IDLE)
or (gpif_state_rx = IDLE and gpif_state_tx /= IDLE)
or (gpif_state_rx = IDLE and gpif_state_tx = IDLE)
report "gpif_state_rx and gpif_state_tx cannot both be non-idle"
severity failure;
end architecture micro_dma_fifo_stress;

View file

@ -108,20 +108,7 @@ entity nios_system is
tx_trigger_ctl_out_port : out std_logic_vector(7 downto 0); -- out_port
xb_gpio_in_port : in std_logic_vector(31 downto 0) := (others => 'X'); -- in_port
xb_gpio_out_port : out std_logic_vector(31 downto 0); -- out_port
xb_gpio_dir_export : out std_logic_vector(31 downto 0); -- export
arbiter_request : in std_logic_vector(1 downto 0) := (others => 'X'); -- request
arbiter_granted : out std_logic_vector(1 downto 0); -- granted
arbiter_ack : in std_logic_vector(1 downto 0) := (others => 'X'); -- ack
wbm_wb_clk_i : in std_logic := 'X'; -- clk_i
wbm_wb_rst_i : in std_logic := 'X'; -- rst_i
wbm_wb_adr_o : out std_logic_vector(31 downto 0); -- adr_o
wbm_wb_dat_o : out std_logic_vector(31 downto 0); -- dat_o
wbm_wb_dat_i : in std_logic_vector(31 downto 0) := (others => 'X'); -- dat_i
wbm_wb_we_o : out std_logic; -- we_o
wbm_wb_sel_o : out std_logic; -- sel_o
wbm_wb_stb_o : out std_logic; -- stb_o
wbm_wb_ack_i : in std_logic := 'X'; -- ack_i
wbm_wb_cyc_o : out std_logic -- cyc_o
xb_gpio_dir_export : out std_logic_vector(31 downto 0) -- export
);
end entity ;
@ -155,14 +142,5 @@ begin
xb_gpio_out_port <= (others =>'0') ;
xb_gpio_dir_export <= (others =>'0') ;
arbiter_granted <= (others => '0');
wbm_wb_adr_o <= (others => '0');
wbm_wb_dat_o <= (others => '0');
wbm_wb_we_o <= '0';
wbm_wb_sel_o <= '0';
wbm_wb_stb_o <= '0';
wbm_wb_cyc_o <= '0';
end architecture ;

View file

@ -32,7 +32,6 @@ library nuand;
use nuand.fifo_readwrite_p.all;
use nuand.common_dcfifo_p.all;
use nuand.bladerf_p.all;
use nuand.fx3_gpif_p.all;
entity rx_timestamp_tb is
generic (
@ -619,8 +618,7 @@ begin
-- variable timestamp : unsigned(63 downto 0) := (others => '0');
begin
wait for 1 ns;
delta_expected := to_unsigned(GPIF_BUF_SIZE_SS-HEADER_LEN, 64) when not EIGHT_BIT_MODE_EN
else to_unsigned(2*(GPIF_BUF_SIZE_SS-HEADER_LEN), 64);
delta_expected := to_unsigned(508, 64) when not EIGHT_BIT_MODE_EN else to_unsigned(1016, 64);
if (ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1) then
delta_expected := delta_expected/2;

View file

@ -26,7 +26,6 @@ library ieee;
library work;
use work.util.all;
use work.fx3_gpif_p.all;
architecture wlan_micro_packet_dma of fx3_model is
@ -109,7 +108,7 @@ begin
done <= rx_done and tx_done;
rx_sample_stream : process
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
constant BLOCK_SIZE : natural := 512;
variable count : natural := START_COUNT;
variable req_time : time;
begin
@ -162,7 +161,7 @@ begin
end process;
tx_sample_stream : process
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
constant BLOCK_SIZE : natural := 512;
variable count : natural := START_COUNT;
variable timestamp_cntr : natural := 100;
variable header_len : natural := 0;

View file

@ -47,9 +47,8 @@ entity tx is
trigger_master : in std_logic;
trigger_line : inout std_logic; -- this is not good, should be in/out/oe
-- Packing modes
eight_bit_mode_en : in std_logic := '0';
highly_packed_mode_en : in std_logic := '0';
-- 8-bit mode
eight_bit_mode_en : in std_logic := '0';
-- Packet from host via FX3
packet_en : in std_logic;
@ -219,7 +218,6 @@ begin
timestamp => tx_timestamp,
eight_bit_mode_en => eight_bit_mode_en,
highly_packed_mode_en => highly_packed_mode_en,
fifo_empty => sample_fifo.rempty,
fifo_usedw => sample_fifo.rused,

View file

@ -33,7 +33,6 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip syn
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/fifo_writer.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/lms6002d/vhdl/lms6002d.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/set_clear_ff.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/bladerf-adsb.vhd]]

View file

@ -33,7 +33,6 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip syn
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/fifo_writer.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/lms6002d/vhdl/lms6002d.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/set_clear_ff.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/bladerf-atsc_tx.vhd]]
set_global_assignment -name QIP_FILE [file normalize nios_system/synthesis/nios_system.qip]

View file

@ -35,7 +35,6 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip syn
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/lms6002d/vhdl/bladerf_agc.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip trigger/trigger.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/set_clear_ff.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/rx_packet_generator.vhd]]
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/bladerf-hosted.vhd]]

View file

@ -105,8 +105,8 @@ set_output_delay -clock [get_clocks altera_reserved_tck] 20 [get_ports altera_re
# Exceptions
# The dcfifo which goes from the C4 TX domain to the PCLK domain seems to have an issue with the clear signal. It isn't generally a issue so ignore it?
set_false_path -from {reset_synchronizer:U_tx_reset|sync} -to {tx_*fifo:U_tx_*_fifo|common_dcfifo:U_common_dcfifo|dcfifo*:auto_generated|dffpipe_3dc:wraclr|dffe*a[0]}
set_false_path -from {reset_synchronizer:U_tx_reset|sync} -to {tx_*fifo:U_tx_*_fifo|common_dcfifo:U_common_dcfifo|dcfifo*:auto_generated|dffpipe_3dc:wraclr|dffe*a[0]}
set_false_path -from {reset_synchronizer:U_tx_reset|sync} -to {tx_*fifo:U_tx_*_fifo|common_dcfifo:U_common_dcfifo|dcfifo*:auto_generated|dffpipe_3dc:wraclr|dffe12a[0]}
set_false_path -from {reset_synchronizer:U_tx_reset|sync} -to {tx_*fifo:U_tx_*_fifo|common_dcfifo:U_common_dcfifo|dcfifo*:auto_generated|dffpipe_3dc:wraclr|dffe13a[0]}
# False path between hold_time and compare_time due to the way the FSM is setup
set_false_path -from {*x_tamer|hold_time[*]} -to {*x_tamer|compare_time[*]}

View file

@ -1,17 +1,16 @@
source ../../../ip/nuand/nuand.do
compile_nuand ../../../ip/nuand bladerf
compile_nuand ../../../ip/nuand
vcom -work nuand -2008 ../../../ip/altera/pll/pll.vhd
vcom -work nuand -2008 ../../../ip/altera/fx3_pll/fx3_pll.vhd
vcom -work nuand -2008 ../../../ip/altera/rx_fifo/rx_fifo.vhd
vcom -work nuand -2008 ../../../ip/altera/tx_fifo/tx_fifo.vhd
vcom -work nuand -2008 ../../../ip/altera/tx_meta_fifo/tx_meta_fifo.vhd
vcom -work nuand -2008 ../../../ip/altera/rx_meta_fifo/rx_meta_fifo.vhd
vcom -work nuand -2008 ../vhdl/tb/nios_system.vhd
vcom -work nuand -2008 ../../common/bladerf/vhdl/fx3_gpif_p.vhd
vcom -work nuand -2008 ../../common/bladerf/vhdl/fx3_gpif.vhd
vcom -work nuand -2008 ../../../ip/nuand/lms6_spi_controller/vhdl/lms6_spi_controller.vhd
vcom -work nuand -2008 ../../../ip/nuand/synthesis/lms6002d/vhdl/bladerf_agc_lms_drv.vhd
vcom -work nuand -2008 ../../../ip/nuand/synthesis/lms6002d/vhdl/bladerf_agc.vhd
vcom -work nuand -2008 ../vhdl/fx3_gpif.vhd
vcom -work nuand -2008 ../vhdl/bladerf.vhd
vcom -work nuand -2008 ../vhdl/bladerf_p.vhd

View file

@ -7,7 +7,7 @@
#define FPGA_VERSION_ID 0x7777
#define FPGA_VERSION_MAJOR 0
#define FPGA_VERSION_MINOR 16
#define FPGA_VERSION_MINOR 14
#define FPGA_VERSION_PATCH 0
#define FPGA_VERSION ((uint32_t)( FPGA_VERSION_MAJOR | \
(FPGA_VERSION_MINOR << 8) | \

View file

@ -769,7 +769,6 @@ begin
meta_en => meta_en_rx,
packet_en => packet_en_rx,
eight_bit_mode_en => '0',
highly_packed_mode_en => '0',
timestamp => rx_timestamp,
mini_exp => mini_exp2 & mini_exp1,
@ -920,7 +919,6 @@ begin
meta_en => meta_en_tx,
packet_en => packet_en_tx,
eight_bit_mode_en => '0',
highly_packed_mode_en => '0',
timestamp => tx_timestamp,
fifo_empty => tx_sample_fifo.rempty,

View file

@ -46,16 +46,7 @@ entity nios_system is
tx_trigger_ctl_in_port : in std_logic_vector(7 downto 0);
tx_trigger_ctl_out_port : out std_logic_vector(7 downto 0);
rx_trigger_ctl_in_port : in std_logic_vector(7 downto 0);
rx_trigger_ctl_out_port : out std_logic_vector(7 downto 0);
arbiter_request : in std_logic_vector(1 downto 0);
arbiter_granted : out std_logic_vector(1 downto 0);
arbiter_ack : in std_logic_vector(1 downto 0);
agc_dc_i_max_export : out std_logic_vector(15 downto 0);
agc_dc_q_max_export : out std_logic_vector(15 downto 0);
agc_dc_i_mid_export : out std_logic_vector(15 downto 0);
agc_dc_q_mid_export : out std_logic_vector(15 downto 0);
agc_dc_i_min_export : out std_logic_vector(15 downto 0);
agc_dc_q_min_export : out std_logic_vector(15 downto 0)
rx_trigger_ctl_out_port : out std_logic_vector(7 downto 0)
);
end entity ;
@ -92,17 +83,5 @@ begin
xb_gpio_out_port <= (others =>'0') ;
xb_gpio_dir_export <= (others =>'0') ;
tx_trigger_ctl_out_port <= (others => '0');
rx_trigger_ctl_out_port <= (others => '0');
arbiter_granted <= (others => '0');
agc_dc_i_max_export <= (others => '0');
agc_dc_q_max_export <= (others => '0');
agc_dc_i_mid_export <= (others => '0');
agc_dc_q_mid_export <= (others => '0');
agc_dc_i_min_export <= (others => '0');
agc_dc_q_min_export <= (others => '0');
end architecture ;

View file

@ -146,7 +146,7 @@ Command-Line Debugging with GDB
- `$QUARTUS_INSTALL_DIR/nios2eds/nios2_command_shell.sh`
- cd into `$BLADERF_DIR/hdl/quartus/work/<platform>-<size>-<rev>/bladeRF_nios`
- Start the Nios gdb client:
- `make WORKDIR=work/<platform>-<size>-<rev> elf-gdb`
- `nios2-elf-gdb -ex "target remote localhost:8888" bladeRF_nios.elf`
- The Nios processor will now be in a paused state. This lets us setup breakpoints and whatnot as needed for debug. When ready to begin the debug process, issue the `continue` command. This will unpause the Nios.
- If a breakpoint is hit, gdb will pause the Nios again until you issue another `continue` command. This may cause a timeout and break the user application. Breakpoints can have [commands associated with them](https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_34.html), so when one is hit, gdb can immediately print a value and continue. The print operation is slow enough that if more than a few characters are printed, it will trigger a timeout in libbladeRF. Refer to the *Debugging Tips* section for how to increase the timeout.

View file

@ -897,8 +897,6 @@ endif # QSYS == 1
@$(ECHO) " Run targets:"
@$(ECHO) " download-elf - Download and run your elf executable"
@$(ECHO) " program-flash - Program flash contents to the board"
@$(ECHO) " gdb-server - Start GDB server on port 8888"
@$(ECHO) " elf-gdb - Connect GDB to running server and load symbols"
# Handy rule to skip making libraries and just make application.
.PHONY : app
@ -1006,7 +1004,7 @@ download-elf : $(ELF)
$(ECHO) Downloading $(ELF) not supported; \
else \
$(ECHO) Info: Downloading $(ELF); \
$(DOWNLOAD) --cpu_name=$(CPU_NAME) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) $(DOWNLOAD_JDI_FLAG) $(WRITE_GMON_OPTION) $(ELF); \
$(DOWNLOAD) --go --cpu_name=$(CPU_NAME) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) $(DOWNLOAD_JDI_FLAG) $(WRITE_GMON_OPTION) $(ELF); \
fi
# Delete the target of a rule if it has changed and its commands exit
@ -1113,13 +1111,3 @@ $(OBJDUMP_NAME) : $(ELF)
.PHONY: print-elf-name
print-elf-name:
@$(ECHO) $(ELF)
.PHONY : elf-gdb
elf-gdb : $(ELF)
@$(ECHO) Info: Starting GDB for $(ELF)
nios2-elf-gdb -ex "target remote localhost:8888" $(ELF)
.PHONY : gdb-server
gdb-server:
@$(ECHO) Info: Starting GDB server on port 8888
nios2-gdb-server --tcpport 8888 --tcppersist

View file

@ -102,7 +102,7 @@
/* Number of RFFE fast lock profiles to store in the Nios.
* Make sure this matches what is defined in bladerf2.c.
*/
#define NUM_BBP_FASTLOCK_PROFILES 256
#define NUM_BBP_FASTLOCK_PROFILES 2048
/* Number of fast lock profiles that can be stored in the RFFE */
#define NUM_RFFE_FASTLOCK_PROFILES 8

View file

@ -98,7 +98,7 @@ static inline bool perform_write(uint8_t id, uint8_t addr, uint32_t data)
#ifdef BOARD_BLADERF_MICRO
case NIOS_PKT_8x32_TARGET_FASTLOCK:
adi_fastlock_save( (addr == 1), (data >> 16), (data & 0xff));
adi_fastlock_save( (addr == 1), (data >> 16), (data & 0xffff));
break;
#endif // BOARD_BLADERF_MICRO

View file

@ -28,6 +28,7 @@
#include "nios_pkt_retune2.h" /* Packet format definition */
#include "devices.h"
#include "debug.h"
#include "sys/alt_stdio.h"
#ifdef BLADERF_NIOS_LIBAD936X
void rfic_invalidate_frequency(bladerf_module module);
@ -41,9 +42,9 @@ void rfic_invalidate_frequency(bladerf_module module);
#endif
/* The enqueue/dequeue routines require that this be a power of two */
#define RETUNE2_QUEUE_MAX 16
#define QUEUE_FULL 0xff
#define QUEUE_EMPTY 0xfe
#define RETUNE2_QUEUE_MAX 2048
#define QUEUE_FULL UINT16_MAX
#define QUEUE_EMPTY (UINT16_MAX - 1)
/* State of items in the retune queue */
enum entry_state {
@ -63,20 +64,20 @@ struct queue_entry {
};
static struct queue {
uint8_t count; /* Total number of items in the queue */
uint8_t ins_idx; /* Insertion index */
uint8_t rem_idx; /* Removal index */
uint16_t count; /* Total number of items in the queue */
uint16_t ins_idx; /* Insertion index */
uint16_t rem_idx; /* Removal index */
struct queue_entry entries[RETUNE2_QUEUE_MAX];
} rx_queue, tx_queue;
/* Returns queue size after enqueue operation, or QUEUE_FULL if we could
* not enqueue the requested item */
static inline uint8_t enqueue_retune(struct queue *q,
static inline uint16_t enqueue_retune(struct queue *q,
fastlock_profile *p,
uint64_t timestamp)
{
uint8_t ret;
uint16_t ret;
if (q->count >= RETUNE2_QUEUE_MAX) {
return QUEUE_FULL;
@ -96,9 +97,9 @@ static inline uint8_t enqueue_retune(struct queue *q,
/* Retune number of items left in the queue after the dequeue operation,
* or QUEUE_EMPTY if there was nothing to dequeue */
static inline uint8_t dequeue_retune(struct queue *q, struct queue_entry *e)
static inline uint16_t dequeue_retune(struct queue *q, struct queue_entry *e)
{
uint8_t ret;
uint16_t ret;
if (q->count == 0) {
return QUEUE_EMPTY;
@ -131,7 +132,7 @@ static inline struct queue_entry* peek_next_retune(struct queue *q)
/* Get the queue element at the given offset relative to the removal index */
static inline struct queue_entry* peek_next_retune_offset(struct queue *q,
uint8_t offset)
uint16_t offset)
{
if (q == NULL) {
return NULL;
@ -294,6 +295,14 @@ static inline void perform_work(struct queue *q, bladerf_module module)
/* Load the fast lock profile into the RFFE */
profile_load(module, e->profile);
#ifdef BLADERF_NIOS_DEBUG
if (time_tamer_read(module) > e->timestamp) {
DBG("Timestamp %x is in the past. SPI write likely too slow.\n", e->timestamp);
DBG("Try increasing timestamp spacing between retunes.\n");
INCREMENT_ERROR_COUNT();
}
#endif
/* Schedule the retune */
e->state = ENTRY_STATE_SCHEDULED;
tamer_schedule(module, e->timestamp);
@ -410,7 +419,7 @@ void pkt_retune2(struct pkt_buf *b)
status = -1;
}
} else {
uint8_t queue_size;
uint16_t queue_size;
switch (module) {
case BLADERF_MODULE_RX:

View file

@ -22,9 +22,6 @@ library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library nuand;
use nuand.fx3_gpif_p.all;
entity fx3_gpif is
port (
-- FX3 control signals
@ -120,6 +117,10 @@ architecture sample_shuffler of fx3_gpif is
constant META_DOWNCOUNT_RESET : natural := 4;
constant FINI_DOWNCOUNT_RESET : natural := 10;
-- GPIF buf sizes for USB high-speed and super-speed
constant GPIF_BUF_SIZE_HS : natural := 256;
constant GPIF_BUF_SIZE_SS : natural := 512;
type dma_handshake_t is record
rx0 : std_logic;
rx1 : std_logic;
@ -179,8 +180,8 @@ architecture sample_shuffler of fx3_gpif is
signal current, future : fsm_t := FSM_RESET_VALUE;
signal can_rx : boolean;
signal can_tx : boolean;
signal can_rx, should_rx : boolean;
signal can_tx, should_tx : boolean;
signal rx_fifo_enough : boolean;
signal tx_fifo_enough : boolean;
signal rx_fifo_critical : boolean;
@ -192,10 +193,14 @@ architecture sample_shuffler of fx3_gpif is
attribute preserve : boolean;
attribute preserve of can_rx : signal is true;
attribute preserve of can_tx : signal is true;
attribute preserve of should_rx : signal is true;
attribute preserve of should_tx : signal is true;
attribute keep : boolean;
attribute keep of can_rx : signal is true;
attribute keep of can_tx : signal is true;
attribute keep of should_rx : signal is true;
attribute keep of should_tx : signal is true;
-- acknowledge(dma_channel) returns a dma_handshake_t with all bits 0
-- except the bit corresponding to dma_channel
@ -275,7 +280,7 @@ begin
-- Can we not fit one more block of data in RX buffer?
rx_fifo_critical <= (unsigned(rx_fifo_usedw) >= ((2**(rx_fifo_usedw'length-1) - gpif_buf_size)));
-- Do we have room for one more block of data in the TX buffer?
tx_fifo_enough <= (unsigned(tx_fifo_usedw) < ((2**(tx_fifo_usedw'length) - gpif_buf_size))) and
tx_fifo_enough <= (unsigned(tx_fifo_usedw) < ((2**(tx_fifo_usedw'length-1) - gpif_buf_size * 4))) and
(unsigned(tx_meta_fifo_usedw) < ((2**(tx_meta_fifo_usedw'length-1) - 4)));
end if;
end process calculate_fifo_waterlines;
@ -333,28 +338,22 @@ begin
end if;
end process gpif_mux;
-- Arbitrate RX and TX requests
-- In the event the FX3 simultaneously requests RX and TX, we generally
-- prioritize the TX first; this helps avoid discontinuities on the TX
-- signal. However, if RX is about to overflow, we'll choose that.
can_and_should : process(pclk, reset)
variable rx_dma_req : boolean;
variable tx_dma_req : boolean;
variable rx_meta_ok : boolean;
begin
if (reset = '1') then
can_rx <= false;
can_tx <= false;
should_rx <= false;
should_tx <= false;
elsif (rising_edge(pclk)) then
rx_dma_req := dma_req.rx0 = '1' or dma_req.rx1 = '1';
rx_meta_ok := meta_enable = '1' nand rx_meta_fifo_empty = '1';
can_rx <= dma_rx_enable = '1' and
rx_fifo_enough and
rx_dma_req and
rx_meta_ok;
tx_dma_req := dma_req.tx2 = '1' or dma_req.tx3 = '1';
can_tx <= dma_tx_enable = '1' and
tx_fifo_enough and
tx_dma_req;
can_rx <= dma_rx_enable = '1' and rx_fifo_enough and (dma_req.rx0 = '1' or dma_req.rx1 = '1');
can_tx <= dma_tx_enable = '1' and tx_fifo_enough and (dma_req.tx2 = '1' or dma_req.tx3 = '1');
should_rx <= can_rx and (not can_tx or rx_fifo_critical);
should_tx <= can_tx and not rx_fifo_critical;
end if;
end process;
@ -410,24 +409,21 @@ begin
future.fini_downcount <= FINI_DOWNCOUNT_RESET;
future.finishing_rx <= '0';
-- Arbitrate RX and TX requests
-- In the event the FX3 simultaneously requests RX and TX, we generally
-- prioritize the TX first; this helps avoid discontinuities on the TX
-- signal. However, if RX is about to overflow, we'll choose that.
if (current.dma_idle = '1') then
future.dma_downcount <= gpif_buf_size-1;
if (can_rx and rx_fifo_critical) then
if (should_rx and ( (rx_meta_fifo_empty = '0' and current.rx_meta_en = '1')
or (current.rx_meta_en = '0') ) ) then
-- There is an RX to perform (sending data to FX3).
future.ack_downcount <= ACK_DOWNCOUNT_READ;
future.dma_downcount <= gpif_buf_size-1;
future.rx_current_dma <= RX0;
future.state <= SETUP_RD;
elsif (can_tx) then
elsif (should_tx) then
-- There is a TX to perform (getting data from FX3).
future.ack_downcount <= ACK_DOWNCOUNT_WRITE;
future.dma_downcount <= gpif_buf_size-1;
future.tx_current_dma <= TX3;
future.state <= SETUP_WR;
elsif (can_rx) then
future.ack_downcount <= ACK_DOWNCOUNT_READ;
future.rx_current_dma <= RX0;
future.state <= SETUP_RD;
end if;
end if;

View file

@ -1,27 +0,0 @@
-- 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;
package fx3_gpif_p is
-- GPIF buf sizes for USB high-speed and super-speed
constant GPIF_BUF_SIZE_HS : natural := 1024;
constant GPIF_BUF_SIZE_SS : natural := 2048;
end package fx3_gpif_p;

View file

@ -3,41 +3,6 @@
# Build a bladeRF fpga image
################################################################################
# Ensure we're in the right directory and submodules are initialized
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# Initialize and update submodules if needed
echo "Checking and initializing submodules..."
cd "$PROJECT_ROOT"
if [ -f .gitmodules ]; then
# Initialize submodules if not already initialized
git submodule init
# Update submodules to ensure they're checked out
git submodule update
echo "Submodules initialized and updated."
fi
cd "$SCRIPT_DIR"
cleanup() {
# Prevent recursive cleanup calls
trap '' INT TERM HUP
echo "Cleaning up and terminating builds..."
if [ -n "${build_pids[*]}" ]; then
for pid in "${build_pids[@]}"; do
pkill -P $pid 2>/dev/null || true
done
fi
exit 1
}
# Set up trap to catch Ctrl+C and other termination signals
trap cleanup INT TERM HUP
function print_boards() {
echo "Supported boards:"
for i in ../fpga/platforms/*/build/platform.conf ; do
@ -68,7 +33,6 @@ function usage()
echo " -r <rev> Quartus project revision"
echo " -s <size> FPGA size"
echo " -a <stp> SignalTap STP file"
echo " -H Build all hosted configurations"
echo " -f Force SignalTap STP insertion by temporarily enabling"
echo " the TalkBack feature of Quartus (required for Web Edition)."
echo " The previous setting will be restored afterward."
@ -80,7 +44,6 @@ function usage()
echo " synth Synthesize the design"
echo " full (default) Fit the design and create programming files"
echo " -S <seed> Fitter seed setting (default: 1)"
echo " -D Output directory name won't contain the date"
echo " -h Show this text"
echo ""
@ -162,9 +125,8 @@ fi
nios_rev="Tiny"
flow="full"
seed="1"
omit_date=false
while getopts ":cb:r:s:a:fn:l:S:DhH" opt; do
while getopts ":cb:r:s:a:fn:l:S:h" opt; do
case $opt in
c)
clear_work_dir=1
@ -187,10 +149,6 @@ while getopts ":cb:r:s:a:fn:l:S:DhH" opt; do
stp=$(readlink -f $OPTARG)
;;
H)
build_hosted=1
;;
f)
echo "Forcing STP insertion"
force="-force"
@ -208,10 +166,6 @@ while getopts ":cb:r:s:a:fn:l:S:DhH" opt; do
seed=$OPTARG
;;
D)
omit_date=true
;;
h)
usage
exit 0
@ -229,39 +183,6 @@ while getopts ":cb:r:s:a:fn:l:S:DhH" opt; do
esac
done
if [ "$build_hosted" == "1" ]; then
mkdir -p build_logs
build_pids=()
echo "Starting parallel builds for all hosted configurations..."
for config in "bladeRF 40" "bladeRF 115" "bladeRF-micro A4" "bladeRF-micro A5" "bladeRF-micro A9"; do
read -r board size <<< "$config"
log_file="build_logs/$board-hosted-$size.log"
$0 -b "$board" -r hosted -s "$size" > "$log_file" 2>&1 &
build_pids+=($!)
echo " → $board $size (PID: ${build_pids[-1]})"
done
echo "Waiting for ${#build_pids[@]} builds to complete..."
# Monitor build processes
failed=0
for pid in "${build_pids[@]}"; do
if ! wait "$pid"; then
failed=1
fi
done
if [ "$failed" -ne 0 ]; then
echo "One or more builds failed. Check build_logs directory for details."
cleanup
exit 1
fi
echo "All hosted builds completed successfully!"
exit 0
fi
if [ "$board" == "" ]; then
echo -e "\nError: board (-b) is required\n" >&2
print_boards
@ -525,11 +446,7 @@ if [[ ${flow} == "full" ]]; then
BUILD_TIME_DONE=$(date -d"$BUILD_TIME_DONE" '+%F_%H.%M.%S')
BUILD_NAME="$rev"x"$size"
if [ "$omit_date" = false ]; then
BUILD_OUTPUT_DIR="$BUILD_NAME"-"$BUILD_TIME_DONE"
else
BUILD_OUTPUT_DIR="$BUILD_NAME"
fi
BUILD_OUTPUT_DIR="$BUILD_NAME"-"$BUILD_TIME_DONE"
RBF=$BUILD_NAME.rbf
mkdir -p "$BUILD_OUTPUT_DIR"
@ -545,18 +462,6 @@ if [[ ${flow} == "full" ]]; then
sha256sum $RBF > $RBF.sha256sum
MD5SUM=$(cat $RBF.md5sum | awk '{ print $1 }')
SHA256SUM=$(cat $RBF.sha256sum | awk '{ print $1 }')
GIT_HASH=$(git rev-parse --short HEAD)
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
GIT_DIRTY=$(git diff --quiet && echo "clean" || echo "dirty")
cat << EOF > git_info.txt
Git Information:
Commit Hash: $GIT_HASH
Branch: $GIT_BRANCH
Working Directory: $GIT_DIRTY
EOF
popd
echo ""
@ -568,10 +473,6 @@ EOF
echo " MD5: $MD5SUM"
echo " SHA256: $SHA256SUM"
echo ""
echo " Git Information:"
echo " Commit: $GIT_HASH ($GIT_DIRTY)"
echo " Branch: $GIT_BRANCH"
echo ""
cat "$BUILD_OUTPUT_DIR/$BUILD_NAME.fit.summary" | sed -e 's/^\(.\)/ \1/g'
echo "##########################################################################"
fi

View file

@ -1,10 +1,9 @@
cmake_minimum_required(VERSION 3.10...3.27)
cmake_minimum_required(VERSION 3.5)
project(bladeRF C)
################################################################################
# Project configuration
################################################################################
add_compile_definitions(NUAND_MODIFICATIONS=1)
# All build output lands in this directory:
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output)
@ -231,6 +230,29 @@ add_custom_target(uninstall
# Windows-only, Post build: Copy libraries to our build output directory
################################################################################
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
find_package(LibPThreadsWin32)
if(LIBPTHREADSWIN32_FOUND)
set(WIN_RUNTIME_ITEMS ${WIN_RUNTIME_ITEMS}
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/pthreads-win32/COPYING.LIB.txt"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/pthreadVC2.dll")
add_custom_command(
OUTPUT "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/pthreads-win32/COPYING.LIB.txt"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${LIBPTHREADSWIN32_LIB_COPYING}"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/pthreads-win32/COPYING.LIB.txt"
COMMENT "Copying pthreads-win32 license to output directory..."
)
add_custom_command(
OUTPUT "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/pthreadVC2.dll"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${LIBPTHREADSWIN32_DLL}"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/"
COMMENT "Copying pthreadVC2.dll to output directory..."
)
endif(LIBPTHREADSWIN32_FOUND)
if(LIBUSB_FOUND)
set(WIN_RUNTIME_ITEMS ${WIN_RUNTIME_ITEMS}
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/libusb/COPYING"

View file

@ -23,6 +23,9 @@ Windows users that wish to use a Cypress driver/library based libbladeRF backend
### CMake ###
[CMake][CMake.org] is used to build the items in this directory. \>= v2.8.5 is required, but the latest available version is recommended.
### pthreads-win32 - Windows-only ###
Windows users will need to get [pthreads-win32], and may (with newer Windows versions) need to build it from scratch.
## Build ##
### Linux and OSX ###
@ -60,6 +63,7 @@ This process was most recently validated on Windows 10 Enterprise with CMake 3.9
- If you run into any failures, check these items, then re-run Configure:
- LIBUSB_PATH (and ENABLE_BACKEND_LIBUSB) - for using libusb
- FX3_SDK_PATH (and ENABLE_BACKEND_CYAPI) - for using the Cypress driver
- LIBPTHREADSWIN32_PATH
- Adjust options as desired and re-run the "Configure" command as needed. Values in red are new, and should be reviewed before running "Configure" again to get the red out.
- Click the CMake GUI's "Generate" button.
- In the ```build``` directory, a Visual Studio solution will now exist. You can click "Open Project" to get there.
@ -67,6 +71,21 @@ This process was most recently validated on Windows 10 Enterprise with CMake 3.9
- Upon building the solution, build artifacts will be present in: ```build\output\<build type>```
- ```<build_type>``` may refer to Debug or Release, for example
#### pthreads-win32 ####
If you are using a newer version of Windows / Visual Studio and are getting ```error C0211: 'timespec': 'struct' type redefinition``` when trying to build bladeRF, you will need to rebuild pthreads-win32. The below process seems to work with pthreads-w32 2.9.1.
- Get full source tree from [pthreads-win32] website, and unpack someplace convenient
- In Visual Studio, open `pthreads-w32-2-9-1-release\pthreads.2\pthread.dsw` (one-way upgrade is OK)
- Right-click the solution, select "Retarget solution", hit OK.
- Change "Solution Configurations" dropdown to "Release" ("Debug" doesn't work, but that's OK)
- Edit pthread.h to add `#define HAVE_STRUCT_TIMESPEC` and `#define PTW32_ARCHx64` near the top, just below the include guard
- Build the solution
- Back over in the bladeRF CMake:
- File -> Delete Cache
- Redo the "Configure" dance as before
- Point `LIBPTHREADSWIN32_PATH` to the `pthreads-w32-2-9-1-release\pthreads.2` directory you were just working in
## CMake Options and Flags ##
Below is a list of useful and project-specific CMake options. Please see the [CMake documentation] for
@ -101,3 +120,4 @@ more information.
[CMake documentation]: http://www.cmake.org/cmake/help/documentation.html (Cmake documentation)
[Cypress FX3 SDK]: http://www.cypress.com/?rID=57990 (Cypress FX3 SDK)
[redhat144967]: https://bugzilla.redhat.com/show_bug.cgi?id=144967 (Red Hat Bugzilla - Bug 144967)
[pthreads-win32]: https://sourceware.org/pthreads-win32/ (POSIX Threads for Win32)

View file

@ -0,0 +1,113 @@
# This is file is based off of the FindLibUSB.cmake file written by Hendrik Sattler,
# from the OpenOBEX project (licensed GPLv2/LGPL). (If this is not correct,
# please contact us so we can attribute the author appropriately.)
#
# https://github.com/zuckschwerdt/openobex/blob/master/CMakeModules/FindLibUSB.cmake
# http://dev.zuckschwerdt.org/openobex/
#
# Find pthreads-win32
#
# This requires the LIBPTHREADSWIN32_PATH variable to be set to the path to the
# a pthreads-win32 release, such as the Pre-built.2 directory from the 2.9.1 release:
# ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip
#
# The following standard variables get defined:
# LIBPTHREADSWIN32_FOUND: true if LibUSB was found
# LIBPTHREADSWIN32_HEADER_FILE: the location of the C header file
# LIBPTHREADSWIN32_INCLUDE_DIRS: the directories that contain headers
# LIBPTHREADSWIN32_LIBRARIES: the library files
# LIBPTHREADSWIN32_LIB_COPYING: the license associated with the library
# LIBPTHREADSWIN32_DLL: the pthreadVC2.dll file
if(DEFINED __INCLUDED_BLADERF_FINDLIBPTHREADSWIN32_CMAKE)
return()
endif()
set(__INCLUDED_BLADERF_FINDLIBPTHREADSWIN32_CMAKE TRUE)
include ( CheckLibraryExists )
include ( CheckIncludeFile )
set(LIBPTHREADSWIN32_PATH
"C:/Program Files (x86)/pthreads-win32"
CACHE
PATH
"Path to win-pthreads files. (This is generally only needed for Windows users who downloaded binary distributions.)"
)
find_file ( LIBPTHREADSWIN32_HEADER_FILE
NAMES
pthread.h
PATHS
${LIBPTHREADSWIN32_PATH}
PATH_SUFFIXES
include include
)
mark_as_advanced ( LIBPTHREADSWIN32_HEADER_FILE )
get_filename_component ( LIBPTHREADSWIN32_INCLUDE_DIRS "${LIBPTHREADSWIN32_HEADER_FILE}" PATH )
if ( WIN32 )
if ( MSVC )
if ( CMAKE_CL_64 )
set ( LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX x64 )
else ( CMAKE_CL_64 )
set ( LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX x86 )
endif ( CMAKE_CL_64 )
elseif ( CMAKE_COMPILER_IS_GNUCC )
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX x64 )
else ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX x86 )
endif ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
endif ( MSVC )
find_library ( PTHREAD_LIBRARY
NAMES
pthreadVC2
PATHS
${LIBPTHREADSWIN32_PATH}
PATH_SUFFIXES
lib/${LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX}
)
mark_as_advanced ( PTHREAD_LIBRARY )
if ( PTHREAD_LIBRARY )
set ( LIBPTHREADSWIN32_LIBRARIES ${PTHREAD_LIBRARY} )
endif ( PTHREAD_LIBRARY )
find_file ( PTHREAD_DLL
NAMES
pthreadVC2.dll
PATHS
${LIBPTHREADSWIN32_PATH}
PATH_SUFFIXES
dll/${LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX}
.
)
mark_as_advanced ( PTHREAD_DLL )
if ( PTHREAD_DLL )
set ( LIBPTHREADSWIN32_DLL ${PTHREAD_DLL} )
endif ( PTHREAD_DLL )
else ( WIN32 )
message(FATAL_ERROR "This file only supports Windows")
endif ( WIN32 )
set ( LIBPTHREADSWIN32_LIB_COPYING
"${LIBPTHREADSWIN32_PATH}/COPYING.LIB" )
if ( NOT EXISTS ${LIBPTHREADSWIN32_LIB_COPYING} )
message(FATAL_ERROR "Unable to find pthread-win32 COPYING.LIB file")
endif ()
if ( LIBPTHREADSWIN32_INCLUDE_DIRS AND LIBPTHREADSWIN32_LIBRARIES AND LIBPTHREADSWIN32_DLL )
set ( LIBPTHREADSWIN32_FOUND true )
endif ( LIBPTHREADSWIN32_INCLUDE_DIRS AND LIBPTHREADSWIN32_LIBRARIES AND LIBPTHREADSWIN32_DLL )
if ( LIBPTHREADSWIN32_FOUND )
set ( CMAKE_REQUIRED_INCLUDES "${LIBPTHREADSWIN32_INCLUDE_DIRS}" )
check_include_file ( "{LIBPTHREADSWIN32_HEADER_FILE}" LIBPTHREADSWIN32_FOUND )
endif ( LIBPTHREADSWIN32_FOUND )
if ( NOT LIBPTHREADSWIN32_FOUND )
message ( FATAL_ERROR "pthreads-win32 not found. If you're using a binary distribution, try setting -DLIBPTHREADSWIN32_PATH=<path_to_win_pthread_files>." )
endif ( NOT LIBPTHREADSWIN32_FOUND )

View file

@ -80,11 +80,6 @@ if(PKGCONFIG_LIBUSB_FOUND AND NOT LIBUSB_FOUND)
mark_as_advanced(${ibase}_LIBRARY)
endforeach(i)
# assume we're using vcpkg
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(LIBUSB_LIBRARY_PATH_SUFFIX bin)
endif()
else(PKGCONFIG_LIBUSB_FOUND)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
# The libusbx binary distribution contains several libs.

View file

@ -316,9 +316,7 @@
/*******************************************************************************
* Miscellaneous utility macros
******************************************************************************/
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(n) (sizeof(n) / sizeof(n[0]))
#endif
/**
* GCC 7+ warns on implicit fallthroughs in switch statements

View file

@ -39,9 +39,7 @@ extern "C" {
#endif // __MACH__
typedef int clockid_t;
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
int clock_gettime(clockid_t clk_id, struct timespec *tp);

View file

@ -32,32 +32,11 @@
/* Currently, only pthreads is supported. In the future, native windows threads
* may be used; one of the objectives of this file is to ease that transistion.
*/
#include <pthread.h>
#include "rel_assert.h"
#if (defined(_WIN32) || defined(USE_NATIVE_THREADS)) && \
!defined(DO_NOT_USE_PTHREADS)
// Do not use pthreads on Windows
#undef USE_PTHREADS
#else
// Use pthreads on non-Windows platforms
#undef USE_PTHREADS
#define USE_PTHREADS
#endif
#ifdef USE_PTHREADS
/* Use pthreads */
#include <pthread.h>
#include <errno.h>
#include <time.h>
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#define THREAD pthread_t
#define MUTEX pthread_mutex_t
#define COND pthread_cond_t
#ifdef ENABLE_LOCK_CHECKS
# define MUTEX_INIT(m) do { \
int status; \
@ -85,103 +64,11 @@
int status = pthread_mutex_destroy(m); \
assert(status == 0 && "Mutex destroy failure");\
} while (0)
#else /* ENABLE_LOCK_CHECKS */
#define MUTEX_INIT(m) pthread_mutex_init(m, NULL)
#define MUTEX_LOCK(m) pthread_mutex_lock(m)
#define MUTEX_UNLOCK(m) pthread_mutex_unlock(m)
#define MUTEX_DESTROY(m) pthread_mutex_destroy(m)
#endif /* ENABLE_LOCK_CHECKS */
# define THREAD_CREATE(x,y,z) pthread_create(x, NULL, y, z)
# define THREAD_SUCCESS 0
# define THREAD_TIMEOUT ETIMEDOUT
# define THREAD_CANCEL(m) pthread_cancel(m)
# define THREAD_JOIN(t, s) pthread_join(t, s)
# define THREAD_EXIT(s) pthread_exit(s)
# define COND_INIT(m) pthread_cond_init(m, NULL)
# define COND_SIGNAL(m) pthread_cond_signal(m)
// POSIX implementation as a function
static inline int posix_cond_timedwait(pthread_cond_t *c,
pthread_mutex_t *m,
unsigned int t)
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += t / 1000;
ts.tv_nsec += (t % 1000) * 1000000;
if (ts.tv_nsec >= 1000000000) {
ts.tv_sec++;
ts.tv_nsec -= 1000000000;
}
return pthread_cond_timedwait(c, m, &ts) == ETIMEDOUT ? -1 : 0;
}
#define COND_TIMED_WAIT(c, m, t) posix_cond_timedwait(c, m, t)
#define COND_WAIT(c, m) pthread_cond_wait(c, m)
#else /* USE_PTHREADS */
#include <windows.h>
#include <time.h>
/* Use C11 threads */
//#include <threads.h>
#define THREAD HANDLE // For thread handles
#define MUTEX CRITICAL_SECTION // For mutexes
#define COND CONDITION_VARIABLE // For condition variables
#ifdef ENABLE_LOCK_CHECKS
# define MUTEX_INIT(m) do { \
int status; \
status = mtx_init(m, mtx_plain | mtx_recursive); \
assert(status == thrd_success && "Mutex init failure"); \
} while (0)
# define MUTEX_LOCK(m) do { \
int status = mtx_lock(m); \
assert(status == thrd_success && "Mutex lock failure");\
} while (0)
# define MUTEX_UNLOCK(m) do { \
int status = mtx_unlock(m); \
assert(status == thrd_success && "Mutex unlock failure");\
} while (0)
# define MUTEX_DESTROY(m) do { \
mtx_destroy(m); \
} while (0)
#else /* ENABLE_LOCK_CHECKS */
#define MUTEX_INIT(m) InitializeCriticalSection(m)
#define MUTEX_LOCK(m) EnterCriticalSection(m)
#define MUTEX_UNLOCK(m) LeaveCriticalSection(m)
#define MUTEX_DESTROY(m) DeleteCriticalSection(m)
#endif /* ENABLE_LOCK_CHECKS */
# define THREAD_CREATE(handle, func, arg) \
((*(handle) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)(func), \
(LPVOID)(arg), 0, NULL)) == NULL ? GetLastError() : 0)
# define THREAD_SUCCESS 0
# define THREAD_TIMEOUT WAIT_TIMEOUT
# define THREAD_CANCEL(m) TerminateThread(m, 0)
# define THREAD_JOIN(t, s) WaitForSingleObject(t, INFINITE)
# define THREAD_EXIT(s) ExitThread(s)
# define COND_INIT(m) (InitializeConditionVariable(m), 0)
# define COND_SIGNAL(m) WakeConditionVariable(m)
# define COND_TIMED_WAIT(c, m, t) \
(SleepConditionVariableCS(c, m, t) ? 0 : GetLastError())
# define COND_WAIT(c, m) (!SleepConditionVariableCS(c, m, INFINITE))
#endif /* USE_PTHREADS */
#else
# define MUTEX_INIT(m) pthread_mutex_init(m, NULL)
# define MUTEX_LOCK(m) pthread_mutex_lock(m)
# define MUTEX_UNLOCK(m) pthread_mutex_unlock(m)
# define MUTEX_DESTROY(m) pthread_mutex_destroy(m)
#endif
#endif

View file

@ -25,7 +25,7 @@
#ifndef WIN_CLOCK_GETTIME_H_
#define WIN_CLOCK_GETTIME_H_
#include "thread.h"
#include <pthread.h>
#ifdef __cplusplus
extern "C" {
@ -36,9 +36,7 @@ extern "C" {
#endif
typedef int clockid_t;
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
int clock_gettime(clockid_t clk_id, struct timespec *tp);

View file

@ -25,7 +25,7 @@
#ifndef WIN_GETTIMEOFDAY_H_
#define WIN_GETTIMEOFDAY_H_
#include "thread.h"
#include <pthread.h>
#ifdef __cplusplus
extern "C" {

View file

@ -25,7 +25,7 @@
#ifndef WIN_NANOSLEEP_H_
#define WIN_NANOSLEEP_H_
#include "thread.h"
#include <pthread.h>
#ifdef __cplusplus
extern "C" {

View file

@ -48,10 +48,9 @@
#endif
#include <Windows.h>
#include <time.h>
#include <stdint.h>
#include "host_config.h"
#include "thread.h"
#include "pthread.h"
#ifdef __cplusplus
extern "C" {

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10...3.27)
cmake_minimum_required(VERSION 3.5)
project(test_dc_calibration C)
set(INCLUDES

View file

@ -94,7 +94,16 @@ target_include_directories(ad936x PUBLIC
if(MSVC)
add_definitions(-DHAVE_STRUCT_TIMESPEC)
target_include_directories(ad936x PUBLIC ${MSVC_C99_INCLUDES})
set(HAVE_THREADS true)
find_package(LibPThreadsWin32 REQUIRED)
if(LIBPTHREADSWIN32_FOUND)
set(HAVE_THREADS true)
target_include_directories(ad936x PUBLIC ${LIBPTHREADSWIN32_INCLUDE_DIRS})
set(LIBAD936X_LIBS
${LIBAD936X_LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
else()
set(HAVE_THREADS false)
endif()
else(MSVC)
find_package(Threads REQUIRED)
if(Threads_FOUND)

View file

@ -1 +0,0 @@
tx_samples.csv

View file

@ -1,25 +0,0 @@
# BladeRF CLI RX MIMO Packed
This example demonstrates how to configure and use the BladeRF CLI to aquire an RX stream of packed 16-bit samples.
## Prerequisites
Before running this example, ensure the Python environment is initialized and install the dependencies:
```bash
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
```
## Running the Example
To run the example, execute the following command:
```bash
./run.sh
```
This will execute the bladeRF-cli script that ingests samples from an internal 12b counter and writes them to a CSV file.
The Python script `validate.py` will then read the CSV file and plot the samples for visual inspection.

View file

@ -1,51 +0,0 @@
import csv
import sys
def generate_csv_normal(filename):
with open(filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
# Generate numbers from 0 to 2047
for i in range(0, 2048, 4):
writer.writerow([i, i+1, i+2, i+3])
# Generate numbers from -2048 to -1
for i in range(-2048, 0, 4):
writer.writerow([i, i+1, i+2, i+3])
def generate_csv_cw(filename):
cw_pattern = [
[0, 2047],
[2047, 0],
[0, -2047],
[-2047, 0]
]
with open(filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
for _ in range(2*4096):
for sample in cw_pattern:
# Duplicate the pattern for both channels
writer.writerow(sample + sample)
if __name__ == "__main__":
filename = 'tx_samples.csv'
if len(sys.argv) > 1:
if sys.argv[1] == "-h" or sys.argv[1] == "--help":
print("Usage: python generate_tx_samples.py [option]")
print("Options:")
print(" -h, --help Show this help message and exit")
print(" cw Generate CSV file with CW pattern")
print(" (no option) Generate CSV file with count pattern")
sys.exit(0)
elif sys.argv[1] == "cw":
generate_csv_cw(filename)
print(f"CSV file '{filename}' has been generated with CW pattern.")
else:
print(f"Unknown option: {sys.argv[1]}")
print("Use -h or --help for usage information.")
sys.exit(1)
else:
generate_csv_normal(filename)
print(f"CSV file '{filename}' has been generated with count pattern.")

View file

@ -1,14 +0,0 @@
contourpy==1.3.0
cycler==0.12.1
fonttools==4.54.1
kiwisolver==1.4.7
matplotlib==3.9.2
numpy==2.1.1
packaging==24.1
pandas==2.2.3
pillow==10.4.0
pyparsing==3.1.4
python-dateutil==2.9.0.post0
pytz==2024.2
six==1.16.0
tzdata==2024.2

View file

@ -1,3 +0,0 @@
set -e
bladeRF-cli -s rx.txt
python3 validate.py /tmp/data.csv

View file

@ -1,8 +0,0 @@
set bitmode packed
set rx_mux 12BIT_COUNTER
# set frequency 915M
set samplerate 61.44M
rx config file=/tmp/data.csv format=csv n=40k channel=1,2
# rx config file=/tmp/data.csv format=csv n=200k
rx start
rx wait

View file

@ -1,6 +0,0 @@
set frequency 915M
set samplerate 20M
set bitmode packed
tx config file=tx_samples.csv format=csv channel=1,2
tx start
tx wait

View file

@ -1,100 +0,0 @@
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import sys
import ast
def import_data(file_path):
try:
# Read the CSV file without header
df = pd.read_csv(file_path, header=None)
# Function to safely convert string representations of tuples to actual tuples
def safe_eval(x):
try:
return ast.literal_eval(x)
except:
return x
# Apply safe_eval to all elements
df = df.apply(lambda col: col.map(safe_eval))
# Rename columns based on the number of columns
if df.shape[1] == 2:
df.columns = ['I', 'Q']
elif df.shape[1] == 4:
df.columns = ['I1', 'Q1', 'I2', 'Q2']
else:
raise ValueError("CSV file must contain either two columns (single channel) or four columns (dual channel)")
# Extract numeric values from tuples if necessary
for col in df.columns:
if df[col].dtype == 'object':
df[col] = df[col].apply(lambda x: x[0] if isinstance(x, (tuple, list)) else x)
# Convert to numeric, coercing errors to NaN
df = df.apply(pd.to_numeric, errors='coerce')
# Drop any rows with NaN values
df = df.dropna()
# Check if all columns are numeric
for col in df.columns:
if not pd.api.types.is_numeric_dtype(df[col]):
raise ValueError(f"{col} samples must be numeric")
return df
except FileNotFoundError:
print(f"Error: File '{file_path}' not found")
sys.exit(1)
except pd.errors.EmptyDataError:
print(f"Error: File '{file_path}' is empty")
sys.exit(1)
except Exception as e:
print(f"Error: {str(e)}")
sys.exit(1)
if len(sys.argv) != 2:
print("Usage: python validate.py <path_to_csv_file>")
sys.exit(1)
file_path = sys.argv[1]
df = import_data(file_path)
# Determine if it's single or dual channel
is_dual_channel = 'I2' in df.columns
plt.figure(figsize=(12, 8))
if is_dual_channel:
# Plot Channel 1
plt.subplot(2, 1, 1)
plt.plot(df.index, df['I1'], label='I (Ch1)', alpha=0.7)
plt.plot(df.index, df['Q1'], label='Q (Ch1)', alpha=0.7)
plt.ylabel('Amplitude (Ch1)')
plt.title('I/Q Components Over Time - Channel 1')
plt.legend(loc='upper right')
plt.grid(True, alpha=0.3)
# Plot Channel 2
plt.subplot(2, 1, 2)
plt.plot(df.index, df['I2'], label='I (Ch2)', alpha=0.7)
plt.plot(df.index, df['Q2'], label='Q (Ch2)', alpha=0.7)
plt.xlabel('Sample Index')
plt.ylabel('Amplitude (Ch2)')
plt.title('I/Q Components Over Time - Channel 2')
plt.legend(loc='upper right')
plt.grid(True, alpha=0.3)
else:
# Plot Single Channel
plt.plot(df.index, df['I'], label='I', alpha=0.7)
plt.plot(df.index, df['Q'], label='Q', alpha=0.7)
plt.xlabel('Sample Index')
plt.ylabel('Amplitude')
plt.title('I/Q Components Over Time - Single Channel')
plt.legend(loc='upper right')
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()

View file

@ -1 +0,0 @@
tx_samples.csv

View file

@ -1,26 +0,0 @@
# BladeRF CLI RX SISO Packed
This example demonstrates how to configure and use the BladeRF CLI to aquire an RX stream of packed 16-bit samples.
## Prerequisites
Before running this example, ensure the Python environment is initialized and install the dependencies:
```bash
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
```
## Running the Example
To run the example, execute the following command:
```bash
./run.sh
```
This will execute the bladeRF-cli script that ingests samples from an internal 12b counter and writes them to a CSV file.
The Python script `validate.py` will then read the CSV file and plot the samples for visual inspection.

View file

@ -1,51 +0,0 @@
import csv
import sys
def generate_csv_normal(filename):
with open(filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
# Generate numbers from 0 to 2047
for i in range(0, 2048, 2):
writer.writerow([i, i+1])
# Generate numbers from -2048 to -1
for i in range(-2048, 0, 2):
writer.writerow([i, i+1])
def generate_csv_cw(filename):
cw_pattern = [
[0, 2047],
[2047, 0],
[0, -2047],
[-2047, 0]
]
with open(filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
for _ in range(2*4096):
for sample in cw_pattern:
# Duplicate the pattern for both channels
writer.writerow(sample)
if __name__ == "__main__":
filename = 'tx_samples.csv'
if len(sys.argv) > 1:
if sys.argv[1] == "-h" or sys.argv[1] == "--help":
print("Usage: python generate_tx_samples.py [option]")
print("Options:")
print(" -h, --help Show this help message and exit")
print(" cw Generate CSV file with CW pattern")
print(" (no option) Generate CSV file with count pattern")
sys.exit(0)
elif sys.argv[1] == "cw":
generate_csv_cw(filename)
print(f"CSV file '{filename}' has been generated with CW pattern.")
else:
print(f"Unknown option: {sys.argv[1]}")
print("Use -h or --help for usage information.")
sys.exit(1)
else:
generate_csv_normal(filename)
print(f"CSV file '{filename}' has been generated with count pattern.")

View file

@ -1,14 +0,0 @@
contourpy==1.3.0
cycler==0.12.1
fonttools==4.54.1
kiwisolver==1.4.7
matplotlib==3.9.2
numpy==2.1.1
packaging==24.1
pandas==2.2.3
pillow==10.4.0
pyparsing==3.1.4
python-dateutil==2.9.0.post0
pytz==2024.2
six==1.16.0
tzdata==2024.2

View file

@ -1,3 +0,0 @@
set -e
bladeRF-cli -s rx.txt
python3 validate.py /tmp/data.csv

View file

@ -1,7 +0,0 @@
set frequency 915M
set samplerate 20M
set rx_mux 12BIT_COUNTER
set bitmode packed
rx config file=/tmp/data.csv format=csv n=200k
rx start
rx wait

View file

@ -1,6 +0,0 @@
set frequency 915M
set samplerate 20M
set bitmode packed
tx config file=tx_samples.csv format=csv
tx start
tx wait

Some files were not shown because too many files have changed in this diff Show more