no-OS
Classes | Macros | Enumerations | Functions
ade7913.h File Reference

Header file of ADE7913 Driver. More...

#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 dependency graph for ade7913.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ade7913_init_param
 ADE7913 Device initialization parameters. More...
 
struct  ade7913_dev
 ADE7913 Device structure. More...
 

Macros

#define ADE7913_SPI_READ   NO_OS_BIT(2)
 
#define ENABLE   1u
 
#define DISABLE   0u
 
#define ADE7913_REG_IWV   0x00
 
#define ADE7913_REG_V1WV   0x01
 
#define ADE7913_REG_V2WV   0x02
 
#define ADE7913_REG_ADC_CRC   0x04
 
#define ADE7913_REG_CTRL_CRC   0x05
 
#define ADE7913_REG_CNT_SNAPSHOT   0x07
 
#define ADE7913_REG_CONFIG   0x08
 
#define ADE7913_REG_STATUS0   0x09
 
#define ADE7913_REG_LOCK   0x0A
 
#define ADE7913_REG_SYNC_SNAP   0x0B
 
#define ADE7913_REG_COUNTER0   0x0C
 
#define ADE7913_REG_COUNTER1   0x0D
 
#define ADE7913_REG_EMI_CTRL   0x0E
 
#define ADE7913_REG_STATUS1   0x0F
 
#define ADE7913_REG_TEMPOS   0x08
 
#define ADE7913_CNT_VAL_MSK   NO_OS_GENMASK(11, 0)
 
#define ADE7913_CLKOUT_EN_MSK   NO_OS_BIT(0)
 
#define ADE7913_PWRDWN_EN_MSK   NO_OS_BIT(2)
 
#define ADE7913_TEMP_EN_MSK   NO_OS_BIT(3)
 
#define ADE7913_ADC_FREQ_MSK   NO_OS_GENMASK(5, 4)
 
#define ADE7913_SWRST_MSK   NO_OS_BIT(6)
 
#define ADE7913_BW_MSK   NO_OS_BIT(7)
 
#define ADE7913_RESET_ON_MSK   NO_OS_BIT(0)
 
#define ADE7913_CRC_STAT_MSK   NO_OS_BIT(1)
 
#define ADE7913_IC_PROT_MSK   NO_OS_BIT(2)
 
#define ADE7913_LOCK_KEY_MSK   NO_OS_GENMASK(5, 4)
 
#define ADE7913_SYNC_MSK   NO_OS_BIT(0)
 
#define ADE7913_SNAP_MSK   NO_OS_BIT(1)
 
#define ADE7913_SLOT0_MSK   NO_OS_BIT(0)
 
#define ADE7913_SLOT1_MSK   NO_OS_BIT(1)
 
#define ADE7913_SLOT2_MSK   NO_OS_BIT(2)
 
#define ADE7913_SLOT3_MSK   NO_OS_BIT(3)
 
#define ADE7913_SLOT4_MSK   NO_OS_BIT(4)
 
#define ADE7913_SLOT5_MSK   NO_OS_BIT(5)
 
#define ADE7913_SLOT6_MSK   NO_OS_BIT(6)
 
#define ADE7913_SLOT7_MSK   NO_OS_BIT(7)
 
#define ADE7913_VERSION_MSK   NO_OS_GENMASK(2, 0)
 
#define ADE7913_ADC_NA_MSK   NO_OS_BIT(6)
 
#define ADE7913_LOCK_KEY   0XCA
 
#define ADE7913_UNLOCK_KEY   0X9C
 
#define ADE7913_3_CHANNEL_ADE7913   3U
 
#define ADE7913_2_CHANNEL_ADE7912   2U
 
#define ADE7913_VREF_V   (788)
 
#define ADE7913_VREF_I   (49)
 

Enumerations

enum  ade7913_adc_freq_e {
  ADE7913_ADC_FREQ_8KHZ,
  ADE7913_ADC_FREQ_4KHZ,
  ADE7913_ADC_FREQ_2KHZ,
  ADE7913_ADC_FREQ_1KHZ
}
 ADE7913 ADC output frequency. More...
 

Functions

int ade7913_read (struct ade7913_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
 Read device register. More...
 
int ade7913_read_waveforms (struct ade7913_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
 Read multiple devices. More...
 
int ade7913_write (struct ade7913_dev *dev, uint8_t reg_addr, uint8_t reg_data)
 Write device register. More...
 
int ade7913_write_broadcast (struct ade7913_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
 Write broadcast. More...
 
int ade7913_init (struct ade7913_dev **device, struct ade7913_init_param init_param)
 Initialize the device. More...
 
int ade7913_remove (struct ade7913_dev *dev)
 Remove the device and release resources. More...
 
int ade7913_sw_reset (struct ade7913_dev *dev)
 Reset the device using SW reset. More...
 
int ade7913_wr_lock (struct ade7913_dev *dev)
 Lock device. More...
 
int ade7913_wr_unlock (struct ade7913_dev *dev)
 Unlock device. More...
 
int ade7913_get_sync_cnt_val (struct ade7913_dev *dev, uint16_t *counter)
 Get synchronization counter value. More...
 
int ade7913_set_clkout_en (struct ade7913_dev *dev, uint8_t clkout_en)
 Set clkout enable. More...
 
int ade7913_pwrdwn (struct ade7913_dev *dev, uint8_t pwrdwn)
 Power down enable. More...
 
int ade7913_temp_en (struct ade7913_dev *dev, uint8_t temp_en)
 Temperature enable. More...
 
int ade7913_sync_en (struct ade7913_dev *dev)
 Sync enable. More...
 
int ade7913_adc_freq (struct ade7913_dev *dev, enum ade7913_adc_freq_e frequency)
 Set ADC frequency. More...
 
int ade7913_lfp_bw (struct ade7913_dev *dev, uint8_t bw)
 Digital lpf bandwith select. More...
 
int ade7913_crc_status (struct ade7913_dev *dev, uint8_t *status)
 CRC of config registers status. More...
 
int ade7913_ic_prot_status (struct ade7913_dev *dev, uint8_t *status)
 IC config regs protection status. More...
 
int ade7913_emi_ctrl (struct ade7913_dev *dev, uint8_t emi_ctrl)
 Set EMI CTRL register. More...
 
int ade7913_adc_na_status (struct ade7913_dev *dev, uint8_t *status)
 ADC not accesed during one period status. More...
 
int ade7913_cnt_snapshot_val (struct ade7913_dev *dev, uint16_t *val)
 Cnt snapshot. More...
 
int ade7913_get_version_product (struct ade7913_dev *dev, uint8_t *ver_product)
 Get version product value. More...
 

Detailed Description

Header file of ADE7913 Driver.

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

Copyright 2023(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.

Macro Definition Documentation

◆ ADE7913_2_CHANNEL_ADE7912

#define ADE7913_2_CHANNEL_ADE7912   2U

◆ ADE7913_3_CHANNEL_ADE7913

#define ADE7913_3_CHANNEL_ADE7913   3U

◆ ADE7913_ADC_FREQ_MSK

#define ADE7913_ADC_FREQ_MSK   NO_OS_GENMASK(5, 4)

◆ ADE7913_ADC_NA_MSK

#define ADE7913_ADC_NA_MSK   NO_OS_BIT(6)

◆ ADE7913_BW_MSK

#define ADE7913_BW_MSK   NO_OS_BIT(7)

◆ ADE7913_CLKOUT_EN_MSK

#define ADE7913_CLKOUT_EN_MSK   NO_OS_BIT(0)

◆ ADE7913_CNT_VAL_MSK

#define ADE7913_CNT_VAL_MSK   NO_OS_GENMASK(11, 0)

◆ ADE7913_CRC_STAT_MSK

#define ADE7913_CRC_STAT_MSK   NO_OS_BIT(1)

◆ ADE7913_IC_PROT_MSK

#define ADE7913_IC_PROT_MSK   NO_OS_BIT(2)

◆ ADE7913_LOCK_KEY

#define ADE7913_LOCK_KEY   0XCA

◆ ADE7913_LOCK_KEY_MSK

#define ADE7913_LOCK_KEY_MSK   NO_OS_GENMASK(5, 4)

◆ ADE7913_PWRDWN_EN_MSK

#define ADE7913_PWRDWN_EN_MSK   NO_OS_BIT(2)

◆ ADE7913_REG_ADC_CRC

#define ADE7913_REG_ADC_CRC   0x04

◆ ADE7913_REG_CNT_SNAPSHOT

#define ADE7913_REG_CNT_SNAPSHOT   0x07

◆ ADE7913_REG_CONFIG

#define ADE7913_REG_CONFIG   0x08

◆ ADE7913_REG_COUNTER0

#define ADE7913_REG_COUNTER0   0x0C

◆ ADE7913_REG_COUNTER1

#define ADE7913_REG_COUNTER1   0x0D

◆ ADE7913_REG_CTRL_CRC

#define ADE7913_REG_CTRL_CRC   0x05

◆ ADE7913_REG_EMI_CTRL

#define ADE7913_REG_EMI_CTRL   0x0E

◆ ADE7913_REG_IWV

#define ADE7913_REG_IWV   0x00

◆ ADE7913_REG_LOCK

#define ADE7913_REG_LOCK   0x0A

◆ ADE7913_REG_STATUS0

#define ADE7913_REG_STATUS0   0x09

◆ ADE7913_REG_STATUS1

#define ADE7913_REG_STATUS1   0x0F

◆ ADE7913_REG_SYNC_SNAP

#define ADE7913_REG_SYNC_SNAP   0x0B

◆ ADE7913_REG_TEMPOS

#define ADE7913_REG_TEMPOS   0x08

◆ ADE7913_REG_V1WV

#define ADE7913_REG_V1WV   0x01

◆ ADE7913_REG_V2WV

#define ADE7913_REG_V2WV   0x02

◆ ADE7913_RESET_ON_MSK

#define ADE7913_RESET_ON_MSK   NO_OS_BIT(0)

◆ ADE7913_SLOT0_MSK

#define ADE7913_SLOT0_MSK   NO_OS_BIT(0)

◆ ADE7913_SLOT1_MSK

#define ADE7913_SLOT1_MSK   NO_OS_BIT(1)

◆ ADE7913_SLOT2_MSK

#define ADE7913_SLOT2_MSK   NO_OS_BIT(2)

◆ ADE7913_SLOT3_MSK

#define ADE7913_SLOT3_MSK   NO_OS_BIT(3)

◆ ADE7913_SLOT4_MSK

#define ADE7913_SLOT4_MSK   NO_OS_BIT(4)

◆ ADE7913_SLOT5_MSK

#define ADE7913_SLOT5_MSK   NO_OS_BIT(5)

◆ ADE7913_SLOT6_MSK

#define ADE7913_SLOT6_MSK   NO_OS_BIT(6)

◆ ADE7913_SLOT7_MSK

#define ADE7913_SLOT7_MSK   NO_OS_BIT(7)

◆ ADE7913_SNAP_MSK

#define ADE7913_SNAP_MSK   NO_OS_BIT(1)

◆ ADE7913_SPI_READ

#define ADE7913_SPI_READ   NO_OS_BIT(2)

◆ ADE7913_SWRST_MSK

#define ADE7913_SWRST_MSK   NO_OS_BIT(6)

◆ ADE7913_SYNC_MSK

#define ADE7913_SYNC_MSK   NO_OS_BIT(0)

◆ ADE7913_TEMP_EN_MSK

#define ADE7913_TEMP_EN_MSK   NO_OS_BIT(3)

◆ ADE7913_UNLOCK_KEY

#define ADE7913_UNLOCK_KEY   0X9C

◆ ADE7913_VERSION_MSK

#define ADE7913_VERSION_MSK   NO_OS_GENMASK(2, 0)

◆ ADE7913_VREF_I

#define ADE7913_VREF_I   (49)

◆ ADE7913_VREF_V

#define ADE7913_VREF_V   (788)

◆ DISABLE

#define DISABLE   0u

◆ ENABLE

#define ENABLE   1u

Enumeration Type Documentation

◆ ade7913_adc_freq_e

ADE7913 ADC output frequency.

Enumerator
ADE7913_ADC_FREQ_8KHZ 
ADE7913_ADC_FREQ_4KHZ 
ADE7913_ADC_FREQ_2KHZ 
ADE7913_ADC_FREQ_1KHZ 

Function Documentation

◆ ade7913_adc_freq()

int ade7913_adc_freq ( struct ade7913_dev dev,
enum ade7913_adc_freq_e  frequency 
)

Set ADC frequency.

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

◆ ade7913_adc_na_status()

int ade7913_adc_na_status ( struct ade7913_dev dev,
uint8_t *  status 
)

ADC not accesed during one period status.

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

◆ ade7913_cnt_snapshot_val()

int ade7913_cnt_snapshot_val ( struct ade7913_dev dev,
uint16_t *  val 
)

Cnt snapshot.

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

◆ ade7913_crc_status()

int ade7913_crc_status ( struct ade7913_dev dev,
uint8_t *  status 
)

CRC of config registers status.

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

◆ ade7913_emi_ctrl()

int ade7913_emi_ctrl ( struct ade7913_dev dev,
uint8_t  emi_ctrl 
)

Set EMI CTRL register.

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

◆ ade7913_get_sync_cnt_val()

int ade7913_get_sync_cnt_val ( struct ade7913_dev dev,
uint16_t *  counter 
)

Get synchronization counter value.

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

◆ ade7913_get_version_product()

int ade7913_get_version_product ( struct ade7913_dev dev,
uint8_t *  ver_product 
)

Get version product value.

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

◆ ade7913_ic_prot_status()

int ade7913_ic_prot_status ( struct ade7913_dev dev,
uint8_t *  status 
)

IC config regs protection status.

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

◆ ade7913_init()

int ade7913_init ( struct ade7913_dev **  device,
struct ade7913_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:

◆ ade7913_lfp_bw()

int ade7913_lfp_bw ( struct ade7913_dev dev,
uint8_t  bw 
)

Digital lpf bandwith select.

Parameters
dev- The device structure.
bw- 0 - BW = 3.3kHz, 1 - BW = 2kHz (for CLKIN 4.096 MHz and ADC freq 8kHz).
Returns
0 in case of success, negative error code otherwise.

◆ ade7913_pwrdwn()

int ade7913_pwrdwn ( struct ade7913_dev dev,
uint8_t  pwrdwn 
)

Power down enable.

Parameters
dev- The device structure.
pwrdwn- 0 - dc-dc is functional, 1 - dc-dc is turned off.
Returns
0 in case of success, negative error code otherwise.

◆ ade7913_read()

int ade7913_read ( struct ade7913_dev dev,
uint8_t  reg_addr,
uint8_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.
Here is the caller graph for this function:

◆ ade7913_read_waveforms()

int ade7913_read_waveforms ( struct ade7913_dev dev,
uint8_t  reg_addr,
uint8_t *  reg_data 
)

Read multiple devices.

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.
Here is the caller graph for this function:

◆ ade7913_remove()

int ade7913_remove ( struct ade7913_dev dev)

Remove the device and release resources.

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

◆ ade7913_set_clkout_en()

int ade7913_set_clkout_en ( struct ade7913_dev dev,
uint8_t  clkout_en 
)

Set clkout enable.

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

◆ ade7913_sw_reset()

int ade7913_sw_reset ( struct ade7913_dev dev)

Reset the device using SW reset.

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

◆ ade7913_sync_en()

int ade7913_sync_en ( struct ade7913_dev dev)

Sync enable.

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

◆ ade7913_temp_en()

int ade7913_temp_en ( struct ade7913_dev dev,
uint8_t  temp_en 
)

Temperature enable.

Parameters
dev- The device structure.
temp_en- 0 - voltage V2P V2M measured, 1 - internal temperature sensor measured .
Returns
0 in case of success, negative error code otherwise.

◆ ade7913_wr_lock()

int ade7913_wr_lock ( struct ade7913_dev dev)

Lock device.

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

◆ ade7913_wr_unlock()

int ade7913_wr_unlock ( struct ade7913_dev dev)

Unlock device.

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

◆ ade7913_write()

int ade7913_write ( struct ade7913_dev dev,
uint8_t  reg_addr,
uint8_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:

◆ ade7913_write_broadcast()

int ade7913_write_broadcast ( struct ade7913_dev dev,
uint8_t  reg_addr,
uint8_t *  reg_data 
)

Write broadcast.

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: