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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Software timersSoftware timerA software timer is an object that calls a user-specified routine after a specified delay. A basically unlimited number ofsoftware timers can be defined with the macro OS_CREATETIMER().Timers can be stopped, started and retriggered much like hardware timers. When defining a timer, you specify anyroutine that is to be called after the expiration of the delay. Timer routines are similar to interrupt routines; they have apriority higher than the priority of all tasks. For that reason they should be kept short just like interrupt routines.Software timers are called by <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> with interrupts enabled, so they can be interrupted by any hardwareinterrupt. Generally, timers run in single-shot mode, which means they expire only once and call their callback routineonly once. By calling OS_RetriggerTimer() from within the callback routine, the timer is restarted with its initialdelay time and therefore works just as a free-running timer.The state of timers can be checked by the functions OS_GetTimerStatus(), OS_GetTimerValue(), andOS_GetTimerPeriod().Maximum timeout / periodThe timeout value is stored as an integer, thus a 16-bit value on 8/16-bit CPUs, a 32-bit value on 32-bit CPUs. Thecomparisons are done as signed comparisons, (because expired time-outs are permitted). This means that only 15-bitscan be used on 8/16 bit CPUs, 31-bits on 32-bit CPUs. Another factor to take into account is the maximum time spentin critical regions. During critical regions timers may expire, but because the timer routine can not be called from acritical region (timers are "put on hold"), the maximum time that the system spends at once in a critical region needsto be deducted. In most systems, this is no more than a single tick. However, to be safe, we have assumed that yoursystem spends no more than up to 255 ticks in a row in a critical region and defined a macro which defines themaximum timeout value. It is normally 0x7F00 for 8/16-bit systems or 0x7FFFFF00 for 32-bit Systems and definedin <strong>RTOS</strong>.h as OS_TIMER_MAX_TIME. If your system spends more than 255 ticks without break in a critical section(effectively disabling the scheduler during this time, which is not recommended), you have to make sure yourapplication uses shorter timeouts.EXTENDED SOFTWARE TIMERThe functionality of extended software timers is identical to regular software timers with the extension that the calleduser-specified routine takes a void pointer as parameter. Refer to OS_CreateTimerEx() on page 44 for an example.PP<strong>RTOS</strong>-2 37

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

Saved successfully!

Ooh no, something went wrong!