Counter Functions

group group_profile_functions_counter

Functions

void Cy_Profile_ClearConfiguration(void)

Clears all counter configurations and sets all counters and overflow counters to 0.

Calls Cy_Profile_ClearCounters() to clear counter registers.

Function Usage


    /* Scenario: A new profiling session with a different set of counter
                 configurations need to be allocated. */
    
    /* List of handles for allocated counters */
    cy_stc_profile_ctr_ptr_t cntHandle[PROFILE_PRFL_CNT_NR] = {0UL};
    
    uint8_t cntIdx;
    
    /* Disable all the counters */
    for(cntIdx = 0u; cntIdx < PROFILE_PRFL_CNT_NR; cntIdx++)
    {
        if(CY_PROFILE_SUCCESS != Cy_Profile_DisableCounter(cntHandle[cntIdx]))
        {
            /* Insert error handling */
        }
    }
    
    /* Clear all counter configurations */
    Cy_Profile_ClearConfiguration();

__STATIC_INLINE void Cy_Profile_ClearCounters (void)

Clears all hardware counters to 0.

Function Usage


    /* Scenario: A new profiling window needs to be started with the counter
                 values reset to 0. */
    
    /* Stop the profiling window */
    Cy_Profile_StopProfiling();
    
    /* Clear all counters before starting a new profiling window */
    Cy_Profile_ClearCounters();
    
    /* If applicable, clear the overflow bits in the data structure */

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

cy_stc_profile_ctr_ptr_t Cy_Profile_ConfigureCounter(en_ep_mon_sel_t monitor, cy_en_profile_duration_t duration, cy_en_profile_ref_clk_t refClk, uint32_t weight)

Configures and assigns a hardware profile counter to the list of used counters.

This function assigns an available profile counter to a slot in the internal software data structure and returns the handle for that slot location. The data structure is used to keep track of the counter status and to implement a 64-bit profile counter. If no counter slots are available, the function returns a NULL pointer.

Return

A pointer to the counter data structure. NULL if no counter is available.

Function Usage


    /* Scenario: SCB0 bus transfers need to be monitored during a fixed window.
                 The profile interrupt is configured using the sysint driver. 
                 It's handler function is Cy_Profile_ISR(). */
    
    /* List of handles for allocated counters */
    cy_stc_profile_ctr_ptr_t cntHandle[PROFILE_PRFL_CNT_NR] = {0UL};
    
    /* Initialize the energy profiler */
    Cy_Profile_Init();
    Cy_Profile_ClearConfiguration();
    
    /* Configure a profile counter to monitor the SCB0 bus transfer events */
    cntHandle[0] = Cy_Profile_ConfigureCounter(SCB0_MONITOR_AHB,        /* SCB0 bus transfer count */
                                                CY_PROFILE_EVENT,       /* Count number of SCB0 bus transfers */ 
                                                CY_PROFILE_CLK_TIMER,   /* Ignored for "event" counting */
                                                20000UL);               /* Weight of 20000 (example) */
    if(cntHandle[0] == NULL)
    {
        /* Cannot allocate this counter. Check and try again. */
    }
    
    /* Enable the assigned counter */
    (void)Cy_Profile_EnableCounter(cntHandle[0]);
    

Parameters
  • monitor: The monitor source number

  • duration: Events are monitored (0), or duration is monitored (1)

  • refClk: Counter reference clock

  • weight: Weighting factor for the counter value

cy_en_profile_status_t Cy_Profile_FreeCounter(cy_stc_profile_ctr_ptr_t ctrAddr)

Frees up a counter from a previously-assigned monitor source.

Cy_Profile_ConfigureCounter() must have been called for this counter before calling this function.

note

The counter is not disabled by this function.

Return

Status of the operation.

Function Usage


    /* Scenario: A profile counter in position #0 was previously in use. It needs
                 to be reconfigured to monitor the CM0+ active cycles count. */
    
    /* List of handles for allocated counters */
    cy_stc_profile_ctr_ptr_t cntHandle[PROFILE_PRFL_CNT_NR] = {0UL};
    
    /* Free the profile counter in position #0 */
    if(CY_PROFILE_SUCCESS != Cy_Profile_FreeCounter(cntHandle[0]))
    {
        /* Insert error handling */
    }
    
    /* Configure a profile counter to monitor the CM0+ active cycle count events */
    cntHandle[0] = Cy_Profile_ConfigureCounter(CPUSS_MONITOR_CM0,       /* CM0+ active cycle count */
                                                CY_PROFILE_EVENT,       /* Count number of CM0+ active cycles */ 
                                                CY_PROFILE_CLK_TIMER,   /* Ignored for "event" counting */
                                                40000UL);               /* Weight of 40000 (example) */
    

Parameters

cy_en_profile_status_t Cy_Profile_EnableCounter(cy_stc_profile_ctr_ptr_t ctrAddr)

Enables an assigned counter.

Cy_Profile_ConfigureCounter() must have been called for this counter before calling this function.

Return

Status of the operation.

Function Usage


    /* Scenario: A profile counter needs to be configured and enabled to count
                 the number of HFCLK0 cycles in the profiling window. The energy 
                 profiler is initialized and the profile interrupt is configured
                 and enabled. */
    
    /* List of handles for allocated counters */
    cy_stc_profile_ctr_ptr_t cntHandle[PROFILE_PRFL_CNT_NR] = {0UL};
    
    /* Configure a profile counter to count the number of HFCLK0 cycles in the profiling window */
    cntHandle[0] = Cy_Profile_ConfigureCounter(PROFILE_ONE,         /* Constant 1 (always count) */
                                                CY_PROFILE_DURATION,/* Count number of clock cycles */ 
                                                CY_PROFILE_CLK_HF,  /* HFCLK0 */
                                                1UL);               /* Normalization weight of 1 */
    
    if(CY_PROFILE_SUCCESS != Cy_Profile_EnableCounter(cntHandle[0]))
    {
        /* Insert error handling */
    }
    
    /* Start the profiling window when ready. */
    

Parameters

cy_en_profile_status_t Cy_Profile_DisableCounter(cy_stc_profile_ctr_ptr_t ctrAddr)

Disables an assigned counter.

Cy_Profile_ConfigureCounter() must have been called for this counter before calling this function.

Return

Status of the operation.

Function Usage


    /* Scenario: A profile counter assigned to position #0 is no longer needed 
       and can be disabled. */
    
    /* List of handles for allocated counters */
    cy_stc_profile_ctr_ptr_t cntHandle[PROFILE_PRFL_CNT_NR] = {0UL};
    
    /* Disable the profile counter in position #0 */
    if(CY_PROFILE_SUCCESS != Cy_Profile_DisableCounter(cntHandle[0]))
    {
        /* Insert error handling */
    }
    
    /* Free the profile counter in position #0 */
    if(CY_PROFILE_SUCCESS != Cy_Profile_FreeCounter(cntHandle[0]))
    {
        /* Insert error handling */
    }
    

Parameters