no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ade7953.c File Reference

Implementation of ADE7953 Driver. More...

#include "ade7953.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 ade7953.c:

Functions

int ade7953_init (struct ade7953_dev **device, struct ade7953_init_param init_param)
 Initialize the device.
 
int ade7953_read (struct ade7953_dev *dev, uint16_t reg_addr, int32_t *reg_data)
 Read device register.
 
int ade7953_write (struct ade7953_dev *dev, uint16_t reg_addr, uint32_t reg_data)
 Write device register.
 
int ade7953_remove (struct ade7953_dev *dev)
 Remove the device and release resources.
 
int ade7953_sw_reset (struct ade7953_dev *dev)
 Reset the device using SW reset.
 
int ade7953_hw_reset (struct ade7953_dev *dev)
 Reset the device using HW reset.
 
int ade7953_wr_lock_8bit (struct ade7953_dev *dev, enum ade7953_write_protect_e regs_select)
 Lock write to registers.
 
int ade7953_version_product (struct ade7953_dev *dev, uint32_t *data_read)
 Version product.
 
int ade7953_reset_iapk_val (struct ade7953_dev *dev, uint32_t *val)
 reset IApeak val
 
int ade7953_reset_ibpk_val (struct ade7953_dev *dev, uint32_t *val)
 reset IBpeak val
 
int ade7953_reset_vpk_val (struct ade7953_dev *dev, uint32_t *val)
 reset Vpeak val
 
int ade7953_get_int_stata (struct ade7953_dev *dev, uint32_t msk, uint8_t *status)
 Get interrupt indicator from STATA register.
 
int ade7953_get_int_statb (struct ade7953_dev *dev, uint32_t msk, uint8_t *status)
 Get interrupt indicator from STATB register.
 
int ade7953_clear_irq_stata (struct ade7953_dev *dev)
 Clear irq stata flags.
 
int ade7953_clear_irq_statb (struct ade7953_dev *dev)
 Clear irq statb flags.
 
int ade7953_enable_int_a (struct ade7953_dev *dev, uint32_t msk, uint8_t en)
 Enable interrupt voltage ch and current ch A.
 
int ade7953_enable_int_b (struct ade7953_dev *dev, uint32_t msk, uint8_t en)
 Enable/disable interrupt voltage ch and current ch B.
 
int ade7953_zx_int_edge_set (struct ade7953_dev *dev, enum ade7953_zx_edge_e sel)
 Zero-crossing interrupt edge selection.
 
int ade7953_cf_output_set (struct ade7953_dev *dev, enum ade7953_cfsel_e sel, enum ade7953_cf_pin_e cf_pin)
 Configure output signal on CF1/CF2 pin.
 
int ade7953_zx_config_pin (struct ade7953_dev *dev, enum ade7953_zx_alt_e sel)
 Configure of ZX pin (Pin1)
 
int ade7953_zxi_config_pin (struct ade7953_dev *dev, enum ade7953_zxi_alt_e sel)
 Configure of ZXI pin (Pin21)
 
int ade7953_revp_pin_config (struct ade7953_dev *dev, enum ade7953_revp_alt_e sel)
 Configure of REVP pin (Pin20)
 
int ade7953_acc_active_engy_mode (struct ade7953_dev *dev, enum ade7953_awattacc_e mode, enum ade7953_i_ch_e channel)
 ACC mode selection for active energy.
 
int ade7953_acc_reactive_engy_mode (struct ade7953_dev *dev, enum ade7953_avaracc_e mode, enum ade7953_i_ch_e channel)
 ACC mode selection for reactive energy.
 
int ade7953_energy_vals (struct ade7953_dev *dev, struct ade7953_energy_values *data, enum ade7953_i_ch_e channel)
 Read energy values.
 
int ade7953_power_vals (struct ade7953_dev *dev, struct ade7953_power_values *data, enum ade7953_i_ch_e channel)
 Read power values.
 
int ade7953_rms_vals (struct ade7953_dev *dev, struct ade7953_rms_values *data, enum ade7953_i_ch_e channel)
 Read rms values.
 
int ade7953_power_quality_vals (struct ade7953_dev *dev, struct ade7953_pq_values *data)
 Read power quaility values.
 

Detailed Description

Implementation of ADE7953 Driver.

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

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

◆ ade7953_acc_active_engy_mode()

int ade7953_acc_active_engy_mode ( struct ade7953_dev * dev,
enum ade7953_awattacc_e mode,
enum ade7953_i_ch_e channel )

ACC mode selection for active energy.

Parameters
dev- The device structure.
mode- mode selection
channel- current channel selector
Returns
0 in case of success, negative error code otherwise.

◆ ade7953_acc_reactive_engy_mode()

int ade7953_acc_reactive_engy_mode ( struct ade7953_dev * dev,
enum ade7953_avaracc_e mode,
enum ade7953_i_ch_e channel )

ACC mode selection for reactive energy.

Parameters
dev- The device structure.
mode- mode selection
channel- current channel selector
Returns
0 in case of success, negative error code otherwise.

◆ ade7953_cf_output_set()

int ade7953_cf_output_set ( struct ade7953_dev * dev,
enum ade7953_cfsel_e sel,
enum ade7953_cf_pin_e cf_pin )

Configure output signal on CF1/CF2 pin.

Parameters
dev- The device structure.
sel- CF signal
cf_pin- 0 for CF1 pin, 1 for CF2 pin;
Returns
0 in case of success, negative error code otherwise.

◆ ade7953_clear_irq_stata()

int ade7953_clear_irq_stata ( struct ade7953_dev * dev)

Clear irq stata flags.

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

◆ ade7953_clear_irq_statb()

int ade7953_clear_irq_statb ( struct ade7953_dev * dev)

Clear irq statb flags.

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

◆ ade7953_enable_int_a()

int ade7953_enable_int_a ( struct ade7953_dev * dev,
uint32_t msk,
uint8_t en )

Enable interrupt voltage ch and current ch A.

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

◆ ade7953_enable_int_b()

int ade7953_enable_int_b ( struct ade7953_dev * dev,
uint32_t msk,
uint8_t en )

Enable/disable interrupt voltage ch and current ch B.

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

◆ ade7953_energy_vals()

int ade7953_energy_vals ( struct ade7953_dev * dev,
struct ade7953_energy_values * data,
enum ade7953_i_ch_e channel )

Read energy values.

Parameters
dev- The device structure.
data- Structure to store energy values
channel- current channel selector
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7953_get_int_stata()

int ade7953_get_int_stata ( struct ade7953_dev * dev,
uint32_t msk,
uint8_t * status )

Get interrupt indicator from STATA register.

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

◆ ade7953_get_int_statb()

int ade7953_get_int_statb ( struct ade7953_dev * dev,
uint32_t msk,
uint8_t * status )

Get interrupt indicator from STATB register.

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

◆ ade7953_hw_reset()

int ade7953_hw_reset ( struct ade7953_dev * dev)

Reset the device using HW reset.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7953_init()

int ade7953_init ( struct ade7953_dev ** device,
struct ade7953_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.
Here is the caller graph for this function:

◆ ade7953_power_quality_vals()

int ade7953_power_quality_vals ( struct ade7953_dev * dev,
struct ade7953_pq_values * data )

Read power quaility values.

Parameters
dev- The device structure.
data- Structure to store power quality values
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7953_power_vals()

int ade7953_power_vals ( struct ade7953_dev * dev,
struct ade7953_power_values * data,
enum ade7953_i_ch_e channel )

Read power values.

Parameters
dev- The device structure.
data- Structure to store power values
channel- current channel selector
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7953_read()

int ade7953_read ( struct ade7953_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.
Here is the caller graph for this function:

◆ ade7953_remove()

int ade7953_remove ( struct ade7953_dev * dev)

Remove the device and release resources.

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

◆ ade7953_reset_iapk_val()

int ade7953_reset_iapk_val ( struct ade7953_dev * dev,
uint32_t * val )

reset IApeak val

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

◆ ade7953_reset_ibpk_val()

int ade7953_reset_ibpk_val ( struct ade7953_dev * dev,
uint32_t * val )

reset IBpeak val

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

◆ ade7953_reset_vpk_val()

int ade7953_reset_vpk_val ( struct ade7953_dev * dev,
uint32_t * val )

reset Vpeak val

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

◆ ade7953_revp_pin_config()

int ade7953_revp_pin_config ( struct ade7953_dev * dev,
enum ade7953_revp_alt_e sel )

Configure of REVP pin (Pin20)

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

◆ ade7953_rms_vals()

int ade7953_rms_vals ( struct ade7953_dev * dev,
struct ade7953_rms_values * data,
enum ade7953_i_ch_e channel )

Read rms values.

Parameters
dev- The device structure.
data- Structure to store rms values
channel- current channel selector
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7953_sw_reset()

int ade7953_sw_reset ( struct ade7953_dev * dev)

Reset the device using SW reset.

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

◆ ade7953_version_product()

int ade7953_version_product ( struct ade7953_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.
Here is the caller graph for this function:

◆ ade7953_wr_lock_8bit()

int ade7953_wr_lock_8bit ( struct ade7953_dev * dev,
enum ade7953_write_protect_e regs_select )

Lock write to registers.

Parameters
dev- The device structure.
regs_select- Selects the registers to be write protected.
Returns
0 in case of success, negative error code otherwise.

◆ ade7953_write()

int ade7953_write ( struct ade7953_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.
Here is the caller graph for this function:

◆ ade7953_zx_config_pin()

int ade7953_zx_config_pin ( struct ade7953_dev * dev,
enum ade7953_zx_alt_e sel )

Configure of ZX pin (Pin1)

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

◆ ade7953_zx_int_edge_set()

int ade7953_zx_int_edge_set ( struct ade7953_dev * dev,
enum ade7953_zx_edge_e sel )

Zero-crossing interrupt edge selection.

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

◆ ade7953_zxi_config_pin()

int ade7953_zxi_config_pin ( struct ade7953_dev * dev,
enum ade7953_zxi_alt_e sel )

Configure of ZXI pin (Pin21)

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