Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adrv9002 new API support #2695

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion drivers/iio/adc/navassa/adrv9002.c
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,8 @@ static int adrv9002_phy_read_raw_no_rf_chan(const struct adrv9002_rf_phy *phy,
case IIO_CHAN_INFO_PROCESSED:
switch (chan->type) {
case IIO_TEMP:
ret = api_call(phy, adi_adrv9001_Temperature_Get, &temp);
ret = api_call(phy, adi_adrv9001_Temperature_Get,
ADI_ADRV9001_TEMPERATURE_READ_SPI, &temp);
if (ret)
return ret;

Expand Down
73 changes: 71 additions & 2 deletions drivers/iio/adc/navassa/common/adi_common_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,68 @@
#include "adi_common_types.h"
#include "adi_common_macros.h"

#ifdef API_MUTEX
/**
* \brief Macro to call API mutex release function
* This macro implements a simple recusive mutex to un-lock API
*
* \param commonDev Pointer to the common device structure
*
*/
#define ADI_MUTEX_ERROR_RELEASE(commonDev)\
{\
if (((adi_common_Device_t *)(commonDev))->error.newAction < ADI_COMMON_ACT_NO_ACTION &&\
((adi_common_Device_t *)(commonDev))->error.unlock != NULL)\
{\
if (((adi_common_Device_t *)(commonDev))->error.locked > 0) \
{\
((adi_common_Device_t *)(commonDev))->error.locked--; \
if (((adi_common_Device_t *)(commonDev))->error.locked == 0) { \
((adi_common_Device_t *)(commonDev))->error.unlock(commonDev); \
}\
}\
}\
}

#define ADI_MUTEX_RELEASE(commonDev)\
{\
if (((adi_common_Device_t *)(commonDev))->error.unlock != NULL)\
{\
if (((adi_common_Device_t *)(commonDev))->error.locked > 0) \
{\
((adi_common_Device_t *)(commonDev))->error.locked--; \
if (((adi_common_Device_t *)(commonDev))->error.locked == 0) { \
((adi_common_Device_t *)(commonDev))->error.unlock(commonDev); \
} \
}\
}\
}

/**
* \brief Macro to call API mutex release function
* This macro implements a simple recusive mutex to un-lock API
*
* \param commonDev Pointer to the common device structure
*
*/
#define ADI_MUTEX_AQUIRE(commonDev) \
{\
if(((adi_common_Device_t *)(commonDev))->error.lock)\
{\
if (((adi_common_Device_t *)(commonDev))->error.locked == 0) \
{\
((adi_common_Device_t *)(commonDev))->error.lock(commonDev); \
}\
((adi_common_Device_t *)(commonDev))->error.locked++; \
}\
}

#else /* API_MUTEX */
#define ADI_MUTEX_RELEASE(commonDev)
#define ADI_MUTEX_ERROR_RELEASE(commonDev)
#define ADI_MUTEX_AQUIRE(commonDev)
#endif /* API_MUTEX */

/**
* \brief Macro to check if device pointer is a valid pointer
* if null pointer detected return ADI_COMMON_ACT_ERR_CHECK_PARAM action
Expand Down Expand Up @@ -57,6 +119,7 @@ if(ptr == NULL)\
if(ptr == NULL) \
{ \
ADI_ERROR_REPORT((adi_common_Device_t *)(commonDev), ADI_COMMON_ERRSRC_API, ADI_COMMON_ERR_NULL_PARAM, ADI_COMMON_ACT_ERR_CHECK_PARAM, ptr, "NULL Pointer passed"); \
ADI_MUTEX_ERROR_RELEASE(commonDev) \
return ADI_COMMON_ACT_ERR_CHECK_PARAM; \
} \
}
Expand Down Expand Up @@ -99,7 +162,7 @@ if(ptr == NULL)\
*/
#define ADI_ERROR_REPORT(commonDev, errorSource, error, action, variable, customError) \
adi_common_ErrorReport((adi_common_Device_t *)(commonDev), (adi_common_ErrSources_e)errorSource, (int32_t)error, (int32_t)action, __FILE__, __FUNCTION__, __LINE__, #variable, customError)
#else
#else /* ADI_COMMON_VERBOSE */
#define ADI_ERROR_REPORT(commonDev, errorSource, errorCode, action, variable, customError) \
do \
{ \
Expand Down Expand Up @@ -145,21 +208,24 @@ if ((value < minimum) || (value > maximum)) \
ADI_COMMON_ACT_ERR_CHECK_PARAM, \
devicePtr, \
devicePtr->common.error.errormessage); \
ADI_MUTEX_ERROR_RELEASE(devicePtr) \
ADI_ERROR_RETURN(devicePtr->common.error.newAction); \
}

/* Legacy - no format specifier defaults to %d */
#define ADI_RANGE_CHECK(devicePtr, value, minimum, maximum) ADI_RANGE_CHECK_X(devicePtr, value, minimum, maximum, "%d")
#else
#else /* ADI_COMMON_VERBOSE */
#define ADI_RANGE_CHECK(devicePtr, value, minimum, maximum) \
if ((value < minimum) || (value > maximum)) \
{ \
ADI_MUTEX_ERROR_RELEASE(devicePtr) \
return ADI_COMMON_ACT_ERR_CHECK_PARAM; \
}

#define ADI_RANGE_CHECK_X(devicePtr, value, minimum, maximum, formatSpecifier) \
if ((value < minimum) || (value > maximum)) \
{ \
ADI_MUTEX_ERROR_RELEASE(devicePtr) \
return ADI_COMMON_ACT_ERR_CHECK_PARAM; \
}
#endif
Expand All @@ -184,6 +250,7 @@ if ((value < minimum) || (value > maximum)) \
int32_t _recoveryAction = ADI_COMMON_ACT_NO_ACTION; \
_recoveryAction = fcnPtr(devicePtr, ##__VA_ARGS__); \
ADI_ERROR_REPORT(&devicePtr->common, ADI_COMMON_ERRSRC_API, devicePtr->common.error.errCode, _recoveryAction, NULL, devicePtr->common.error.errormessage); \
ADI_MUTEX_ERROR_RELEASE(devicePtr) \
ADI_ERROR_RETURN(devicePtr->common.error.newAction); \
}

Expand All @@ -208,6 +275,7 @@ if ((value < minimum) || (value > maximum)) \
int32_t _recoveryAction = ADI_COMMON_ACT_NO_ACTION; \
_recoveryAction = fcnPtr(devicePtr, ##__VA_ARGS__); \
ADI_ERROR_REPORT(&devicePtr->common, ADI_COMMON_ERRSRC_API, devicePtr->common.error.errCode, _recoveryAction, NULL, errMsg); \
ADI_MUTEX_ERROR_RELEASE(devicePtr) \
ADI_ERROR_RETURN(devicePtr->common.error.newAction); \
}

Expand Down Expand Up @@ -276,6 +344,7 @@ if ((value < minimum) || (value > maximum)) \
ADI_COMMON_ACT_ERR_CHECK_PARAM, \
arraySize, \
"Invalid arraySize"); \
ADI_MUTEX_ERROR_RELEASE(devicePtr) \
ADI_ERROR_RETURN(devicePtr->common.error.newAction); \
} \
}
Expand Down
11 changes: 11 additions & 0 deletions drivers/iio/adc/navassa/common/adi_common_error_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ extern "C" {

#define ADI_ERROR_MSG_MAX_LEN 314

/**
* \brief API (un)lock function pointers
*/
typedef int (*api_lock)(void*device);
typedef int (*api_unlock)(void*device);

/**
* \brief ADI common error structure
*/
Expand All @@ -46,6 +52,11 @@ typedef struct adi_common_ErrStruct
int32_t lastAction; /*!< Previous action detected */
int32_t newAction; /*!< Current action detected */
uint8_t logEnable; /*!< Log errors enable flag */
#ifdef API_MUTEX
api_lock lock; /* HW semaphore lock */
api_unlock unlock; /* HW semaphore unlock */
int locked; /* HW semaphore lock status */
#endif /* API_MUTEX */
} adi_common_ErrStruct_t;

/**
Expand Down
1 change: 1 addition & 0 deletions drivers/iio/adc/navassa/common/adi_common_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#else
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#endif

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,17 @@ int32_t adi_adrv9001_Profiles_Verify(adi_adrv9001_Device_t *adrv9001, adi_adrv90
/**
* \brief Gets the temperature in Celsius from the internal temperature sensor
*
* \note Message type: \ref timing_mailbox "Mailbox command"
* \note Message type: Mailbox commands or direct register access
*
* \pre Channel state any of STANDBY, CALIBRATED, PRIMED, RF_ENABLED
*
* \param[in] adrv9001 Context variable - Pointer to the ADRV9001 device settings data structure
* \param[in] tempReadMode Options to read temperature : Default option - Mailbox, Other option - Direct Register Access
* \param[out] temperature_C The current temperature, in Celsius
*
* \returns A code indicating success (ADI_COMMON_ACT_NO_ACTION) or the required action to recover
*/
int32_t adi_adrv9001_Temperature_Get(adi_adrv9001_Device_t *adrv9001, int16_t *temperature_C);
int32_t adi_adrv9001_Temperature_Get(adi_adrv9001_Device_t *adrv9001, adi_adrv9001_TempReadMode_e tempReadMode, int16_t *temperature_C);

/**
* \brief Reads back the part number for the ADRV9001 variant device
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ typedef enum adi_adrv9001_GpioSignal
ADI_ADRV9001_GPIO_SIGNAL_FH_HOP2_NCO_ASYNC_CHANGE, /*!< Asynchronously change NCO for Hop2 */
ADI_ADRV9001_GPIO_SIGNAL_RX1_INTERFACEGAIN_SEED_SAVE = 52, /*!< Seed (rising edge) or save (falling edge) the RX1 InterfaceGain */
ADI_ADRV9001_GPIO_SIGNAL_RX2_INTERFACEGAIN_SEED_SAVE = 53, /*!< Seed (rising edge) or save (falling edge) the RX2 InterfaceGain */
ADI_ADRV9001_GPIO_SIGNAL_RX1_AGC_FREEZE = 54, /*!< Asynchronous update Rx1 AGC freeze */
ADI_ADRV9001_GPIO_SIGNAL_RX2_AGC_FREEZE = 55, /*!< Asynchronous update Rx2 AGC freeze */

ADI_ADRV9001_GPIO_NUM_SIGNALS = 54, /*!< Total Number of signals from BBIC*/
ADI_ADRV9001_GPIO_NUM_SIGNALS = 56, /*!< Total Number of signals from BBIC*/
} adi_adrv9001_GpioSignal_e;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int32_t adi_adrv9001_Rx_GainTable_Write(adi_adrv9001_Device_t *adrv9001,
* \param[in] adrv9001 Context variable - Pointer to the ADRV9001 device data structure
* \param[in] channel The Rx Channel from which to read the gain table
* \param[in] gainIndexOffset The gain index from which gain table read back should start
* \param[out] gainTableRows Read back array for gain table row entries which will be updated with the read back values
* \param[in,out] gainTableRows Read back array for gain table row entries which will be updated with the read back values; must be initialized
* \param[in] arraySize The size of the gainTableRows array; the max number of gain table rows to read
* \param[out] numGainIndicesRead The actual no. of gain indices read. Pass NULL if this info is not needed
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ typedef struct adi_adrv9001_ExtLna
uint8_t settlingDelay; /*!< External LNA Settling Delay. Valid range is from 0 to 255 */
} adi_adrv9001_ExtLna_t;

/**
* \brief Available AGC FREEZE options
*/
typedef enum adi_adrv9001_AgcFreezeType
{
ADI_ADRV9001_RX_AGC_HW_FREEZE,
ADI_ADRV9001_RX_AGC_SW_FREEZE
} adi_adrv9001_AgcFreezeType_e;

/**
* \brief Gain control configuration settings for initialization
* The Transceiver Evaluation Software can be used to generate a structure with suggested settings.
Expand Down Expand Up @@ -143,6 +152,7 @@ typedef struct adi_adrv9001_GainControlCfg
adi_adrv9001_ExtLna_t extLna;
bool rxQecFreezeEnable; /*!< RXQEC Freeze Enable/Disable, only applies in AGC mode*/
adi_adrv9001_GpioPin_e gpioFreezePin; /*!< GPIO pin to activate to freeze AGC - set to 0/UNASSIGNED if unused */
adi_adrv9001_AgcFreezeType_e agcFreezeType; /*!< HW_FREEZE = 0 or SW_FREEZE = 1 */
} adi_adrv9001_GainControlCfg_t;

typedef struct adi_adrv9001_RxGainControlPinCfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ typedef enum adi_adrv9001_FirGain
ADRV9001_FIR_GAIN_POS_26_DB = 26 /*!< FIR gain 26 */
} adi_adrv9001_FirGain_e;

/**
* \brief Enumerated list of Temperature Read options from internal temperature sensor
*/
typedef enum adi_adrv9001_TempReadMode
{
ADI_ADRV9001_TEMPERATURE_READ_MAILBOX = 0, /*!< Reads temperature value using Mailbox command, only after ADC completes temperature measurement */
ADI_ADRV9001_TEMPERATURE_READ_SPI = 1 /*!< Instantly reads the Aux ADC temperature sense result from register via direct register access,
irrespective of ADC temperature measurement done or not.
Hence, the value readback may be an older one */
} adi_adrv9001_TempReadMode_e;

/*
*********************************************************************************************************
* Structure definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern "C" {
#endif

/* Auto-generated version number - DO NOT MANUALLY EDIT */
#define ADI_ADRV9001_CURRENT_VERSION "68.13.7"
#define ADI_ADRV9001_CURRENT_VERSION "68.14.10"

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "adrv9001_reg_addr_macros.h"
#include "adrv9001_arm_macros.h"
#include "object_ids.h"
#include "adrv9001_bf.h"

int32_t adi_adrv9001_HwOpen(adi_adrv9001_Device_t *device, adi_adrv9001_SpiSettings_t *spiSettings)
{
Expand Down Expand Up @@ -527,45 +528,65 @@ int32_t adi_adrv9001_Profiles_Verify(adi_adrv9001_Device_t *device, adi_adrv9001
}

static __maybe_unused int32_t __maybe_unused adrv9001_TemperatureGetValidate(adi_adrv9001_Device_t *device,
int16_t *temperature_C)
adi_adrv9001_TempReadMode_e tempReadMode,
int16_t *temperature_C)
{
ADI_NULL_PTR_RETURN(&device->common, temperature_C);

ADI_RANGE_CHECK(device, tempReadMode, ADI_ADRV9001_TEMPERATURE_READ_MAILBOX, ADI_ADRV9001_TEMPERATURE_READ_SPI);
ADI_API_RETURN(device);
}

int32_t adi_adrv9001_Temperature_Get(adi_adrv9001_Device_t *device, int16_t *temperature_C)
int32_t adi_adrv9001_Temperature_Get(adi_adrv9001_Device_t *device, adi_adrv9001_TempReadMode_e tempReadMode, int16_t *temperature_C)
{
uint8_t channelMask = 0;
uint8_t armExtData[2] = {0};
uint8_t armReadBack[2] = {0};
uint16_t temperatureSenseResult = 0;
const uint8_t TEMP_SENSOR_DFL_OFFSET_CODE_VALUE = 0x10;
const uint16_t KELVIN_TO_CELSIUS = 0x111;

ADI_PERFORM_VALIDATION(adrv9001_TemperatureGetValidate, device, temperature_C);
ADI_PERFORM_VALIDATION(adrv9001_TemperatureGetValidate, device, tempReadMode, temperature_C);

*temperature_C = 0;

/* Channel mask is not used */
armExtData[0] = channelMask;
armExtData[1] = OBJID_GO_TEMP_SENSOR;

/* send ARM GET opcode */
ADI_EXPECT(adi_adrv9001_arm_Cmd_Write, device, (uint8_t)ADRV9001_ARM_GET_OPCODE, armExtData, sizeof(armExtData));

/* Wait for command to finish executing */
ADRV9001_ARM_CMD_STATUS_WAIT_EXPECT(device,
ADRV9001_ARM_GET_OPCODE,
armExtData[1],
ADI_ADRV9001_READ_TEMP_SENSOR_TIMEOUT_US,
ADI_ADRV9001_READ_TEMP_SENSOR_INTERVAL_US);
if (tempReadMode == ADI_ADRV9001_TEMPERATURE_READ_MAILBOX)
{

/* read the ARM memory to get temperature */
/* TODO: Enable auto increment if it works with non multiples of 4 */
ADI_EXPECT(adi_adrv9001_arm_Memory_Read, device, ADRV9001_ADDR_ARM_MAILBOX_GET, armReadBack,
sizeof(armReadBack), false)
/* Channel mask is not used */
armExtData[0] = channelMask;
armExtData[1] = OBJID_GO_TEMP_SENSOR;

/* send ARM GET opcode */
ADI_EXPECT(adi_adrv9001_arm_Cmd_Write, device, (uint8_t)ADRV9001_ARM_GET_OPCODE, armExtData, sizeof(armExtData));

/* Wait for command to finish executing */
ADRV9001_ARM_CMD_STATUS_WAIT_EXPECT(device,
ADRV9001_ARM_GET_OPCODE,
armExtData[1],
ADI_ADRV9001_READ_TEMP_SENSOR_TIMEOUT_US,
ADI_ADRV9001_READ_TEMP_SENSOR_INTERVAL_US);

/* read the ARM memory to get temperature */
/* TODO: Enable auto increment if it works with non multiples of 4 */
ADI_EXPECT(adi_adrv9001_arm_Memory_Read,
device,
ADRV9001_ADDR_ARM_MAILBOX_GET,
armReadBack,
sizeof(armReadBack),
false)

/* Reconstruct temperature */
*temperature_C = (int16_t)(((int16_t)armReadBack[0] << 0) |
((int16_t)armReadBack[1] << 8));
}
else if (tempReadMode == ADI_ADRV9001_TEMPERATURE_READ_SPI)
{
/* Readback from the aux adc temperature sense result */
ADI_EXPECT(adrv9001_NvsRegmapCore_TdegcReadback_Get, device, &temperatureSenseResult);

/* Reconstruct temperature */
*temperature_C = (int16_t)(((int16_t)armReadBack[0] << 0) |
((int16_t)armReadBack[1] << 8));
/* Retrieve temperature in Celsius */
*temperature_C = temperatureSenseResult - (TEMP_SENSOR_DFL_OFFSET_CODE_VALUE + KELVIN_TO_CELSIUS);
}

ADI_API_RETURN(device);
}
Expand Down
Loading
Loading