no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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#include "ade9430.h"
38#include "adi_pqlib.h"
39#include "common_data.h"
40#include "no_os_util.h"
41#include "status.h"
42#include <stdint.h>
43#include <string.h>
44#include "nhd_c12832a1z.h"
45
47#define BITM_WFB_CFG_BURST_ALL_CHAN 0x00000000
49#define BITM_WFB_CFG_WF_CAP_RESAMPLED_SEL 0x00000000
51#define REG_WAVEFORM_FIRST_HALF_ADDRESS 0x801
53#define REG_WAVEFORM_SECOND_HALF_ADDRESS 0xC01
55#define BITM_ACCMODE_SELFREQ_50HZ 0x0
57#define BITM_ACCMODE_SELFREQ_60HZ 0x0100
59#define BITM_FREQ_VCONSEL_ICONSEL 0xFE0F
61#define BITM_CONFIG0_PERIOD_AVG_CFG_AV8 0x00010000
63#define BITM_CONFIG0_PERIOD_AVG_CFG_AV16 0x00020000
65#define LP_SEL_APERIOD 0x0000
67#define LP_SEL_BPERIOD 0x0008
69#define LP_SEL_CPERIOD 0x0010
71#define ZX_SEL_ZXVA 0x0000
73#define ZX_SEL_ZXVB 0x0002
75#define ZX_SEL_ZXVC 0x0004
77#define SPI_TIMEOUT 100
79typedef uint32_t AFE_OUTPUT_STATUS;
81#define SPI_HEADER_SIZE 2
83#define MAX_SPI_DATA_SIZE 4
85#define SPI_16BIT_DATA_SIZE 2
87#define SPI_32BIT_DATA_SIZE 4
89#define MAX_SPI_BUFFER_SIZE SPI_HEADER_SIZE + MAX_SPI_DATA_SIZE
90
100
106int init_lcd(void);
107
112int spi_device_init(void);
113
120int config_wfb(void);
121
125int reset_afe(void);
126
132int afe_start(void);
133
139int afe_init(void);
140
148int afe_read_waveform(uint16_t *pData, uint16_t numSamples);
149
158int afe_read_period(uint32_t *pPeriod, uint16_t numPeriods);
159
167int afe_read_rms_one(uint32_t *pRMS, uint16_t numRMS);
168
176int afe_read_rms_1012(uint32_t *pRMS, uint16_t numRMS);
177
186int afe_read_angle(uint16_t *pAngle, uint16_t numAngles,
187 uint16_t angleVolCur);
188
195int afe_read_status_1(uint32_t *pSTATUS1);
196
203int afe_read_status0(uint32_t *pSTATUS0);
204
209void afe_wait_settling(uint32_t cycles);
210
217int afe_read_version(uint32_t *pVersion);
218
224int config_afe_irq(void);
225
234int afe_set_acc_mode(uint16_t frequency, uint16_t vconsel,
235 uint16_t iconsel);
236
243int afe_set_ref_channel(uint16_t refChannel);
252int afe_read_32bit_buff(uint16_t addr, uint16_t numSamples,
253 uint32_t *pData);
254
263int afe_read_16bit_buff(uint16_t addr, uint16_t numSamples,
264 uint16_t *pData);
271int afe_write_32bit_reg(uint16_t addr, uint32_t *pData);
272
279int afe_write_16bit_reg(uint16_t addr, uint16_t *pData);
280
281#endif /* __AFE_CONFIG_H__ */
Header file of ADE9430 Driver.
int afe_read_period(uint32_t *pPeriod, uint16_t numPeriods)
reads period registers.
Definition afe_config.c:298
int spi_device_init(void)
SPI Initialization Function.
Definition afe_config.c:478
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:521
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:412
int afe_read_angle(uint16_t *pAngle, uint16_t numAngles, uint16_t angleVolCur)
reads angle registers.
Definition afe_config.c:331
int afe_read_waveform(uint16_t *pData, uint16_t numSamples)
reads waveform buffer.
Definition afe_config.c:274
AFE_SPI_STATUS
Definition afe_config.h:95
@ AFE_SPI_STATUS_DMA_RUNNING
Definition afe_config.h:97
@ AFE_SPI_STATUS_DMA_COMPLETED
Definition afe_config.h:98
@ AFE_SPI_STATUS_DMA_IDLE
Definition afe_config.h:96
int afe_write_32bit_reg(uint16_t addr, uint32_t *pData)
write the 32bit value to the register
Definition afe_config.c:376
uint32_t AFE_OUTPUT_STATUS
Definition afe_config.h:79
int init_lcd(void)
Initialize LCD screen and text.
Definition afe_config.c:40
int afe_read_status_1(uint32_t *pSTATUS1)
Read STATUS1 register.
Definition afe_config.c:350
int config_afe_irq(void)
Configures IRQ flags.
Definition afe_config.c:226
void afe_wait_settling(uint32_t cycles)
Waits for passed number of cycles.
Definition afe_config.c:507
int reset_afe(void)
resets the AFE
Definition afe_config.c:452
int afe_init(void)
Initializes SPI handler, AFE register values.
Definition afe_config.c:121
int afe_read_rms_1012(uint32_t *pRMS, uint16_t numRMS)
reads rms1012value registers.
Definition afe_config.c:321
int afe_set_ref_channel(uint16_t refChannel)
sets refChannel.
Definition afe_config.c:552
int afe_read_rms_one(uint32_t *pRMS, uint16_t numRMS)
reads rmsonevalue registers.
Definition afe_config.c:311
int afe_read_version(uint32_t *pVersion)
reads AFE version.
Definition afe_config.c:366
int config_wfb(void)
configure WFB_CFB register, initialized with start filling
Definition afe_config.c:241
int afe_start(void)
Starts the AFE.
Definition afe_config.c:198
int afe_read_status0(uint32_t *pSTATUS0)
Read STATUS0 register.
Definition afe_config.c:483
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:432
int afe_write_16bit_reg(uint16_t addr, uint16_t *pData)
write the 16bit value to the register
Definition afe_config.c:394
Header file of nhd_c12832a1z.
Header file of utility functions.