ADuCM302x Device Drivers API Reference Manual
Release 3.1.2.0
|
ADC Driver. More...
Modules | |
Static Configuration | |
Data Structures | |
struct | __ADI_ADC_BUFFER |
Macros | |
#define | ADI_ADC_MEMORY_SIZE (48u + ADI_SEM_SIZE) |
#define | ADI_ADC_CHANNEL_0 (1u << 0u) |
#define | ADI_ADC_CHANNEL_1 (1u << 1u) |
#define | ADI_ADC_CHANNEL_2 (1u << 2u) |
#define | ADI_ADC_CHANNEL_3 (1u << 3u) |
#define | ADI_ADC_CHANNEL_4 (1u << 4u) |
#define | ADI_ADC_CHANNEL_5 (1u << 5u) |
#define | ADI_ADC_CHANNEL_6 (1u << 6u) |
#define | ADI_ADC_CHANNEL_7 (1u << 7u) |
Typedefs | |
typedef uint32_t | ADI_ADC_CHANNEL |
typedef struct __ADI_ADC_BUFFER | ADI_ADC_BUFFER |
typedef struct __ADI_ADC_DEVICE * | ADI_ADC_HANDLE |
Functions | |
ADI_ADC_RESULT | adi_adc_Open (uint32_t nDeviceNum, void *pMemory, uint32_t nMemorySize, ADI_ADC_HANDLE *phDevice) |
Opens an ADC device instance. More... | |
ADI_ADC_RESULT | adi_adc_Close (ADI_ADC_HANDLE hDevice) |
Close the given device instance. More... | |
ADI_ADC_RESULT | adi_adc_PowerUp (ADI_ADC_HANDLE hDevice, bool bPowerUp) |
Power up ADC. More... | |
ADI_ADC_RESULT | adi_adc_RegisterCallback (ADI_ADC_HANDLE hDevice, ADI_CALLBACK pfCallback, void *pCBParam) |
Registering a callback function. More... | |
ADI_ADC_RESULT | adi_adc_EnableADCSubSystem (ADI_ADC_HANDLE hDevice, bool bEnable) |
Enable/Disables the ADC Subsystem. More... | |
ADI_ADC_RESULT | adi_adc_IsReady (ADI_ADC_HANDLE hDevice, bool *pbReady) |
Returns whether the ADC Subsystem is ready. More... | |
ADI_ADC_RESULT | adi_adc_SetVrefSource (ADI_ADC_HANDLE hDevice, ADI_ADC_VREF_SRC eVrefSrc) |
Set the Voltage Reference source. More... | |
ADI_ADC_RESULT | adi_adc_SinkEnable (ADI_ADC_HANDLE hDevice, bool bEnable) |
Enable/Disable Current Sink. More... | |
ADI_ADC_RESULT | adi_adc_StartCalibration (ADI_ADC_HANDLE hDevice) |
Start the ADC calibration. More... | |
ADI_ADC_RESULT | adi_adc_IsCalibrationDone (ADI_ADC_HANDLE hDevice, bool *pbCalibrationDone) |
Returns the status of the calibration which was initiated. More... | |
ADI_ADC_RESULT | adi_adc_SetAcquisitionTime (ADI_ADC_HANDLE hDevice, uint32_t nAcqTimeInAClkCycles) |
Set the acquisition time of ADC in ADC clock cycles. More... | |
ADI_ADC_RESULT | adi_adc_SetDelayTime (ADI_ADC_HANDLE hDevice, uint32_t nDelayInAClkCycles) |
Set the delay time of ADC in ADC cycles for multi iteration mode. More... | |
ADI_ADC_RESULT | adi_adc_SetResolution (ADI_ADC_HANDLE hDevice, ADI_ADC_RESOLUTION eResolution) |
Set the resolution of ADC. he default resolution of ADC is 12-bit and the ADC increases the resolution by oversampling. Averaging will be disabled when the resolution is more than 12-bits. More... | |
ADI_ADC_RESULT | adi_adc_EnableAveraging (ADI_ADC_HANDLE hDevice, uint16_t nAveragingSamples) |
Enable Averaging for all ADC channels. More... | |
ADI_ADC_RESULT | adi_adc_SetLowLimit (ADI_ADC_HANDLE hDevice, ADI_ADC_CHANNEL eChannel, bool bEnable, uint16_t nLowLimit) |
Configure low limit for an ADC channel when it is used as a digital comparator. More... | |
ADI_ADC_RESULT | adi_adc_SetHighLimit (ADI_ADC_HANDLE hDevice, ADI_ADC_CHANNEL eChannel, bool bEnable, uint16_t nHighLimit) |
Configure high limit for an ADC channel when it's used as a digital comparator. More... | |
ADI_ADC_RESULT | adi_adc_SetHysteresis (ADI_ADC_HANDLE hDevice, ADI_ADC_CHANNEL eChannel, bool bEnable, uint16_t nHysteresis) |
Configure hysteresis for an ADC channel when it's used as a digital comparator. More... | |
ADI_ADC_RESULT | adi_adc_SetNumMonitorCycles (ADI_ADC_HANDLE hDevice, ADI_ADC_CHANNEL eChannel, uint32_t nNumMonitorCycles) |
Configure number of monitor cycles for an ADC channel when it's used as a digital comparator. More... | |
ADI_ADC_RESULT | adi_adc_EnableDigitalComparator (ADI_ADC_HANDLE hDevice, bool bEnableComparator) |
Enable/Disable digital comparator for the given channel(s) More... | |
ADI_ADC_RESULT | adi_adc_SubmitBuffer (ADI_ADC_HANDLE hDevice, ADI_ADC_BUFFER *pBuffer) |
Submit the ADC buffer for processing to the ADC Module. More... | |
ADI_ADC_RESULT | adi_adc_GetBuffer (ADI_ADC_HANDLE hDevice, ADI_ADC_BUFFER **ppBuffer) |
Get a processed buffer from the ADC Driver. This function is a blocking call and will only return once it has the buffer or if any error occurred. If a callback is registered then any call to this function will fail. More... | |
ADI_ADC_RESULT | adi_adc_Enable (ADI_ADC_HANDLE hDevice, bool bEnable) |
Enable/Disable ADC for sampling. More... | |
ADI_ADC_RESULT | adi_adc_IsBufferAvailable (ADI_ADC_HANDLE hDevice, bool *pbIsBufferAvailable) |
This function return whether a filled buffer is available to be returned to the user. If this function return true, then a call to adi_adc_GetBuffer will not block. More... | |
ADI_ADC_RESULT | adi_adc_ReadChannels (ADI_ADC_HANDLE hDevice, uint32_t nChannels, uint32_t nNumConversionPasses, void *pBuffer, uint32_t nBuffLength) |
Sample the given channels for the given number of conversion passes and put it into the given buffer. This function only return after the channels are sampled the given number of conversion times or if any error occurs. More... | |
ADI_ADC_RESULT | adi_adc_GetBatteryVoltage (ADI_ADC_HANDLE hDevice, uint32_t nRefVoltage, uint32_t *pnBatVoltage) |
Returns the battery voltage. More... | |
ADI_ADC_RESULT | adi_adc_EnableTemperatureSensor (ADI_ADC_HANDLE hDevice, bool bEnable) |
Enable or disable the temperature sensor. More... | |
ADI_ADC_RESULT | adi_adc_GetTemperature (ADI_ADC_HANDLE hDevice, uint32_t nRefVoltage, int32_t *pnTemperature) |
Return the temperature in fixed point format in degree Celcius. More... | |
ADC Driver.
The ADC driver manages all instances of the ADC peripheral.
#define ADI_ADC_MEMORY_SIZE (48u + ADI_SEM_SIZE) |
Amount of memory(In bytes) required by the ADC device driver for managing the operation of a ADC controller. The memory is passed to the driver when the driver is opended. The memory is completely owned by the driver till the the driver is closed.Memory Size of the buffer required by the ADC driver
Definition at line 66 of file adi_adc.h.
Referenced by adi_adc_Open().
#define ADI_ADC_CHANNEL_0 (1u << 0u) |
typedef struct __ADI_ADC_BUFFER ADI_ADC_BUFFER |
Structure which hold the details of the buffer and sampling details
typedef struct __ADI_ADC_DEVICE* ADI_ADC_HANDLE |
enum ADI_ADC_RESULT |
ADC API return codes
enum ADI_ADC_VREF_SRC |
enum ADI_ADC_RESOLUTION |
enum ADI_ADC_EVENT |
Callback events from the ADC driver.
Enumerator | |
---|---|
ADI_ADC_EVENT_CALIBRATION_DONE | Calibration done event. arg to the callback function will be NULL. |
ADI_ADC_EVENT_ADC_READY | ADC Ready event. arg to the callback function will be null |
ADI_ADC_EVENT_OVERFLOW | Overflow event occurred. The channel(ADI_ADC_CHANNEL) for which the overflow occurred will be passed as arg to the callback function. |
ADI_ADC_EVENT_HIGH_LIMIT_CROSSED | High Limit crossed event. The channel(ADI_ADC_CHANNEL) for which the limit is crossed will be passed as arg to the callback function. |
ADI_ADC_EVENT_LOW_LIMIT_CROSSED | Low Limit crossed event. The channel(ADI_ADC_CHANNEL) for which the limit is crossed will be passed as arg to the callback function. |
ADI_ADC_RESULT adi_adc_Open | ( | uint32_t | nDeviceNum, |
void * | pMemory, | ||
uint32_t | nMemorySize, | ||
ADI_ADC_HANDLE * | phDevice | ||
) |
Opens an ADC device instance.
[in] | nDeviceNum | Device number to open |
[in] | pMemory | Pointer to a ADI_ADC_MEMORY_SIZE sized buffer to manage the device instance. |
[in] | nMemorySize | Size of the buffer to which "pMemory" points |
[out] | phDevice | Pointer to a location where ADC device handle is to be written. |
ADI_ADC_RESULT adi_adc_Close | ( | ADI_ADC_HANDLE | hDevice | ) |
Close the given device instance.
[in] | hDevice | Handle to the device instance |
ADI_ADC_RESULT adi_adc_PowerUp | ( | ADI_ADC_HANDLE | hDevice, |
bool | bPowerUp | ||
) |
Power up ADC.
[in] | hDevice | Handle to the device instance |
[in] | bPowerUp | 'true' to power up and 'false' to power down the ADC. |
Definition at line 309 of file adi_adc.c.
Referenced by adi_adc_Close().
ADI_ADC_RESULT adi_adc_RegisterCallback | ( | ADI_ADC_HANDLE | hDevice, |
ADI_CALLBACK | pfCallback, | ||
void * | pCBParam | ||
) |
Registering a callback function.
[in] | hDevice | Handle to the device instance |
[in] | pfCallback | Function pointer to callback function. Passing a NULL pointer will unregister the call back function. |
[in] | pCBParam | Call back function parameter |
This function registers a call back function. Registered function will be called when the given computation is over. It will also be called when the digital comparitor is being used and a limit has been broken.
ADI_ADC_RESULT adi_adc_EnableADCSubSystem | ( | ADI_ADC_HANDLE | hDevice, |
bool | bEnable | ||
) |
Enable/Disables the ADC Subsystem.
[in] | hDevice | Handle to the device instance |
[in] | bEnable | 'true' to Enable and 'false' to Disable` |
Enables/Disables the ADC Subsystem. The ADC subsystem need to be enabled before using the ADC for sampling the signal. The driver should check whether the ADC is ready by calling adi_adc_IsReady API before continuing. If internal reference buffer is used as voltage reference then application has to wait at least 3.5ms after enabling irrespective of whether adi_adc_IsReady returns ready or not.
Definition at line 438 of file adi_adc.c.
Referenced by adi_adc_PowerUp().
ADI_ADC_RESULT adi_adc_IsReady | ( | ADI_ADC_HANDLE | hDevice, |
bool * | pbReady | ||
) |
Returns whether the ADC Subsystem is ready.
[in] | hDevice | Handle to the device instance |
[in] | pbReady | Pointer to a bool variable. The variable will be set to 'true' if the ADC is ready else 'false' |
Returns whether the ADC is ready for sampling. This API should be called after enabling the ADC sub-system using adi_adc_EnableADCSubSystem API. If internal reference buffer is used as voltage reference then application has to wait at least 3.5ms after enabling irrespective of whether adi_adc_IsReady returns ready or not.
ADI_ADC_RESULT adi_adc_SetVrefSource | ( | ADI_ADC_HANDLE | hDevice, |
ADI_ADC_VREF_SRC | eVrefSrc | ||
) |
Set the Voltage Reference source.
[in] | hDevice | Handle to the device instance |
[in] | eVrefSrc | Voltage Reference source to be used |
The API can be used to select the voltage reference to be used by the ADC. This option need to be set before enabling the ADC subsystem.
ADI_ADC_RESULT adi_adc_SinkEnable | ( | ADI_ADC_HANDLE | hDevice, |
bool | bEnable | ||
) |
Enable/Disable Current Sink.
[in] | hDevice | Handle to the device instance |
[in] | bEnable | 'true' to Enable and 'false' to Disable current sink |
If the volatage reference is required to sink current then this option need to be enabled. The ADC subsystem has the capability to sink upto 50uA at Vref of 1.25V and 100uA at Vref of 2.5V
ADI_ADC_RESULT adi_adc_StartCalibration | ( | ADI_ADC_HANDLE | hDevice | ) |
Start the ADC calibration.
[in] | hDevice | Handle to the device instance |
The call to this function initiate calibration of the ADC. The user is recommended to do calibration of the ADC after enabling the ADC subsystem. The status of the calibration can be checked using adi_adc_IsCalibrationDone API.
ADI_ADC_RESULT adi_adc_IsCalibrationDone | ( | ADI_ADC_HANDLE | hDevice, |
bool * | pbCalibrationDone | ||
) |
Returns the status of the calibration which was initiated.
[in] | hDevice | Handle to the device instance |
[out] | pbCalibrationDone | Pointer to the location to which the status of calibration is written. 'true' if the calibration started by call to is done else 'false' |
ADI_ADC_RESULT adi_adc_SetAcquisitionTime | ( | ADI_ADC_HANDLE | hDevice, |
uint32_t | nAcqTimeInAClkCycles | ||
) |
Set the acquisition time of ADC in ADC clock cycles.
Set the acquisition time of ADC in ADC clock cycles. The acquisition phase is (ADC_CNV_TIME.SAMPTIME + 1) ACLK cycles
[in] | hDevice | Handle to the device instance |
[in] | nAcqTimeInAClkCycles | Acquisition time in ADC clock cycles. A valid range is 1u to the width of the SAMPTIME field + 1. |
ADI_ADC_RESULT adi_adc_SetDelayTime | ( | ADI_ADC_HANDLE | hDevice, |
uint32_t | nDelayInAClkCycles | ||
) |
Set the delay time of ADC in ADC cycles for multi iteration mode.
[in] | hDevice | Handle to the device instance |
[in] | nDelayInAClkCycles | Delay time in ADC clock cycles. |
ADI_ADC_RESULT adi_adc_SetResolution | ( | ADI_ADC_HANDLE | hDevice, |
ADI_ADC_RESOLUTION | eResolution | ||
) |
Set the resolution of ADC. he default resolution of ADC is 12-bit and the ADC increases the resolution by oversampling. Averaging will be disabled when the resolution is more than 12-bits.
[in] | hDevice | Handle to the device instance |
[in] | eResolution | Enum of ADC resolution |
ADI_ADC_RESULT adi_adc_EnableAveraging | ( | ADI_ADC_HANDLE | hDevice, |
uint16_t | nAveragingSamples | ||
) |
Enable Averaging for all ADC channels.
[in] | hDevice | Handle to the device instance |
[in] | nAveragingSamples | Specifies the number of samples used for averaging. The valid value is between 1-256, in the steps of power of 2. 1 is for disabling averaging. The averaging require that the resolution of ADC is 12-bit. |
ADI_ADC_RESULT adi_adc_SetLowLimit | ( | ADI_ADC_HANDLE | hDevice, |
ADI_ADC_CHANNEL | eChannel, | ||
bool | bEnable, | ||
uint16_t | nLowLimit | ||
) |
Configure low limit for an ADC channel when it is used as a digital comparator.
[in] | hDevice | Handle to the device instance |
[in] | eChannel | The ADC channel for which to configure the comparator |
[in] | bEnable | Enable or disable the low limit of the digital comparator |
[in] | nLowLimit | The low limit of the digital comparator. If bEnable is false, this paramter is omitted. |
ADI_ADC_RESULT adi_adc_SetHighLimit | ( | ADI_ADC_HANDLE | hDevice, |
ADI_ADC_CHANNEL | eChannel, | ||
bool | bEnable, | ||
uint16_t | nHighLimit | ||
) |
Configure high limit for an ADC channel when it's used as a digital comparator.
[in] | hDevice | Handle to the device instance |
[in] | eChannel | The ADC channel for which to configure the comparator |
[in] | bEnable | Enable or disable the high limit of the digital comparator |
[in] | nHighLimit | The high limit of the digital comparator. If bEnable is false, this paramter is omitted. |
ADI_ADC_RESULT adi_adc_SetHysteresis | ( | ADI_ADC_HANDLE | hDevice, |
ADI_ADC_CHANNEL | eChannel, | ||
bool | bEnable, | ||
uint16_t | nHysteresis | ||
) |
Configure hysteresis for an ADC channel when it's used as a digital comparator.
[in] | hDevice | Handle to the device instance |
[in] | eChannel | The ADC channel for which to configure the comparator |
[in] | bEnable | Enable or disable the hysteresis of the digital comparator |
[in] | nHysteresis | The hysteresis to be used. If bEnable is false, this paramter is omitted. |
ADI_ADC_RESULT adi_adc_SetNumMonitorCycles | ( | ADI_ADC_HANDLE | hDevice, |
ADI_ADC_CHANNEL | eChannel, | ||
uint32_t | nNumMonitorCycles | ||
) |
Configure number of monitor cycles for an ADC channel when it's used as a digital comparator.
[in] | hDevice | Handle to the device instance |
[in] | eChannel | The ADC channel for which to configure the comparator |
[in] | nNumMonitorCycles | Number of Monitor cycles before giving interrupt |
ADI_ADC_RESULT adi_adc_EnableDigitalComparator | ( | ADI_ADC_HANDLE | hDevice, |
bool | bEnableComparator | ||
) |
Enable/Disable digital comparator for the given channel(s)
[in] | hDevice | Handle to the device instance |
[in] | bEnableComparator | 'true' to Enable and 'false' to disable |
ADI_ADC_RESULT adi_adc_SubmitBuffer | ( | ADI_ADC_HANDLE | hDevice, |
ADI_ADC_BUFFER * | pBuffer | ||
) |
Submit the ADC buffer for processing to the ADC Module.
[in] | hDevice | Handle to the device instance. |
[in] | pBuffer | Pointer to the ADI_ADC_BUFFER structure which contains details of the buffers required by the driver. |
ADI_ADC_RESULT adi_adc_GetBuffer | ( | ADI_ADC_HANDLE | hDevice, |
ADI_ADC_BUFFER ** | ppBuffer | ||
) |
Get a processed buffer from the ADC Driver. This function is a blocking call and will only return once it has the buffer or if any error occurred. If a callback is registered then any call to this function will fail.
[in] | hDevice | Handle to the device instance. |
[out] | ppBuffer | Pointer to a pointer to ADI_ADC_BUFFER structure. The returned pointer to ADI_ADC_BUFFER is written here. |
ADI_ADC_RESULT adi_adc_Enable | ( | ADI_ADC_HANDLE | hDevice, |
bool | bEnable | ||
) |
Enable/Disable ADC for sampling.
[in] | hDevice | Handle to the device instance |
[in] | bEnable | 'true' to Enable and 'false' to disable |
ADI_ADC_RESULT adi_adc_IsBufferAvailable | ( | ADI_ADC_HANDLE | hDevice, |
bool * | pbIsBufferAvailable | ||
) |
This function return whether a filled buffer is available to be returned to the user. If this function return true, then a call to adi_adc_GetBuffer will not block.
[in] | hDevice | Handle to the device instance. |
[out] | pbIsBufferAvailable | Pointer to a bool variable to which the availability of buffer will be written. The variable will be set to 'true' if buffer is available else 'false' |
ADI_ADC_RESULT adi_adc_ReadChannels | ( | ADI_ADC_HANDLE | hDevice, |
uint32_t | nChannels, | ||
uint32_t | nNumConversionPasses, | ||
void * | pBuffer, | ||
uint32_t | nBuffLength | ||
) |
Sample the given channels for the given number of conversion passes and put it into the given buffer. This function only return after the channels are sampled the given number of conversion times or if any error occurs.
[in] | hDevice | Handle to the device instance |
[in] | nChannels | Channels to sample. Should be an ORed value of ADI_ADC_CHANNEL types. |
[in] | nNumConversionPasses | Number of conversion passes. In one conversion pass, the ADC will sample all the given channel(s) once. |
[in] | pBuffer | Pointer to the buffer to which the sampled data is put. |
[in] | nBuffLength | Length of the buffer. The length of the buffer should be at least 2*(Num of Channels)*nNumConversionPasses bytes. |
Sample all the given channels for the given number of conversion passes and put the samples values into the given buffers. The channels will be sampled starting from the lower number. This function only return after the channels are sampled the given number of conversion times or if any error occurs.
ADI_ADC_RESULT adi_adc_GetBatteryVoltage | ( | ADI_ADC_HANDLE | hDevice, |
uint32_t | nRefVoltage, | ||
uint32_t * | pnBatVoltage | ||
) |
Returns the battery voltage.
[in] | hDevice | Handle to the device instance. |
[in] | nRefVoltage | Reference voltage in fixed point(16.16) format. |
[out] | pnBatVoltage | Pointer to a variable to which the voltage of the battery will be written. The battery voltage will be in fixed point (16.16) format. |
ADI_ADC_RESULT adi_adc_EnableTemperatureSensor | ( | ADI_ADC_HANDLE | hDevice, |
bool | bEnable | ||
) |
Enable or disable the temperature sensor.
[in] | hDevice | Handle to the device instance. |
[in] | bEnable | 'true' to enable and 'false' to disable the temperature sensor |
ADI_ADC_RESULT adi_adc_GetTemperature | ( | ADI_ADC_HANDLE | hDevice, |
uint32_t | nRefVoltage, | ||
int32_t * | pnTemperature | ||
) |
Return the temperature in fixed point format in degree Celcius.
[in] | hDevice | Handle to the device instance. |
[in] | nRefVoltage | Reference voltage in fixed point(16.16) format. |
[out] | pnTemperature | Pointer to a variable to which the ADC die temperature (in degree Celsius) will be written. The temperature will be in fixed point (16.16) format. |