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

Implementation of ADE7754 Driver. More...

#include "ade7754.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "no_os_util.h"
#include "no_os_spi.h"
#include "no_os_gpio.h"
#include "no_os_irq.h"
#include "no_os_delay.h"
#include "no_os_units.h"
#include "no_os_alloc.h"
#include "no_os_crc16.h"
#include "no_os_print_log.h"
#include <stdlib.h>
#include <errno.h>
#include <math.h>
Include dependency graph for ade7754.c:

Functions

int ade7754_init (struct ade7754_dev **device, struct ade7754_init_param init_param)
 Initialize the device.
 
int ade7754_setup (struct ade7754_dev *dev)
 Setup the ADE7754 device.
 
int ade7754_read (struct ade7754_dev *dev, uint16_t reg_addr, int32_t *reg_data)
 Read device register.
 
int ade7754_write (struct ade7754_dev *dev, uint16_t reg_addr, uint32_t reg_data)
 Write device register.
 
int ade7754_update_bits (struct ade7754_dev *dev, uint16_t reg_addr, uint32_t mask, uint32_t reg_data)
 Update specific register bits.
 
int ade7754_remove (struct ade7754_dev *dev)
 Remove the device and release resources.
 
int ade7754_sw_reset (struct ade7754_dev *dev)
 Reset the device using SW reset.
 
int ade7754_hw_reset (struct ade7754_dev *dev)
 Reset the device using HW reset.
 
int ade7754_version_product (struct ade7754_dev *dev, uint32_t *data_read)
 Version product.
 
int ade7754_write_ipk_val (struct ade7754_dev *dev, uint32_t val)
 Write Ipeak val.
 
int ade7754_write_vpk_val (struct ade7754_dev *dev, uint32_t val)
 Write Vpeak val.
 
int ade7754_get_int_status (struct ade7754_dev *dev, uint32_t msk, uint8_t *status)
 Get interrupt indicator from STATUS register.
 
int ade7754_clear_irq_status (struct ade7754_dev *dev, int32_t *reg_data)
 Clear irq status flags.
 
int ade7754_enable_irq (struct ade7754_dev *dev, uint32_t msk, uint8_t en)
 Enable/Disable interrupt.
 
int ade7754_wave_update_rate (struct ade7754_dev *dev, enum ade7754_data_rate sel)
 Select waveform register update rate.
 
int ade7754_wave_sample_data_source (struct ade7754_dev *dev, enum ade7754_wavsel sel)
 Select source of sampled data for wave register.
 
int ade7754_current_gain (struct ade7754_dev *dev, enum ade7754_pga_gain sel)
 Select the gain of the current channels inputs.
 
int ade7754_voltage_gain (struct ade7754_dev *dev, enum ade7754_pga_gain sel)
 Select the gain of the voltage channels inputs.
 
int ade7754_active_energy_formula (struct ade7754_dev *dev, enum ade7754_watm sel)
 Select the formula used for active energy calculation.
 
int ade7754_apparent_energy_formula (struct ade7754_dev *dev, enum ade7754_vamod sel)
 Select the formula used for apparent energy calculation.
 
int ade7754_period_source (struct ade7754_dev *dev, enum ade7754_phsel sel)
 Select the source of the measurement of the voltage line period.
 
int ade7754_zxsel (struct ade7754_dev *dev, enum ade7754_phsel sel)
 Select the phases used for counting the number of zero crossing in the line active and apparent accumulation modes and enables these phases for the zero-crossing timeout detection, zero crossing, period measurement, and SAG detection.
 
int ade7754_lwat_formula_term (struct ade7754_dev *dev, enum ade7754_formsel sel)
 Select part of the line active energy formula separately, depending on the line active energy measurement method.
 
int ade7754_lva_formula_term (struct ade7754_dev *dev, enum ade7754_formsel sel)
 Select part of the line apparent energy formula separately, depending on the line active energy measurement method.
 
int ade7754_wat_formula_term (struct ade7754_dev *dev, enum ade7754_formsel sel)
 Select part of the active energy formula separately, depending on the line active energy measurement method.
 
int ade7754_va_formula_term (struct ade7754_dev *dev, enum ade7754_formsel sel)
 Select part of the apparent energy formula separately, depending on the line active energy measurement method.
 
int ade7754_peak_source (struct ade7754_dev *dev, enum ade7754_phsel sel)
 Select the source of the voltage & current peak detection.
 
int ade7754_adcs_mode (struct ade7754_dev *dev, enum ade7754_dismod sel)
 Operation mode of the ADCs.
 
int ade7754_energy_vals (struct ade7754_dev *dev, struct ade7754_energy_values *data)
 Read energy values.
 
int ade7754_rms_vals_phase_a (struct ade7754_dev *dev, struct ade7754_rms_values *data)
 Read rms values phase A.
 
int ade7754_rms_vals_phase_b (struct ade7754_dev *dev, struct ade7754_rms_values *data)
 Read rms values phase B.
 
int ade7754_rms_vals_phase_c (struct ade7754_dev *dev, struct ade7754_rms_values *data)
 Read rms values phase C.
 
int ade7754_period_val (struct ade7754_dev *dev, struct ade7754_period_value *data)
 Read period value.
 
int ade7754_temperature_val (struct ade7754_dev *dev, struct ade7754_temp_value *data)
 Read temperature value.
 

Detailed Description

Implementation of ADE7754 Driver.

Author
REtz (radu..nosp@m.etz@.nosp@m.analo.nosp@m.g.co.nosp@m.m)

Copyright 2025(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ ade7754_active_energy_formula()

int ade7754_active_energy_formula ( struct ade7754_dev * dev,
enum ade7754_watm sel )

Select the formula used for active energy calculation.

Parameters
dev- The device structure.
sel- formula value
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_adcs_mode()

int ade7754_adcs_mode ( struct ade7754_dev * dev,
enum ade7754_dismod sel )

Operation mode of the ADCs.

Parameters
dev- The device structure.
sel- mode of the ADCs
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_apparent_energy_formula()

int ade7754_apparent_energy_formula ( struct ade7754_dev * dev,
enum ade7754_vamod sel )

Select the formula used for apparent energy calculation.

Parameters
dev- The device structure.
sel- formula value
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_clear_irq_status()

int ade7754_clear_irq_status ( struct ade7754_dev * dev,
int32_t * reg_data )

Clear irq status flags.

Parameters
dev- The device structure.
reg_data- value of the status register
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_current_gain()

int ade7754_current_gain ( struct ade7754_dev * dev,
enum ade7754_pga_gain sel )

Select the gain of the current channels inputs.

Parameters
dev- The device structure.
sel- gain value
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_enable_irq()

int ade7754_enable_irq ( struct ade7754_dev * dev,
uint32_t msk,
uint8_t en )

Enable/Disable interrupt.

Parameters
dev- The device structure.
msk- Interrupt mask.
en-Enable/Disable
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_energy_vals()

int ade7754_energy_vals ( struct ade7754_dev * dev,
struct ade7754_energy_values * data )

Read energy values.

Parameters
dev- The device structure.
data- Structure to store energy values
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_get_int_status()

int ade7754_get_int_status ( struct ade7754_dev * dev,
uint32_t msk,
uint8_t * status )

Get interrupt indicator from STATUS register.

Parameters
dev- The device structure.
msk- Interrupt mask.
status- Status indicator.
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_hw_reset()

int ade7754_hw_reset ( struct ade7754_dev * dev)

Reset the device using HW reset.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_init()

int ade7754_init ( struct ade7754_dev ** device,
struct ade7754_init_param init_param )

Initialize the device.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_lva_formula_term()

int ade7754_lva_formula_term ( struct ade7754_dev * dev,
enum ade7754_formsel sel )

Select part of the line apparent energy formula separately, depending on the line active energy measurement method.

Parameters
dev- The device structure.
sel- formula part selection
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_lwat_formula_term()

int ade7754_lwat_formula_term ( struct ade7754_dev * dev,
enum ade7754_formsel sel )

Select part of the line active energy formula separately, depending on the line active energy measurement method.

Parameters
dev- The device structure.
sel- formula part selection
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_peak_source()

int ade7754_peak_source ( struct ade7754_dev * dev,
enum ade7754_phsel sel )

Select the source of the voltage & current peak detection.

Parameters
dev- The device structure.
sel- peak detection source
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_period_source()

int ade7754_period_source ( struct ade7754_dev * dev,
enum ade7754_phsel sel )

Select the source of the measurement of the voltage line period.

Parameters
dev- The device structure.
sel- period measurement source
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_period_val()

int ade7754_period_val ( struct ade7754_dev * dev,
struct ade7754_period_value * data )

Read period value.

Parameters
dev- The device structure.
data- Structure to store the period val
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_read()

int ade7754_read ( struct ade7754_dev * dev,
uint16_t reg_addr,
int32_t * reg_data )

Read device register.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_data- The data read from 32bit register.
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_remove()

int ade7754_remove ( struct ade7754_dev * dev)

Remove the device and release resources.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_rms_vals_phase_a()

int ade7754_rms_vals_phase_a ( struct ade7754_dev * dev,
struct ade7754_rms_values * data )

Read rms values phase A.

Parameters
dev- The device structure.
data- Structure to store rms values
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_rms_vals_phase_b()

int ade7754_rms_vals_phase_b ( struct ade7754_dev * dev,
struct ade7754_rms_values * data )

Read rms values phase B.

Parameters
dev- The device structure.
data- Structure to store rms values
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_rms_vals_phase_c()

int ade7754_rms_vals_phase_c ( struct ade7754_dev * dev,
struct ade7754_rms_values * data )

Read rms values phase C.

Parameters
dev- The device structure.
data- Structure to store rms values
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_setup()

int ade7754_setup ( struct ade7754_dev * dev)

Setup the ADE7754 device.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_sw_reset()

int ade7754_sw_reset ( struct ade7754_dev * dev)

Reset the device using SW reset.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_temperature_val()

int ade7754_temperature_val ( struct ade7754_dev * dev,
struct ade7754_temp_value * data )

Read temperature value.

Parameters
dev- The device structure.
data- Structure to store the temperature val
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_update_bits()

int ade7754_update_bits ( struct ade7754_dev * dev,
uint16_t reg_addr,
uint32_t mask,
uint32_t reg_data )

Update specific register bits.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- Specific bits mask.
reg_data- The data to be written.
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_va_formula_term()

int ade7754_va_formula_term ( struct ade7754_dev * dev,
enum ade7754_formsel sel )

Select part of the apparent energy formula separately, depending on the line active energy measurement method.

Parameters
dev- The device structure.
sel- formula part selection
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_version_product()

int ade7754_version_product ( struct ade7754_dev * dev,
uint32_t * data_read )

Version product.

Parameters
dev- The device structure.
data_read- The version product read value
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_voltage_gain()

int ade7754_voltage_gain ( struct ade7754_dev * dev,
enum ade7754_pga_gain sel )

Select the gain of the voltage channels inputs.

Parameters
dev- The device structure.
sel- gain value
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_wat_formula_term()

int ade7754_wat_formula_term ( struct ade7754_dev * dev,
enum ade7754_formsel sel )

Select part of the active energy formula separately, depending on the line active energy measurement method.

Parameters
dev- The device structure.
sel- formula part selection
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_wave_sample_data_source()

int ade7754_wave_sample_data_source ( struct ade7754_dev * dev,
enum ade7754_wavsel sel )

Select source of sampled data for wave register.

Parameters
dev- The device structure.
sel- Update rate
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_wave_update_rate()

int ade7754_wave_update_rate ( struct ade7754_dev * dev,
enum ade7754_data_rate sel )

Select waveform register update rate.

Parameters
dev- The device structure.
sel- Update rate
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_write()

int ade7754_write ( struct ade7754_dev * dev,
uint16_t reg_addr,
uint32_t reg_data )

Write device register.

Parameters
dev-The device structure.
reg_addr- The register address.
reg_data- The data to be written.
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_write_ipk_val()

int ade7754_write_ipk_val ( struct ade7754_dev * dev,
uint32_t val )

Write Ipeak val.

Parameters
dev- The device structure.
val- Ipeak set val
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_write_vpk_val()

int ade7754_write_vpk_val ( struct ade7754_dev * dev,
uint32_t val )

Write Vpeak val.

Parameters
dev- The device structure.
val- Vpeak set val
Returns
0 in case of success, negative error code otherwise.

◆ ade7754_zxsel()

int ade7754_zxsel ( struct ade7754_dev * dev,
enum ade7754_phsel sel )

Select the phases used for counting the number of zero crossing in the line active and apparent accumulation modes and enables these phases for the zero-crossing timeout detection, zero crossing, period measurement, and SAG detection.

Parameters
dev- The device structure.
sel- phase selection
Returns
0 in case of success, negative error code otherwise.