# Calculation Functions¶

group group_profile_functions_calculation

Functions

cy_en_profile_status_t Cy_Profile_GetRawCount(cy_stc_profile_ctr_ptr_t ctrAddr, uint64_t *result)

Reports the raw count value for a specified counter.

Function Usage


/* Scenario: The raw count value of profile counter assigned to position #0
in the previous profiling window needs to be read. */

/* List of handles for allocated counters */
cy_stc_profile_ctr_ptr_t cntHandle[PROFILE_PRFL_CNT_NR] = {0UL};

/* Start the profiling window */
Cy_Profile_StartProfiling();

/* Perform some activity... */

/* When ready to read the results of the counter values, stop the profiling window */
Cy_Profile_StopProfiling();

/* Variable for storing the raw count */
uint64_t rawCnt;

/* Get the raw count value of profile counter #0 */
if(CY_PROFILE_SUCCESS != Cy_Profile_GetRawCount(cntHandle[0], &rawCnt))
{
/* Insert error handling */
}



Parameters
• ctrAddr – The handle to the assigned counter, (returned by calling Cy_Profile_ConfigureCounter()).

• result – Output parameter used to write in the result.

Returns

Status of the operation.

cy_en_profile_status_t Cy_Profile_GetWeightedCount(cy_stc_profile_ctr_ptr_t ctrAddr, uint64_t *result)

Reports the count value for a specified counter, multiplied by the weight factor for that counter.

Function Usage


/* Scenario: The weighted count value of the profile counter assigned to
position #0 in the previous profiling window needs to be read. */

/* List of handles for allocated counters */
cy_stc_profile_ctr_ptr_t cntHandle[PROFILE_PRFL_CNT_NR] = {0UL};

/* Start the profiling window */
Cy_Profile_StartProfiling();

/* When ready to read the results of the counter values, stop the profiling window. */
Cy_Profile_StopProfiling();

/* Variable for storing the weighted count */
uint64_t weightedCnt;

/* Get the weighted count value of profile counter #0 */
if(CY_PROFILE_SUCCESS != Cy_Profile_GetWeightedCount(cntHandle[0], &weightedCnt))
{
/* Insert error handling */
}



Parameters
• ctrAddr – The handle to the assigned counter, (returned by calling Cy_Profile_ConfigureCounter()).

• result – Output parameter used to write in the result.

Returns

Status of the operation.

uint64_t Cy_Profile_GetSumWeightedCounts(cy_stc_profile_ctr_ptr_t ptrsArray[], uint32_t numCounters)

Reports the weighted sum result of the first n number of counter count values starting from the specified profile counter data structure base address.

Each count value is multiplied by its weighing factor before the summing operation is performed.

Function Usage


/* Scenario: The weighted average of assigned profile counters in positions
#0 to #5 in the previous profiling window needs to be read. */

/* List of handles for allocated counters */
cy_stc_profile_ctr_ptr_t cntHandle[PROFILE_PRFL_CNT_NR] = {0UL};

/* Start the profiling window */
Cy_Profile_StartProfiling();

/* When ready to read the results of the counter values, stop the profiling window */
Cy_Profile_StopProfiling();

/* Energy limit (example) of a profiling window */
uint64_t energyLimit =  0x00020000UL;

/* Get the weighted average of assigned profile counters in positions #0 to #5 */
uint64_t weightedAvg = Cy_Profile_GetSumWeightedCounts(&cntHandle[0], 6UL);

if(weightedAvg > energyLimit)
{
/* The energy consumption is more than expected for this profiling window.
Take appropriate measures to reduce the energy consumption. */
}



Parameters
• ptrsArray – Base address of the profile counter data structure

• numCounters – Number of measured counters in ptrsArray[]

Returns

The weighted sum of the specified counters