Adding Instrumentation to Target Software for Microcontroller Energy Analysis

Instrumentation needs to be added to your application code to allow energy analysis for microcontrollers to monitor power consumption and machine state. The instrumentation calls log events and time stamps to a memory buffer. These events are later moved off of the system via the JTAG port and processed on the host system.

Annotations are implemented via the SOC_WATCH_LOG_EVENT() macro, which takes the event identifier and a value as arguments. The event identifier specifies the type of event being logged (halt, sleep, interrupt, or register read). The value parameter provides details about the event, such as identifying which register was read or which interrupt occurred.

All instrumentation for HALT, SLEEP, and register reads and writes that change the state of the SOC (such as clock frequency changes) are instrumented in QMSI software. Applications that use the QMSI APIs for power and frequency transitions have the tracing available by default. The only instrumentation that needs to be added by the application is the Interrupt Service Routine (ISR) to trace the wake-up sources.

SOC_WATCH_LOG_EVENT() is conditionally compiled based upon the definition of the SOC_WATCH_ENABLE identifier in the build. When SOC_WATCH_ENABLE=1 is specified on the make command line, the event log calls are built into the application and into QMSI. If SOC_WATCH_ENABLE is not set to 1 during the build, then the macros are not included and they do not add code to your application.

Use the following steps to instrument your code:

  1. At the top of the file, add the following header file inclusion: #include "soc_watch.h"

  2. Add the appropriate Interrupt instrumentation.

    On Intel® Quark™ microprocessors, wake-ups always occur from interrupts. Energy analysis needs to know when the system wakes up from a sleep state as the result of a wakeup-causing interrupt. Add interrupt annotations to all ISRs that can cause wake-ups. Interrupts that do not cause wake-ups do not need to be annotated. The value parameter for interrupt annotations should specify the interrupt vector. Interrupt annotations should be placed as early in an ISR as possible. This minimizes the amount of time the system is running without a corresponding wake-up event being logged.

    void rtc_isr(void)
                            /* Log event and reschedule next tick. */
                                             (QM_RTC[QM_RTC_0].rtc_ccvr +
                                              (QM_RTC_ALARM_SECOND / 2)));
  3. Compile the project.

    Using Eclipse:

    1. Right-click the project and select Properties or select the project and press ALT+ENTER.
    2. Select the C/C++ Build option from the Properties window.
    3. Switch to the Builder Settings tab.
    4. Unselect the option for Use default build command and change the Build command to make SOC_WATCH_ENABLE=1.
    5. Click OK.
    6. Rebuild the project to enable energy analysis.

    From a command prompt, run the appropriate make command with SOC_WATCH_ENABLE=1 appended.

For more complete information about compiler optimizations, see our Optimization Notice.