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

Implementation of AD405X IIO Application Interface. More...

#include <string.h>
#include <math.h>
#include "app_config.h"
#include "ad405x.h"
#include "ad405x_iio.h"
#include "ad405x_user_config.h"
#include "common.h"
#include "no_os_error.h"
#include "no_os_gpio.h"
#include "no_os_pwm.h"
#include "no_os_alloc.h"
#include "no_os_util.h"
#include "iio_trigger.h"
Include dependency graph for ad405x_iio.c:

Macros

#define AD405X_CHN_ATTR(_name, _priv)
 
#define AD405X_CHN_AVAIL_ATTR(_name, _priv)
 
#define DATA_BUFFER_SIZE   (131072)
 
#define NUM_OF_IIO_DEVICES   1
 
#define AD405X_IIO_TRIGGER_NAME   ACTIVE_DEVICE_NAME"_iio_trigger"
 
#define REAL_BITS   ADC_SAMPLE_MODE_RESOLUTION
 
#define STORAGE_BITS   16
 
#define BYTES_PER_SAMPLE   (STORAGE_BITS/8)
 
#define INTERNAL_SAMPLING_CLK_NS   500
 
#define CONVERSION_TIME_NS   250
 
#define SPI_BURST_DATA_READ_TIME_NS   1100
 
#define MAX_SAMPLING_TIME_NS   (((float)(1.0/SAMPLING_RATE) * 1000000000) / 2)
 
#define MAX_SAMPLING_PERIOD_NSEC   1000000
 
#define PWM_PERIOD_TO_FREQUENCY(x)   (1000000000.0 / x)
 
#define BUF_READ_TIMEOUT   0xffffffff
 
#define BUFFER_UPDATE_RATE   400
 
#define MAX_LOCAL_BUF_SIZE   32000
 
#define MAX_DMA_NDTR   (no_os_min(65535, MAX_LOCAL_BUF_SIZE/2))
 

Enumerations

enum  ad405x_attribute_ids {
  ADC_RAW ,
  ADC_SCALE ,
  ADC_OFFSET ,
  ADC_OPERATING_MODE ,
  ADC_SAMPLE_RATE
}
 

Functions

int32_t ad405x_stop_data_capture (void)
 Stop a data capture from continuous/burst mode. More...
 
void data_capture_callback (void *context)
 Interrupt Service Routine to monitor data ready event. More...
 
int32_t iio_ad405x_initialize (void)
 Initialize the IIO interface for AD405X IIO device. More...
 
void iio_ad405x_event_handler (void)
 Run the AD405X IIO event handler. More...
 

Variables

struct ad405x_dev * p_ad405x_dev = NULL
 
struct iio_device * p_iio_ad405x_dev
 
volatile bool data_ready = false
 
volatile uint32_t * buff_start_addr
 
uint8_t local_buf [MAX_LOCAL_BUF_SIZE]
 
volatile bool dma_config_updated = false
 
volatile struct iio_device_data * iio_dev_data_g
 
uint32_t nb_of_samples_g
 
int32_t data_read
 
struct no_os_spi_msg ad405x_spi_msg
 
struct stm32_spi_init_param * spi_init_param
 

Detailed Description

Implementation of AD405X IIO Application Interface.

This module acts as an interface for AD405X IIO device

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

◆ AD405X_CHN_ATTR

#define AD405X_CHN_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.show = iio_ad405x_attr_get,\
.store = iio_ad405x_attr_set\
}

◆ AD405X_CHN_AVAIL_ATTR

#define AD405X_CHN_AVAIL_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.show = iio_ad405x_attr_available_get,\
.store = iio_ad405x_attr_available_set\
}

◆ AD405X_IIO_TRIGGER_NAME

#define AD405X_IIO_TRIGGER_NAME   ACTIVE_DEVICE_NAME"_iio_trigger"

◆ BUF_READ_TIMEOUT

#define BUF_READ_TIMEOUT   0xffffffff

◆ BUFFER_UPDATE_RATE

#define BUFFER_UPDATE_RATE   400

◆ BYTES_PER_SAMPLE

#define BYTES_PER_SAMPLE   (STORAGE_BITS/8)

◆ CONVERSION_TIME_NS

#define CONVERSION_TIME_NS   250

◆ DATA_BUFFER_SIZE

#define DATA_BUFFER_SIZE   (131072)

◆ INTERNAL_SAMPLING_CLK_NS

#define INTERNAL_SAMPLING_CLK_NS   500

◆ MAX_DMA_NDTR

#define MAX_DMA_NDTR   (no_os_min(65535, MAX_LOCAL_BUF_SIZE/2))

◆ MAX_LOCAL_BUF_SIZE

#define MAX_LOCAL_BUF_SIZE   32000

◆ MAX_SAMPLING_PERIOD_NSEC

#define MAX_SAMPLING_PERIOD_NSEC   1000000

◆ MAX_SAMPLING_TIME_NS

#define MAX_SAMPLING_TIME_NS   (((float)(1.0/SAMPLING_RATE) * 1000000000) / 2)

◆ NUM_OF_IIO_DEVICES

#define NUM_OF_IIO_DEVICES   1

◆ PWM_PERIOD_TO_FREQUENCY

#define PWM_PERIOD_TO_FREQUENCY (   x)    (1000000000.0 / x)

◆ REAL_BITS

#define REAL_BITS   ADC_SAMPLE_MODE_RESOLUTION

◆ SPI_BURST_DATA_READ_TIME_NS

#define SPI_BURST_DATA_READ_TIME_NS   1100

◆ STORAGE_BITS

#define STORAGE_BITS   16

Enumeration Type Documentation

◆ ad405x_attribute_ids

Enumerator
ADC_RAW 
ADC_SCALE 
ADC_OFFSET 
ADC_OPERATING_MODE 
ADC_SAMPLE_RATE 

Function Documentation

◆ ad405x_stop_data_capture()

int32_t ad405x_stop_data_capture ( void  )

Stop a data capture from continuous/burst mode.

Returns
0 in case of success, negative error code otherwise

◆ data_capture_callback()

void data_capture_callback ( void *  context)

Interrupt Service Routine to monitor data ready event.

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

◆ iio_ad405x_event_handler()

void iio_ad405x_event_handler ( void  )

Run the AD405X IIO event handler.

Returns
none

This function monitors the new IIO client event

Here is the caller graph for this function:

◆ iio_ad405x_initialize()

int32_t iio_ad405x_initialize ( void  )

Initialize the IIO interface for AD405X IIO device.

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

Variable Documentation

◆ ad405x_spi_msg

struct no_os_spi_msg ad405x_spi_msg

◆ buff_start_addr

volatile uint32_t* buff_start_addr

◆ data_read

int32_t data_read

◆ data_ready

volatile bool data_ready = false

◆ dma_config_updated

volatile bool dma_config_updated = false

◆ iio_dev_data_g

volatile struct iio_device_data* iio_dev_data_g

◆ local_buf

uint8_t local_buf[MAX_LOCAL_BUF_SIZE]

◆ nb_of_samples_g

uint32_t nb_of_samples_g

◆ p_ad405x_dev

struct ad405x_dev* p_ad405x_dev = NULL

◆ p_iio_ad405x_dev

struct iio_device* p_iio_ad405x_dev

◆ spi_init_param

struct stm32_spi_init_param* spi_init_param