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

Implementation of AD7768-1 IIO application interfaces. More...

#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include "app_config.h"
#include "ad77681_iio.h"
#include "ad77681_user_config.h"
#include "ad77681_regs.h"
#include "ad77681_support.h"
#include "common.h"
#include "iio_trigger.h"
#include "no_os_error.h"
#include "no_os_util.h"
Include dependency graph for ad77681_iio.c:

Macros

#define NUM_OF_IIO_DEVICES   1
 
#define IIO_TRIGGER_NAME   "ad77681_iio_trigger"
 
#define AD77681_NUM_CHANNELS   1
 
#define BYTES_PER_SAMPLE   sizeof(uint32_t)
 
#define CHN_STORAGE_BITS   (BYTES_PER_SAMPLE * 8)
 
#define AD77681_SCALE_FACTOR   (1 << ADC_RESOLUTION)
 
#define AD77681_DEFAULT_SCALE   ((((float)(AD77681_VOLTAGE_REF / 1000.00) * 2) / AD77681_SCALE_FACTOR) * 1000)
 
#define AD77681_REG_MAX_ADDR   AD77681_REG_MCLK_COUNTER + 1
 
#define SINGLE_MODE_CONV_STANDBY   6
 
#define PERIODIC_MODE_CONV_STANDBY   7
 
#define DATA_BUFFER_SIZE   (32768)
 

Functions

int get_raw (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
 Getter/Setter for the raw attribute value. More...
 
int set_raw (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
 
int get_scale (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
 Getter/Setter for the scale attribute value. More...
 
int set_scale (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
 
int get_power_mode (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
 Getter/Setter for the power mode attribute value. More...
 
int set_power_mode (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
 
int get_conv_mode (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
 Getter/Setter for the conversion mode attribute value. More...
 
int set_conv_mode (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
 
int get_mclk_division (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
 Getter/Setter for the MCLK division attribute value. More...
 
int set_mclk_division (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
 
bool debug_get_reg_value (uint8_t reg, uint8_t *Reg_add)
 Get the actual register address value from the list. More...
 
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 iio_ad77681_trigger_handler (struct iio_device_data *iio_dev_data)
 Push data into IIO buffer when trigger handler IRQ is invoked. More...
 
int32_t ad77681_iio_initialize (void)
 Initialize the IIO interface for AD7768-1 IIO device. More...
 
void ad77681_iio_event_handler (void)
 Run the AD77681 IIO event handler. More...
 

Variables

struct ad77681_devp_ad77681_dev_inst = NULL
 
struct ad77681_status_registersp_ad77681_stat_reg = NULL
 
struct iio_attribute channel_input_attributes []
 
struct scan_type chn_scan
 

Detailed Description

Implementation of AD7768-1 IIO application interfaces.

This module acts as an interface for AD7768-1 IIO application

Copyright (c) 2021-23 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

◆ AD77681_DEFAULT_SCALE

#define AD77681_DEFAULT_SCALE   ((((float)(AD77681_VOLTAGE_REF / 1000.00) * 2) / AD77681_SCALE_FACTOR) * 1000)

◆ AD77681_NUM_CHANNELS

#define AD77681_NUM_CHANNELS   1

◆ AD77681_REG_MAX_ADDR

#define AD77681_REG_MAX_ADDR   AD77681_REG_MCLK_COUNTER + 1

◆ AD77681_SCALE_FACTOR

#define AD77681_SCALE_FACTOR   (1 << ADC_RESOLUTION)

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

◆ IIO_TRIGGER_NAME

#define IIO_TRIGGER_NAME   "ad77681_iio_trigger"

◆ NUM_OF_IIO_DEVICES

#define NUM_OF_IIO_DEVICES   1

◆ PERIODIC_MODE_CONV_STANDBY

#define PERIODIC_MODE_CONV_STANDBY   7

◆ SINGLE_MODE_CONV_STANDBY

#define SINGLE_MODE_CONV_STANDBY   6

Function Documentation

◆ ad77681_iio_event_handler()

void ad77681_iio_event_handler ( void  )

Run the AD77681 IIO event handler.

Returns
none

This function monitors the new IIO client event

Here is the caller graph for this function:

◆ ad77681_iio_initialize()

int32_t ad77681_iio_initialize ( void  )

Initialize the IIO interface for AD7768-1 IIO device.

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

◆ debug_get_reg_value()

bool debug_get_reg_value ( uint8_t  reg,
uint8_t *  Reg_add 
)

Get the actual register address value from the list.

Parameters
reg-Register address to read from
Reg_add- actual value of Register address
Returns
true in case of success, false value 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-Pointer to IIO device instance
reg-Register address to read from
readval-Pointer to variable to read data into
Returns
0 in case of success, 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-Pointer to IIO device instance
reg-Register address to write into
writeval-Register value to write
Returns
0 in case of success, negative value otherwise

◆ get_conv_mode()

int get_conv_mode ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  id 
)

Getter/Setter for the conversion mode attribute value.

Parameters
device-pointer to IIO device structure
buf-pointer to buffer holding attribute value
len-length of buffer string data
channel-pointer to IIO channel structure
id-Attribute ID (optional)
Returns
Number of characters read/written

◆ get_mclk_division()

int get_mclk_division ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  id 
)

Getter/Setter for the MCLK division attribute value.

Parameters
device-pointer to IIO device structure
buf-pointer to buffer holding attribute value
len-length of buffer string data
channel-pointer to IIO channel structure
id-Attribute ID (optional)
Returns
Number of characters read/written

◆ get_power_mode()

int get_power_mode ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  id 
)

Getter/Setter for the power mode attribute value.

Parameters
device-pointer to IIO device structure
buf-pointer to buffer holding attribute value
len-length of buffer string data
channel-pointer to IIO channel structure
id-Attribute ID (optional)
Returns
Number of characters read/written

◆ get_raw()

int get_raw ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  id 
)

Getter/Setter for the raw attribute value.

Parameters
device-pointer to IIO device structure
buf-pointer to buffer holding attribute value
len-length of buffer string data
channel-pointer to IIO channel structure
id-Attribute ID (optional)
Returns
Number of characters read/written

◆ get_scale()

int get_scale ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  id 
)

Getter/Setter for the scale attribute value.

Parameters
device-pointer to IIO device structure
buf-pointer to buffer holding attribute value
len-length of buffer string data
channel-pointer to IIO channel structure
id-Attribute ID (optional)
Returns
Number of characters read/written

◆ iio_ad77681_trigger_handler()

int32_t iio_ad77681_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

◆ set_conv_mode()

int set_conv_mode ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  id 
)

◆ set_mclk_division()

int set_mclk_division ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  id 
)

◆ set_power_mode()

int set_power_mode ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  id 
)

◆ set_raw()

int set_raw ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  id 
)

◆ set_scale()

int set_scale ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info *  channel,
intptr_t  id 
)

Variable Documentation

◆ channel_input_attributes

struct iio_attribute channel_input_attributes[]
Initial value:
= {
{
.name = "raw",
.show = get_raw,
.store = set_raw,
},
{
.name = "scale",
.show = get_scale,
.store = set_scale,
},
END_ATTRIBUTES_ARRAY
}
int set_raw(void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
Definition: ad77681_iio.c:185
int get_raw(void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
Getter/Setter for the raw attribute value.
Definition: ad77681_iio.c:169
int set_scale(void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
Definition: ad77681_iio.c:213
int get_scale(void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t id)
Getter/Setter for the scale attribute value.
Definition: ad77681_iio.c:204

◆ chn_scan

struct scan_type chn_scan
Initial value:
= {
.sign = 's',
.realbits = ADC_RESOLUTION,
.storagebits = CHN_STORAGE_BITS,
.shift = 0,
.is_big_endian = false
}
#define ADC_RESOLUTION
Definition: app_config.h:162
#define CHN_STORAGE_BITS
Definition: ad77681_iio.c:48

◆ p_ad77681_dev_inst

struct ad77681_dev* p_ad77681_dev_inst = NULL

◆ p_ad77681_stat_reg

struct ad77681_status_registers* p_ad77681_stat_reg = NULL