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

Implementation of ADE9039 Driver. More...

#include <stdlib.h>
#include <errno.h>
#include "ade9039.h"
#include "no_os_delay.h"
#include "no_os_units.h"
#include "no_os_alloc.h"
Include dependency graph for ade9039.c:

Functions

int ade9039_read (struct ade9039_dev *dev, uint16_t reg_addr, uint32_t *reg_data)
 Read device register.
 
int ade9039_write (struct ade9039_dev *dev, uint16_t reg_addr, uint32_t reg_data)
 Write device register.
 
int ade9039_set_power_mode (struct ade9039_dev *dev)
 Set power mode.
 
int ade9039_update_bits (struct ade9039_dev *dev, uint16_t reg_addr, uint32_t mask, uint32_t reg_data)
 Update specific register bits.
 
int ade9039_get_int_status0 (struct ade9039_dev *dev, uint32_t msk, uint8_t *status)
 Get interrupt indicator from STATUS0 register.
 
int ade9039_read_rms_ph (struct ade9039_dev *dev, enum ade9039_phase phase)
 Read the rms values for a specific phase.
 
int ade9039_read_power_ph (struct ade9039_dev *dev, enum ade9039_phase phase)
 Read the power values for a specific phase.
 
int ade9039_read_energy_ph (struct ade9039_dev *dev, enum ade9039_phase phase)
 Read the energy values for a specific phase.
 
int ade9039_read_power_factor_ph (struct ade9039_dev *dev, enum ade9039_phase phase)
 Read the power factor values for a specific phase.
 
int ade9039_set_egy_model (struct ade9039_dev *dev, enum ade9039_egy_model model, uint16_t value)
 Set User Energy use model.
 
int ade9039_init (struct ade9039_dev **device, struct ade9039_init_param init_param)
 Initialize the device.
 
int ade9039_setup (struct ade9039_dev *dev)
 Setup the device.
 
int ade9039_read_temp (struct ade9039_dev *dev)
 Read the ADE9039 temperature using the conversion ready status.
 
int ade9039_remove (struct ade9039_dev *dev)
 Remove the device and release resources.
 
int ade9039_check_bit_status (struct ade9039_dev *dev, uint16_t reg_addr, uint32_t bit_mask, uint8_t *status)
 Check bit status of a register.
 

Detailed Description

Implementation of ADE9039 Driver.

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

Copyright 2026(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ ade9039_check_bit_status()

int ade9039_check_bit_status ( struct ade9039_dev * dev,
uint16_t reg_addr,
uint32_t bit_mask,
uint8_t * status )

Check bit status of a register.

Parameters
dev- The device structure.
reg_addr- The register address.
bit_mask- The bit mask to check.
status- The status of the bit (1 if set, 0 if not).
Returns
0 in case of success, negative error code otherwise.

◆ ade9039_get_int_status0()

int ade9039_get_int_status0 ( struct ade9039_dev * dev,
uint32_t msk,
uint8_t * status )

Get interrupt indicator from STATUS0 register.

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

◆ ade9039_init()

int ade9039_init ( struct ade9039_dev ** device,
struct ade9039_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.

◆ ade9039_read()

int ade9039_read ( struct ade9039_dev * dev,
uint16_t reg_addr,
uint32_t * reg_data )

Read device register.

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

◆ ade9039_read_energy_ph()

int ade9039_read_energy_ph ( struct ade9039_dev * dev,
enum ade9039_phase phase )

Read the energy values for a specific phase.

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

◆ ade9039_read_power_factor_ph()

int ade9039_read_power_factor_ph ( struct ade9039_dev * dev,
enum ade9039_phase phase )

Read the power factor values for a specific phase.

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

◆ ade9039_read_power_ph()

int ade9039_read_power_ph ( struct ade9039_dev * dev,
enum ade9039_phase phase )

Read the power values for a specific phase.

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

◆ ade9039_read_rms_ph()

int ade9039_read_rms_ph ( struct ade9039_dev * dev,
enum ade9039_phase phase )

Read the rms values for a specific phase.

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

◆ ade9039_read_temp()

int ade9039_read_temp ( struct ade9039_dev * dev)

Read the ADE9039 temperature using the conversion ready status.

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

◆ ade9039_remove()

int ade9039_remove ( struct ade9039_dev * dev)

Remove the device and release resources.

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

◆ ade9039_set_egy_model()

int ade9039_set_egy_model ( struct ade9039_dev * dev,
enum ade9039_egy_model model,
uint16_t value )

Set User Energy use model.

Parameters
dev- The device structure.
model- The User Energy use model to be set.
value- value specific to the user energy use model, it can be either 1 for reading with reset, number of half line cycles or number of samples.
Returns
0 in case of success, negative error code otherwise.

◆ ade9039_set_power_mode()

int ade9039_set_power_mode ( struct ade9039_dev * dev)

Set power mode.

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

◆ ade9039_setup()

int ade9039_setup ( struct ade9039_dev * dev)

Setup the device.

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

◆ ade9039_update_bits()

int ade9039_update_bits ( struct ade9039_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.

◆ ade9039_write()

int ade9039_write ( struct ade9039_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.