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

Implementation of AD4080 IIO Appication Interface. More...

#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include "common.h"
#include "app_config.h"
#include "ad4080_iio.h"
#include "ad4080.h"
#include "ad4080_regs.h"
#include "ad4080_user_config.h"
#include "no_os_error.h"
#include "no_os_delay.h"
#include "no_os_alloc.h"
#include "iio.h"
#include "iio_trigger.h"
#include "version.h"
Include dependency graph for ad4080_iio.c:

Macros

#define BYTES_PER_SAMPLE   sizeof(uint32_t)
 
#define CHN_STORAGE_BITS   (BYTES_PER_SAMPLE * 8)
 
#define AD4080_IIO_TRIGGER_NAME   "ad4080_iio_trigger"
 
#define AD4080_SCAN
 
#define AD4080_CHN_ATTR(_name, _priv)
 
#define AD4080_CHN_AVAIL_ATTR(_name, _priv)
 
#define IIO_AD4080_CHANNEL(_idx)
 
#define DATA_BUFFER_SIZE   65536
 
#define AD4080_DEFAULT_SCALE   ((((float)ADC_REF_VOLTAGE) / ADC_MAX_COUNT) * 1E3)
 
#define AD4080_LAST_REG_ADDR   AD4080_REG_FILTER_CONFIG
 
#define FIFO_SIZE   16384
 
#define MAX_THRESHOLD_CODE   0x7FF
 
#define MAX_HYSTERESIS_CODE   0x7FF
 
#define OFFSET_CORRECTION_COEFF_VAL_BITS   12
 
#define BUF_READ_TIMEOUT   0xffffffff
 

Enumerations

enum  ad4080_attribute_id {
  RAW_ATTR_ID ,
  SCALE_ATTR_ID ,
  OFFSET_ATTR_ID ,
  FIFO_FULL_ATTR_ID ,
  FIFO_READ_DONE_ATTR_ID ,
  FIFO_MODE_ATTR_ID ,
  FIFO_WATERMARK_ATTR_ID ,
  THRESHOLD_EVENT_DETECTED_ATTR_ID ,
  DATA_LANES_ATTR_ID ,
  GPIO1_OUTPUT_ENABLE_ATTR_ID ,
  GPIO2_OUTPUT_ENABLE_ATTR_ID ,
  GPIO3_OUTPUT_ENABLE_ATTR_ID ,
  GPIO1_OUTPUT_FUNC_ATTR_ID ,
  GPIO2_OUTPUT_FUNC_ATTR_ID ,
  GPIO3_OUTPUT_FUNC_ATTR_ID ,
  HI_THRESHOLD_ATTR_ID ,
  LO_THRESHOLD_ATTR_ID ,
  HYSTERESIS_ATTR_ID ,
  FILTER_SEL_ATTR_ID ,
  SINC_DEC_RATE_ATTR_ID ,
  EVENT_TRIGGER_ATTR_ID ,
  OPERATING_MODE_ATTR_ID ,
  ODR_ATTR_ID ,
  AFE_CTRL_ATTR_ID ,
  SELECT_SAMPLING_FREQ_ATTR_ID
}
 

Functions

int32_t ad4080_deassert_oscillators (void)
 Deassert all oscillators.
 
int32_t ad4080_iio_start_fifo_mode_capture (uint32_t samples, bool update_fifo_watermark)
 Initiates data capture into FIFO.
 
int32_t ad4080_read_fifo_data (struct ad4080_dev *dev, uint8_t *adc_data, int32_t samples)
 Reads data from the ADC FIFO.
 
int32_t ad4080_iio_end_fifo_mode_capture (uint32_t *formatted_fifo_data, uint8_t *raw_fifo_data, uint32_t samples)
 Initiates data capture into FIFO.
 
int32_t ad4080_iio_initialize (void)
 Initialize the IIO interface for AD4080 IIO device.
 
void ad4080_iio_event_handler (void)
 Run the AD4080 IIO event handler.
 

Variables

uint32_t ad4080_sampling_freq = AD4080_CNV_CLK_FREQ_HZ
 

Detailed Description

Implementation of AD4080 IIO Appication Interface.

This module acts as an interface for AD4080 IIO device

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

◆ AD4080_CHN_ATTR

#define AD4080_CHN_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.show = iio_ad4080_attr_get,\
.store = iio_ad4080_attr_set\
}

◆ AD4080_CHN_AVAIL_ATTR

#define AD4080_CHN_AVAIL_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.show = iio_ad4080_attr_available_get,\
.store = iio_ad4080_attr_available_set\
}

◆ AD4080_DEFAULT_SCALE

#define AD4080_DEFAULT_SCALE   ((((float)ADC_REF_VOLTAGE) / ADC_MAX_COUNT) * 1E3)

◆ AD4080_IIO_TRIGGER_NAME

#define AD4080_IIO_TRIGGER_NAME   "ad4080_iio_trigger"

◆ AD4080_LAST_REG_ADDR

#define AD4080_LAST_REG_ADDR   AD4080_REG_FILTER_CONFIG

◆ AD4080_SCAN

#define AD4080_SCAN
Value:
{\
.sign = 's',\
.storagebits = CHN_STORAGE_BITS,\
.shift = 0,\
.is_big_endian = false\
}
#define AD4080_ADC_RESOLUTION_BITS
Definition app_config.h:135
#define CHN_STORAGE_BITS
Definition ad4080_iio.c:81

◆ BUF_READ_TIMEOUT

#define BUF_READ_TIMEOUT   0xffffffff

◆ BYTES_PER_SAMPLE

#define BYTES_PER_SAMPLE   sizeof(uint32_t)

◆ CHN_STORAGE_BITS

#define CHN_STORAGE_BITS   (BYTES_PER_SAMPLE * 8)

◆ DATA_BUFFER_SIZE

#define DATA_BUFFER_SIZE   65536

◆ FIFO_SIZE

#define FIFO_SIZE   16384

◆ IIO_AD4080_CHANNEL

#define IIO_AD4080_CHANNEL (   _idx)
Value:
{\
.name = "voltage" # _idx,\
.ch_type = IIO_VOLTAGE,\
.channel = _idx,\
.scan_index = _idx,\
.indexed = true,\
.scan_type = &ad4080_iio_scan_type[_idx],\
.ch_out = false,\
.attributes = ad4080_iio_ch_attributes,\
}

◆ MAX_HYSTERESIS_CODE

#define MAX_HYSTERESIS_CODE   0x7FF

◆ MAX_THRESHOLD_CODE

#define MAX_THRESHOLD_CODE   0x7FF

◆ OFFSET_CORRECTION_COEFF_VAL_BITS

#define OFFSET_CORRECTION_COEFF_VAL_BITS   12

Enumeration Type Documentation

◆ ad4080_attribute_id

Enumerator
RAW_ATTR_ID 
SCALE_ATTR_ID 
OFFSET_ATTR_ID 
FIFO_FULL_ATTR_ID 
FIFO_READ_DONE_ATTR_ID 
FIFO_MODE_ATTR_ID 
FIFO_WATERMARK_ATTR_ID 
THRESHOLD_EVENT_DETECTED_ATTR_ID 
DATA_LANES_ATTR_ID 
GPIO1_OUTPUT_ENABLE_ATTR_ID 
GPIO2_OUTPUT_ENABLE_ATTR_ID 
GPIO3_OUTPUT_ENABLE_ATTR_ID 
GPIO1_OUTPUT_FUNC_ATTR_ID 
GPIO2_OUTPUT_FUNC_ATTR_ID 
GPIO3_OUTPUT_FUNC_ATTR_ID 
HI_THRESHOLD_ATTR_ID 
LO_THRESHOLD_ATTR_ID 
HYSTERESIS_ATTR_ID 
FILTER_SEL_ATTR_ID 
SINC_DEC_RATE_ATTR_ID 
EVENT_TRIGGER_ATTR_ID 
OPERATING_MODE_ATTR_ID 
ODR_ATTR_ID 
AFE_CTRL_ATTR_ID 
SELECT_SAMPLING_FREQ_ATTR_ID 

Function Documentation

◆ ad4080_deassert_oscillators()

int32_t ad4080_deassert_oscillators ( void  )

Deassert all oscillators.

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

◆ ad4080_iio_end_fifo_mode_capture()

int32_t ad4080_iio_end_fifo_mode_capture ( uint32_t *  formatted_fifo_data,
uint8_t *  raw_fifo_data,
uint32_t  samples 
)

Initiates data capture into FIFO.

Parameters
formatted_fifo_data[out]- Pointer to formatted FIFO data buffer.
raw_fifo_data[in]- Pointer to raw FIFO data buffer.
samples[in]- Number of requested samples.
Returns
0 in case of success, negative error code otherwise.

◆ ad4080_iio_event_handler()

void ad4080_iio_event_handler ( void  )

Run the AD4080 IIO event handler.

Returns
none

This function monitors the new IIO client event

Here is the caller graph for this function:

◆ ad4080_iio_initialize()

int32_t ad4080_iio_initialize ( void  )

Initialize the IIO interface for AD4080 IIO device.

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

◆ ad4080_iio_start_fifo_mode_capture()

int32_t ad4080_iio_start_fifo_mode_capture ( uint32_t  samples,
bool  update_fifo_watermark 
)

Initiates data capture into FIFO.

Parameters
samples[in]- Number of requested samples.
update_fifo_watermark[in]- Indication to update ADC FIFO watermark.
Returns
0 in case of success, negative error code otherwise.

◆ ad4080_read_fifo_data()

int32_t ad4080_read_fifo_data ( struct ad4080_dev *  dev,
uint8_t *  adc_data,
int32_t  samples 
)

Reads data from the ADC FIFO.

Parameters
dev[in,out]-Pointer to IIO device instance
adc_data[in,out]-Pointer to array to hold FIFO data
samples[in]-Number of samples to read from FIFO
Returns
0 in case of success, negative error code otherwise.

Variable Documentation

◆ ad4080_sampling_freq

uint32_t ad4080_sampling_freq = AD4080_CNV_CLK_FREQ_HZ