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

Utility functions for input handling and data conversion in EVAL-POWRMS project. More...

#include "powrms_utils.h"
#include "powrms_gpios.h"
#include "no_os_eeprom.h"
#include "no_os_delay.h"
#include "iio_powrms.h"
#include <math.h>
Include dependency graph for powrms_utils.c:

Functions

uint8_t read_input ()
 Read and decode user input from UART.
 
void powrms_float_to_str (float var, char *text_buf, uint8_t int_precision, uint8_t float_precision, bool is_settings_variable)
 Convert float value to string representation.
 
void powrms_int_to_str (int var, char *text_buf)
 Convert integer value to string representation.
 
int powrms_eeprom_get_use_def_cal_data (int32_t *use_cal_data)
 Initialize EEPROM and set first byte to 1 if it's 0.
 
int powrms_eeprom_set_use_def_cal_data (int32_t value)
 Write a value to the first byte of the EEPROM.
 
int powrms_eeprom_get_temp_comp_data (int32_t *use_temp_comp)
 Read temperature compensation flag from EEPROM.
 
int powrms_eeprom_set_temp_comp_data (int32_t value)
 Write temperature compensation flag to EEPROM.
 
int powrms_eeprom_write_precision_array (const int32_t *precision_array)
 Write precision array to EEPROM starting from the second byte.
 
int powrms_eeprom_read_precision_array (int32_t *precision_array)
 Read precision array from EEPROM starting from the second byte.
 
int powrms_eeprom_write_def_precision_array (const int32_t *precision_array)
 Write default precision array to EEPROM.
 
int powrms_eeprom_read_def_precision_array (int32_t *precision_array)
 Read default precision array from EEPROM.
 
int powrms_eeprom_write_precision_array_reverse (const int32_t *precision_array)
 Write reverse precision array to EEPROM.
 
int powrms_eeprom_read_precision_array_reverse (int32_t *precision_array)
 Read reverse precision array from EEPROM.
 
int powrms_eeprom_write_def_precision_array_reverse (const int32_t *precision_array)
 Write default reverse precision array to EEPROM.
 
int powrms_eeprom_read_def_precision_array_reverse (int32_t *precision_array)
 Read default reverse precision array from EEPROM.
 
int powrms_eeprom_write_poly_5000MHz_coeffs (const double *coeffs)
 Write polynomial calibration coefficients for 5000MHz to EEPROM.
 
int powrms_eeprom_read_poly_5000MHz_coeffs (double *coeffs)
 Read polynomial calibration coefficients for 5000MHz from EEPROM.
 
int powrms_eeprom_write_def_poly_5000MHz_coeffs (const double *coeffs)
 Write default polynomial calibration coefficients for 5000MHz to EEPROM.
 
int powrms_eeprom_read_def_poly_5000MHz_coeffs (double *coeffs)
 Read default polynomial calibration coefficients for 5000MHz from EEPROM.
 
int powrms_eeprom_write_poly_5000MHz_reverse_coeffs (const double *coeffs)
 Write polynomial calibration coefficients for 5000MHz reverse to EEPROM.
 
int powrms_eeprom_read_poly_5000MHz_reverse_coeffs (double *coeffs)
 Read polynomial calibration coefficients for 5000MHz reverse from EEPROM.
 
int powrms_eeprom_write_def_poly_5000MHz_reverse_coeffs (const double *coeffs)
 Write default polynomial calibration coefficients for 5000MHz reverse to EEPROM.
 
int powrms_eeprom_read_def_poly_5000MHz_reverse_coeffs (double *coeffs)
 Read default polynomial calibration coefficients for 5000MHz reverse from EEPROM.
 
void powrms_get_firmware_version (char *version_buf)
 Get firmware version string in format "major.minor.patch".
 
int powrms_init_memory_upon_boot ()
 

Detailed Description

Utility functions for input handling and data conversion in EVAL-POWRMS project.

Author
Robert Budai (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.

Function Documentation

◆ powrms_eeprom_get_temp_comp_data()

int powrms_eeprom_get_temp_comp_data ( int32_t * use_temp_comp)

Read temperature compensation flag from EEPROM.

This function reads the temperature compensation flag from the EEPROM at the designated memory position. The EEPROM should already be initialized before calling this function.

Parameters
use_temp_compPointer to store the temperature compensation flag value
Returns
int 0 on success, negative error code on failure

◆ powrms_eeprom_get_use_def_cal_data()

int powrms_eeprom_get_use_def_cal_data ( int32_t * use_cal_data)

Initialize EEPROM and set first byte to 1 if it's 0.

This function reads the first byte of the EEPROM and if it's 0, sets it to 1. If it's already 1, leaves it as is. The EEPROM should already be initialized before calling this function.

Returns
int 0 on success, negative error code on failure

◆ powrms_eeprom_read_def_poly_5000MHz_coeffs()

int powrms_eeprom_read_def_poly_5000MHz_coeffs ( double * coeffs)

Read default polynomial calibration coefficients for 5000MHz from EEPROM.

This function reads the default 10 polynomial calibration coefficients (double array) from the EEPROM at the designated memory position for factory data. The EEPROM should already be initialized before calling this function.

Parameters
coeffsPointer to array where 10 double default polynomial coefficients will be stored
Returns
int 0 on success, negative error code on failure

◆ powrms_eeprom_read_def_poly_5000MHz_reverse_coeffs()

int powrms_eeprom_read_def_poly_5000MHz_reverse_coeffs ( double * coeffs)

Read default polynomial calibration coefficients for 5000MHz reverse from EEPROM.

This function reads the default 10 polynomial calibration coefficients (double array) for reverse power from the EEPROM at the designated memory position for factory data. The EEPROM should already be initialized before calling this function.

Parameters
coeffsPointer to array where 10 double default polynomial coefficients will be stored
Returns
int 0 on success, negative error code on failure

◆ powrms_eeprom_read_def_precision_array()

int powrms_eeprom_read_def_precision_array ( int32_t * precision_array)

Read default precision array from EEPROM.

This function reads the precision array from the default precision array memory position using single-byte reads to avoid I2C bus blocking issues that can occur with large transfers. Each int32_t value is read byte by byte and reconstructed in little-endian format.

◆ powrms_eeprom_read_def_precision_array_reverse()

int powrms_eeprom_read_def_precision_array_reverse ( int32_t * precision_array)

Read default reverse precision array from EEPROM.

This function reads the precision array from the default reverse precision array memory position using single-byte reads to avoid I2C bus blocking issues that can occur with large transfers. Each int32_t value is read byte by byte and reconstructed in little-endian format.

◆ powrms_eeprom_read_poly_5000MHz_coeffs()

int powrms_eeprom_read_poly_5000MHz_coeffs ( double * coeffs)

Read polynomial calibration coefficients for 5000MHz from EEPROM.

This function reads 10 polynomial coefficients (double array) from EEPROM. Uses single-byte reads to avoid I2C bus blocking.

◆ powrms_eeprom_read_poly_5000MHz_reverse_coeffs()

int powrms_eeprom_read_poly_5000MHz_reverse_coeffs ( double * coeffs)

Read polynomial calibration coefficients for 5000MHz reverse from EEPROM.

This function reads 10 polynomial coefficients (double array) from EEPROM for reverse power. Uses single-byte reads to avoid I2C bus blocking.

◆ powrms_eeprom_read_precision_array()

int powrms_eeprom_read_precision_array ( int32_t * precision_array)

Read precision array from EEPROM starting from the second byte.

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

◆ powrms_eeprom_read_precision_array_reverse()

int powrms_eeprom_read_precision_array_reverse ( int32_t * precision_array)

Read reverse precision array from EEPROM.

This function reads the precision array from the reverse precision array memory position using single-byte reads to avoid I2C bus blocking issues that can occur with large transfers. Each int32_t value is read byte by byte and reconstructed in little-endian format.

◆ powrms_eeprom_set_temp_comp_data()

int powrms_eeprom_set_temp_comp_data ( int32_t value)

Write temperature compensation flag to EEPROM.

This function writes the specified temperature compensation flag to the EEPROM at the designated memory position. The EEPROM should already be initialized before calling this function.

Parameters
valueThe temperature compensation flag value to write (0 or 1)
Returns
int 0 on success, negative error code on failure

◆ powrms_eeprom_set_use_def_cal_data()

int powrms_eeprom_set_use_def_cal_data ( int32_t value)

Write a value to the first byte of the EEPROM.

This function writes the specified value to the first byte (address 0) of the EEPROM. The EEPROM should already be initialized before calling this function.

Parameters
valueThe value to write to the first byte
Returns
int 0 on success, negative error code on failure

◆ powrms_eeprom_write_def_poly_5000MHz_coeffs()

int powrms_eeprom_write_def_poly_5000MHz_coeffs ( const double * coeffs)

Write default polynomial calibration coefficients for 5000MHz to EEPROM.

This function writes the default 10 polynomial calibration coefficients (double array) to the EEPROM at the designated memory position for factory data. The EEPROM should already be initialized before calling this function.

Parameters
coeffsPointer to array of 10 double default polynomial coefficients
Returns
int 0 on success, negative error code on failure

◆ powrms_eeprom_write_def_poly_5000MHz_reverse_coeffs()

int powrms_eeprom_write_def_poly_5000MHz_reverse_coeffs ( const double * coeffs)

Write default polynomial calibration coefficients for 5000MHz reverse to EEPROM.

This function writes the default 10 polynomial calibration coefficients (double array) for reverse power to the EEPROM at the designated memory position for factory data. The EEPROM should already be initialized before calling this function.

Parameters
coeffsPointer to array of 10 double default polynomial coefficients
Returns
int 0 on success, negative error code on failure

◆ powrms_eeprom_write_def_precision_array()

int powrms_eeprom_write_def_precision_array ( const int32_t * precision_array)

Write default precision array to EEPROM.

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

◆ powrms_eeprom_write_def_precision_array_reverse()

int powrms_eeprom_write_def_precision_array_reverse ( const int32_t * precision_array)

Write default reverse precision array to EEPROM.

This function writes the precision array to the default reverse precision array memory position using single-byte writes to avoid I2C bus blocking issues that can occur with large transfers. Each int32_t value is broken down into bytes and written individually in little-endian format.

◆ powrms_eeprom_write_poly_5000MHz_coeffs()

int powrms_eeprom_write_poly_5000MHz_coeffs ( const double * coeffs)

Write polynomial calibration coefficients for 5000MHz to EEPROM.

This function writes 10 polynomial coefficients (double array) to EEPROM. Uses single-byte writes to avoid I2C bus blocking.

◆ powrms_eeprom_write_poly_5000MHz_reverse_coeffs()

int powrms_eeprom_write_poly_5000MHz_reverse_coeffs ( const double * coeffs)

Write polynomial calibration coefficients for 5000MHz reverse to EEPROM.

This function writes 10 polynomial coefficients (double array) to EEPROM for reverse power. Uses single-byte writes to avoid I2C bus blocking.

◆ powrms_eeprom_write_precision_array()

int powrms_eeprom_write_precision_array ( const int32_t * precision_array)

Write precision array to EEPROM starting from the second byte.

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

◆ powrms_eeprom_write_precision_array_reverse()

int powrms_eeprom_write_precision_array_reverse ( const int32_t * precision_array)

Write reverse precision array to EEPROM.

This function writes the precision array to the reverse precision array memory position using single-byte writes to avoid I2C bus blocking issues that can occur with large transfers. Each int32_t value is broken down into bytes and written individually in little-endian format.

◆ powrms_float_to_str()

void powrms_float_to_str ( float var,
char * text_buf,
uint8_t int_digits,
uint8_t float_digits,
bool with_floating_comma )

Convert float value to string representation.

Parameters
varFloat value to convert
text_bufOutput buffer for string representation
int_digitsNumber of integer digits
float_digitsNumber of decimal digits
with_floating_commaIf true, include decimal point in output

◆ powrms_get_firmware_version()

void powrms_get_firmware_version ( char * version_buf)

Get firmware version string in format "major.minor.patch".

Parameters
version_bufBuffer to store the version string (minimum 16 bytes)

◆ powrms_init_memory_upon_boot()

int powrms_init_memory_upon_boot ( )

◆ powrms_int_to_str()

void powrms_int_to_str ( int var,
char * text_buf )

Convert integer value to string representation.

Parameters
varInteger value to convert
text_bufOutput buffer for string representation

◆ read_input()

uint8_t read_input ( )

Read and decode user input from UART.

Returns
uint8_t Input command code:
  • 0: No input received
  • 1: 'q' - Next/Navigate forward
  • 2: 'w' - Back/Increment (context dependent)
  • 3: 'e' - Enter/Confirm