no-OS
Loading...
Searching...
No Matches
iio_powrms.c File Reference

Source code file for IIO POWRMS example. More...

#include "iio_powrms.h"
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include "no_os_error.h"
#include "no_os_alloc.h"
#include "common_data.h"
#include "powrms_data_processing.h"
#include "powrms_utils.h"
Include dependency graph for iio_powrms.c:

Macros

#define POWRMS_VOLTAGE_CHANNEL(_idx, _name)
 
#define POWRMS_POWER_CHANNEL(_idx, _name)
 
#define POWRMS_PRECISION_CHANNEL(_idx, _name)
 
#define POWRMS_POLY_CALIB_CHANNEL(_idx, _name)
 
#define POWRMS_POLY_CALIB_REVERSE_CHANNEL(_idx, _name)
 

Functions

int powrms_eeprom_read_v_temp_comp_val (int32_t *value)
 Read voltage temperature compensation value from EEPROM.
 
int powrms_eeprom_read_def_v_temp_comp_val (int32_t *value)
 Read default voltage temperature compensation value from EEPROM.
 
int powrms_eeprom_write_v_temp_comp_val (int32_t value)
 Write voltage temperature compensation value to EEPROM.
 
int powrms_eeprom_write_def_v_temp_comp_val (int32_t value)
 Write default voltage temperature compensation value to EEPROM.
 
int powrms_set_temperature_compensation_value (float value)
 
float powrms_get_temperature_compensation_value (void)
 
int powrms_set_temperature_compensation_value_raw (int32_t raw_value)
 
int32_t powrms_get_temperature_compensation_value_raw (void)
 
int powrms_buffers_init (void)
 
void powrms_buffers_cleanup (void)
 
int powrms_push_vin0 (float value)
 
int powrms_push_vin1 (float value)
 
int powrms_push_p_fwd (float value)
 
int powrms_push_p_rev (float value)
 
int powrms_get_latest_vin0 (float *value)
 
int powrms_get_latest_vin1 (float *value)
 
int powrms_get_latest_p_fwd (float *value)
 
int powrms_get_latest_p_rev (float *value)
 
int powrms_set_precision_value (int index, float value)
 
float powrms_get_precision_value (int index)
 
int powrms_set_precision_array (const float *values, int count)
 
int powrms_get_precision_array (float *values, int max_count)
 
int powrms_set_precision_value_raw (int index, int32_t raw_value)
 
int32_t powrms_get_precision_value_raw (int index)
 
int powrms_set_precision_array_raw (const int32_t *raw_values, int count)
 
int powrms_get_precision_array_raw (int32_t *raw_values, int max_count)
 
int powrms_set_precision_value_reverse (int index, float value)
 
float powrms_get_precision_value_reverse (int index)
 
int powrms_set_precision_array_reverse (const float *values, int count)
 
int powrms_get_precision_array_reverse (float *values, int max_count)
 
int powrms_set_precision_value_raw_reverse (int index, int32_t raw_value)
 
int32_t powrms_get_precision_value_raw_reverse (int index)
 
int powrms_set_precision_array_raw_reverse (const int32_t *raw_values, int count)
 
int powrms_get_precision_array_raw_reverse (int32_t *raw_values, int max_count)
 
int powrms_set_frequency_range (int index, uint32_t frequency_MHz)
 
uint32_t powrms_get_frequency_range (int index)
 
int powrms_set_frequency_ranges (const uint32_t *frequencies, int count)
 
int powrms_get_frequency_ranges (uint32_t *frequencies, int max_count)
 

Variables

struct powrms_variables input_variables [VARIABLE_NUMBER]
 
struct iio_attribute powrms_voltage_channel_attributes []
 
struct iio_attribute powrms_precision_attributes []
 
struct iio_attribute powrms_poly_calib_attributes []
 
struct iio_attribute powrms_poly_calib_reverse_attributes []
 
struct iio_attribute powrms_global_attributes []
 
struct scan_type powrms_scan_type
 
struct iio_device powrms_iio_descriptor
 
IIO_BUFF_TYPE iio_data_buffer_loc [MAX_SIZE_BASE_ADDR] = {0}
 
struct no_os_circular_buffer * powrms_vin0_buffer = NULL
 
struct no_os_circular_buffer * powrms_vin1_buffer = NULL
 
struct no_os_circular_buffer * powrms_p_fwd_buffer = NULL
 
struct no_os_circular_buffer * powrms_p_rev_buffer = NULL
 

Detailed Description

Source code file for IIO POWRMS example.

Author
rober.nosp@m.t.bu.nosp@m.dai@a.nosp@m.nalo.nosp@m.g.com

Copyright 2025(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ POWRMS_POLY_CALIB_CHANNEL

#define POWRMS_POLY_CALIB_CHANNEL ( _idx,
_name )
Value:
{ \
.name = _name, .ch_type = IIO_VOLTAGE, .channel = _idx, \
.scan_index = -1, .indexed = true, .scan_type = NULL, \
.attributes = powrms_poly_calib_attributes, .ch_out = false \
}
struct iio_attribute powrms_poly_calib_attributes[]
Definition iio_powrms.c:336
@ IIO_VOLTAGE
Definition iio_types.h:56
#define NULL
Definition wrapper.h:64

◆ POWRMS_POLY_CALIB_REVERSE_CHANNEL

#define POWRMS_POLY_CALIB_REVERSE_CHANNEL ( _idx,
_name )
Value:
{ \
.name = _name, .ch_type = IIO_VOLTAGE, .channel = _idx, \
.scan_index = -1, .indexed = true, .scan_type = NULL, \
.attributes = powrms_poly_calib_reverse_attributes, .ch_out = false \
}
struct iio_attribute powrms_poly_calib_reverse_attributes[]
Definition iio_powrms.c:401

◆ POWRMS_POWER_CHANNEL

#define POWRMS_POWER_CHANNEL ( _idx,
_name )
Value:
{ \
.name = _name, .ch_type = IIO_POWER, .channel = _idx, \
.scan_index = -1, .indexed = true, .scan_type = NULL, \
.attributes = powrms_voltage_channel_attributes, .ch_out = false \
}
struct iio_attribute powrms_voltage_channel_attributes[]
Definition iio_powrms.c:167
@ IIO_POWER
Definition iio_types.h:73

◆ POWRMS_PRECISION_CHANNEL

#define POWRMS_PRECISION_CHANNEL ( _idx,
_name )
Value:
{ \
.name = _name, .ch_type = IIO_VOLTAGE, .channel = _idx, \
.scan_index = -1, .indexed = true, .scan_type = NULL, \
.attributes = powrms_precision_attributes, .ch_out = false \
}
struct iio_attribute powrms_precision_attributes[]
Definition iio_powrms.c:186

◆ POWRMS_VOLTAGE_CHANNEL

#define POWRMS_VOLTAGE_CHANNEL ( _idx,
_name )
Value:
{ \
.name = _name, .ch_type = IIO_VOLTAGE, .channel = _idx, \
.scan_index = -1, .indexed = true, .scan_type = NULL, \
.attributes = powrms_voltage_channel_attributes, .ch_out = false \
}

Function Documentation

◆ powrms_buffers_cleanup()

void powrms_buffers_cleanup ( void )

◆ powrms_buffers_init()

int powrms_buffers_init ( void )

◆ powrms_eeprom_read_def_v_temp_comp_val()

int powrms_eeprom_read_def_v_temp_comp_val ( int32_t * value)

Read default voltage temperature compensation value from EEPROM.

This function reads the default voltage temperature compensation value using single-byte reads to avoid I2C bus blocking issues that can occur with large transfers. The int32_t value is read byte by byte and reconstructed in little-endian format.

◆ powrms_eeprom_read_v_temp_comp_val()

int powrms_eeprom_read_v_temp_comp_val ( int32_t * value)

Read voltage temperature compensation value from EEPROM.

This function reads the voltage temperature compensation value using single-byte reads to avoid I2C bus blocking issues that can occur with large transfers. The int32_t value is read byte by byte and reconstructed in little-endian format.

◆ powrms_eeprom_write_def_v_temp_comp_val()

int powrms_eeprom_write_def_v_temp_comp_val ( int32_t value)

Write default voltage temperature compensation value to EEPROM.

This function writes the default voltage temperature compensation value using single-byte writes to avoid I2C bus blocking issues that can occur with large transfers. The int32_t value is broken down into bytes and written individually in little-endian format.

◆ powrms_eeprom_write_v_temp_comp_val()

int powrms_eeprom_write_v_temp_comp_val ( int32_t value)

Write voltage temperature compensation value to EEPROM.

This function writes the voltage temperature compensation value using single-byte writes to avoid I2C bus blocking issues that can occur with large transfers. The int32_t value is broken down into bytes and written individually in little-endian format.

◆ powrms_get_frequency_range()

uint32_t powrms_get_frequency_range ( int index)

◆ powrms_get_frequency_ranges()

int powrms_get_frequency_ranges ( uint32_t * frequencies,
int max_count )

◆ powrms_get_latest_p_fwd()

int powrms_get_latest_p_fwd ( float * value)

◆ powrms_get_latest_p_rev()

int powrms_get_latest_p_rev ( float * value)

◆ powrms_get_latest_vin0()

int powrms_get_latest_vin0 ( float * value)

◆ powrms_get_latest_vin1()

int powrms_get_latest_vin1 ( float * value)

◆ powrms_get_precision_array()

int powrms_get_precision_array ( float * values,
int max_count )

◆ powrms_get_precision_array_raw()

int powrms_get_precision_array_raw ( int32_t * raw_values,
int max_count )

◆ powrms_get_precision_array_raw_reverse()

int powrms_get_precision_array_raw_reverse ( int32_t * raw_values,
int max_count )

◆ powrms_get_precision_array_reverse()

int powrms_get_precision_array_reverse ( float * values,
int max_count )

◆ powrms_get_precision_value()

float powrms_get_precision_value ( int index)

◆ powrms_get_precision_value_raw()

int32_t powrms_get_precision_value_raw ( int index)

◆ powrms_get_precision_value_raw_reverse()

int32_t powrms_get_precision_value_raw_reverse ( int index)

◆ powrms_get_precision_value_reverse()

float powrms_get_precision_value_reverse ( int index)

◆ powrms_get_temperature_compensation_value()

float powrms_get_temperature_compensation_value ( void )

◆ powrms_get_temperature_compensation_value_raw()

int32_t powrms_get_temperature_compensation_value_raw ( void )

◆ powrms_push_p_fwd()

int powrms_push_p_fwd ( float value)

◆ powrms_push_p_rev()

int powrms_push_p_rev ( float value)

◆ powrms_push_vin0()

int powrms_push_vin0 ( float value)

◆ powrms_push_vin1()

int powrms_push_vin1 ( float value)

◆ powrms_set_frequency_range()

int powrms_set_frequency_range ( int index,
uint32_t frequency_MHz )

◆ powrms_set_frequency_ranges()

int powrms_set_frequency_ranges ( const uint32_t * frequencies,
int count )

◆ powrms_set_precision_array()

int powrms_set_precision_array ( const float * values,
int count )

◆ powrms_set_precision_array_raw()

int powrms_set_precision_array_raw ( const int32_t * raw_values,
int count )

◆ powrms_set_precision_array_raw_reverse()

int powrms_set_precision_array_raw_reverse ( const int32_t * raw_values,
int count )

◆ powrms_set_precision_array_reverse()

int powrms_set_precision_array_reverse ( const float * values,
int count )

◆ powrms_set_precision_value()

int powrms_set_precision_value ( int index,
float value )

◆ powrms_set_precision_value_raw()

int powrms_set_precision_value_raw ( int index,
int32_t raw_value )

◆ powrms_set_precision_value_raw_reverse()

int powrms_set_precision_value_raw_reverse ( int index,
int32_t raw_value )

◆ powrms_set_precision_value_reverse()

int powrms_set_precision_value_reverse ( int index,
float value )

◆ powrms_set_temperature_compensation_value()

int powrms_set_temperature_compensation_value ( float value)

◆ powrms_set_temperature_compensation_value_raw()

int powrms_set_temperature_compensation_value_raw ( int32_t raw_value)

Variable Documentation

◆ iio_data_buffer_loc

IIO_BUFF_TYPE iio_data_buffer_loc[MAX_SIZE_BASE_ADDR] = {0}

◆ input_variables

struct powrms_variables input_variables[VARIABLE_NUMBER]
extern

◆ powrms_global_attributes

struct iio_attribute powrms_global_attributes[]

◆ powrms_iio_descriptor

struct iio_device powrms_iio_descriptor
Initial value:
= {
.channels = iio_powrms_channels,
.attributes = powrms_global_attributes,
.debug_attributes = NULL,
.buffer_attributes = NULL,
.pre_enable = NULL,
.post_disable = NULL,
.trigger_handler = (int32_t(*)())NULL,
.submit = NULL,
}
struct iio_attribute powrms_global_attributes[]
Definition iio_powrms.c:466
#define IIO_POWRMS_NUM_CHANNELS
Definition iio_powrms.h:71

◆ powrms_p_fwd_buffer

struct no_os_circular_buffer* powrms_p_fwd_buffer = NULL

◆ powrms_p_rev_buffer

struct no_os_circular_buffer* powrms_p_rev_buffer = NULL

◆ powrms_poly_calib_attributes

struct iio_attribute powrms_poly_calib_attributes[]

◆ powrms_poly_calib_reverse_attributes

struct iio_attribute powrms_poly_calib_reverse_attributes[]

◆ powrms_precision_attributes

struct iio_attribute powrms_precision_attributes[]

◆ powrms_scan_type

struct scan_type powrms_scan_type
Initial value:
= {
.sign = 's',
.realbits = IIO_SCAN_REALBITS,
.storagebits = IIO_SCAN_STORAGEBITS,
.shift = IIO_SCAN_SHIFT,
.is_big_endian = false
}
#define IIO_SCAN_STORAGEBITS
Definition iio_powrms.h:75
#define IIO_SCAN_REALBITS
Definition iio_powrms.h:74
#define IIO_SCAN_SHIFT
Definition iio_powrms.h:76

◆ powrms_vin0_buffer

struct no_os_circular_buffer* powrms_vin0_buffer = NULL

◆ powrms_vin1_buffer

struct no_os_circular_buffer* powrms_vin1_buffer = NULL

◆ powrms_voltage_channel_attributes

struct iio_attribute powrms_voltage_channel_attributes[]
Initial value:
= {
{
.name = "raw",
.show = read_ch_raw,
.priv = IIO_ATTR_SCALE,
},
{
.name = "scale",
.show = read_ch_attr,
.priv = IIO_ATTR_SCALE,
},
{
.name = "offset",
.show = read_ch_attr,
.priv = IIO_ATTR_OFFSET,
},
}
#define IIO_ATTR_SCALE
Definition iio_powrms.h:65
#define IIO_ATTR_OFFSET
Definition iio_powrms.h:66
#define END_ATTRIBUTES_ARRAY
Definition iio_types.h:108