libbladeRF: Adding VCTCXO tamer mode selection support

This commit is contained in:
Jon Szymaniak 2015-11-23 23:46:04 -05:00 • committed by Jon Szymaniak
commit 9cdfbedd5d
10 changed files with 202 additions and 1 deletions

View file

@ -192,5 +192,4 @@ static inline void nios_pkt_8x8_resp_unpack(const uint8_t *buf, uint8_t *target,
}
}
#endif

View file

@ -1491,6 +1491,32 @@ int CALL_CONV bladerf_xb200_get_path(struct bladerf *dev,
bladerf_module module,
bladerf_xb200_path *path);
/**
* Set the VCTCXO tamer mode.
*
* @param dev Device handle
* @param mode VCTCXO taming mode
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode mode);
/**
* Get the current VCTCXO tamer mode
*
* @param[in] dev Device handle
* @param[out] mode Current VCTCXO taming mode or
* BLADERF_VCTCXO_TAMER_INVALID if a failure
* occurs.
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_get_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode *mode);
/** @} (End of FN_CTRL) */
/**

View file

@ -143,6 +143,12 @@ struct backend_fns {
int (*vctcxo_dac_write)(struct bladerf *dev, uint16_t value);
int (*vctcxo_dac_read)(struct bladerf *dev, uint16_t *value);
int (*set_vctcxo_tamer_mode)(struct bladerf *dev,
bladerf_vctcxo_tamer_mode mode);
int (*get_vctcxo_tamer_mode)(struct bladerf *dev,
bladerf_vctcxo_tamer_mode *mode);
/* Expansion board SPI */
int (*xb_spi)(struct bladerf *dev, uint32_t value);

View file

@ -195,6 +195,19 @@ static int dummy_vctcxo_dac_write(struct bladerf *dev, uint16_t value)
return 0;
}
int dummy_set_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode mode)
{
return 0;
}
int dummy_get_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode *mode)
{
*mode = BLADERF_VCTCXO_TAMER_INVALID;
return 0;
}
static int dummy_vctcxo_dac_read(struct bladerf *dev, uint16_t *value)
{
return 0;
@ -307,6 +320,9 @@ const struct backend_fns backend_fns_dummy = {
FIELD_INIT(.vctcxo_dac_write, dummy_vctcxo_dac_write),
FIELD_INIT(.vctcxo_dac_read, dummy_vctcxo_dac_read),
FIELD_INIT(.set_vctcxo_tamer_mode, dummy_set_vctcxo_tamer_mode),
FIELD_INIT(.get_vctcxo_tamer_mode, dummy_get_vctcxo_tamer_mode),
FIELD_INIT(.xb_spi, dummy_xb_spi),
FIELD_INIT(.set_firmware_loopback, dummy_set_firmware_loopback),

View file

@ -464,6 +464,65 @@ int nios_vctcxo_trim_dac_read(struct bladerf *dev, uint16_t *value)
return status;
}
int nios_set_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode mode)
{
int status;
if (!have_cap(dev, BLADERF_CAP_VCTCXO_TAMING_MODE)) {
log_debug("FPGA %s does not support VCTCXO taming via an input source\n",
dev->fpga_version.describe);
return BLADERF_ERR_UNSUPPORTED;
}
status = nios_8x8_write(dev,
NIOS_PKT_8x8_TARGET_VCTCXO_TAMER, 0xff,
(uint8_t) mode);
if (status == 0) {
log_verbose("%s: Wrote mode=0x%02x\n", __FUNCTION__, mode);
}
return status;
}
int nios_get_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode *mode)
{
int status;
uint8_t tmp;
*mode = BLADERF_VCTCXO_TAMER_INVALID;
if (!have_cap(dev, BLADERF_CAP_VCTCXO_TAMING_MODE)) {
log_debug("FPGA %s does not support VCTCXO taming via an input source\n",
dev->fpga_version.describe);
return BLADERF_ERR_UNSUPPORTED;
}
status = nios_8x8_read(dev, NIOS_PKT_8x8_TARGET_VCTCXO_TAMER, 0xff, &tmp);
if (status == 0) {
log_verbose("%s: Read mode=0x%02x\n", __FUNCTION__, tmp);
switch ((bladerf_vctcxo_tamer_mode) tmp) {
case BLADERF_VCTCXO_TAMER_DISABLED:
case BLADERF_VCTCXO_TAMER_1_PPS:
case BLADERF_VCTCXO_TAMER_10_MHZ:
*mode = (bladerf_vctcxo_tamer_mode) tmp;
break;
default:
status = BLADERF_ERR_UNEXPECTED;
}
}
return status;
}
int nios_get_iq_gain_correction(struct bladerf *dev, bladerf_module module,
int16_t *value)
{

View file

@ -146,6 +146,29 @@ int nios_vctcxo_trim_dac_write(struct bladerf *dev, uint16_t value);
*/
int nios_vctcxo_trim_dac_read(struct bladerf *dev, uint16_t *value);
/**
* Write VCTCXO tamer mode selection
*
* @param[in] dev Device handle
* @param[in] mode Tamer mode to use, or BLADERF_VCTCXO_TAMER_DISABLED
* to disable the tamer.
*
* @return 0 on success, BLADERF_ERR_* code on error.
*/
int nios_set_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode mode);
/**
* Read the current VCTCXO mode selection
*
* @param[in] dev Device handle
* @param[out] mode Current tamer mode in use.
*
* @return 0 on success, BLADERF_ERR_* code on error.
*/
int nios_get_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode *mode);
/**
* Read a IQ gain correction value
*

View file

@ -392,6 +392,21 @@ int nios_legacy_vctcxo_trim_dac_write(struct bladerf *dev, uint16_t value)
return status;
}
int nios_legacy_set_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode mode)
{
log_debug("This operation is not supported by the legacy NIOS packet format\n");
return BLADERF_ERR_UNSUPPORTED;
}
int nios_legacy_get_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode *mode)
{
log_debug("This operation is not supported by the legacy NIOS packet format\n");
*mode = BLADERF_VCTCXO_TAMER_INVALID;
return BLADERF_ERR_UNSUPPORTED;
}
static int get_iq_correction(struct bladerf *dev, uint8_t addr, int16_t *value)
{
int i;

View file

@ -1058,6 +1058,23 @@ static int usb_load_fw_from_bootloader(bladerf_backend backend,
return status;
}
/* Default handlers for operations unsupported by the NIOS II legacy packet
* format */
static int set_vctcxo_tamer_mode_unsupported(struct bladerf *dev,
bladerf_vctcxo_tamer_mode mode)
{
log_debug("Operation not supported with legacy NIOS packet format.\n");
return BLADERF_ERR_UNSUPPORTED;
}
static int get_vctcxo_tamer_mode_unsupported(struct bladerf *dev,
bladerf_vctcxo_tamer_mode *mode)
{
*mode = BLADERF_VCTCXO_TAMER_INVALID;
log_debug("Operation not supported with legacy NIOS packet format.\n");
return BLADERF_ERR_UNSUPPORTED;
}
/* USB backend that used legacy format for communicating with NIOS II */
const struct backend_fns backend_fns_usb_legacy = {
FIELD_INIT(.matches, usb_matches),
@ -1105,6 +1122,9 @@ const struct backend_fns backend_fns_usb_legacy = {
FIELD_INIT(.vctcxo_dac_write, nios_legacy_vctcxo_trim_dac_write),
FIELD_INIT(.vctcxo_dac_read, nios_vctcxo_trim_dac_read),
FIELD_INIT(.set_vctcxo_tamer_mode, set_vctcxo_tamer_mode_unsupported),
FIELD_INIT(.get_vctcxo_tamer_mode, get_vctcxo_tamer_mode_unsupported),
FIELD_INIT(.xb_spi, nios_legacy_xb200_synth_write),
FIELD_INIT(.set_firmware_loopback, usb_set_firmware_loopback),
@ -1169,6 +1189,9 @@ const struct backend_fns backend_fns_usb = {
FIELD_INIT(.vctcxo_dac_write, nios_vctcxo_trim_dac_write),
FIELD_INIT(.vctcxo_dac_read, nios_vctcxo_trim_dac_read),
FIELD_INIT(.set_vctcxo_tamer_mode, nios_set_vctcxo_tamer_mode),
FIELD_INIT(.get_vctcxo_tamer_mode, nios_get_vctcxo_tamer_mode),
FIELD_INIT(.xb_spi, nios_xb200_synth_write),
FIELD_INIT(.set_firmware_loopback, usb_set_firmware_loopback),

View file

@ -1852,6 +1852,34 @@ int bladerf_dac_read(struct bladerf *dev, uint16_t *val)
return status;
}
/*------------------------------------------------------------------------------
* VCTCXO tamer control
*----------------------------------------------------------------------------*/
int bladerf_set_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode mode)
{
int status;
MUTEX_LOCK(&dev->ctrl_lock);
status = dev->fn->set_vctcxo_tamer_mode(dev, mode);
MUTEX_UNLOCK(&dev->ctrl_lock);
return status;
}
int bladerf_get_vctcxo_tamer_mode(struct bladerf *dev,
bladerf_vctcxo_tamer_mode *mode)
{
int status;
MUTEX_LOCK(&dev->ctrl_lock);
status = dev->fn->get_vctcxo_tamer_mode(dev, mode);
MUTEX_UNLOCK(&dev->ctrl_lock);
return status;
}
/*------------------------------------------------------------------------------
* XB SPI register write
*----------------------------------------------------------------------------*/

View file

@ -89,6 +89,12 @@
*/
#define BLADERF_CAP_MASKED_XBIO_WRITE (1 << 7)
/**
* FPGA v0.5.0 introduces the ability to tame the VCTCXO via a 1 pps or 10 MHz
* input source on the mini expansion header.
*/
#define BLADERF_CAP_VCTCXO_TAMING_MODE (1 << 8)
/**
* Firmware 1.7.1 introduced firmware-based loopback
*/