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

Implementation of ad559xr IIO application interfaces. More...

#include <string.h>
#include <stdlib.h>
#include "ad559xr_user_config.h"
#include "ad559xr_iio.h"
#include "no_os_error.h"
#include "no_os_delay.h"
#include "no_os_util.h"
#include "app_config.h"
#include "iio_trigger.h"
#include "version.h"
Include dependency graph for ad559xr_iio.c:

Macros

#define AD559XR_IIO_TRIGGER_NAME   "ad559xr_iio_trigger"
 
#define NUM_OF_IIO_DEVICES   3
 
#define NO_OF_CHANNELS   8
 
#define GPIO_BIT   1
 
#define SAMPLING_FREQUENCY   1
 
#define DATA_BUFFER_SIZE   (32768)
 
#define AD559XR_CHN_ATTR(_name, _priv)
 
#define AD559XR_GPIO_ATTR(_name, _priv)
 
#define AD559XR_DEFAULT_CHN_SCAN
 
#define AD559XR_GPIO_CHN_SCAN
 
#define AD559XR_CHN_AVAIL_ATTR(_name, _priv)
 
#define AD559XR_CH(_name, _dev, _idx, _type)
 
#define AD5592R_REG_ADC_SEQ_ADDR_MSK(x)   ((x >> 12) & 0x0F)
 
#define MAX_ADC_CODE   4095.0
 
#define ADC_GAIN_LOW_CONVERSION_VALUE   2.654
 
#define ADC_GAIN_HIGH_CONVERSION_VALUE   1.327
 
#define TEMP_SAMPLE_SIZE   5
 
#define GPIO_CHANNEL_NAME_SIZE   6
 
#define CHANNEL_NAME_SIZE   9
 

Enumerations

enum  ad559xr_attribute_ids {
  IIO_RAW ,
  IIO_SCALE ,
  IIO_OFFSET ,
  POWER_DOWN ,
  CH_MODE ,
  CH_OFFSTATE ,
  NUM_OF_CHN_ATTR ,
  ADC_SAMPLING_FREQUENCY ,
  ADC_RANGE ,
  DAC_RANGE ,
  REF_SELECT ,
  VREF_IN_V ,
  TEMP ,
  ADC_BUFFER ,
  LDAC_MODE ,
  REPETITION ,
  DEVICE_NAME ,
  RESTART_IIO_ATTR_ID ,
  NUM_OF_DEV_ATTR = RESTART_IIO_ATTR_ID - NUM_OF_CHN_ATTR
}
 
enum  device_name {
  AD5592R ,
  AD5593R
}
 

Functions

int ad559xr_read_die_temp (float *result)
 Reads the temperature of the die.
 
void ad559xr_get_scale (uint8_t chn)
 Function to get scale value.
 
int ad559xr_set_rep_bit (bool rep_status)
 Function to set rep bit in adc sequencer.
 
int ad5592r_read_converted_data (struct ad5592r_dev *dev, uint16_t *values)
 Read the converted data for channels enabled.
 
int ad5593r_read_converted_data (struct ad5592r_dev *dev, uint16_t *values)
 Read the converted data for channels enabled.
 
int ad559xr_start_data_capture (void)
 Start the ADC data capture.
 
int ad559xr_end_data_capture (void)
 End the ADC data capture.
 
int32_t ad559xr_trigger_handler (struct iio_device_data *iio_dev_data)
 Push data into IIO buffer when trigger handler IRQ is invoked.
 
int32_t iio_app_initialize (void)
 Initialize the ad559xr IIO Interface.
 
void iio_app_event_handler (void)
 Run the ad559xr IIO event handler.
 

Variables

struct scan_type ad559xr_iio_scan_type [NUM_OF_IIO_DEVICES][NO_OF_CHANNELS]
 
struct iio_device * p_iio_ad559xr_dev [NUM_OF_IIO_DEVICES]
 
struct ad5592r_dev * ad559xr_dev_inst = NULL
 
float attr_scale [NO_OF_CHANNELS]
 
uint16_t dac_value
 
uint8_t num_of_active_channels = 0
 
uint32_t channel_mask
 
uint8_t ad559xr_channels = 0
 
bool device_select = false
 
bool gpio_enabled = false
 
bool gpio_unused_enabled = false
 
bool gpio_cached_val [NO_OF_CHANNELS]
 
uint8_t active_device = AD5592R
 
uint16_t addl_offset [NO_OF_CHANNELS] = { 0, 3000, 3000, 5500, 8500, 10500, 11500, 13500 }
 
uint8_t non_gpio_channels [NO_OF_CHANNELS]
 
uint8_t num_non_gpio_channels = 0
 

Detailed Description

Implementation of ad559xr IIO application interfaces.

This module acts as an interface for ad559xr IIO application

Copyright (c) 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

◆ AD5592R_REG_ADC_SEQ_ADDR_MSK

#define AD5592R_REG_ADC_SEQ_ADDR_MSK (   x)    ((x >> 12) & 0x0F)

◆ AD559XR_CH

#define AD559XR_CH (   _name,
  _dev,
  _idx,
  _type 
)
Value:
{\
.name = _name, \
.ch_type = _type,\
.ch_out = 0,\
.indexed = true,\
.channel = _idx,\
.scan_index = _idx,\
.scan_type = ad559xr_iio_scan_type[_dev],\
.attributes = ad559xr_iio_ch_attributes[_dev]\
}
struct scan_type ad559xr_iio_scan_type[NUM_OF_IIO_DEVICES][NO_OF_CHANNELS]
Definition ad559xr_iio.c:136

◆ AD559XR_CHN_ATTR

#define AD559XR_CHN_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.show = ad559xr_iio_attr_get,\
.store = ad559xr_iio_attr_set\
}

◆ AD559XR_CHN_AVAIL_ATTR

#define AD559XR_CHN_AVAIL_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.show = ad559xr_iio_attr_available_get,\
.store = ad559xr_iio_attr_available_set\
}

◆ AD559XR_DEFAULT_CHN_SCAN

#define AD559XR_DEFAULT_CHN_SCAN
Value:
{\
.sign = 'u',\
.realbits = ADC_RESOLUTION,\
.storagebits = STORAGE_BITS,\
.shift = 0,\
.is_big_endian = false\
}
#define ADC_RESOLUTION
Definition app_config.h:161
#define STORAGE_BITS
Definition app_config.h:71

◆ AD559XR_GPIO_ATTR

#define AD559XR_GPIO_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.show = ad559xr_iio_gpio_attr_get,\
.store = ad559xr_iio_gpio_attr_set\
}

◆ AD559XR_GPIO_CHN_SCAN

#define AD559XR_GPIO_CHN_SCAN
Value:
{\
.sign = 'u',\
.realbits = GPIO_BIT,\
.storagebits = GPIO_BIT,\
.shift = 0,\
.is_big_endian = false\
}
#define GPIO_BIT
Definition ad559xr_iio.c:79

◆ AD559XR_IIO_TRIGGER_NAME

#define AD559XR_IIO_TRIGGER_NAME   "ad559xr_iio_trigger"

◆ ADC_GAIN_HIGH_CONVERSION_VALUE

#define ADC_GAIN_HIGH_CONVERSION_VALUE   1.327

◆ ADC_GAIN_LOW_CONVERSION_VALUE

#define ADC_GAIN_LOW_CONVERSION_VALUE   2.654

◆ CHANNEL_NAME_SIZE

#define CHANNEL_NAME_SIZE   9

◆ DATA_BUFFER_SIZE

#define DATA_BUFFER_SIZE   (32768)

◆ GPIO_BIT

#define GPIO_BIT   1

◆ GPIO_CHANNEL_NAME_SIZE

#define GPIO_CHANNEL_NAME_SIZE   6

◆ MAX_ADC_CODE

#define MAX_ADC_CODE   4095.0

◆ NO_OF_CHANNELS

#define NO_OF_CHANNELS   8

◆ NUM_OF_IIO_DEVICES

#define NUM_OF_IIO_DEVICES   3

◆ SAMPLING_FREQUENCY

#define SAMPLING_FREQUENCY   1

◆ TEMP_SAMPLE_SIZE

#define TEMP_SAMPLE_SIZE   5

Enumeration Type Documentation

◆ ad559xr_attribute_ids

Enumerator
IIO_RAW 
IIO_SCALE 
IIO_OFFSET 
POWER_DOWN 
CH_MODE 
CH_OFFSTATE 
NUM_OF_CHN_ATTR 
ADC_SAMPLING_FREQUENCY 
ADC_RANGE 
DAC_RANGE 
REF_SELECT 
VREF_IN_V 
TEMP 
ADC_BUFFER 
LDAC_MODE 
REPETITION 
DEVICE_NAME 
RESTART_IIO_ATTR_ID 
NUM_OF_DEV_ATTR 

◆ device_name

Enumerator
AD5592R 
AD5593R 

Function Documentation

◆ ad5592r_read_converted_data()

int ad5592r_read_converted_data ( struct ad5592r_dev *  dev,
uint16_t *  values 
)

Read the converted data for channels enabled.

Parameters
dev[in]- IIO device instance
values[in,out]- ADC raw values
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ ad5593r_read_converted_data()

int ad5593r_read_converted_data ( struct ad5592r_dev *  dev,
uint16_t *  values 
)

Read the converted data for channels enabled.

Parameters
dev[in]- IIO device instance
values[in,out]- ADC raw values
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ ad559xr_end_data_capture()

int ad559xr_end_data_capture ( void  )

End the ADC data capture.

Returns
0 in case of success, negative error code otherwise

◆ ad559xr_get_scale()

void ad559xr_get_scale ( uint8_t  chn)

Function to get scale value.

Parameters
chn[in]- Channel number
Returns
none

◆ ad559xr_read_die_temp()

int ad559xr_read_die_temp ( float *  result)

Reads the temperature of the die.

Sets the devices to perform a temperature readback. Performs a number of samples based on TEMP_SAMPLE_SIZE

Parameters
result[out]- Result of the ADC Temp Channel
Returns
0 in case of success, negative error code otherwise

◆ ad559xr_set_rep_bit()

int ad559xr_set_rep_bit ( bool  rep_status)

Function to set rep bit in adc sequencer.

Parameters
rep_status[in]- Status of repeat bit
Returns
none
Here is the caller graph for this function:

◆ ad559xr_start_data_capture()

int ad559xr_start_data_capture ( void  )

Start the ADC data capture.

Returns
0 in case of success, negative error code otherwise

◆ ad559xr_trigger_handler()

int32_t ad559xr_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

◆ iio_app_event_handler()

void iio_app_event_handler ( void  )

Run the ad559xr IIO event handler.

Run the AD3530R IIO event handler.

Returns
None

◆ iio_app_initialize()

int32_t iio_app_initialize ( void  )

Initialize the ad559xr IIO Interface.

Initialize the IIO interface for AD3530R IIO device.

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

Variable Documentation

◆ active_device

uint8_t active_device = AD5592R

◆ ad559xr_channels

uint8_t ad559xr_channels = 0

◆ ad559xr_dev_inst

struct ad5592r_dev* ad559xr_dev_inst = NULL

◆ ad559xr_iio_scan_type

struct scan_type ad559xr_iio_scan_type[NUM_OF_IIO_DEVICES][NO_OF_CHANNELS]
Initial value:
= {
}
#define AD559XR_DEFAULT_CHN_SCAN
Definition ad559xr_iio.c:110
#define AD559XR_GPIO_CHN_SCAN
Definition ad559xr_iio.c:119

◆ addl_offset

uint16_t addl_offset[NO_OF_CHANNELS] = { 0, 3000, 3000, 5500, 8500, 10500, 11500, 13500 }

◆ attr_scale

float attr_scale[NO_OF_CHANNELS]

◆ channel_mask

uint32_t channel_mask

◆ dac_value

uint16_t dac_value

◆ device_select

bool device_select = false

◆ gpio_cached_val

bool gpio_cached_val[NO_OF_CHANNELS]

◆ gpio_enabled

bool gpio_enabled = false

◆ gpio_unused_enabled

bool gpio_unused_enabled = false

◆ non_gpio_channels

uint8_t non_gpio_channels[NO_OF_CHANNELS]

◆ num_non_gpio_channels

uint8_t num_non_gpio_channels = 0

◆ num_of_active_channels

uint8_t num_of_active_channels = 0

◆ p_iio_ad559xr_dev

struct iio_device* p_iio_ad559xr_dev[NUM_OF_IIO_DEVICES]