PSoC 6 Peripheral Driver Library
Profile (Energy Profiler)

General Description

The energy profiler driver is an API for configuring and using the profile hardware block.

The functions and other declarations used in this driver are in cy_profile.h. You can include cy_pdl.h to get access to all functions and declarations in the PDL.

The profile block enables measurement of the signal activity of select peripherals and monitor sources during a measurement window. Using these measurements, you can construct a profile of the energy consumed in the device by scaling the individual peripheral activities with appropriate scaling (weight) factors. This gives the application the ability to monitor the energy consumed by the internal resources with minimal CPU overhead and without external monitoring hardware.


Profile Hardware

The profile hardware consists of a number of profile counters that accept specific triggers for incrementing the count value. This allows the events of the source (such as the number of SCB0 bus accesses or the duration of time the BLE RX radio is active) to be counted during the measurement window. The available monitor sources in the device can be found in the en_ep_mon_sel_t enum in the device configuration file (e.g. psoc62_config.h). These can be sourced to any of the profile counters as triggers. There are two methods of using the monitor sources in a profile counter.

Many of the available monitor sources are suitable for event type monitoring. Using a duration type on these signals may not give valuable information. Review the device TRM for more information on the monitor sources and detail on how they should be used.

Measurement Types

Depending on the item of interest, energy measurement can be performed by using the following methods.

Driver Usage

At the highest level, the energy profiler must perform the following steps to obtain a measurement:

  1. Initialize the profile hardware block.
  2. Initialize the profile interrupt (profile_interrupt_IRQn).
  3. Configure, initialize, and enable the profile counters.
  4. Enable the profile interrupt and start the profiling/measurement window.
  5. Perform run-time reads of the counters (if needed).
  6. Disable the profile interrupt and stop the profiling/measurement window.
  7. Read the counters and gather the results.
  8. Calculate the energy consumption.

Refer to the SysInt driver on the details of configuring the profile hardware interrupt.

The profile interrupt triggers when a counter overflow event is detected on any of the enabled profile counters. A sample interrupt service routine Cy_Profile_ISR() is provided, which can be used to update the internal counter states stored in RAM. Refer to the Configuration Considerations for more information.

Configuration Considerations

Each counter is a 32-bit register that counts either a number of clock cycles, or a number of events. Overflowing the 32-bit register is possible. To address this issue, the driver implements a 32-bit overflow counter. Combined with the 32-bit register, this gives a 64-bit counter for each monitored source.

When an overflow occurs, the profile hardware generates an interrupt. The interrupt is configured using the SysInt driver, where the sample interrupt handler Cy_Profile_ISR() can be used as the ISR. The ISR increments the overflow counter for each profiling counter and clears the interrupt.

More Information

See the profiler chapter of the device technical reference manual (TRM).

MISRA-C Compliance

MISRA Rule Rule Class (Required/Advisory) Rule Description Description of Deviation(s)
12.4 R Right hand operand of '&&' or '||' is an expression with possible side effects. Function-like macros are used to achieve more efficient code.
16.7 A A pointer parameter can be of type 'pointer to const'. The pointer is cast for comparison purposes and thus can't be a const.


VersionChangesReason for Change
1.20.1 Minor documentation updates. Documentation enhancement.
1.20 Updated API function Cy_Profile_GetSumWeightedCounts(). Minor defect fixing: now the function supports the correct number of counters.
1.10 Flattened the organization of the driver source code into the single source directory and the single include directory. Driver library directory-structure simplification.
Added register access layer. Use register access macros instead of direct register access using dereferenced pointers. Makes register access device-independent, so that the PDL does not need to be recompiled for each supported part number.
Added parameter check asserts. Driver defect fix.
1.0 Initial version

API Reference

 Data Structures
 Enumerated Types