precision-converters-firmware
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Enumerations | Functions | Variables
ad4130_iio.c File Reference

Implementation of AD4130 IIO application interfaces. More...

#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include "app_config.h"
#include "ad4130_iio.h"
#include "ad4130_support.h"
#include "ad4130_user_config.h"
#include "ad4130_temperature_sensor.h"
#include "ad4130_regs.h"
#include "common.h"
#include "no_os_error.h"
#include "board_info.h"
#include "iio_trigger.h"
#include "pl_gui_views.h"
#include "pl_gui_events.h"
#include "adi_fft.h"
Include dependency graph for ad4130_iio.c:

Classes

struct  adc_calibration_configs
 

Macros

#define AD4130_CHN_ATTR(_name, _priv)
 
#define AD4130_CHN_AVAIL_ATTR(_name, _priv)
 
#define AD4130_CH(_name, _idx, _type)
 
#define AD4130_MIN_SAMPLING_FREQ   (50 / ADC_USER_CHANNELS)
 
#define AD4130_DEFAULT_OFFSET   0x800000
 
#define NUM_OF_IIO_DEVICES   1
 
#define AD4130_IIO_TRIGGER_NAME   "ad4130_iio_trigger"
 
#define BYTES_PER_SAMPLE   sizeof(uint32_t)
 
#define CHN_STORAGE_BITS   (BYTES_PER_SAMPLE * 8)
 
#define LOADCELL_SAMPLES_COUNT   10
 
#define CJC_CHANNEL   1
 
#define I_RSENSE   10
 
#define V_SCALE   6
 
#define FIFO_SIZE   256
 
#define BUF_READ_TIMEOUT   0xffffffff
 
#define DATA_BUFFER_SIZE   (16384)
 
#define APP_LOCAL_BACKEND_BUF_SIZE   0x1000
 

Enumerations

enum  ad4130_attribute_id {
  RAW_ATTR_ID ,
  SCALE_ATTR_ID ,
  OFFSET_ATTR_ID ,
  SAMPLING_FREQ_ATTR_ID ,
  DEMO_CONFIG_ATTR_ID ,
  INTERNAL_CALIB_ID ,
  SYSTEM_CALIB_ID ,
  LOADCELL_GAIN_CALIB_ID ,
  LOADCELL_OFFSET_CALIB_ID
}
 
enum  calibration_state {
  FULL_SCALE_CALIB_STATE ,
  ZERO_SCALE_CALIB_STATE ,
  CALIB_COMPLETE_STATE
}
 
enum  calib_status {
  CALIB_NOT_DONE ,
  CALIB_IN_PROGRESS ,
  CALIB_DONE ,
  CALIB_ERROR ,
  CALIB_SKIPPED
}
 
enum  context_attr_ids {
  HW_MEZZANINE_ID ,
  HW_CARRIER_ID ,
  HW_NAME_ID ,
  DEF_NUM_OF_CONTXT_ATTRS
}
 

Functions

int32_t debug_reg_read (void *dev, uint32_t reg, uint32_t *readval)
 Read the debug register value.
 
int32_t debug_reg_write (void *dev, uint32_t reg, uint32_t writeval)
 Write into the debug register.
 
int32_t start_burst_mode_capture (void)
 Start the burst mode data capture.
 
int32_t iio_ad4130_trigger_handler (struct iio_device_data *iio_dev_data)
 Push data into IIO buffer when trigger handler IRQ is invoked.
 
void ad4130_fifo_event_handler (void *ctx)
 This is an ISR (Interrupt Service Routine) to monitor FIFO data available event. This function is expected to be called asynchronously when data from internal device FIFO is available to read.
 
int32_t ad4130_data_capture_init (void)
 Function to init the data capture for AD4130 device.
 
int32_t ad4130_iio_init (struct iio_device **desc)
 Init for reading/writing and parameterization of a ad4130 IIO device.
 
int32_t ad4130_iio_remove (struct iio_desc *desc)
 Release resources allocated for IIO device.
 
int32_t ad4130_iio_initialize (void)
 Initialize the IIO interface for AD4130 IIO device.
 
void ad4130_iio_event_handler (void)
 Run the AD4130 IIO event handler.
 

Variables

struct ad413x_dev * ad4130_dev_inst = NULL
 
struct pl_gui_views pocket_lab_gui_views []
 
struct adi_fft_init_params fft_init_params
 
struct pl_gui_device_param pl_gui_device_params
 
struct pl_gui_descpocket_lab_gui_desc
 

Detailed Description

Implementation of AD4130 IIO application interfaces.

This module acts as an interface for AD4130 IIO application

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

◆ AD4130_CH

#define AD4130_CH (   _name,
  _idx,
  _type 
)
Value:
{\
.name = _name, \
.ch_type = _type,\
.ch_out = 0,\
.indexed = true,\
.channel = _idx,\
.scan_index = _idx,\
.scan_type = &chn_scan,\
.attributes = ad4130_iio_ch_attributes\
}
struct scan_type chn_scan[RESOLVER_CHANNELS]
Definition ad2s1210_iio.c:110

◆ AD4130_CHN_ATTR

#define AD4130_CHN_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.show = iio_ad4130_attr_get,\
.store = iio_ad4130_attr_set\
}

◆ AD4130_CHN_AVAIL_ATTR

#define AD4130_CHN_AVAIL_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.show = iio_ad4130_attr_available_get,\
.store = iio_ad4130_attr_available_set\
}

◆ AD4130_DEFAULT_OFFSET

#define AD4130_DEFAULT_OFFSET   0x800000

◆ AD4130_IIO_TRIGGER_NAME

#define AD4130_IIO_TRIGGER_NAME   "ad4130_iio_trigger"

◆ AD4130_MIN_SAMPLING_FREQ

#define AD4130_MIN_SAMPLING_FREQ   (50 / ADC_USER_CHANNELS)

◆ APP_LOCAL_BACKEND_BUF_SIZE

#define APP_LOCAL_BACKEND_BUF_SIZE   0x1000

◆ 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)

◆ CJC_CHANNEL

#define CJC_CHANNEL   1

◆ DATA_BUFFER_SIZE

#define DATA_BUFFER_SIZE   (16384)

◆ FIFO_SIZE

#define FIFO_SIZE   256

◆ I_RSENSE

#define I_RSENSE   10

◆ LOADCELL_SAMPLES_COUNT

#define LOADCELL_SAMPLES_COUNT   10

◆ NUM_OF_IIO_DEVICES

#define NUM_OF_IIO_DEVICES   1

◆ V_SCALE

#define V_SCALE   6

Enumeration Type Documentation

◆ ad4130_attribute_id

Enumerator
RAW_ATTR_ID 
SCALE_ATTR_ID 
OFFSET_ATTR_ID 
SAMPLING_FREQ_ATTR_ID 
DEMO_CONFIG_ATTR_ID 
INTERNAL_CALIB_ID 
SYSTEM_CALIB_ID 
LOADCELL_GAIN_CALIB_ID 
LOADCELL_OFFSET_CALIB_ID 

◆ calib_status

Enumerator
CALIB_NOT_DONE 
CALIB_IN_PROGRESS 
CALIB_DONE 
CALIB_ERROR 
CALIB_SKIPPED 

◆ calibration_state

Enumerator
FULL_SCALE_CALIB_STATE 
ZERO_SCALE_CALIB_STATE 
CALIB_COMPLETE_STATE 

◆ context_attr_ids

Enumerator
HW_MEZZANINE_ID 
HW_CARRIER_ID 
HW_NAME_ID 
DEF_NUM_OF_CONTXT_ATTRS 

Function Documentation

◆ ad4130_data_capture_init()

int32_t ad4130_data_capture_init ( void  )

Function to init the data capture for AD4130 device.

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

◆ ad4130_fifo_event_handler()

void ad4130_fifo_event_handler ( void *  ctx)

This is an ISR (Interrupt Service Routine) to monitor FIFO data available event. This function is expected to be called asynchronously when data from internal device FIFO is available to read.

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

◆ ad4130_iio_event_handler()

void ad4130_iio_event_handler ( void  )

Run the AD4130 IIO event handler.

Returns
none

This function monitors the new IIO client event

Here is the caller graph for this function:

◆ ad4130_iio_init()

int32_t ad4130_iio_init ( struct iio_device **  desc)

Init for reading/writing and parameterization of a ad4130 IIO device.

Parameters
desc[in,out]- IIO device descriptor
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ ad4130_iio_initialize()

int32_t ad4130_iio_initialize ( void  )

Initialize the IIO interface for AD4130 IIO device.

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

◆ ad4130_iio_remove()

int32_t ad4130_iio_remove ( struct iio_desc *  desc)

Release resources allocated for IIO device.

Parameters
desc[in]- IIO device descriptor
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ debug_reg_read()

int32_t debug_reg_read ( void *  dev,
uint32_t  reg,
uint32_t *  readval 
)

Read the debug register value.

Parameters
dev[in]-Pointer to IIO device instance
reg[in]-Register address to read from
readval[in,out]-Pointer to variable to read data into
Returns
0 in case of success or negative value otherwise
Here is the caller graph for this function:

◆ debug_reg_write()

int32_t debug_reg_write ( void *  dev,
uint32_t  reg,
uint32_t  writeval 
)

Write into the debug register.

Parameters
dev[in]-Pointer to IIO device instance
reg[in]-Register address to write into
writeval[in]-Register value to write
Returns
0 in case of success or negative value otherwise
Here is the caller graph for this function:

◆ iio_ad4130_trigger_handler()

int32_t iio_ad4130_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
Here is the caller graph for this function:

◆ start_burst_mode_capture()

int32_t start_burst_mode_capture ( void  )

Start the burst mode data capture.

Returns
0 in case of success, negative error code otherwise

Variable Documentation

◆ ad4130_dev_inst

struct ad413x_dev* ad4130_dev_inst = NULL

◆ fft_init_params

struct adi_fft_init_params fft_init_params
Initial value:
= {
.sample_rate = AD4130_MIN_SAMPLING_FREQ,
.samples_count = ADI_FFT_MAX_SAMPLES,
.input_data_zero_scale = ADC_MAX_COUNT_BIPOLAR,
.input_data_full_scale = ADC_MAX_COUNT_UNIPOLAR,
.convert_data_to_volt_without_vref = &ad4130_data_to_voltage_without_vref,
.convert_data_to_volt_wrt_vref = &ad4130_data_to_voltage_wrt_vref,
.convert_code_to_straight_binary = &ad4130_code_to_straight_binary
}
#define ADC_MAX_COUNT_UNIPOLAR
Definition app_config.h:184
#define ADC_MAX_COUNT_BIPOLAR
Definition app_config.h:187
#define AD4170_2_5V_INT_REF_VOLTAGE
Definition app_config.h:180
#define AD4130_MIN_SAMPLING_FREQ
Definition ad4130_iio.c:95
#define ADI_FFT_MAX_SAMPLES
Definition adi_fft.h:33

◆ pl_gui_device_params

struct pl_gui_device_param pl_gui_device_params
Initial value:
= {
.fft_params = &fft_init_params
}
struct adi_fft_init_params fft_init_params
Definition ad4130_iio.c:387

◆ pocket_lab_gui_desc

struct pl_gui_desc* pocket_lab_gui_desc

◆ pocket_lab_gui_views

struct pl_gui_views pocket_lab_gui_views[]
Initial value:
= {
{ NULL }
}
#define PL_GUI_ADD_DMM_DEF_VIEW
Definition pl_gui_views.h:43
#define PL_GUI_ADD_ATTR_EDIT_DEF_VIEW
Definition pl_gui_views.h:33
#define PL_GUI_ADD_REG_DEBUG_DEF_VIEW
Definition pl_gui_views.h:38
#define PL_GUI_ADD_CAPTURE_DEF_VIEW
Definition pl_gui_views.h:48
#define PL_GUI_ADD_ANALYSIS_DEF_VIEW
Definition pl_gui_views.h:53
#define PL_GUI_ADD_ABOUT_DEF_VIEW
Definition pl_gui_views.h:58