precision-converters-firmware
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 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   (32768)
 

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 ,
  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 ,
  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 ,
  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. More...
 
int32_t debug_reg_write (void *dev, uint32_t reg, uint32_t writeval)
 Write into the debug register. More...
 
int32_t start_burst_mode_capture (void)
 Start the burst mode data capture. More...
 
int32_t iio_ad4130_trigger_handler (struct iio_device_data *iio_dev_data)
 Push data into IIO buffer when trigger handler IRQ is invoked. More...
 
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. More...
 
int32_t ad4130_data_capture_init (void)
 Function to init the data capture for AD4130 device. More...
 
int32_t ad4130_iio_init (struct iio_device **desc)
 Init for reading/writing and parameterization of a ad4130 IIO device. More...
 
int32_t ad4130_iio_remove (struct iio_desc *desc)
 Release resources allocated for IIO device. More...
 
int32_t ad4130_iio_initialize (void)
 Initialize the IIO interface for AD4130 IIO device. More...
 
void ad4130_iio_event_handler (void)
 Run the AD4130 IIO event handler. More...
 

Variables

struct ad413x_dev * ad4130_dev_inst = NULL
 

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)

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

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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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