no-OS
iio_pqm.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * @file iio_pqm.h
3  * @brief IIO pqm interfacing 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 #ifndef __IIO_PQM_H__
34 #define __IIO_PQM_H__
35 
36 /******************************************************************************/
37 /***************************** Include Files **********************************/
38 /******************************************************************************/
39 
40 #include "common_data.h"
41 #include "pqlib_afe.h"
42 #include "pqlib_convert.h"
43 #include "pqlib_example.h"
44 #include "status.h"
45 #include <inttypes.h>
46 
47 /******************************************************************************/
48 /********************** Macros and Constants Definitions **********************/
49 /******************************************************************************/
50 
51 // Device specific attributes
52 #define ATTR_U2 0
53 #define ATTR_U0 1
54 #define SNEG_VOLTAGE 2
55 #define SPOS_VOLTAGE 3
56 #define SZRO_VOLTAGE 4
57 #define ATTR_I2 5
58 #define ATTR_I0 6
59 #define SNEG_CURRENT 7
60 #define SPOS_CURRENT 8
61 #define SZRO_CURRENT 9
62 #define NOMINAL_VOLTAGE 10
63 #define VOLTAGE_SCALE 11
64 #define CURRENT_SCALE 12
65 #define I_CONSEL_ENABLE 13
66 #define DIP_THRESHOLD 14
67 #define DIP_HYSTERESIS 15
68 #define SWELL_THRESHOLD 16
69 #define SWELL_HYSTERESIS 17
70 #define INTERP_THRESHOLD 18
71 #define INTERP_HYSTERESIS 19
72 #define RVC_THRESHOLD 20
73 #define RVC_HYSTERESIS 21
74 #define MSV_CARRIER_FREQUENCY 22
75 #define MSV_RECORDING_LENGTH 23
76 #define MSV_THRESHOLD 24
77 #define SAMPLING_FREQUENCY 25
78 #define V_CONSEL 26
79 #define V_CONSEL_AVAILABLE 27
80 #define FLICKER_MODEL 28
81 #define FLICKER_MODEL_AVAILABLE 29
82 #define NOMINAL_FREQUENCY 30
83 #define NOMINAL_FREQUENCY_AVAILABLE 31
84 #define PROCESS_DATA 32
85 #define FW_VERSION_NR 33
86 
87 // Channel specific attributes
88 #define CHAN_RMS 0
89 #define CHAN_ANGLE 1
90 #define CHAN_HARMONICS 2
91 #define CHAN_INTER_HARMONICS 3
92 #define CHAN_SCALE 4
93 #define CHAN_OFFSET 5
94 #define CHAN_THD 6
95 #define CHAN_RAW 7
96 #define CHAN_VOLTAGE_UNDER_DEV 8
97 #define CHAN_VOLTAGE_OVER_DEV 9
98 #define CHAN_VOLTAGE_PINST 10
99 #define CHAN_VOLTAGE_PST 11
100 #define CHAN_VOLTAGE_PLT 12
101 
102 
103 #define RESAMPLED_WAVEFORM_FULL_SCALE 18196
104 
105 extern struct iio_device pqm_iio_descriptor;
106 extern volatile bool configChanged;
107 extern volatile bool processData;
108 
109 #endif
EXAMPLE_CONFIG::msvCarrierFrequency
float msvCarrierFrequency
Definition: pqlib_example.h:114
EXAMPLE_CONFIG::msvThreshold
float msvThreshold
Definition: pqlib_example.h:113
EXAMPLE_CONFIG::dipThreshold
float dipThreshold
Definition: pqlib_example.h:105
write_pqm_attr
int write_pqm_attr(void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t attr_id)
Write a pqm device attribute.
Definition: iio_pqm.c:213
ATTR_U2
#define ATTR_U2
Definition: iio_pqm.h:52
NOMINAL_FREQUENCY
#define NOMINAL_FREQUENCY
Definition: iio_pqm.h:82
NOMINAL_FREQUENCY_AVAILABLE
#define NOMINAL_FREQUENCY_AVAILABLE
Definition: iio_pqm.h:83
END_ATTRIBUTES_ARRAY
#define END_ATTRIBUTES_ARRAY
Definition: iio_types.h:116
MSV_THRESHOLD
#define MSV_THRESHOLD
Definition: iio_pqm.h:76
SZRO_VOLTAGE
#define SZRO_VOLTAGE
Definition: iio_pqm.h:56
PQM_DEVICE_ATTR_NUMBER
#define PQM_DEVICE_ATTR_NUMBER
Definition: common_data.h:69
iio_channel
Struct describing the scan type.
Definition: iio_types.h:168
PQM_VOLTAGE_CHANNEL
#define PQM_VOLTAGE_CHANNEL(_idx, _scan_idx, _name)
Definition: iio_pqm.c:44
scan_type::sign
char sign
Definition: iio_types.h:153
current_pqm_attributes
struct iio_attribute current_pqm_attributes[]
Definition: iio_pqm.c:649
configChanged
volatile bool configChanged
Definition: iio_pqm.c:62
read_pqm_attr
int read_pqm_attr(void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t attr_id)
Read a pqm device attribute.
Definition: iio_pqm.c:105
iio_device_data::dev
void * dev
Definition: iio_types.h:227
pqm_desc::pqm_global_attr
float pqm_global_attr[PQM_DEVICE_ATTR_NUMBER]
Definition: common_data.h:106
pqm_iio_descriptor
struct iio_device pqm_iio_descriptor
Definition: iio_pqm.c:904
CHAN_VOLTAGE_UNDER_DEV
#define CHAN_VOLTAGE_UNDER_DEV
Definition: iio_pqm.h:96
iio_ch_info
Structure holding channel attributess.
Definition: iio_types.h:103
CHAN_VOLTAGE_PINST
#define CHAN_VOLTAGE_PINST
Definition: iio_pqm.h:98
RESAMPLED_WAVEFORM_FULL_SCALE
#define RESAMPLED_WAVEFORM_FULL_SCALE
Definition: iio_pqm.h:103
EXAMPLE_CONFIG::rvcHysteresis
float rvcHysteresis
Definition: pqlib_example.h:112
iio_buffer::bytes_per_scan
uint32_t bytes_per_scan
Definition: iio_types.h:215
PQM_CURRENT_CHANNEL
#define PQM_CURRENT_CHANNEL(_idx, _scan_idx, _name)
Definition: iio_pqm.c:51
pqm_desc
Definition: common_data.h:104
TOTAL_PQM_CHANNELS
#define TOTAL_PQM_CHANNELS
Definition: common_data.h:66
read_samples
int32_t read_samples(struct iio_device_data *dev_data)
function for reading samples from the device.
Definition: iio_pqm.c:529
device
Definition: ad9361_util.h:69
EXAMPLE_CONFIG::intrpHysteresis
float intrpHysteresis
Definition: pqlib_example.h:110
NO_OS_ARRAY_SIZE
#define NO_OS_ARRAY_SIZE(x)
Definition: no_os_util.h:49
PQLIB_EXAMPLE::no_os_cb_desc
struct no_os_circular_buffer * no_os_cb_desc
Definition: pqlib_example.h:154
CHAN_OFFSET
#define CHAN_OFFSET
Definition: iio_pqm.h:93
pqm_trigger_handler
int32_t pqm_trigger_handler(struct iio_device_data *dev_data)
Handles trigger: reads one data-set and writes it to the buffer.
Definition: iio_pqm.c:548
global_pqm_attributes
struct iio_attribute global_pqm_attributes[]
Definition: iio_pqm.c:695
FLICKER_MODEL
#define FLICKER_MODEL
Definition: iio_pqm.h:80
CURRENT_SCALE
#define CURRENT_SCALE
Definition: iio_pqm.h:64
VOLTAGE_CH_NUMBER
#define VOLTAGE_CH_NUMBER
Definition: common_data.h:67
pqlib_convert.h
PQLIB_MAX_INTER_HARMONICS
#define PQLIB_MAX_INTER_HARMONICS
Definition: pqlib_example.h:57
EXAMPLE_CONFIG::swellThreshold
float swellThreshold
Definition: pqlib_example.h:107
pqm_desc::active_ch
uint32_t active_ch
Definition: common_data.h:108
EXAMPLE_CONFIG::intrpThreshold
float intrpThreshold
Definition: pqlib_example.h:109
pqm_desc::pqm_ch_attr
uint32_t pqm_ch_attr[TOTAL_PQM_CHANNELS][MAX_CH_ATTRS]
Definition: common_data.h:107
SAMPLING_FREQUENCY
#define SAMPLING_FREQUENCY
Definition: iio_pqm.h:77
EXAMPLE_CONFIG::rvcThreshold
float rvcThreshold
Definition: pqlib_example.h:111
read_ch_attr
int read_ch_attr(void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t attr_id)
Read a channel attribute.
Definition: iio_pqm.c:330
EXAMPLE_CONFIG::currentScale
float currentScale
Definition: pqlib_example.h:117
pqm_desc::ext_buff_len
uint32_t ext_buff_len
Definition: common_data.h:109
V_CONSEL_AVAILABLE
#define V_CONSEL_AVAILABLE
Definition: iio_pqm.h:79
iio_attribute::name
const char * name
Definition: iio_types.h:131
pqlib_afe.h
pqm_scan_type
struct scan_type pqm_scan_type
Definition: iio_pqm.c:889
iio_buffer::size
uint32_t size
Definition: iio_types.h:213
CHAN_VOLTAGE_OVER_DEV
#define CHAN_VOLTAGE_OVER_DEV
Definition: iio_pqm.h:97
MSV_CARRIER_FREQUENCY
#define MSV_CARRIER_FREQUENCY
Definition: iio_pqm.h:74
RVC_HYSTERESIS
#define RVC_HYSTERESIS
Definition: iio_pqm.h:73
configChanged
volatile bool configChanged
Definition: iio_pqm.c:62
CHAN_VOLTAGE_PST
#define CHAN_VOLTAGE_PST
Definition: iio_pqm.h:99
iio_attribute
Structure holding pointers to show and store functions.
Definition: iio_types.h:129
pqlib_example.h
convert_rms_type
float convert_rms_type(ADI_AFE_RMS_TYPE mag, float scale)
Converts ADI_AFE_RMS_TYPE to voltage/current magnitude.
Definition: pqlib_convert.c:53
pqm_desc::ext_buff
int16_t * ext_buff
Definition: common_data.h:110
FLICKER_MODEL_AVAILABLE
#define FLICKER_MODEL_AVAILABLE
Definition: iio_pqm.h:81
ATTR_I0
#define ATTR_I0
Definition: iio_pqm.h:58
SZRO_CURRENT
#define SZRO_CURRENT
Definition: iio_pqm.h:61
processData
volatile bool processData
Definition: iio_pqm.c:63
iio_buffer::buf
struct no_os_circular_buffer * buf
Definition: iio_types.h:221
IIO_CURRENT
@ IIO_CURRENT
Definition: iio_types.h:66
EXAMPLE_CONFIG::swellHysteresis
float swellHysteresis
Definition: pqlib_example.h:108
IIO_VOLTAGE
@ IIO_VOLTAGE
Definition: iio_types.h:65
SWELL_THRESHOLD
#define SWELL_THRESHOLD
Definition: iio_pqm.h:68
convert_angle_type
ADI_AFE_ANGLE_TYPE convert_angle_type(ADI_AFE_ANGLE_TYPE angleRaw)
Definition: pqlib_convert.c:45
SWELL_HYSTERESIS
#define SWELL_HYSTERESIS
Definition: iio_pqm.h:69
CHAN_SCALE
#define CHAN_SCALE
Definition: iio_pqm.h:92
FW_VERSION
#define FW_VERSION
Definition: common_data.h:58
iio_device_data::buffer
struct iio_buffer * buffer
Definition: iio_types.h:228
iio_pqm.h
I_CONSEL_ENABLE
#define I_CONSEL_ENABLE
Definition: iio_pqm.h:65
FW_VERSION_NR
#define FW_VERSION_NR
Definition: iio_pqm.h:85
voltage_pqm_attributes
struct iio_attribute voltage_pqm_attributes[]
Definition: iio_pqm.c:578
pqlibExample
PQLIB_EXAMPLE pqlibExample
Definition: pqlib_example.c:45
convert_pct_type
float convert_pct_type(ADI_PQLIB_PCT_TYPE val)
Converts ADI_PQLIB_PCT_TYPE to percentage.
Definition: pqlib_convert.c:63
iio_channel::attributes
struct iio_attribute * attributes
Definition: iio_types.h:186
EXAMPLE_CONFIG::msvRecordingLength
float msvRecordingLength
Definition: pqlib_example.h:115
iio_device::num_ch
uint16_t num_ch
Definition: iio_types.h:252
RVC_THRESHOLD
#define RVC_THRESHOLD
Definition: iio_pqm.h:72
CHAN_THD
#define CHAN_THD
Definition: iio_pqm.h:94
update_pqm_channels
int32_t update_pqm_channels(void *dev, uint32_t mask)
active pqm channels
Definition: basic_example.c:78
pqm_iio_descriptor
struct iio_device pqm_iio_descriptor
Definition: iio_pqm.c:904
iio_ch_info::type
enum iio_chan_type type
Definition: iio_types.h:109
SNEG_CURRENT
#define SNEG_CURRENT
Definition: iio_pqm.h:59
NOMINAL_VOLTAGE
#define NOMINAL_VOLTAGE
Definition: iio_pqm.h:62
NULL
#define NULL
Definition: wrapper.h:64
MSV_RECORDING_LENGTH
#define MSV_RECORDING_LENGTH
Definition: iio_pqm.h:75
SNEG_VOLTAGE
#define SNEG_VOLTAGE
Definition: iio_pqm.h:54
EXAMPLE_CONFIG::voltageScale
float voltageScale
Definition: pqlib_example.h:116
iio_ch_info::ch_num
int16_t ch_num
Definition: iio_types.h:105
iio_device
Structure holding channels and attributes of a device.
Definition: iio_types.h:247
close_pqm_channels
int32_t close_pqm_channels(void *dev)
close all channels
Definition: basic_example.c:91
INTERP_THRESHOLD
#define INTERP_THRESHOLD
Definition: iio_pqm.h:70
PQLIB_MAX_HARMONICS
#define PQLIB_MAX_HARMONICS
Definition: pqlib_example.h:56
ATTR_I2
#define ATTR_I2
Definition: iio_pqm.h:57
V_CONSEL
#define V_CONSEL
Definition: iio_pqm.h:78
CHAN_ANGLE
#define CHAN_ANGLE
Definition: iio_pqm.h:89
CHAN_HARMONICS
#define CHAN_HARMONICS
Definition: iio_pqm.h:90
CHAN_VOLTAGE_PLT
#define CHAN_VOLTAGE_PLT
Definition: iio_pqm.h:100
scan_type
Definition: iio_types.h:151
PQLIB_EXAMPLE::exampleConfig
EXAMPLE_CONFIG exampleConfig
Definition: pqlib_example.h:150
CHAN_RAW
#define CHAN_RAW
Definition: iio_pqm.h:95
DIP_HYSTERESIS
#define DIP_HYSTERESIS
Definition: iio_pqm.h:67
EXAMPLE_CONFIG::nominalVoltage
float nominalVoltage
Definition: pqlib_example.h:118
CHAN_RMS
#define CHAN_RMS
Definition: iio_pqm.h:88
iio_device_data
Definition: iio_types.h:226
PQLIB_EXAMPLE::inputCycle
ADI_PQLIB_CYCLE_INPUT inputCycle
Definition: pqlib_example.h:147
PQLIB_EXAMPLE::output
ADI_PQLIB_OUTPUT * output
Definition: pqlib_example.h:151
MAX_CH_ATTRS
#define MAX_CH_ATTRS
Definition: common_data.h:68
VOLTAGE_SCALE
#define VOLTAGE_SCALE
Definition: iio_pqm.h:63
ATTR_U0
#define ATTR_U0
Definition: iio_pqm.h:53
INTERP_HYSTERESIS
#define INTERP_HYSTERESIS
Definition: iio_pqm.h:71
DIP_THRESHOLD
#define DIP_THRESHOLD
Definition: iio_pqm.h:66
common_data.h
SPOS_CURRENT
#define SPOS_CURRENT
Definition: iio_pqm.h:60
PROCESS_DATA
#define PROCESS_DATA
Definition: iio_pqm.h:84
status.h
iio_buffer_push_scan
int iio_buffer_push_scan(struct iio_buffer *buffer, void *data)
Definition: iio.c:1434
processData
volatile bool processData
Definition: iio_pqm.c:63
EXAMPLE_CONFIG::dipHysteresis
float dipHysteresis
Definition: pqlib_example.h:106
SPOS_VOLTAGE
#define SPOS_VOLTAGE
Definition: iio_pqm.h:55
no_os_cb_read
int32_t no_os_cb_read(struct no_os_circular_buffer *desc, void *data, uint32_t nb_elements)
CHAN_INTER_HARMONICS
#define CHAN_INTER_HARMONICS
Definition: iio_pqm.h:91