no-OS
Functions | Variables
pqlib_example.c File Reference
#include "pqlib_example.h"
#include "iio_pqm.h"
Include dependency graph for pqlib_example.c:

Functions

int pqm_measurement_init (void)
 Initializes Power Quality Measurement. More...
 
int pqm_start_measurement (bool waitingForSync)
 Starts Power Quality measurement as per configured cycles. More...
 
int pqm_one_cycle (void)
 One complete cycle for IIO callback function. More...
 
int open_pqlib (PQLIB_EXAMPLE *pExample)
 Call adi_pqlib_Open with required buffers. Serves as an example how to call adi_pqlib_Open API. More...
 
int config_measurement (PQLIB_EXAMPLE *pExample)
 Configures AFE and the library . This serves as an example on how to call APIs adi_pqlib_SetConfig and adi_pqlib_SetCorrectionCoefficients. More...
 
int process_and_prepare_output ()
 The function gets AFE input and calls main processing APIs of the library. This also gets the measurement parameter output from the library and displays it on the console. More...
 
int cpy_correction_coeffs (ADI_PQLIB_NOMINAL_FREQUENCY nominalFrequency, ADI_PQLIB_CORR_COEF *pCorrCoef)
 Copies the user provided correction factors to the interface structure. This shows how floating point correction factors can be converted to the format required by adi_pqlib_SetCorrectionCoefficients Requires both current and voltage pointers should be populated. The code assumes numCorrCoef is same for both and if it is less than 40 these are last 'N' coefficients. More...
 
void populate_event_config (EXAMPLE_CONFIG *pExampleConfig)
 Populates event configuration using user configuration Serves as an example on how to convert thresholds and hysteresis to the form required by the API. More...
 
int wait_for_zero_crossing (PQLIB_EXAMPLE *pExample, ADI_PQLIB_RESULT pqlibStatus)
 Looks at the return code from library and checks whether there is a zero crossing timeout. This is only needed for testing. We wanted to know when actual signal comes and start monitoring test output only after a predefined settling time. More...
 
int process_pqlib_error (PQLIB_EXAMPLE *pExample, ADI_PQLIB_RESULT pqlibStatus)
 Prints error message for errors from the library. Serves as an examples on how to handle the errors from the library. More...
 
void set_default_config (EXAMPLE_CONFIG *pConfig)
 Sets default configuration of the example as floating points Note that this function doesn't configure the library or AFE. More...
 
int SyncLibTime (PQLIB_EXAMPLE *pExample, bool checkRtcTime)
 Sets library internal time using RTC time. Serves as an example how to call the APIs. This also syncs the library time to the user provided time. More...
 
void SyncToDip (PQLIB_EXAMPLE *pExample, ADI_PQLIB_RESULT pqlibStatus)
 Sync the time to a dip or interruption event. Serves as an example how to sync to an external time event. More...
 

Variables

PQLIB_EXAMPLE pqlibExample
 
volatile uint8_t newSyncTimeAvailable = 0
 
volatile bool configChanged
 

Function Documentation

◆ config_measurement()

int config_measurement ( PQLIB_EXAMPLE pExample)

Configures AFE and the library . This serves as an example on how to call APIs adi_pqlib_SetConfig and adi_pqlib_SetCorrectionCoefficients.

Parameters
[in]pExample- Pointer to structure for example configurations.
Returns
0 on success 1 on failure
Here is the caller graph for this function:

◆ cpy_correction_coeffs()

int cpy_correction_coeffs ( ADI_PQLIB_NOMINAL_FREQUENCY  nominalFrequency,
ADI_PQLIB_CORR_COEF *  pCorrCoef 
)

Copies the user provided correction factors to the interface structure. This shows how floating point correction factors can be converted to the format required by adi_pqlib_SetCorrectionCoefficients Requires both current and voltage pointers should be populated. The code assumes numCorrCoef is same for both and if it is less than 40 these are last 'N' coefficients.

Parameters
[in]nominalFrequency- structure for nominal frequency
[in]pCorrCoef- pointer to structure for correctionCoefficients
Returns
0 on Success 1 on Copy is not success because both current and voltage correction coefficients are not available.
Here is the caller graph for this function:

◆ open_pqlib()

int open_pqlib ( PQLIB_EXAMPLE pExample)

Call adi_pqlib_Open with required buffers. Serves as an example how to call adi_pqlib_Open API.

Parameters
[in]pExample- Pointer to main example structure.
Here is the caller graph for this function:

◆ populate_event_config()

void populate_event_config ( EXAMPLE_CONFIG pExampleConfig)

Populates event configuration using user configuration Serves as an example on how to convert thresholds and hysteresis to the form required by the API.

Parameters
[in]pExampleConfig- pointer to structure for example configurations.
Here is the caller graph for this function:

◆ pqm_measurement_init()

int pqm_measurement_init ( void  )

Initializes Power Quality Measurement.

Returns
0 on Success 1 on Failure
Here is the caller graph for this function:

◆ pqm_one_cycle()

int pqm_one_cycle ( void  )

One complete cycle for IIO callback function.

Returns
0 - on success, different from 0 otherwise

◆ pqm_start_measurement()

int pqm_start_measurement ( bool  waitingForSync)

Starts Power Quality measurement as per configured cycles.

Parameters
[in]waitingForSync- Flag to indicate whether the code should look for a sync event to synchronize the RTC time.
Returns
0 on Success 1 on Failure
Here is the caller graph for this function:

◆ process_and_prepare_output()

int process_and_prepare_output ( )

The function gets AFE input and calls main processing APIs of the library. This also gets the measurement parameter output from the library and displays it on the console.

This serves as an example for the APIs adi_pqlib_ProcessOneCycle adi_pqlib_ProcessWaveform adi_pqlib_Process1012Cycles adi_pqlib_GetOutputStatus

Returns
0 on Success 1 on Failure
Here is the caller graph for this function:

◆ process_pqlib_error()

int process_pqlib_error ( PQLIB_EXAMPLE pExample,
ADI_PQLIB_RESULT  pqlibStatus 
)

Prints error message for errors from the library. Serves as an examples on how to handle the errors from the library.

Parameters
[in]pExample- Pointer to PQLIB_EXAMPLE structure.
[in]pqlibStatus- return code for the library.
Returns
0 - Error handled successfully. 1 - Fatal error.
Here is the caller graph for this function:

◆ set_default_config()

void set_default_config ( EXAMPLE_CONFIG pConfig)

Sets default configuration of the example as floating points Note that this function doesn't configure the library or AFE.

Parameters
[in]pConfig- Pointer to example configuration structure.
Here is the caller graph for this function:

◆ SyncLibTime()

int SyncLibTime ( PQLIB_EXAMPLE pExample,
bool  checkRtcTime 
)

Sets library internal time using RTC time. Serves as an example how to call the APIs. This also syncs the library time to the user provided time.

Parameters
[in]pExample- Pointer to example structure.
[in]checkRtcTime- Checks RTC time.
Returns
0 on success 1 on failure
Here is the caller graph for this function:

◆ SyncToDip()

void SyncToDip ( PQLIB_EXAMPLE pExample,
ADI_PQLIB_RESULT  pqlibStatus 
)

Sync the time to a dip or interruption event. Serves as an example how to sync to an external time event.

Parameters
[in]pExample- Pointer to example structure.
[in]pqlibStatus- Status from adi_pqlib_ProcessOneCycle.
Here is the caller graph for this function:

◆ wait_for_zero_crossing()

int wait_for_zero_crossing ( PQLIB_EXAMPLE pExample,
ADI_PQLIB_RESULT  pqlibStatus 
)

Looks at the return code from library and checks whether there is a zero crossing timeout. This is only needed for testing. We wanted to know when actual signal comes and start monitoring test output only after a predefined settling time.

Parameters
[in]pExample- Pointer to PQLIB_EXAMPLE structure
[in]pqlibStatus- return code for the library
Returns
SYS_STATUS_NO_SIGNAL - If no signal comes within timeout period SYS_STATUS_PQLIB_RUNNING - We are waiting for zerocrossing SYS_STATUS_SUCCESS -We have received enough zero crossing and good to process 10/12 cycle inputs from the library
Here is the caller graph for this function:

Variable Documentation

◆ configChanged

volatile bool configChanged

◆ newSyncTimeAvailable

volatile uint8_t newSyncTimeAvailable = 0

◆ pqlibExample

PQLIB_EXAMPLE pqlibExample