Recording Interrupts

From SEGGER Wiki
Jump to: navigation, search

SystemView can record entering and leaving interrupts with instrumented interrupt service routines (ISRs). The SystemView API provides instrumentation functions for these events which can be added directly to the ISRs or to the OS instrumentation when it provides functions to mark interrupt execution.

When the OS scheduler is controlled by interrupts, for example the SysTick interrupt, the exit interrupt event can distinguish between resuming normal execution or switching into the scheduler.

High priority interrupts (Zero latency)

With an OS, such as embOS, which supports zero-latency interrupts, typically not all interrupts are completely disabled, but only up to a medium priority. Higher priority interrupts are not used and controlled by the OS. They can and should only be used for very time critical interrupts requiring zero latency.

SystemView records all events using the RTT layer, which requires all interrupts that could generate events to be disabled. Therefore usually only medium priority interrupts that are controlled by the OS should be instrumented, and the locking routine and priority should be specified using the RTT configuration file SEGGER_RTT_Conf.h.

If high-priority interrupts should be recorded, SystemView and RTT need to be configured to lock these interrupts, too. In this case, the interrupts are high priority, e.g. are not controlled by the OS and cannot be interrupted by OS interrupts, but they are not zero latency anymore, because the are disabled certain times by RTT.

Enter Interrupt

On entering an ISR, SEGGER_SYSVIEW_RecordEnterISR() needs to be called to record interrupt execution.

When an instrumented OS is used, which does the interrupt handling, the function could be added to the OS instrumentation. Otherwise it needs to be added to each ISR that should be recorded.

SEGGER_SYSVIEW_RecordEnterISR() automatically retrieves the interrupt ID via the SEGGER_SYSVIEW_GET_INTERRUPT_ID() function macro as defined in SEGGER_SYSVIEW_Conf.h .

Example

void OS_EnterInterrupt(void) {
  
  [OS specific code ...]
  
  SEGGER_SYSVIEW_RecordEnterISR();
}
void Interrupt_Handler(void) {
  OS_EnterInterrupt();
  
  [ISR Handler code...]
  
  OS_LeaveInterrupt();
}

Leave Interrupt

Before leaving an ISR, SEGGER_SYSVIEW_RecordExitISR() or <codeSEGGER_SYSVIEW_RecordExitISRToScheduler() should be called to record finish of interrupt execution.

When the target system will continue execution where it has been interrupted, a regular Interrupt Exit event is generated with SEGGER_SYSVIEW_RecordExitISR(). When the OS will modify the execution, e.g. to run another task, an Exit to Scheduler event is generated with SEGGER_SYSVIEW_RecordExitISRToScheduler().

Example

void OS_LeaveInterrupt(void) {
  
  [OS specific code ...]
  //
  // If the interrupt will switch to the Scheduler
  //
  SEGGER_SYSVIEW_RecordExitISRToScheduler();
  //
  // Otherwise
  //
  SEGGER_SYSVIEW_RecordExitISR();
}