precision-converters-firmware
Macros | Enumerations | Functions | Variables
ad7091r_iio.c File Reference

Implementation of AD7091R IIO application interfaces. More...

#include <stdio.h>
#include <string.h>
#include "app_config.h"
#include "ad7091r_iio.h"
#include "ad7091r_user_config.h"
#include "ad7091r_support.h"
#include "common.h"
#include "iio_trigger.h"
#include "no_os_util.h"
#include "no_os_pwm.h"
#include "no_os_irq.h"
Include dependency graph for ad7091r_iio.c:

Macros

#define AD7091R_CHN_ATTR(_name, _priv)
 
#define AD7091R_CHN_AVAIL_ATTR(_name, _priv)
 
#define AD7091R_CH(_name, _dev, _idx, _type)
 
#define AD7091R_DEFAULT_CHN_SCAN
 
#define NUM_OF_IIO_DEVICES   1
 
#define AD7091R_IIO_TRIGGER_NAME   "ad7091r_iio_trigger"
 
#define BYTES_PER_SAMPLE   sizeof(uint16_t)
 
#define CHN_STORAGE_BITS   (BYTES_PER_SAMPLE * 8)
 
#define REGISTER_MAX_VAL   AD7091R8_REG_CH_HYSTERESIS(7)
 
#define AD7091R_LIMIT_REG_BIT_SHIFT   3
 
#define DATA_BUFFER_SIZE   (32768)
 
#define BUF_READ_TIMEOUT   0xffffffff
 
#define MAX_LOCAL_BUF_SIZE   8000
 
#define MAX_DMA_NDTR   (no_os_min(65535, MAX_LOCAL_BUF_SIZE))
 

Enumerations

enum  ad7091r_iio_attr_id {
  ADC_RAW ,
  ADC_SCALE ,
  ADC_OFFSET ,
  ADC_LOW_LIMIT_REG ,
  ADC_HIGH_LIMIT_REG ,
  ADC_HYSTERESIS_REG ,
  ADC_THRESHOLD_ALERT ,
  NUM_OF_CHN_ATTR ,
  REFERENCE_SELECT ,
  REFERENCE_IN_VOLTS ,
  DEVICE_MODE ,
  SAMPLING_FREQUENCY ,
  ALERT_BUSY_GPO0_EN ,
  ALERT_POL_OR_GPO0_VAL ,
  NUM_OF_DEV_ATTR = ALERT_POL_OR_GPO0_VAL - NUM_OF_CHN_ATTR
}
 

Functions

int32_t ad7091r_set_sampling_rate (uint32_t *sampling_rate)
 Set the sampling rate and get the updated value supported by MCU platform. More...
 
void burst_capture_callback (void *context)
 Interrupt Service Routine to monitor end of conversion event. More...
 
int32_t ad7091r_trigger_handler (struct iio_device_data *iio_dev_data)
 Push data into IIO buffer when trigger handler IRQ is invoked. More...
 
int ad7091r_iio_init ()
 Initialize the IIO interface for AD7091R IIO device. More...
 
void ad7091r_iio_event_handler (void)
 Run the AD7091R IIO event handler. More...
 

Variables

struct ad7091r8_dev * ad7091r_dev_desc
 
struct scan_type ad7091r_iio_scan_type = AD7091R_DEFAULT_CHN_SCAN
 
volatile bool ad7091r_conversion_flag = false
 
volatile struct iio_device_data * global_iio_dev_data
 
uint32_t global_nb_of_samples
 
int32_t data_read
 
volatile uint32_t * buff_start_addr
 
volatile bool dma_config_updated = false
 
struct stm32_spi_init_param * spi_init_param
 
uint8_t local_buf [MAX_LOCAL_BUF_SIZE]
 

Detailed Description

Implementation of AD7091R IIO application interfaces.

Copyright (c) 2024 Analog Devices, Inc. All rights reserved.

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

◆ AD7091R_CH

#define AD7091R_CH (   _name,
  _dev,
  _idx,
  _type 
)
Value:
{\
.name = _name, \
.ch_type = _type,\
.ch_out = false,\
.indexed = true,\
.channel = _idx,\
.scan_index = _idx,\
.scan_type = &ad7091r_iio_scan_type,\
.attributes = ad7091r_iio_ch_attributes[_dev]\
}
struct scan_type ad7091r_iio_scan_type
Definition: ad7091r_iio.c:195

◆ AD7091R_CHN_ATTR

#define AD7091R_CHN_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.show = ad7091r_iio_attr_get,\
.store = ad7091r_iio_attr_set\
}

◆ AD7091R_CHN_AVAIL_ATTR

#define AD7091R_CHN_AVAIL_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.show = ad7091r_iio_attr_available_get,\
.store = ad7091r_iio_attr_available_set\
}

◆ AD7091R_DEFAULT_CHN_SCAN

#define AD7091R_DEFAULT_CHN_SCAN
Value:
{\
.sign = 'u',\
.realbits = ADC_RESOLUTION,\
.storagebits = CHN_STORAGE_BITS,\
.shift = 0,\
.is_big_endian = true\
}
#define ADC_RESOLUTION
Definition: app_config.h:162
#define CHN_STORAGE_BITS
Definition: ad7091r_iio.c:101

◆ AD7091R_IIO_TRIGGER_NAME

#define AD7091R_IIO_TRIGGER_NAME   "ad7091r_iio_trigger"

◆ AD7091R_LIMIT_REG_BIT_SHIFT

#define AD7091R_LIMIT_REG_BIT_SHIFT   3

◆ BUF_READ_TIMEOUT

#define BUF_READ_TIMEOUT   0xffffffff

◆ BYTES_PER_SAMPLE

#define BYTES_PER_SAMPLE   sizeof(uint16_t)

◆ CHN_STORAGE_BITS

#define CHN_STORAGE_BITS   (BYTES_PER_SAMPLE * 8)

◆ DATA_BUFFER_SIZE

#define DATA_BUFFER_SIZE   (32768)

◆ MAX_DMA_NDTR

#define MAX_DMA_NDTR   (no_os_min(65535, MAX_LOCAL_BUF_SIZE))

◆ MAX_LOCAL_BUF_SIZE

#define MAX_LOCAL_BUF_SIZE   8000

◆ NUM_OF_IIO_DEVICES

#define NUM_OF_IIO_DEVICES   1

◆ REGISTER_MAX_VAL

#define REGISTER_MAX_VAL   AD7091R8_REG_CH_HYSTERESIS(7)

Enumeration Type Documentation

◆ ad7091r_iio_attr_id

Enumerator
ADC_RAW 
ADC_SCALE 
ADC_OFFSET 
ADC_LOW_LIMIT_REG 
ADC_HIGH_LIMIT_REG 
ADC_HYSTERESIS_REG 
ADC_THRESHOLD_ALERT 
NUM_OF_CHN_ATTR 
REFERENCE_SELECT 
REFERENCE_IN_VOLTS 
DEVICE_MODE 
SAMPLING_FREQUENCY 
ALERT_BUSY_GPO0_EN 
ALERT_POL_OR_GPO0_VAL 
NUM_OF_DEV_ATTR 

Function Documentation

◆ ad7091r_iio_event_handler()

void ad7091r_iio_event_handler ( void  )

Run the AD7091R IIO event handler.

Returns
none.

This function monitors the new IIO client event.

Here is the caller graph for this function:

◆ ad7091r_iio_init()

int ad7091r_iio_init ( void  )

Initialize the IIO interface for AD7091R IIO device.

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

◆ ad7091r_set_sampling_rate()

int32_t ad7091r_set_sampling_rate ( uint32_t *  sampling_rate)

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

Parameters
samplig_rate[in,out]- Sampling rate value
Returns
0 in case of success, negative error code otherwise

◆ ad7091r_trigger_handler()

int32_t ad7091r_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, negative error code otherwise

◆ burst_capture_callback()

void burst_capture_callback ( void *  context)

Interrupt Service Routine to monitor end of conversion event.

Parameters
context[in]- Callback context (unused)
Returns
none

Variable Documentation

◆ ad7091r_conversion_flag

volatile bool ad7091r_conversion_flag = false

◆ ad7091r_dev_desc

struct ad7091r8_dev* ad7091r_dev_desc

◆ ad7091r_iio_scan_type

struct scan_type ad7091r_iio_scan_type = AD7091R_DEFAULT_CHN_SCAN

◆ buff_start_addr

volatile uint32_t* buff_start_addr

◆ data_read

int32_t data_read

◆ dma_config_updated

volatile bool dma_config_updated = false

◆ global_iio_dev_data

volatile struct iio_device_data* global_iio_dev_data

◆ global_nb_of_samples

uint32_t global_nb_of_samples

◆ local_buf

uint8_t local_buf[MAX_LOCAL_BUF_SIZE]

◆ spi_init_param

struct stm32_spi_init_param* spi_init_param