no-OS
Functions
ade7816.c File Reference

Source file of ADE7816 Driver. More...

#include "no_os_alloc.h"
#include "no_os_delay.h"
#include "no_os_units.h"
#include "ade7816.h"
Include dependency graph for ade7816.c:

Functions

int ade7816_read_reg (struct ade7816_desc *desc, uint16_t reg, uint32_t *val)
 Register read wrapper function. More...
 
int ade7816_write_reg (struct ade7816_desc *desc, uint16_t reg, uint32_t val)
 Register write wrapper function. More...
 
int ade7816_reg_update (struct ade7816_desc *desc, uint16_t reg, uint32_t mask, uint32_t val)
 Register update function. More...
 
int ade7816_sw_reset (struct ade7816_desc *desc)
 ADE7816 software reset function. More...
 
int ade7816_hw_reset (struct ade7816_desc *desc)
 ADE7816 hardware reset function. More...
 
int ade7816_set_comm (struct ade7816_desc *desc, enum ade7816_comm_type type)
 ADE7816 set communication function. More...
 
int ade7816_read_active_energy (struct ade7816_desc *desc, enum ade7816_channel chan, int32_t *val)
 ADE7816 read active energy function. More...
 
int ade7816_set_active_thr (struct ade7816_desc *desc, uint16_t freq)
 ADE7816 set active energy threshold value function. More...
 
int ade7816_get_active_thr (struct ade7816_desc *desc, uint16_t *freq)
 ADE7816 get active energy threshold value function. More...
 
int ade7816_read_reactive_energy (struct ade7816_desc *desc, enum ade7816_channel chan, int32_t *val)
 ADE7816 read reactive energy value function. More...
 
int ade7816_set_reactive_thr (struct ade7816_desc *desc, uint16_t freq)
 ADE7816 set reactive energy threshold value function. More...
 
int ade7816_get_reactive_thr (struct ade7816_desc *desc, uint16_t *freq)
 ADE7816 get reactive energy threshold value function. More...
 
int ade7816_set_lcycle_mode (struct ade7816_desc *desc, bool enable, uint16_t cycles, bool lenergy)
 ADE7816 set line cycle mode function. More...
 
int ade7816_read_rms (struct ade7816_desc *desc, enum ade7816_channel chan, uint32_t *rms)
 ADE7816 read root mean square measurement value function. More...
 
int ade7816_set_no_load (struct ade7816_desc *desc, uint16_t voltage, uint16_t current, bool enable)
 ADE7816 set no load condition function. More...
 
int ade7816_set_gain (struct ade7816_desc *desc, enum ade7816_channel chan, int16_t scale, enum ade7816_gain_type gain)
 ADE7816 set gain value for channel function. More...
 
int ade7816_get_gain (struct ade7816_desc *desc, enum ade7816_channel chan, int16_t *scale, enum ade7816_gain_type gain)
 ADE7816 get gain value for channel function. More...
 
int ade7816_set_offset (struct ade7816_desc *desc, enum ade7816_channel chan, int16_t scale, enum ade7816_gain_type gain)
 ADE7816 set offset value for channel function. More...
 
int ade7816_get_offset (struct ade7816_desc *desc, enum ade7816_channel chan, int16_t *scale, enum ade7816_gain_type gain)
 ADE7816 get offset value for channel function. More...
 
int ade7816_set_phase (struct ade7816_desc *desc, enum ade7816_channel chan, enum ade7816_pcf_coeff pcf_coeff)
 ADE7816 set phase calibration coefficient function. More...
 
int ade7816_calib_rms (struct ade7816_desc *desc, enum ade7816_channel chan, int32_t rms)
 ADE7816 root mean square measurement calibration function. More...
 
int ade7816_group_sel (struct ade7816_desc *desc, enum ade7816_channel chan)
 ADE7816 group selection for channels function. More...
 
int ade7816_zx_detect (struct ade7816_desc *desc, enum ade7816_channel chan)
 ADE7816 zero-crossing detection for channel function. More...
 
int ade7816_zx_timeout (struct ade7816_desc *desc, uint32_t timeout_us)
 ADE7816 zero-crossing detection timeout value function. More...
 
int ade7816_peak_detect (struct ade7816_desc *desc, enum ade7816_channel chan, enum ade7816_mmode_sel mmode, uint8_t no_of_cycles)
 ADE7816 set peak detection for channel function. More...
 
int ade7816_power_dir (struct ade7816_desc *desc, enum ade7816_channel chan)
 ADE7816 set power direction for channel function. More...
 
int ade7816_read_dir (struct ade7816_desc *desc, enum ade7816_channel chan, bool *sign)
 ADE7816 get power direction for channel function. More...
 
int ade7816_angle_meas (struct ade7816_desc *desc, enum ade7816_channel chan, enum ade7816_angle_sel sel)
 ADE7816 angle measurement function. More...
 
int ade7816_read_period (struct ade7816_desc *desc, uint32_t *period_us)
 ADE7816 read period value function. More...
 
int ade7816_set_interrupt (struct ade7816_desc *desc, enum ade7816_status_int status_int, bool enable)
 ADE7816 set interrupts function. More...
 
int ade7816_get_interrupt (struct ade7816_desc *desc, enum ade7816_status_int status_int, bool *enable)
 ADE7816 get interrupts function. More...
 
int ade7816_rms_to_micro (struct ade7816_desc *desc, enum ade7816_channel chan, uint32_t rms, uint32_t *micro)
 ADE7816 root mean square measurement value conversion to microunits function. More...
 
int ade7816_init (struct ade7816_desc **desc, struct ade7816_init_param *init_param)
 Initialize and configure the ADE7816 device. More...
 
int ade7816_remove (struct ade7816_desc *desc)
 Free the resources allocated during init. More...
 

Detailed Description

Source file of ADE7816 Driver.

Author
Radu Sabau (radu..nosp@m.saba.nosp@m.u@ana.nosp@m.log..nosp@m.com)

Copyright 2024(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

◆ ade7816_angle_meas()

int ade7816_angle_meas ( struct ade7816_desc desc,
enum ade7816_channel  chan,
enum ade7816_angle_sel  sel 
)

ADE7816 angle measurement function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
sel- Angle selection value.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_calib_rms()

int ade7816_calib_rms ( struct ade7816_desc desc,
enum ade7816_channel  chan,
int32_t  rms 
)

ADE7816 root mean square measurement calibration function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
rms- Expected root mean square measurement value.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_get_active_thr()

int ade7816_get_active_thr ( struct ade7816_desc desc,
uint16_t *  freq 
)

ADE7816 get active energy threshold value function.

Parameters
desc- ADE7816 device descriptor.
freq- Update rate frequency.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_get_gain()

int ade7816_get_gain ( struct ade7816_desc desc,
enum ade7816_channel  chan,
int16_t *  scale,
enum ade7816_gain_type  gain 
)

ADE7816 get gain value for channel function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
scale- Scale percentage of full-scale (100.00% = 10000)
gain- Gain type.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_get_interrupt()

int ade7816_get_interrupt ( struct ade7816_desc desc,
enum ade7816_status_int  status_int,
bool enable 
)

ADE7816 get interrupts function.

Parameters
desc-ADE7816 device descriptor.
status_int- Interrupt selection value.
enable- False = Disable True = Enable
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_get_offset()

int ade7816_get_offset ( struct ade7816_desc desc,
enum ade7816_channel  chan,
int16_t *  scale,
enum ade7816_gain_type  gain 
)

ADE7816 get offset value for channel function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
scale- Scale percentage value (100.00% = 10000)
gain- Gain type.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_get_reactive_thr()

int ade7816_get_reactive_thr ( struct ade7816_desc desc,
uint16_t *  freq 
)

ADE7816 get reactive energy threshold value function.

Parameters
desc- ADE7816 device descriptor.
freq- Update rate frequency.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_group_sel()

int ade7816_group_sel ( struct ade7816_desc desc,
enum ade7816_channel  chan 
)

ADE7816 group selection for channels function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_hw_reset()

int ade7816_hw_reset ( struct ade7816_desc desc)

ADE7816 hardware reset function.

Parameters
desc- ADE7816 device descriptor
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_init()

int ade7816_init ( struct ade7816_desc **  desc,
struct ade7816_init_param init_param 
)

Initialize and configure the ADE7816 device.

Parameters
desc- device descriptor for the ADE7816 that will be initialized.
init_param- initialization parameter for the device.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_peak_detect()

int ade7816_peak_detect ( struct ade7816_desc desc,
enum ade7816_channel  chan,
enum ade7816_mmode_sel  mmode,
uint8_t  no_of_cycles 
)

ADE7816 set peak detection for channel function.

Parameters
desc-ADE7816 device descriptor.
chan- Channel number.
mmode- Measurement mode selection value.
no_of_cycles- Set the line cycles number over which peak measurements are performed.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_power_dir()

int ade7816_power_dir ( struct ade7816_desc desc,
enum ade7816_channel  chan 
)

ADE7816 set power direction for channel function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_read_active_energy()

int ade7816_read_active_energy ( struct ade7816_desc desc,
enum ade7816_channel  chan,
int32_t *  val 
)

ADE7816 read active energy function.

Parameters
desc- ADE7816 device descriptor
chan- Channel number.
val- Active energy value.
Here is the caller graph for this function:

◆ ade7816_read_dir()

int ade7816_read_dir ( struct ade7816_desc desc,
enum ade7816_channel  chan,
bool sign 
)

ADE7816 get power direction for channel function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
sign- Power direction sign.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_read_period()

int ade7816_read_period ( struct ade7816_desc desc,
uint32_t *  period_us 
)

ADE7816 read period value function.

Parameters
desc- ADE7816 device descriptor.
period_us- Period value in microseconds.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_read_reactive_energy()

int ade7816_read_reactive_energy ( struct ade7816_desc desc,
enum ade7816_channel  chan,
int32_t *  val 
)

ADE7816 read reactive energy value function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
val- Reactive energy value.
Returns
0 in case of succes, negativeerror code otherwise.
Here is the caller graph for this function:

◆ ade7816_read_reg()

int ade7816_read_reg ( struct ade7816_desc desc,
uint16_t  reg,
uint32_t *  val 
)

Register read wrapper function.

Parameters
desc- ADE7816 device descriptor.
reg- Register Address value.
val- Register Value to be read.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_read_rms()

int ade7816_read_rms ( struct ade7816_desc desc,
enum ade7816_channel  chan,
uint32_t *  rms 
)

ADE7816 read root mean square measurement value function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
rms- RMS value.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_reg_update()

int ade7816_reg_update ( struct ade7816_desc desc,
uint16_t  reg,
uint32_t  mask,
uint32_t  val 
)

Register update function.

Parameters
desc- ADE7816 device descriptor.
reg- address of the register.
mask- bit mask of the field to be updated.
val- value of the masked field. Should be bit shifted by using no_os_field_prep(mask, val).
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_remove()

int ade7816_remove ( struct ade7816_desc desc)

Free the resources allocated during init.

Parameters
desc- device descriptor for the ADE7816 that will be initialized.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_rms_to_micro()

int ade7816_rms_to_micro ( struct ade7816_desc desc,
enum ade7816_channel  chan,
uint32_t  rms,
uint32_t *  micro 
)

ADE7816 root mean square measurement value conversion to microunits function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
rms- RMS value.
micro- RMs value in microunits.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_set_active_thr()

int ade7816_set_active_thr ( struct ade7816_desc desc,
uint16_t  freq 
)

ADE7816 set active energy threshold value function.

Parameters
desc- ADE7816 device descriptor.
freq- Update rate frequency.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_set_comm()

int ade7816_set_comm ( struct ade7816_desc desc,
enum ade7816_comm_type  type 
)

ADE7816 set communication function.

Parameters
desc- ADE7816 device descriptor
type- Communication type.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_set_gain()

int ade7816_set_gain ( struct ade7816_desc desc,
enum ade7816_channel  chan,
int16_t  scale,
enum ade7816_gain_type  gain 
)

ADE7816 set gain value for channel function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
scale- Scale percentage of full-scale (100.00% = 10000)
gain- Gain type.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_set_interrupt()

int ade7816_set_interrupt ( struct ade7816_desc desc,
enum ade7816_status_int  status_int,
bool  enable 
)

ADE7816 set interrupts function.

Parameters
desc-ADE7816 device descriptor.
status_int- Interrupt selection value.
enable- False = Disable True = Enable
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_set_lcycle_mode()

int ade7816_set_lcycle_mode ( struct ade7816_desc desc,
bool  enable,
uint16_t  cycles,
bool  lenergy 
)

ADE7816 set line cycle mode function.

Parameters
desc- ADE7816 device descriptor.
enable- False = Disable True = Enable
cycles- Cycle lines number.
lenergy- Set lenergy bit.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_set_no_load()

int ade7816_set_no_load ( struct ade7816_desc desc,
uint16_t  voltage,
uint16_t  current,
bool  enable 
)

ADE7816 set no load condition function.

Parameters
desc- ADE7816 device descriptor.
voltage- Voltage percent of the full-scale (100.00% = 10000).
current- Current percent of the full-scale (100.00% = 10000).
enable- False = Disable True = Enable
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_set_offset()

int ade7816_set_offset ( struct ade7816_desc desc,
enum ade7816_channel  chan,
int16_t  scale,
enum ade7816_gain_type  gain 
)

ADE7816 set offset value for channel function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
scale- Scale percentage value (100.00% = 10000)
gain- Gain type.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_set_phase()

int ade7816_set_phase ( struct ade7816_desc desc,
enum ade7816_channel  chan,
enum ade7816_pcf_coeff  pcf_coeff 
)

ADE7816 set phase calibration coefficient function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
pcf_coeff- Phase coefficient value.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_set_reactive_thr()

int ade7816_set_reactive_thr ( struct ade7816_desc desc,
uint16_t  freq 
)

ADE7816 set reactive energy threshold value function.

Parameters
desc- ADE7816 device descriptor.
freq- Update rate frequency.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_sw_reset()

int ade7816_sw_reset ( struct ade7816_desc desc)

ADE7816 software reset function.

Parameters
desc- ADE7816 device descriptor.
Returns
0 in case of succes, negative error code otherwise.

◆ ade7816_write_reg()

int ade7816_write_reg ( struct ade7816_desc desc,
uint16_t  reg,
uint32_t  val 
)

Register write wrapper function.

Parameters
desc- ADE7816 device descriptor
reg- Register Address value.
val- Register Value to be written.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_zx_detect()

int ade7816_zx_detect ( struct ade7816_desc desc,
enum ade7816_channel  chan 
)

ADE7816 zero-crossing detection for channel function.

Parameters
desc- ADE7816 device descriptor.
chan- Channel number.
Returns
0 in case of succes, negative error code otherwise.
Here is the caller graph for this function:

◆ ade7816_zx_timeout()

int ade7816_zx_timeout ( struct ade7816_desc desc,
uint32_t  timeout_us 
)

ADE7816 zero-crossing detection timeout value function.

Parameters
desc- ADE7816 device descriptor.
timeout_us- Timeout value in microseconds.
Returns
0 in case of succes, negative error code otherwise.