11.07.2015 Views

IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

InterruptsRules for interrupt handlersGENERAL RULESThere are some general rules for interrupt handlers. These rules apply to both single-task programming as well as tomultitask programming using <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong>.●●Interrupt handlers preserve all registers.Interrupt handlers must restore the environment of a task completely. This environment normally consists of theregisters only, so the ISR has to make sure that all registers modified during interrupt execution are saved at thebeginning and restored at the end of the interrupt routineInterrupt handlers have to be finished quickly.Intensive calculations should be kept out of interrupt handlers. An interrupt handler should only be used for storinga received value or to trigger an operation in the regular program (task). It should not wait in any form or perform apolling operation.ADDITIONAL RULES FOR PREEMPTIVE MULTITASKINGA preemptive multitasking system like <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> needs to know if the program that is executing is part ofthe current task or an interrupt handler. This is because <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> cannot perform a task switch during theexecution of an interrupt handler; it can only do so at the end of an interrupt handler.If a task switch were to occur during the execution of an ISR, the ISR would continue as soon as the interrupted taskbecame the current task again. This is not a problem for interrupt handlers that do not allow further interruptions (whichdo not enable interrupts) and that do not call any <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> functions.This leads us to the following rule:● Interrupt functions that re-enable interrupts or use any <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> function need to callOS_EnterInterrupt() at the beginning, before executing any other command, and before they return, call eitherOS_LeaveInterrupt() or OS_LeaveInterruptNoSwitch() as last command.If a higher priority task is made ready by the ISR, the task switch then occurs in the routine OS_LeaveInterrupt().The end of the ISR is executed at a later point, when the interrupted task is made ready again. If you debug an interruptroutine, do not be confused. This has proven to be the most efficient way of initiating a task switch from within aninterrupt service routine.If fast task-activation at the end of an interrupt service routine is not required, OS_LeaveInterruptNoSwitch() canbe used instead.Calling <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> routines from within an ISRBefore calling any <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> function from within an ISR, <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> has to be informed thatan interrupt service routine is running.PP<strong>RTOS</strong>-2101

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!