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>
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. | |
Implementation of ADE7953 Driver.
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:
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.
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.
dev | - The device structure. |
mode | - mode selection |
channel | - current channel selector |
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.
dev | - The device structure. |
mode | - mode selection |
channel | - current channel selector |
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.
dev | - The device structure. |
sel | - CF signal |
cf_pin | - 0 for CF1 pin, 1 for CF2 pin; |
int ade7953_clear_irq_stata | ( | struct ade7953_dev * | dev | ) |
Clear irq stata flags.
dev | - The device structure. |
int ade7953_clear_irq_statb | ( | struct ade7953_dev * | dev | ) |
Clear irq statb flags.
dev | - The device structure. |
int ade7953_enable_int_a | ( | struct ade7953_dev * | dev, |
uint32_t | msk, | ||
uint8_t | en ) |
Enable interrupt voltage ch and current ch A.
dev | - The device structure. |
msk | - Interrupt mask. |
en | -Enable/Disable |
int ade7953_enable_int_b | ( | struct ade7953_dev * | dev, |
uint32_t | msk, | ||
uint8_t | en ) |
Enable/disable interrupt voltage ch and current ch B.
dev | - The device structure. |
msk | - Interrupt mask. |
en | -Enable/Disable |
int ade7953_energy_vals | ( | struct ade7953_dev * | dev, |
struct ade7953_energy_values * | data, | ||
enum ade7953_i_ch_e | channel ) |
Read energy values.
dev | - The device structure. |
data | - Structure to store energy values |
channel | - current channel selector |
int ade7953_get_int_stata | ( | struct ade7953_dev * | dev, |
uint32_t | msk, | ||
uint8_t * | status ) |
Get interrupt indicator from STATA register.
dev | - The device structure. |
msk | - Interrupt mask. |
status | - Status indicator. |
int ade7953_get_int_statb | ( | struct ade7953_dev * | dev, |
uint32_t | msk, | ||
uint8_t * | status ) |
Get interrupt indicator from STATB register.
dev | - The device structure. |
msk | - Interrupt mask. |
status | - Status indicator. |
int ade7953_hw_reset | ( | struct ade7953_dev * | dev | ) |
Reset the device using HW reset.
dev | - The device structure. |
int ade7953_init | ( | struct ade7953_dev ** | device, |
struct ade7953_init_param | init_param ) |
Initialize the device.
device | - The device structure. |
init_param | - The structure that contains the device initial parameters. |
int ade7953_power_quality_vals | ( | struct ade7953_dev * | dev, |
struct ade7953_pq_values * | data ) |
Read power quaility values.
dev | - The device structure. |
data | - Structure to store power quality values |
int ade7953_power_vals | ( | struct ade7953_dev * | dev, |
struct ade7953_power_values * | data, | ||
enum ade7953_i_ch_e | channel ) |
Read power values.
dev | - The device structure. |
data | - Structure to store power values |
channel | - current channel selector |
int ade7953_read | ( | struct ade7953_dev * | dev, |
uint16_t | reg_addr, | ||
int32_t * | reg_data ) |
Read device register.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The data read from 32bit register. |
int ade7953_remove | ( | struct ade7953_dev * | dev | ) |
Remove the device and release resources.
dev | - The device structure. |
int ade7953_reset_iapk_val | ( | struct ade7953_dev * | dev, |
uint32_t * | val ) |
reset IApeak val
dev | - The device structure. |
val | - Iapeak val |
int ade7953_reset_ibpk_val | ( | struct ade7953_dev * | dev, |
uint32_t * | val ) |
reset IBpeak val
dev | - The device structure. |
val | - Ibpeak val |
int ade7953_reset_vpk_val | ( | struct ade7953_dev * | dev, |
uint32_t * | val ) |
reset Vpeak val
dev | - The device structure. |
val | - Vpeak val |
int ade7953_revp_pin_config | ( | struct ade7953_dev * | dev, |
enum ade7953_revp_alt_e | sel ) |
Configure of REVP pin (Pin20)
dev | - The device structure. |
sel | - REVP pin configuration |
int ade7953_rms_vals | ( | struct ade7953_dev * | dev, |
struct ade7953_rms_values * | data, | ||
enum ade7953_i_ch_e | channel ) |
Read rms values.
dev | - The device structure. |
data | - Structure to store rms values |
channel | - current channel selector |
int ade7953_sw_reset | ( | struct ade7953_dev * | dev | ) |
Reset the device using SW reset.
dev | - The device structure. |
int ade7953_version_product | ( | struct ade7953_dev * | dev, |
uint32_t * | data_read ) |
Version product.
dev | - The device structure. |
data_read | - The version product read value |
int ade7953_wr_lock_8bit | ( | struct ade7953_dev * | dev, |
enum ade7953_write_protect_e | regs_select ) |
Lock write to registers.
dev | - The device structure. |
regs_select | - Selects the registers to be write protected. |
int ade7953_write | ( | struct ade7953_dev * | dev, |
uint16_t | reg_addr, | ||
uint32_t | reg_data ) |
Write device register.
dev- | The device structure. |
reg_addr | - The register address. |
reg_data | - The data to be written. |
int ade7953_zx_config_pin | ( | struct ade7953_dev * | dev, |
enum ade7953_zx_alt_e | sel ) |
Configure of ZX pin (Pin1)
dev | - The device structure. |
sel | - ZX pin configuration |
int ade7953_zx_int_edge_set | ( | struct ade7953_dev * | dev, |
enum ade7953_zx_edge_e | sel ) |
Zero-crossing interrupt edge selection.
dev | - The device structure. |
sel | - Edge selection |
int ade7953_zxi_config_pin | ( | struct ade7953_dev * | dev, |
enum ade7953_zxi_alt_e | sel ) |
Configure of ZXI pin (Pin21)
dev | - The device structure. |
sel | - ZXI pin configuration |