libbladeRF: Added vctcxo trim dac readback support

This commit is contained in:
Jon Szymaniak 2015-06-22 22:34:23 -04:00
commit c9acfecef4
9 changed files with 69 additions and 12 deletions

View file

@ -2785,16 +2785,26 @@ int CALL_CONV bladerf_get_timestamp(struct bladerf *dev, bladerf_module mod,
uint64_t *value);
/**
* Write value to VCTCXO DAC
* Write value to VCTCXO trim DAC
*
* @param dev Device handle
* @param val Data to write to DAC register
* @param val Value to write to VCTCXO trim DAC
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_dac_write(struct bladerf *dev, uint16_t val);
/**
* Read value from VCTCXO trim DAC
*
* @param[in] dev Device handle
* @param[out] val Value to read from VCTCXO trim DAC
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_dac_read(struct bladerf *dev, uint16_t *val);
/**
* Write value to secondary XB SPI

View file

@ -134,8 +134,9 @@ struct backend_fns {
int (*lms_write)(struct bladerf *dev, uint8_t addr, uint8_t data);
int (*lms_read)(struct bladerf *dev, uint8_t addr, uint8_t *data);
/* VCTCXO accessor */
int (*dac_write)(struct bladerf *dev, uint16_t value);
/* VCTCXO accessors */
int (*vctcxo_dac_write)(struct bladerf *dev, uint16_t value);
int (*vctcxo_dac_read)(struct bladerf *dev, uint16_t *value);
/* Expansion board SPI */
int (*xb_spi)(struct bladerf *dev, uint32_t value);

View file

@ -188,7 +188,12 @@ static int dummy_lms_read(struct bladerf *dev, uint8_t addr, uint8_t *data)
return 0;
}
static int dummy_dac_write(struct bladerf *dev, uint16_t value)
static int dummy_vctcxo_dac_write(struct bladerf *dev, uint16_t value)
{
return 0;
}
static int dummy_vctcxo_dac_read(struct bladerf *dev, uint16_t *value)
{
return 0;
}
@ -296,7 +301,7 @@ const struct backend_fns backend_fns_dummy = {
FIELD_INIT(.lms_write, dummy_lms_write),
FIELD_INIT(.lms_read, dummy_lms_read),
FIELD_INIT(.dac_write, dummy_dac_write),
FIELD_INIT(.vctcxo_dac_write, dummy_vctcxo_dac_write),
FIELD_INIT(.xb_spi, dummy_xb_spi),

View file

@ -392,6 +392,18 @@ int nios_vctcxo_trim_dac_write(struct bladerf *dev, uint16_t value)
return status;
}
int nios_vctcxo_trim_dac_read(struct bladerf *dev, uint16_t *value)
{
int status;
status = nios_8x16_read(dev, NIOS_PKT_8x16_TARGET_VCTCXO_DAC, 0x98, value);
if (status != 0) {
*value = 0;
}
return status;
}
int nios_get_iq_gain_correction(struct bladerf *dev, bladerf_module module,
int16_t *value)
{

View file

@ -136,6 +136,16 @@ int nios_lms6_write(struct bladerf *dev, uint8_t addr, uint8_t data);
*/
int nios_vctcxo_trim_dac_write(struct bladerf *dev, uint16_t value);
/**
* Read the current VCTCXO trim DAC value
*
* @param[in] dev Device handle
* @param[out] value On success, updated with VCTCXO value
*
* @return 0 on success, BLADERF_ERR_* code on error.
*/
int nios_vctcxo_trim_dac_read(struct bladerf *dev, uint16_t *value);
/**
* Read a IQ gain correction value
*

View file

@ -1057,6 +1057,12 @@ static int usb_load_fw_from_bootloader(bladerf_backend backend,
return status;
}
static int unsupported_trim_dac_read(struct bladerf *dev, uint16_t *val)
{
*val = 0x800;
log_debug("VCTCXO readback requires FPGA >= v0.3.x\n");
return BLADERF_ERR_UNSUPPORTED;
}
/* USB backend that used legacy format for communicating with NIOS II */
const struct backend_fns backend_fns_usb_legacy = {
@ -1102,7 +1108,8 @@ const struct backend_fns backend_fns_usb_legacy = {
FIELD_INIT(.lms_write, nios_legacy_lms6_write),
FIELD_INIT(.lms_read, nios_legacy_lms6_read),
FIELD_INIT(.dac_write, nios_legacy_vctcxo_trim_dac_write),
FIELD_INIT(.vctcxo_dac_write, nios_legacy_vctcxo_trim_dac_write),
FIELD_INIT(.vctcxo_dac_read, unsupported_trim_dac_read),
FIELD_INIT(.xb_spi, nios_legacy_xb200_synth_write),
@ -1165,7 +1172,8 @@ const struct backend_fns backend_fns_usb = {
FIELD_INIT(.lms_write, nios_lms6_write),
FIELD_INIT(.lms_read, nios_lms6_read),
FIELD_INIT(.dac_write, nios_vctcxo_trim_dac_write),
FIELD_INIT(.vctcxo_dac_write, nios_vctcxo_trim_dac_write),
FIELD_INIT(.vctcxo_dac_read, nios_vctcxo_trim_dac_read),
FIELD_INIT(.xb_spi, nios_xb200_synth_write),

View file

@ -1660,7 +1660,7 @@ int bladerf_get_timestamp(struct bladerf *dev, bladerf_module module, uint64_t *
}
/*------------------------------------------------------------------------------
* VCTCXO DAC register write
* VCTCXO trim DAC access
*----------------------------------------------------------------------------*/
int bladerf_dac_write(struct bladerf *dev, uint16_t val)
@ -1668,12 +1668,22 @@ int bladerf_dac_write(struct bladerf *dev, uint16_t val)
int status;
MUTEX_LOCK(&dev->ctrl_lock);
status = DAC_WRITE(dev, val);
status = VCTCXO_DAC_WRITE(dev, val);
MUTEX_UNLOCK(&dev->ctrl_lock);
return status;
}
int bladerf_dac_read(struct bladerf *dev, uint16_t *val)
{
int status;
MUTEX_LOCK(&dev->ctrl_lock);
status = VCTCXO_DAC_READ(dev, val);
MUTEX_UNLOCK(&dev->ctrl_lock);
return status;
}
/*------------------------------------------------------------------------------
* XB SPI register write

View file

@ -252,7 +252,7 @@ int init_device(struct bladerf *dev)
}
/* Set the calibrated VCTCXO DAC value */
status = DAC_WRITE(dev, dev->dac_trim);
status = VCTCXO_DAC_WRITE(dev, dev->dac_trim);
if (status != 0) {
return status;
}

View file

@ -59,7 +59,8 @@
#define CONFIG_GPIO_WRITE(dev, val) config_gpio_write(dev, val)
#define CONFIG_GPIO_READ(dev, val) dev->fn->config_gpio_read(dev, val)
#define DAC_WRITE(dev, val) dev->fn->dac_write(dev, val)
#define VCTCXO_DAC_WRITE(dev, val) dev->fn->vctcxo_dac_write(dev, val)
#define VCTCXO_DAC_READ(dev, val_ptr) dev->fn->vctcxo_dac_read(dev, val_ptr)
/* Forward declaration for the function table */
struct bladerf;