FreeRTOS:
Common I/O
AWS IoT Common I/O library
|
Return to main page ↑ |
File for the HAL APIs of ADC called by application layer. More...
Go to the source code of this file.
Data Structures | |
struct | IotAdcConfig_t |
data structures for ioctl request More... | |
struct | IotAdcChStatus_t |
data structure for ioctl GetChStatus More... | |
struct | IotAdcChBuffer_t |
data structure for ioctl SetChBuffer setting channel data buffer is optional using this ioctl if client doesn't pass in data buffer for driver to use, callback is triggered for every ADC sample to pass data back to client as driver doesn't have buffer to accumulate data. As soon as callback returns, xConverted_Data becomes invalid. On the other hand however if client does pass a buffer for driver to use, callback is triggered only after driver has filled buffer with xBufLen samples, client buffer is passed back in callback as XConverted_Data whose life span is controlled by the client even after callback returns. More... | |
struct | IotAdcChain_t |
Some ADC host controller supports grouping multiple ADC channels into a chain. When the chain is triggered to sample ADC data, all ADC channels in the group are sampled in sequence so that client doesn't need to trigger each channel individually. Coverted ADC samples from such chain group can be passed back to the client with a single callback. This data structure is used for ioctl to define ADC chain setting. More... | |
Macros | |
#define | IOT_ADC_SUCCESS ( 0 ) |
Error code returned by ADC driver. More... | |
#define | IOT_ADC_FAILED ( 1 ) |
#define | IOT_ADC_INVALID_VALUE ( 2 ) |
#define | IOT_ADC_NOT_OPEN ( 3 ) |
#define | IOT_ADC_FUNCTION_NOT_SUPPORTED ( 4 ) |
#define | IOT_ADC_CH_BUSY ( 5 ) |
Typedefs | |
typedef struct IotAdcDescriptor * | IotAdcHandle_t |
IotAdcHandle_t is the handle type returned by calling iot_adc_open(). This is initialized in open and returned to caller. The caller must pass this pointer to the rest of the ADC APIs. | |
typedef void(* | IotAdcCallback_t) (uint16_t *pusConvertedData, void *pvUserContext) |
adc notification callback type More... | |
Enumerations | |
enum | IotAdcChState_t { eChStateIdle, eChStateBusy } |
enum | IotAdcIoctlRequest_t { eSetAdcConfig, eGetAdcConfig, eGetChStatus, eSetChBuffer, eSetAdcChain } |
adc ioctl request types. More... | |
Functions | |
IotAdcHandle_t | iot_adc_open (int32_t lAdc) |
Initializes ADC controller with default configuration. init ADC controller, enable ADC clock, reset HW FIFO, set default configuration parameters, etc. Also allocate all required resources for ADC operation such as software data buffer etc. More... | |
int32_t | iot_adc_close (IotAdcHandle_t const pxAdc) |
Close ADC controller. All pending operation will be cancelled, put ADC module in reset state or low power state if possible. Release all resources claimed during open call. More... | |
void | iot_adc_set_callback (IotAdcHandle_t const pxAdc, uint8_t ucAdcChannel, IotAdcCallback_t xAdcCallback, void *pvUserContext) |
Sets channel callback on availability of channel scan data. On availability of ADC scan data, the application is notified with a function callback. The callback function and user context for callback are set using iot_adc_set_callback. More... | |
int32_t | iot_adc_start (IotAdcHandle_t const pxAdc, uint8_t ucAdcChannel) |
Start data acquisition for ADC channel until iot_adc_stop API is called. data will be passed back to client using callback function. by default each callback will pass back one data sample, however if client has used ioctl to pass in data buffer, only when buffer is full will callback be triggered. More... | |
int32_t | iot_adc_stop (IotAdcHandle_t const pxAdc, uint8_t ucAdcChannel) |
Stop data acquisition for ADC channel. More... | |
int32_t | iot_adc_read_sample (IotAdcHandle_t const pxAdc, uint8_t ucAdcChannel, uint16_t *pusAdcSample) |
read one ADC data sample. This API will return one ADC sample. More... | |
int32_t | iot_adc_ioctl (IotAdcHandle_t const pxAdc, IotAdcIoctlRequest_t xRequest, void *const pvBuffer) |
Used for various ADC control functions. More... | |
File for the HAL APIs of ADC called by application layer.
#define IOT_ADC_SUCCESS ( 0 ) |
Error code returned by ADC driver.
ADC operation completed successfully.
#define IOT_ADC_FAILED ( 1 ) |
ADC operation failed.
#define IOT_ADC_INVALID_VALUE ( 2 ) |
At least one parameter is invalid.
#define IOT_ADC_NOT_OPEN ( 3 ) |
ADC operation not possible unless ADC instance is opened.
#define IOT_ADC_FUNCTION_NOT_SUPPORTED ( 4 ) |
ADC operation not supported.
#define IOT_ADC_CH_BUSY ( 5 ) |
ADC channel is busy at current time.
typedef void( * IotAdcCallback_t) (uint16_t *pusConvertedData, void *pvUserContext) |
adc notification callback type
[in] | pvUserContext | User Context passed when setting the callback. This is not used or modified by the driver. The context is provided by the caller when setting the callback, and is passed back to the caller in the callback. |
[out] | pusConvertedData | pointer to converted ADC sample data. |
enum IotAdcChState_t |
enum IotAdcIoctlRequest_t |
adc ioctl request types.
Enumerator | |
---|---|
eSetAdcConfig | Set the ADC Configuration. Takes IotAdcConfig_t parameter. |
eGetAdcConfig | Get the ADC Configuration. Returns results in IotAdcConfig_t parameter. |
eGetChStatus | Get the Channel Status. Returns results in IotAdcChStatus_t parameter. |
eSetChBuffer | Set the buffer for ADC values to be stored in. Takes IotAdcChBuffer_t parameter. |
eSetAdcChain | ADC Chain for multiple ADC channels. Takes IotAdcChain_t parameter. |
IotAdcHandle_t iot_adc_open | ( | int32_t | lAdc | ) |
Initializes ADC controller with default configuration. init ADC controller, enable ADC clock, reset HW FIFO, set default configuration parameters, etc. Also allocate all required resources for ADC operation such as software data buffer etc.
[in] | lAdc | The instance of ADC controller to initialize. |
int32_t iot_adc_close | ( | IotAdcHandle_t const | pxAdc | ) |
Close ADC controller. All pending operation will be cancelled, put ADC module in reset state or low power state if possible. Release all resources claimed during open call.
[in] | pxAdc | handle to ADC controller returned from iot_adc_open() call. |
void iot_adc_set_callback | ( | IotAdcHandle_t const | pxAdc, |
uint8_t | ucAdcChannel, | ||
IotAdcCallback_t | xAdcCallback, | ||
void * | pvUserContext | ||
) |
Sets channel callback on availability of channel scan data. On availability of ADC scan data, the application is notified with a function callback. The callback function and user context for callback are set using iot_adc_set_callback.
[in] | pxAdc | The Adc handle returned in the open() call. |
[in] | ucAdcChannel | The Adc channel for which the callback is set |
[in] | xAdcCallback | The callback function to be called on availability of ADC channel data. |
[in] | pvUserContext | The user context to be passed when callback is called. |
Example Callback Function For asychronous ADC calls, a callback function is used to signal when the async task is complete. This example uses a Semaphore to signal the completion.
int32_t iot_adc_start | ( | IotAdcHandle_t const | pxAdc, |
uint8_t | ucAdcChannel | ||
) |
Start data acquisition for ADC channel until iot_adc_stop API is called. data will be passed back to client using callback function. by default each callback will pass back one data sample, however if client has used ioctl to pass in data buffer, only when buffer is full will callback be triggered.
[in] | pxAdc. | The ADC handle returned in the open() call |
[in] | ucAdcChannel. | The ADC channel to start data acquisition |
int32_t iot_adc_stop | ( | IotAdcHandle_t const | pxAdc, |
uint8_t | ucAdcChannel | ||
) |
Stop data acquisition for ADC channel.
[in] | pxAdc. | The ADC handle returned in the open() call |
[in] | ucAdcChannel. | The ADC channel to stop data acquisition |
int32_t iot_adc_read_sample | ( | IotAdcHandle_t const | pxAdc, |
uint8_t | ucAdcChannel, | ||
uint16_t * | pusAdcSample | ||
) |
read one ADC data sample. This API will return one ADC sample.
[in] | pxAdc. | The ADC handle returned in the open() call |
[in] | ucAdcChannel. | The ADC channel to read data from |
[out] | pusAdcSample. | ADC channel read sample value |
int32_t iot_adc_ioctl | ( | IotAdcHandle_t const | pxAdc, |
IotAdcIoctlRequest_t | xRequest, | ||
void *const | pvBuffer | ||
) |
Used for various ADC control functions.
[in] | pxAdc | The Adc handle returned in the open() call. |
[in] | xRequest | ioctl request defined by IotAdcIoctlRequest_s enums |
[in/out] | pvBuffer data buffer for ioctl request | |
[in] | pvBuffer | size |