precision-converters-firmware
Loading...
Searching...
No Matches
Macros | Enumerations | Functions | Variables
ad4692_iio.c File Reference

Implementation of AD4692 IIO application interfaces. More...

#include <string.h>
#include "ad4692_user_config.h"
#include "ad4692_support.h"
#include "ad4692_iio.h"
#include "iio_trigger.h"
#include "no_os_error.h"
#include "no_os_delay.h"
#include "no_os_util.h"
#include "no_os_alloc.h"
#include "app_config.h"
#include "common.h"
#include "ad4692.h"
#include "version.h"
#include "ad4692_attrs.h"
Include dependency graph for ad4692_iio.c:

Macros

#define AD4692_IIO_TRIGGER_NAME   "ad4692_iio_trigger"
 
#define adc_data_buffer   SDRAM_START_ADDRESS + (N_CYCLE_OFFSET * BYTES_PER_SAMPLE)
 
#define DATA_BUFFER_SIZE   SDRAM_SIZE_BYTES
 
#define DATA_BUFFER_SIZE_CONT   (32768)
 
#define AD4692_DEFAULT_CHN_SCAN
 
#define AD4692_IIO_CH(_name, _dev, _idx)
 
#define BUF_READ_TIMEOUT   0xffffffff
 
#define CS_CHANGE   1
 
#define AD4692_N_CNV_TOGGLES   2
 
#define AD4692_EXIT_MANUAL_MODE   0x0
 
#define ACC_COUNT_MIN_VAL   0
 
#define ACC_COUNT_MAX_VAL   64
 
#define AD4692_ADC_MODE_STOP_STATE_MASK   NO_OS_BIT(5)
 
#define AD4692_STOP_STATE_DATA_READYb   0x1
 
#define ADC_MAX_COUNT_UNIPOLAR   (uint32_t) ((1 << ADC_RESOLUTION) - 1)
 
#define AD4692_SCALE   (((float) (AD4692_VREF) / 1000000.0f) / (float)(ADC_MAX_COUNT_UNIPOLAR) * 1000.0f)
 
#define AD4692_OFFSET   0
 
#define PWM_PERIOD_TO_FREQUENCY(x)   (1000000000.0 / x)
 
#define AD4692_MAX_PRIORITIES   2
 
#define AD4692_RES_16   16
 
#define AD4692_RES_24   24
 
#define AD4692_N_BYTES_CNV_CLOCK_24BIT   5
 
#define AD4692_N_BYTES_CNV_CLOCK_16BIT   4
 
#define MAX_LOCAL_BUF_SIZE   65536
 
#define MAX_DMA_NDTR   (no_os_min(65532, (MAX_LOCAL_BUF_SIZE)))
 

Enumerations

enum  ad4692_board_attribute_ids {
  PRIORITY ,
  PRIORITY_AVAILABLE
}
 
enum  ad4692_readback_options {
  AVERAGED_DATA ,
  ACCUMULATOR_DATA
}
 

Functions

int ad4692_update_sampling_frequency (uint32_t *sampling_rate)
 Set the sampling rate and get the updated value supported by MCU platform.
 
int ad4692_iio_attr_get (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t priv)
 Getter/Setter for the raw, offset and scale attribute value.
 
int ad4692_iio_attr_set (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t priv)
 Setter function for AD4692 attributes.
 
int ad4692_iio_attr_available_get (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t priv)
 Attribute available getter function for AD4692 attributes.
 
int ad4692_iio_attr_available_set (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t priv)
 Attribute available setter function for AD4692 attributes.
 
int32_t ad4692_trigger_handler (struct iio_device_data *iio_dev_data)
 Push data into IIO buffer when trigger handler IRQ is invoked.
 
void ad4692_data_capture_callback (void *ctx)
 Interrupt Service Routine to monitor end of conversion event.
 
int32_t ad4692_configure_sampling_rate (void)
 
int32_t iio_app_initialize (void)
 Initialize the AD4692 IIO Application.
 
void iio_params_deinit (void)
 DeInitialize the IIO parameters.
 
void iio_app_event_handler (void)
 Run the ad4692 IIO event handler.
 

Variables

struct scan_type ad4692_iio_scan_type [NUM_OF_IIO_DEVICES][NO_OF_CHANNELS]
 
struct ad4692_desc * ad4692_dev = NULL
 
volatile uint8_t chan_id = 0
 
uint8_t num_of_active_channels = 0
 
uint8_t data_buff [BYTES_PER_SAMPLE] = { 0x0 }
 
struct no_os_spi_msg ad4692_spi_msg_manual_mode
 
uint16_t channel_mask = 0x1
 
uint8_t ad4692_acc_count [NO_OF_CHANNELS] = { 0x0 }
 
enum ad4692_interface_modes ad4692_interface_mode = SPI_DMA
 
enum ad4692_data_capture_modes ad4692_data_capture_mode = BURST
 
enum ad4692_readback_options ad4692_readback_option = AVERAGED_DATA
 
uint32_t ad4692_sampling_frequency
 
uint32_t ad4692_sampling_frequency_max
 
uint8_t channel_priorities [NO_OF_CHANNELS] = { 0x0 }
 
uint8_t channel_sequence [AD4692_MAX_SLOTS_AS] = { 0x0 }
 
uint8_t num_of_as_slots = 0
 
uint8_t n_data_bytes
 
struct stm32_spi_init_param * spi_init_param
 
volatile struct iio_device_data * iio_dev_data_g
 
uint32_t nb_of_samples_g
 
uint32_t data_read
 
volatile bool dma_config_updated = false
 
volatile bool ad4692_dma_buff_full = false
 
volatile uint32_t * buff_start_addr
 
uint8_t local_buf [MAX_LOCAL_BUF_SIZE+(NO_OF_CHANNELS *N_CYCLE_OFFSET)]
 
uint32_t callback_count = 0
 
struct iio_init_param iio_init_params
 

Detailed Description

Implementation of AD4692 IIO application interfaces.

This module acts as an interface for AD4692 IIO application

Copyright (c) 2024, 2026 Analog Devices, Inc.

This software is proprietary to Analog Devices, Inc. and its licensors. By using this software you agree to the terms of the associated Analog Devices Software License Agreement.

Macro Definition Documentation

◆ ACC_COUNT_MAX_VAL

#define ACC_COUNT_MAX_VAL   64

◆ ACC_COUNT_MIN_VAL

#define ACC_COUNT_MIN_VAL   0

◆ AD4692_ADC_MODE_STOP_STATE_MASK

#define AD4692_ADC_MODE_STOP_STATE_MASK   NO_OS_BIT(5)

◆ AD4692_DEFAULT_CHN_SCAN

#define AD4692_DEFAULT_CHN_SCAN
Value:
{\
.sign = 'u',\
.realbits = ADC_RESOLUTION,\
.storagebits = CHN_STORAGE_BITS,\
.shift = 0,\
.is_big_endian = true\
}
#define CHN_STORAGE_BITS
Definition ad2s1210_iio.c:70
#define ADC_RESOLUTION
Definition app_config.h:161

◆ AD4692_EXIT_MANUAL_MODE

#define AD4692_EXIT_MANUAL_MODE   0x0

◆ AD4692_IIO_CH

#define AD4692_IIO_CH (   _name,
  _dev,
  _idx 
)
Value:
{\
.name = _name,\
.ch_type = IIO_VOLTAGE,\
.ch_out = false,\
.indexed = true,\
.channel = _idx,\
.scan_index = _idx,\
.scan_type = ad4692_iio_scan_type[_dev],\
.attributes = ad4692_iio_ch_attributes[_dev]\
}
struct scan_type ad4692_iio_scan_type[NUM_OF_IIO_DEVICES][NO_OF_CHANNELS]
Definition ad4692_iio.c:74

◆ AD4692_IIO_TRIGGER_NAME

#define AD4692_IIO_TRIGGER_NAME   "ad4692_iio_trigger"

◆ AD4692_MAX_PRIORITIES

#define AD4692_MAX_PRIORITIES   2

◆ AD4692_N_BYTES_CNV_CLOCK_16BIT

#define AD4692_N_BYTES_CNV_CLOCK_16BIT   4

◆ AD4692_N_BYTES_CNV_CLOCK_24BIT

#define AD4692_N_BYTES_CNV_CLOCK_24BIT   5

◆ AD4692_N_CNV_TOGGLES

#define AD4692_N_CNV_TOGGLES   2

◆ AD4692_OFFSET

#define AD4692_OFFSET   0

◆ AD4692_RES_16

#define AD4692_RES_16   16

◆ AD4692_RES_24

#define AD4692_RES_24   24

◆ AD4692_SCALE

#define AD4692_SCALE   (((float) (AD4692_VREF) / 1000000.0f) / (float)(ADC_MAX_COUNT_UNIPOLAR) * 1000.0f)

◆ AD4692_STOP_STATE_DATA_READYb

#define AD4692_STOP_STATE_DATA_READYb   0x1

◆ adc_data_buffer

#define adc_data_buffer   SDRAM_START_ADDRESS + (N_CYCLE_OFFSET * BYTES_PER_SAMPLE)

◆ ADC_MAX_COUNT_UNIPOLAR

#define ADC_MAX_COUNT_UNIPOLAR   (uint32_t) ((1 << ADC_RESOLUTION) - 1)

◆ BUF_READ_TIMEOUT

#define BUF_READ_TIMEOUT   0xffffffff

◆ CS_CHANGE

#define CS_CHANGE   1

◆ DATA_BUFFER_SIZE

#define DATA_BUFFER_SIZE   SDRAM_SIZE_BYTES

◆ DATA_BUFFER_SIZE_CONT

#define DATA_BUFFER_SIZE_CONT   (32768)

◆ MAX_DMA_NDTR

#define MAX_DMA_NDTR   (no_os_min(65532, (MAX_LOCAL_BUF_SIZE)))

◆ MAX_LOCAL_BUF_SIZE

#define MAX_LOCAL_BUF_SIZE   65536

◆ PWM_PERIOD_TO_FREQUENCY

#define PWM_PERIOD_TO_FREQUENCY (   x)    (1000000000.0 / x)

Enumeration Type Documentation

◆ ad4692_board_attribute_ids

Enumerator
PRIORITY 
PRIORITY_AVAILABLE 

◆ ad4692_readback_options

Enumerator
AVERAGED_DATA 
ACCUMULATOR_DATA 

Function Documentation

◆ ad4692_configure_sampling_rate()

int32_t ad4692_configure_sampling_rate ( void  )
Here is the caller graph for this function:

◆ ad4692_data_capture_callback()

void ad4692_data_capture_callback ( void *  ctx)

Interrupt Service Routine to monitor end of conversion event.

Parameters
ctx[in]- Callback context (unused)
Returns
none
Note
Callback registered for the the DRDY interrupt to indicate end of conversion in case of burst data capturing with SPI operation.

◆ ad4692_iio_attr_available_get()

int ad4692_iio_attr_available_get ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  priv 
)

Attribute available getter function for AD4692 attributes.

Parameters
device[in,out]-Pointer to IIO device instance
buf[in]-IIO input data buffer
len[in]-Number of input bytes
channel[in]- input channel
priv[in]- Attribute private ID
Returns
len in case of SUCCESS, negative error code otherwise

◆ ad4692_iio_attr_available_set()

int ad4692_iio_attr_available_set ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  priv 
)

Attribute available setter function for AD4692 attributes.

Parameters
device[in,out]-Pointer to IIO device instance
buf[in]-IIO input data buffer
len[in]-Number of input bytes
channel[in]- input channel
priv[in]- Attribute private ID
Returns
len in case of success, negative error code otherwise

◆ ad4692_iio_attr_get()

int ad4692_iio_attr_get ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  priv 
)

Getter/Setter for the raw, offset and scale attribute value.

Parameters
device[in,out]-Pointer to IIO device instance
buf[in]-IIO input data buffer
len[in]-Number of input bytes
channel[in]- input channel
priv[in]- Attribute private ID
Returns
Number of characters read/written, negative error code otherwise

◆ ad4692_iio_attr_set()

int ad4692_iio_attr_set ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  priv 
)

Setter function for AD4692 attributes.

Parameters
device[in,out]-Pointer to IIO device instance
buf[in]-IIO input data buffer
len[in]-Number of expected bytes
channel[in]- input channel
priv[in]- Attribute private ID
Returns
len in case of success, negative error code otherwise

◆ ad4692_trigger_handler()

int32_t ad4692_trigger_handler ( struct iio_device_data *  iio_dev_data)

Push data into IIO buffer when trigger handler IRQ is invoked.

Parameters
iio_dev_data[in]- IIO device data instance
Returns
0 in case of success or negative value otherwise

◆ ad4692_update_sampling_frequency()

int ad4692_update_sampling_frequency ( uint32_t *  sampling_rate)

Set the sampling rate and get the updated value supported by MCU platform.

Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ iio_app_event_handler()

void iio_app_event_handler ( void  )

Run the ad4692 IIO event handler.

Run the AD405X IIO event handler.

Returns
None

◆ iio_app_initialize()

int32_t iio_app_initialize ( void  )

Initialize the AD4692 IIO Application.

Initialize the IIO interface for AD405X IIO device.

Returns
0 in case of success, negative value otherwise
Here is the caller graph for this function:

◆ iio_params_deinit()

void iio_params_deinit ( void  )

DeInitialize the IIO parameters.

Here is the caller graph for this function:

Variable Documentation

◆ ad4692_acc_count

uint8_t ad4692_acc_count[NO_OF_CHANNELS] = { 0x0 }

◆ ad4692_data_capture_mode

enum ad4692_data_capture_modes ad4692_data_capture_mode = BURST

◆ ad4692_dev

struct ad4692_desc* ad4692_dev = NULL

◆ ad4692_dma_buff_full

volatile bool ad4692_dma_buff_full = false

◆ ad4692_iio_scan_type

struct scan_type ad4692_iio_scan_type[NUM_OF_IIO_DEVICES][NO_OF_CHANNELS]

◆ ad4692_interface_mode

enum ad4692_interface_modes ad4692_interface_mode = SPI_DMA

◆ ad4692_readback_option

enum ad4692_readback_options ad4692_readback_option = AVERAGED_DATA

◆ ad4692_sampling_frequency

uint32_t ad4692_sampling_frequency

◆ ad4692_sampling_frequency_max

uint32_t ad4692_sampling_frequency_max

◆ ad4692_spi_msg_manual_mode

struct no_os_spi_msg ad4692_spi_msg_manual_mode
Initial value:
= {
.cs_change = CS_CHANGE,
.tx_buff = data_buff,
.rx_buff = data_buff,
.bytes_number = BYTES_PER_SAMPLE
}
#define BYTES_PER_SAMPLE
Definition ad2s1210_iio.c:67
uint8_t data_buff[BYTES_PER_SAMPLE]
Definition ad4692_iio.c:258
#define CS_CHANGE
Definition ad4692_iio.c:135

◆ buff_start_addr

volatile uint32_t* buff_start_addr

◆ callback_count

uint32_t callback_count = 0

◆ chan_id

volatile uint8_t chan_id = 0

◆ channel_mask

uint16_t channel_mask = 0x1

◆ channel_priorities

uint8_t channel_priorities[NO_OF_CHANNELS] = { 0x0 }

◆ channel_sequence

uint8_t channel_sequence[AD4692_MAX_SLOTS_AS] = { 0x0 }

◆ data_buff

uint8_t data_buff[BYTES_PER_SAMPLE] = { 0x0 }

◆ data_read

uint32_t data_read

◆ dma_config_updated

volatile bool dma_config_updated = false

◆ iio_dev_data_g

volatile struct iio_device_data* iio_dev_data_g

◆ iio_init_params

struct iio_init_param iio_init_params
Initial value:
= {
.phy_type = USE_UART,
}

◆ local_buf

◆ n_data_bytes

uint8_t n_data_bytes

◆ nb_of_samples_g

uint32_t nb_of_samples_g

◆ num_of_active_channels

uint8_t num_of_active_channels = 0

◆ num_of_as_slots

uint8_t num_of_as_slots = 0

◆ spi_init_param

struct stm32_spi_init_param* spi_init_param