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  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of Analog Devices, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25  * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *******************************************************************************/
33 
34 #ifndef __AFE_CONFIG_H__
35 #define __AFE_CONFIG_H__
36 
37 /******************************************************************************/
38 /***************************** Include Files **********************************/
39 /******************************************************************************/
40 
41 #include "ade9430.h"
42 #include "adi_pqlib.h"
43 #include "common_data.h"
44 #include "no_os_util.h"
45 #include "status.h"
46 #include <stdint.h>
47 #include <string.h>
48 #include "nhd_c12832a1z.h"
49 
50 /******************************************************************************/
51 /********************** Macros and Constants Definitions **********************/
52 /******************************************************************************/
53 
55 #define BITM_WFB_CFG_BURST_ALL_CHAN 0x00000000
56 
57 #define BITM_WFB_CFG_WF_CAP_RESAMPLED_SEL 0x00000000
58 
59 #define REG_WAVEFORM_FIRST_HALF_ADDRESS 0x801
60 
61 #define REG_WAVEFORM_SECOND_HALF_ADDRESS 0xC01
62 
63 #define BITM_ACCMODE_SELFREQ_50HZ 0x0
64 
65 #define BITM_ACCMODE_SELFREQ_60HZ 0x0100
66 
67 #define BITM_FREQ_VCONSEL_ICONSEL 0xFE0F
68 
69 #define BITM_CONFIG0_PERIOD_AVG_CFG_AV8 0x00010000
70 
71 #define BITM_CONFIG0_PERIOD_AVG_CFG_AV16 0x00020000
72 
73 #define LP_SEL_APERIOD 0x0000
74 
75 #define LP_SEL_BPERIOD 0x0008
76 
77 #define LP_SEL_CPERIOD 0x0010
78 
79 #define ZX_SEL_ZXVA 0x0000
80 
81 #define ZX_SEL_ZXVB 0x0002
82 
83 #define ZX_SEL_ZXVC 0x0004
84 
85 #define SPI_TIMEOUT 100
86 
87 typedef uint32_t AFE_OUTPUT_STATUS;
89 #define SPI_HEADER_SIZE 2
90 
91 #define MAX_SPI_DATA_SIZE 4
92 
93 #define SPI_16BIT_DATA_SIZE 2
94 
95 #define SPI_32BIT_DATA_SIZE 4
96 
97 #define MAX_SPI_BUFFER_SIZE SPI_HEADER_SIZE + MAX_SPI_DATA_SIZE
98 
103 typedef enum {
108 
109 /******************************************************************************/
110 /************************ Functions Definitions *******************************/
111 /******************************************************************************/
112 
118 int init_lcd(void);
119 
124 int spi_device_init(void);
125 
132 int config_wfb(void);
133 
137 int reset_afe(void);
138 
144 int afe_start(void);
145 
151 int afe_init(void);
152 
160 int afe_read_waveform(uint16_t *pData, uint16_t numSamples);
161 
170 int afe_read_period(uint32_t *pPeriod, uint16_t numPeriods);
171 
179 int afe_read_rms_one(uint32_t *pRMS, uint16_t numRMS);
180 
188 int afe_read_rms_1012(uint32_t *pRMS, uint16_t numRMS);
189 
198 int afe_read_angle(uint16_t *pAngle, uint16_t numAngles,
199  uint16_t angleVolCur);
200 
207 int afe_read_status_1(uint32_t *pSTATUS1);
208 
215 int afe_read_status0(uint32_t *pSTATUS0);
216 
221 void afe_wait_settling(uint32_t cycles);
222 
229 int afe_read_version(uint32_t *pVersion);
230 
236 int config_afe_irq(void);
237 
246 int afe_set_acc_mode(uint16_t frequency, uint16_t vconsel,
247  uint16_t iconsel);
248 
255 int afe_set_ref_channel(uint16_t refChannel);
264 int afe_read_32bit_buff(uint16_t addr, uint16_t numSamples,
265  uint32_t *pData);
266 
275 int afe_read_16bit_buff(uint16_t addr, uint16_t numSamples,
276  uint16_t *pData);
283 int afe_write_32bit_reg(uint16_t addr, uint32_t *pData);
284 
291 int afe_write_16bit_reg(uint16_t addr, uint16_t *pData);
292 
293 #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:79
SYS_STATUS_AFE_READWAVEFORM_FAILED
#define SYS_STATUS_AFE_READWAVEFORM_FAILED
Definition: status.h:54
afe_read_angle
int afe_read_angle(uint16_t *pAngle, uint16_t numAngles, uint16_t angleVolCur)
reads angle registers.
Definition: afe_config.c:343
LP_SEL_APERIOD
#define LP_SEL_APERIOD
Definition: afe_config.h:73
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:362
SYS_STATUS_AFE_READRMSONE_FAILED
#define SYS_STATUS_AFE_READRMSONE_FAILED
Definition: status.h:56
BITM_FREQ_VCONSEL_ICONSEL
#define BITM_FREQ_VCONSEL_ICONSEL
Definition: afe_config.h:67
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:159
afe_read_status_1
int afe_read_status_1(uint32_t *pSTATUS1)
Read STATUS1 register.
Definition: afe_config.c:362
nhd_c12832a1z_init_param
nhd_c12832a1z Initialization parameters.
Definition: nhd_c12832a1z.h:99
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:406
nhd_c12832a1z.h
Header file of nhd_c12832a1z.
afe_set_ref_channel
int afe_set_ref_channel(uint16_t refChannel)
sets refChannel.
Definition: afe_config.c:564
afe_read_rms_1012
int afe_read_rms_1012(uint32_t *pRMS, uint16_t numRMS)
reads rms1012value registers.
Definition: afe_config.c:333
SYS_STATUS_AFE_READVERSION_FAILED
#define SYS_STATUS_AFE_READVERSION_FAILED
Definition: status.h:59
SYS_STATUS_AFE_MASK0_FAILED
#define SYS_STATUS_AFE_MASK0_FAILED
Definition: status.h:51
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:406
AFE_SPI_STATUS_DMA_COMPLETED
@ AFE_SPI_STATUS_DMA_COMPLETED
Definition: afe_config.h:106
no_os_spi_msg
Definition: no_os_spi.h:100
SPI_SS_POL_LOW
@ SPI_SS_POL_LOW
Definition: maxim_spi.h:49
BITM_ACCMODE_SELFREQ_50HZ
#define BITM_ACCMODE_SELFREQ_50HZ
Definition: afe_config.h:63
AFE_OUTPUT_STATUS
uint32_t AFE_OUTPUT_STATUS
Definition: afe_config.h:87
config_afe_irq
int config_afe_irq(void)
Configures IRQ flags.
Definition: afe_config.c:238
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:444
no_os_gpio_init_param::port
int32_t port
Definition: no_os_gpio.h:81
afe_read_version
int afe_read_version(uint32_t *pVersion)
reads AFE version.
Definition: afe_config.c:378
afe_read_waveform
int afe_read_waveform(uint16_t *pData, uint16_t numSamples)
reads waveform buffer.
Definition: afe_config.c:286
SYS_STATUS_AFE_CONFIG2_FAILED
#define SYS_STATUS_AFE_CONFIG2_FAILED
Definition: status.h:48
SPI_16BIT_DATA_SIZE
#define SPI_16BIT_DATA_SIZE
Definition: afe_config.h:93
SYS_STATUS_AFE_READANGLE_FAILED
#define SYS_STATUS_AFE_READANGLE_FAILED
Definition: status.h:58
reset_afe
int reset_afe(void)
resets the AFE
Definition: afe_config.c:464
NO_OS_PULL_NONE
@ NO_OS_PULL_NONE
Definition: no_os_gpio.h:66
NO_OS_SPI_MODE_3
@ NO_OS_SPI_MODE_3
Definition: no_os_spi.h:67
config_wfb
int config_wfb(void)
configure WFB_CFB register, initialized with start filling
Definition: afe_config.c:253
no_os_spi_init_param::device_id
uint32_t device_id
Definition: no_os_spi.h:142
AFE_SPI_STATUS_DMA_RUNNING
@ AFE_SPI_STATUS_DMA_RUNNING
Definition: afe_config.h:105
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:126
SYS_STATUS_SUCCESS
#define SYS_STATUS_SUCCESS
Definition: status.h:41
BITM_ACCMODE_SELFREQ_60HZ
#define BITM_ACCMODE_SELFREQ_60HZ
Definition: afe_config.h:65
afe_start
int afe_start(void)
Starts the AFE.
Definition: afe_config.c:210
max_spi_init_param
Maxim specific SPI initialization parameters.
Definition: maxim_spi.h:53
SYS_STATUS_AFE_RUN_FAILED
#define SYS_STATUS_AFE_RUN_FAILED
Definition: status.h:52
nhd_c12832a1z_init_param::spi_ip
struct no_os_spi_init_param * spi_ip
Definition: nhd_c12832a1z.h:105
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:444
afe_read_rms_one
int afe_read_rms_one(uint32_t *pRMS, uint16_t numRMS)
reads rmsonevalue registers.
Definition: afe_config.c:323
hSPI
struct no_os_spi_desc * hSPI
Definition: afe_config.c:44
SYS_STATUS_AFE_WFB_CFG_FAILED
#define SYS_STATUS_AFE_WFB_CFG_FAILED
Definition: status.h:53
SYS_STATUS_AFE_STATUS0_FAILED
#define SYS_STATUS_AFE_STATUS0_FAILED
Definition: status.h:61
SYS_STATUS_AFE_READRMS1012_FAILED
#define SYS_STATUS_AFE_READRMS1012_FAILED
Definition: status.h:55
AFE_SPI_STATUS
AFE_SPI_STATUS
Definition: afe_config.h:103
REG_WAVEFORM_SECOND_HALF_ADDRESS
#define REG_WAVEFORM_SECOND_HALF_ADDRESS
Definition: afe_config.h:61
afe_init
int afe_init(void)
Initializes SPI handler, AFE register values.
Definition: afe_config.c:133
afe_read_period
int afe_read_period(uint32_t *pPeriod, uint16_t numPeriods)
reads period registers.
Definition: afe_config.c:310
afe_start
int afe_start(void)
Starts the AFE.
Definition: afe_config.c:210
max_spi_ops
const struct no_os_spi_platform_ops max_spi_ops
maxim platform specific SPI platform ops structure
Definition: maxim_spi.c:795
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:104
config_wfb
int config_wfb(void)
configure WFB_CFB register, initialized with start filling
Definition: afe_config.c:253
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
ZX_SEL_ZXVA
#define ZX_SEL_ZXVA
Definition: afe_config.h:79
spiMsg
struct no_os_spi_msg spiMsg
Definition: afe_config.c:45
max_gpio_ops
const struct no_os_gpio_platform_ops max_gpio_ops
maxim platform specific GPIO platform ops structure
Definition: maxim_gpio.c:320
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
SYS_STATUS_PQLIB_CONFIG_ERROR
#define SYS_STATUS_PQLIB_CONFIG_ERROR
Definition: status.h:45
REG_CONFIG0
#define REG_CONFIG0
Definition: ad9361.h:207
SPI_32BIT_DATA_SIZE
#define SPI_32BIT_DATA_SIZE
Definition: afe_config.h:95
nhd_c12832a1z_dev
nhd_c12832a1z device structure.
Definition: nhd_c12832a1z.h:86
max_gpio_init_param::vssel
mxc_gpio_vssel_t vssel
Definition: maxim_gpio.h:57
SYS_STATUS_AFE_ZX_LP_SEL_FAILED
#define SYS_STATUS_AFE_ZX_LP_SEL_FAILED
Definition: status.h:50
BITM_WFB_CFG_BURST_ALL_CHAN
#define BITM_WFB_CFG_BURST_ALL_CHAN
Definition: afe_config.h:55
max_gpio_init_param
GPIO platform specific init parameters.
Definition: maxim_gpio.h:55
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:49
nhd_c12832a1z_init
int nhd_c12832a1z_init(struct nhd_c12832a1z_dev **device, struct nhd_c12832a1z_init_param init_param)
Initializes nhd_c12832a1z for display screening.
Definition: nhd_c12832a1z.c:467
SYS_STATUS_AFE_READPERIOD_FAILED
#define SYS_STATUS_AFE_READPERIOD_FAILED
Definition: status.h:57
afe_init
int afe_init(void)
Initializes SPI handler, AFE register values.
Definition: afe_config.c:133
afe_read_period
int afe_read_period(uint32_t *pPeriod, uint16_t numPeriods)
reads period registers.
Definition: afe_config.c:310
LP_SEL_BPERIOD
#define LP_SEL_BPERIOD
Definition: afe_config.h:75
BITM_CONFIG0_PERIOD_AVG_CFG_AV16
#define BITM_CONFIG0_PERIOD_AVG_CFG_AV16
Definition: afe_config.h:71
NO_OS_SPI_BIT_ORDER_MSB_FIRST
@ NO_OS_SPI_BIT_ORDER_MSB_FIRST
Definition: no_os_spi.h:76
SYS_STATUS_AFE_STATUS1_FAILED
#define SYS_STATUS_AFE_STATUS1_FAILED
Definition: status.h:60
nhd_c12832a1z_print_string
int nhd_c12832a1z_print_string(struct nhd_c12832a1z_dev *dev, char *msg)
nhd_c12832a1z print string on LCD.
Definition: nhd_c12832a1z.c:358
afe_set_ref_channel
int afe_set_ref_channel(uint16_t refChannel)
sets refChannel.
Definition: afe_config.c:564
init_lcd
int init_lcd(void)
Initialize LCD screen and text.
Definition: afe_config.c:52
REG_WAVEFORM_FIRST_HALF_ADDRESS
#define REG_WAVEFORM_FIRST_HALF_ADDRESS
Definition: afe_config.h:59
SYS_STATUS_AFE_ACCMODE_FAILED
#define SYS_STATUS_AFE_ACCMODE_FAILED
Definition: status.h:49
afe_wait_settling
void afe_wait_settling(uint32_t cycles)
Waits for passed number of cycles.
Definition: afe_config.c:519
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:197
init_lcd
int init_lcd(void)
Initialize LCD screen and text.
Definition: afe_config.c:52
reset_gpio_ip
struct no_os_gpio_init_param reset_gpio_ip
Definition: common_data.c:226
afe_wait_settling
void afe_wait_settling(uint32_t cycles)
Waits for passed number of cycles.
Definition: afe_config.c:519
config_afe_irq
int config_afe_irq(void)
Configures IRQ flags.
Definition: afe_config.c:238
afe_read_version
int afe_read_version(uint32_t *pVersion)
reads AFE version.
Definition: afe_config.c:378
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:533
afe_read_waveform
int afe_read_waveform(uint16_t *pData, uint16_t numSamples)
reads waveform buffer.
Definition: afe_config.c:286
afe_read_angle
int afe_read_angle(uint16_t *pAngle, uint16_t numAngles, uint16_t angleVolCur)
reads angle registers.
Definition: afe_config.c:343
BITM_WFB_CFG_WF_CAP_RESAMPLED_SEL
#define BITM_WFB_CFG_WF_CAP_RESAMPLED_SEL
Definition: afe_config.h:57
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:388
AFE_SPI_STATUS_DMA_IDLE
@ AFE_SPI_STATUS_DMA_IDLE
Definition: afe_config.h:104
spi_egy_ip
struct no_os_spi_init_param spi_egy_ip
Definition: common_data.c:216
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:533
ZX_SEL_ZXVC
#define ZX_SEL_ZXVC
Definition: afe_config.h:83
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:52
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:323
reset_afe
int reset_afe(void)
resets the AFE
Definition: afe_config.c:464
no_os_util.h
Header file of utility functions.
spi_extra_ip
struct stm32_spi_init_param spi_extra_ip
Definition: parameters.c:138
afe_read_rms_1012
int afe_read_rms_1012(uint32_t *pRMS, uint16_t numRMS)
reads rms1012value registers.
Definition: afe_config.c:333
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:424
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:147
common_data.h
afe_read_status0
int afe_read_status0(uint32_t *pSTATUS0)
Read STATUS0 register.
Definition: afe_config.c:495
spi_device_init
int spi_device_init(void)
SPI Initialization Function.
Definition: afe_config.c:490
LP_SEL_CPERIOD
#define LP_SEL_CPERIOD
Definition: afe_config.h:77
status.h
SYS_STATUS_AFE_CONFIG1_FAILED
#define SYS_STATUS_AFE_CONFIG1_FAILED
Definition: status.h:47
SYS_STATUS_AFE_CONFIG0_FAILED
#define SYS_STATUS_AFE_CONFIG0_FAILED
Definition: status.h:46
gpio_extra_ip
struct xil_gpio_init_param gpio_extra_ip
Definition: parameters.c:63
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:388
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:424
ZX_SEL_ZXVB
#define ZX_SEL_ZXVB
Definition: afe_config.h:81
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140
afe_read_status0
int afe_read_status0(uint32_t *pSTATUS0)
Read STATUS0 register.
Definition: afe_config.c:495
spi_device_init
int spi_device_init(void)
SPI Initialization Function.
Definition: afe_config.c:490