no-OS
afe_config.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * @file afe_config.h
3  * @brief Analog frontend header file
4  * @author Robert Budai (robert.budai@analog.com)
5  ********************************************************************************
6  * Copyright (c) 2024 Analog Devices, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  * - Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * - Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  * - Neither the name of Analog Devices, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  * - The use of this software may or may not infringe the patent rights
22  * of one or more patent holders. This license does not release you
23  * from the requirement that you obtain separate licenses from these
24  * patent holders to use this software.
25  * - Use of the software either in source or binary form, must be run
26  * on or directly connected to an Analog Devices Inc. component.
27  *
28  * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31  * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33  * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *******************************************************************************/
39 
40 #ifndef __AFE_CONFIG_H__
41 #define __AFE_CONFIG_H__
42 
43 /******************************************************************************/
44 /***************************** Include Files **********************************/
45 /******************************************************************************/
46 
47 #include "ade9430.h"
48 #include "adi_pqlib.h"
49 #include "common_data.h"
50 #include "no_os_util.h"
51 #include "status.h"
52 #include <stdint.h>
53 #include <string.h>
54 
55 /******************************************************************************/
56 /********************** Macros and Constants Definitions **********************/
57 /******************************************************************************/
58 
60 #define BITM_WFB_CFG_BURST_ALL_CHAN 0x00000000
61 
62 #define BITM_WFB_CFG_WF_CAP_RESAMPLED_SEL 0x00000000
63 
64 #define REG_WAVEFORM_FIRST_HALF_ADDRESS 0x801
65 
66 #define REG_WAVEFORM_SECOND_HALF_ADDRESS 0xC01
67 
68 #define BITM_ACCMODE_SELFREQ_50HZ 0x0
69 
70 #define BITM_ACCMODE_SELFREQ_60HZ 0x0100
71 
72 #define BITM_FREQ_VCONSEL_ICONSEL 0xFE0F
73 
74 #define BITM_CONFIG0_PERIOD_AVG_CFG_AV8 0x00010000
75 
76 #define BITM_CONFIG0_PERIOD_AVG_CFG_AV16 0x00020000
77 
78 #define LP_SEL_APERIOD 0x0000
79 
80 #define LP_SEL_BPERIOD 0x0008
81 
82 #define LP_SEL_CPERIOD 0x0010
83 
84 #define ZX_SEL_ZXVA 0x0000
85 
86 #define ZX_SEL_ZXVB 0x0002
87 
88 #define ZX_SEL_ZXVC 0x0004
89 
90 #define SPI_TIMEOUT 100
91 
92 typedef uint32_t AFE_OUTPUT_STATUS;
94 #define SPI_HEADER_SIZE 2
95 
96 #define MAX_SPI_DATA_SIZE 4
97 
98 #define SPI_16BIT_DATA_SIZE 2
99 
100 #define SPI_32BIT_DATA_SIZE 4
101 
102 #define MAX_SPI_BUFFER_SIZE SPI_HEADER_SIZE + MAX_SPI_DATA_SIZE
103 
108 typedef enum {
113 
114 /******************************************************************************/
115 /************************ Functions Definitions *******************************/
116 /******************************************************************************/
117 
122 int spi_device_init(void);
123 
130 int config_wfb(void);
131 
135 int reset_afe(void);
136 
142 int afe_start(void);
143 
149 int afe_init(void);
150 
158 int afe_read_waveform(uint16_t *pData, uint16_t numSamples);
159 
168 int afe_read_period(uint32_t *pPeriod, uint16_t numPeriods);
169 
177 int afe_read_rms_one(uint32_t *pRMS, uint16_t numRMS);
178 
186 int afe_read_rms_1012(uint32_t *pRMS, uint16_t numRMS);
187 
196 int afe_read_angle(uint16_t *pAngle, uint16_t numAngles,
197  uint16_t angleVolCur);
198 
205 int afe_read_status_1(uint32_t *pSTATUS1);
206 
213 int afe_read_status0(uint32_t *pSTATUS0);
214 
219 void afe_wait_settling(uint32_t cycles);
220 
227 int afe_read_version(uint32_t *pVersion);
228 
234 int config_afe_irq(void);
235 
244 int afe_set_acc_mode(uint16_t frequency, uint16_t vconsel,
245  uint16_t iconsel);
246 
253 int afe_set_ref_channel(uint16_t refChannel);
262 int afe_read_32bit_buff(uint16_t addr, uint16_t numSamples,
263  uint32_t *pData);
264 
273 int afe_read_16bit_buff(uint16_t addr, uint16_t numSamples,
274  uint16_t *pData);
281 int afe_write_32bit_reg(uint16_t addr, uint32_t *pData);
282 
289 int afe_write_16bit_reg(uint16_t addr, uint16_t *pData);
290 
291 #endif /* __AFE_CONFIG_H__ */
no_os_memswap64
void no_os_memswap64(void *buf, uint32_t bytes, uint32_t step)
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:85
SYS_STATUS_AFE_READWAVEFORM_FAILED
#define SYS_STATUS_AFE_READWAVEFORM_FAILED
Definition: status.h:60
afe_read_angle
int afe_read_angle(uint16_t *pAngle, uint16_t numAngles, uint16_t angleVolCur)
reads angle registers.
Definition: afe_config.c:270
LP_SEL_APERIOD
#define LP_SEL_APERIOD
Definition: afe_config.h:78
ade9430.h
Header file of ADE9430 Driver.
afe_read_status_1
int afe_read_status_1(uint32_t *pSTATUS1)
Read STATUS1 register.
Definition: afe_config.c:289
SYS_STATUS_AFE_READRMSONE_FAILED
#define SYS_STATUS_AFE_READRMSONE_FAILED
Definition: status.h:62
BITM_FREQ_VCONSEL_ICONSEL
#define BITM_FREQ_VCONSEL_ICONSEL
Definition: afe_config.h:72
no_os_spi_write_and_read
int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: no_os_spi.c:165
afe_read_status_1
int afe_read_status_1(uint32_t *pSTATUS1)
Read STATUS1 register.
Definition: afe_config.c:289
afe_write_16bit_reg
int afe_write_16bit_reg(uint16_t addr, uint16_t *pData)
write the 16bit value to the register
Definition: afe_config.c:333
afe_set_ref_channel
int afe_set_ref_channel(uint16_t refChannel)
sets refChannel.
Definition: afe_config.c:495
afe_read_rms_1012
int afe_read_rms_1012(uint32_t *pRMS, uint16_t numRMS)
reads rms1012value registers.
Definition: afe_config.c:260
SYS_STATUS_AFE_READVERSION_FAILED
#define SYS_STATUS_AFE_READVERSION_FAILED
Definition: status.h:65
SYS_STATUS_AFE_MASK0_FAILED
#define SYS_STATUS_AFE_MASK0_FAILED
Definition: status.h:57
afe_write_16bit_reg
int afe_write_16bit_reg(uint16_t addr, uint16_t *pData)
write the 16bit value to the register
Definition: afe_config.c:333
AFE_SPI_STATUS_DMA_COMPLETED
@ AFE_SPI_STATUS_DMA_COMPLETED
Definition: afe_config.h:111
no_os_spi_msg
Definition: no_os_spi.h:91
BITM_ACCMODE_SELFREQ_50HZ
#define BITM_ACCMODE_SELFREQ_50HZ
Definition: afe_config.h:68
AFE_OUTPUT_STATUS
uint32_t AFE_OUTPUT_STATUS
Definition: afe_config.h:92
config_afe_irq
int config_afe_irq(void)
Configures IRQ flags.
Definition: afe_config.c:165
afe_read_16bit_buff
int afe_read_16bit_buff(uint16_t addr, uint16_t numSamples, uint16_t *pData)
reads the 16bit value from the register and saves to a 16bitbuffer.
Definition: afe_config.c:371
afe_read_version
int afe_read_version(uint32_t *pVersion)
reads AFE version.
Definition: afe_config.c:305
afe_read_waveform
int afe_read_waveform(uint16_t *pData, uint16_t numSamples)
reads waveform buffer.
Definition: afe_config.c:213
SYS_STATUS_AFE_CONFIG2_FAILED
#define SYS_STATUS_AFE_CONFIG2_FAILED
Definition: status.h:54
SPI_16BIT_DATA_SIZE
#define SPI_16BIT_DATA_SIZE
Definition: afe_config.h:98
SYS_STATUS_AFE_READANGLE_FAILED
#define SYS_STATUS_AFE_READANGLE_FAILED
Definition: status.h:64
reset_afe
int reset_afe(void)
resets the AFE
Definition: afe_config.c:391
config_wfb
int config_wfb(void)
configure WFB_CFB register, initialized with start filling
Definition: afe_config.c:180
AFE_SPI_STATUS_DMA_RUNNING
@ AFE_SPI_STATUS_DMA_RUNNING
Definition: afe_config.h:110
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:132
SYS_STATUS_SUCCESS
#define SYS_STATUS_SUCCESS
Definition: status.h:47
BITM_ACCMODE_SELFREQ_60HZ
#define BITM_ACCMODE_SELFREQ_60HZ
Definition: afe_config.h:70
afe_start
int afe_start(void)
Starts the AFE.
Definition: afe_config.c:137
SYS_STATUS_AFE_RUN_FAILED
#define SYS_STATUS_AFE_RUN_FAILED
Definition: status.h:58
afe_read_16bit_buff
int afe_read_16bit_buff(uint16_t addr, uint16_t numSamples, uint16_t *pData)
reads the 16bit value from the register and saves to a 16bitbuffer.
Definition: afe_config.c:371
afe_read_rms_one
int afe_read_rms_one(uint32_t *pRMS, uint16_t numRMS)
reads rmsonevalue registers.
Definition: afe_config.c:250
hSPI
struct no_os_spi_desc * hSPI
Definition: afe_config.c:51
SYS_STATUS_AFE_WFB_CFG_FAILED
#define SYS_STATUS_AFE_WFB_CFG_FAILED
Definition: status.h:59
SYS_STATUS_AFE_STATUS0_FAILED
#define SYS_STATUS_AFE_STATUS0_FAILED
Definition: status.h:67
SYS_STATUS_AFE_READRMS1012_FAILED
#define SYS_STATUS_AFE_READRMS1012_FAILED
Definition: status.h:61
AFE_SPI_STATUS
AFE_SPI_STATUS
Definition: afe_config.h:108
REG_WAVEFORM_SECOND_HALF_ADDRESS
#define REG_WAVEFORM_SECOND_HALF_ADDRESS
Definition: afe_config.h:66
afe_init
int afe_init(void)
Initializes SPI handler, AFE register values.
Definition: afe_config.c:59
afe_read_period
int afe_read_period(uint32_t *pPeriod, uint16_t numPeriods)
reads period registers.
Definition: afe_config.c:237
afe_start
int afe_start(void)
Starts the AFE.
Definition: afe_config.c:137
no_os_gpio_remove
int32_t no_os_gpio_remove(struct no_os_gpio_desc *desc)
Free the resources allocated by no_os_gpio_get().
Definition: no_os_gpio.c:110
config_wfb
int config_wfb(void)
configure WFB_CFB register, initialized with start filling
Definition: afe_config.c:180
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:177
ZX_SEL_ZXVA
#define ZX_SEL_ZXVA
Definition: afe_config.h:84
spiMsg
struct no_os_spi_msg spiMsg
Definition: afe_config.c:52
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:102
SYS_STATUS_PQLIB_CONFIG_ERROR
#define SYS_STATUS_PQLIB_CONFIG_ERROR
Definition: status.h:51
REG_CONFIG0
#define REG_CONFIG0
Definition: ad9361.h:213
SPI_32BIT_DATA_SIZE
#define SPI_32BIT_DATA_SIZE
Definition: afe_config.h:100
SYS_STATUS_AFE_ZX_LP_SEL_FAILED
#define SYS_STATUS_AFE_ZX_LP_SEL_FAILED
Definition: status.h:56
BITM_WFB_CFG_BURST_ALL_CHAN
#define BITM_WFB_CFG_BURST_ALL_CHAN
Definition: afe_config.h:60
no_os_gpio_get
int32_t no_os_gpio_get(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Obtain the GPIO decriptor.
Definition: no_os_gpio.c:55
SYS_STATUS_AFE_READPERIOD_FAILED
#define SYS_STATUS_AFE_READPERIOD_FAILED
Definition: status.h:63
afe_init
int afe_init(void)
Initializes SPI handler, AFE register values.
Definition: afe_config.c:59
afe_read_period
int afe_read_period(uint32_t *pPeriod, uint16_t numPeriods)
reads period registers.
Definition: afe_config.c:237
LP_SEL_BPERIOD
#define LP_SEL_BPERIOD
Definition: afe_config.h:80
BITM_CONFIG0_PERIOD_AVG_CFG_AV16
#define BITM_CONFIG0_PERIOD_AVG_CFG_AV16
Definition: afe_config.h:76
SYS_STATUS_AFE_STATUS1_FAILED
#define SYS_STATUS_AFE_STATUS1_FAILED
Definition: status.h:66
afe_set_ref_channel
int afe_set_ref_channel(uint16_t refChannel)
sets refChannel.
Definition: afe_config.c:495
REG_WAVEFORM_FIRST_HALF_ADDRESS
#define REG_WAVEFORM_FIRST_HALF_ADDRESS
Definition: afe_config.h:64
SYS_STATUS_AFE_ACCMODE_FAILED
#define SYS_STATUS_AFE_ACCMODE_FAILED
Definition: status.h:55
afe_wait_settling
void afe_wait_settling(uint32_t cycles)
Waits for passed number of cycles.
Definition: afe_config.c:448
no_os_gpio_set_value
int32_t no_os_gpio_set_value(struct no_os_gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
Definition: no_os_gpio.c:203
reset_gpio_ip
struct no_os_gpio_init_param reset_gpio_ip
Definition: common_data.c:140
afe_wait_settling
void afe_wait_settling(uint32_t cycles)
Waits for passed number of cycles.
Definition: afe_config.c:448
config_afe_irq
int config_afe_irq(void)
Configures IRQ flags.
Definition: afe_config.c:165
afe_read_version
int afe_read_version(uint32_t *pVersion)
reads AFE version.
Definition: afe_config.c:305
afe_set_acc_mode
int afe_set_acc_mode(uint16_t frequency, uint16_t vconsel, uint16_t iconsel)
sets ACCMODE register for nominal frequency, ICONSEL, VCONSEL.
Definition: afe_config.c:464
afe_read_waveform
int afe_read_waveform(uint16_t *pData, uint16_t numSamples)
reads waveform buffer.
Definition: afe_config.c:213
afe_read_angle
int afe_read_angle(uint16_t *pAngle, uint16_t numAngles, uint16_t angleVolCur)
reads angle registers.
Definition: afe_config.c:270
BITM_WFB_CFG_WF_CAP_RESAMPLED_SEL
#define BITM_WFB_CFG_WF_CAP_RESAMPLED_SEL
Definition: afe_config.h:62
afe_write_32bit_reg
int afe_write_32bit_reg(uint16_t addr, uint32_t *pData)
write the 32bit value to the register
Definition: afe_config.c:315
AFE_SPI_STATUS_DMA_IDLE
@ AFE_SPI_STATUS_DMA_IDLE
Definition: afe_config.h:109
spi_egy_ip
struct no_os_spi_init_param spi_egy_ip
Definition: common_data.c:130
afe_set_acc_mode
int afe_set_acc_mode(uint16_t frequency, uint16_t vconsel, uint16_t iconsel)
sets ACCMODE register for nominal frequency, ICONSEL, VCONSEL.
Definition: afe_config.c:464
ZX_SEL_ZXVC
#define ZX_SEL_ZXVC
Definition: afe_config.h:88
no_os_spi_init
int32_t no_os_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: no_os_spi.c:58
afe_config.h
afe_read_rms_one
int afe_read_rms_one(uint32_t *pRMS, uint16_t numRMS)
reads rmsonevalue registers.
Definition: afe_config.c:250
reset_afe
int reset_afe(void)
resets the AFE
Definition: afe_config.c:391
no_os_util.h
Header file of utility functions.
afe_read_rms_1012
int afe_read_rms_1012(uint32_t *pRMS, uint16_t numRMS)
reads rms1012value registers.
Definition: afe_config.c:260
afe_read_32bit_buff
int afe_read_32bit_buff(uint16_t addr, uint16_t numSamples, uint32_t *pData)
reads the 32bit value from the register and saves to a 32bit buffer.
Definition: afe_config.c:351
no_os_gpio_direction_output
int32_t no_os_gpio_direction_output(struct no_os_gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
Definition: no_os_gpio.c:153
common_data.h
afe_read_status0
int afe_read_status0(uint32_t *pSTATUS0)
Read STATUS0 register.
Definition: afe_config.c:422
spi_device_init
int spi_device_init(void)
SPI Initialization Function.
Definition: afe_config.c:417
LP_SEL_CPERIOD
#define LP_SEL_CPERIOD
Definition: afe_config.h:82
status.h
SYS_STATUS_AFE_CONFIG1_FAILED
#define SYS_STATUS_AFE_CONFIG1_FAILED
Definition: status.h:53
SYS_STATUS_AFE_CONFIG0_FAILED
#define SYS_STATUS_AFE_CONFIG0_FAILED
Definition: status.h:52
afe_write_32bit_reg
int afe_write_32bit_reg(uint16_t addr, uint32_t *pData)
write the 32bit value to the register
Definition: afe_config.c:315
init_interrupt
int init_interrupt(void)
Initialize interrupt from ade9430 for STATUS polling.
Definition: intrpt_handler.c:64
afe_read_32bit_buff
int afe_read_32bit_buff(uint16_t addr, uint16_t numSamples, uint32_t *pData)
reads the 32bit value from the register and saves to a 32bit buffer.
Definition: afe_config.c:351
ZX_SEL_ZXVB
#define ZX_SEL_ZXVB
Definition: afe_config.h:86
rmsOneReady
volatile uint8_t rmsOneReady
Definition: afe_config.c:50
afe_read_status0
int afe_read_status0(uint32_t *pSTATUS0)
Read STATUS0 register.
Definition: afe_config.c:422
spi_device_init
int spi_device_init(void)
SPI Initialization Function.
Definition: afe_config.c:417