IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide IAR PowerPac RTOS User Guide

ie.ksu.edu.tw
from ie.ksu.edu.tw More from this publisher
11.07.2015 Views

USING A DIFFERENT TIMER TO GENERATE THE TICK-INTERRUPTS FOR IAR POWERPAC RTOSRelevant routinesOS_ InitHW()IAR PowerPac RTOS usually generates 1 interrupt per ms, making the timer-interrupt, or tick, normally equal to 1 ms.This is done by a timer initialized in the routine OS_InitHW(). If you have to use a different timer for your application,you must modify OS_InitHW() to initialize the appropriate timer. For details about initialization, read the commentsin RTOSInit.c.CHANGING THE TICK FREQUENCYRelevant definesOS_FSYSAs noted above, IAR PowerPac RTOS usually generates 1 interrupt per ms. OS_FSYS defines the clock frequency ofyour system in Hz (times per second). The value of OS_FSYS is used for calculating the desired reload counter valuefor the system timer for 1000 interrupts/sec. The interrupt frequency is therefore normally 1 kHz.Different (lower or higher) interrupt rates are possible. If you choose an interrupt frequency different from 1 kHz, thevalue of the time variable OS_Time will no longer be equivalent to multiples of 1 ms. However, if you use a multipleof 1 ms as tick time, the basic time unit can be made 1 ms by using the (optional) configuration macro OS_CONFIG().The basic time unit does not have to be 1 ms; it might just as well be 100 µs or 10 ms or any other value. For mostapplications, 1 ms is an appropriate value.OS_CONFIG()OS_CONFIG() can be used for configuration of IAR PowerPac RTOS in situations where the basic timer-interruptinterval (tick) is a multiple of 1 ms and the time values for delays still should use 1 ms as the time base. OS_CONFIG()tells IAR PowerPac RTOS how many system time units expire per IAR PowerPac RTOS tick and what the systemfrequency is.Examples4 The following will increment the time variable OS_Time by 1 per RTOS timer-interrupt. This is the default for IARPowerPac RTOS, so usage of OS_CONFIG() is not required.OS_CONFIG(8000000,8000); /* Configure OS : System-frequency, ticks/int */5 The following will increment the time variable OS_Time by 2 per IAR PowerPac RTOS timer-interrupt.OS_CONFIG(8000000,16000); /* Configure OS : System-frequency, ticks/int */If, for example, the basic timer was initialized to 500 Hz, which would result in an IAR PowerPac RTOS timer-interruptevery 2 ms, a call of OS_Delay(10) would result in a delay of 20 ms, because all timing values are interpreted asticks. A call of OS_CONFIG() with the parameter shown in example 2 would compensate for the difference, resultingin a delay of 10 ms when calling OS_Delay(10).STOP / HALT / IDLE modesMost CPUs support power-saving STOP, HALT, or IDLE modes. Using these types of modes is one possible way tosave power consumption during idle times. As long as the timer-interrupt will wake up the system with every IARPowerPac RTOS tick, or as long as other interrupts will activate tasks, these modes may be used for saving powerconsumption.If required, you may modify the OS_Idle() routine, which is part of the hardware-dependant module RTOSInit.c,to switch the CPU to power-saving mode during idle times. Refer to the CPU & Compiler Specific manual of embOSdocumentation for details about your processor.112IAR PowerPac RTOSfor ARM CoresPPRTOS-2

Time measurementIntroductionIAR PowerPac RTOS supports 2 types of time measurement:● Low resolution (using a time variable)● High resolution (using a hardware timer)Both are explained in this chapter.IAR PowerPac RTOS supports two basic types of run-time measurement which may be used for calculating theexecution time of any section of user code. Low-resolution measurements use a time base of ticks, while highresolutionmeasurements are based on a time unit called a cycle. The length of a cycle depends on the timer clockfrequency.Low-resolution measurementThe system time variable OS_Time is measured in ticks, or ms. The low-resolution functions OS_GetTime() andOS_GetTime32() are used for returning the current contents of this variable. The basic idea behind low-resolutionmeasurement is quite simple: The system time is returned once before the section of code to be timed and once after,and the first value is subtracted from the second to obtain the time it took for the code to execute.The term low-resolution is used because the time values returned are measured in completed ticks. Consider thefollowing: with a normal tick of 1 ms, the variable OS_Time is incremented with every tick-interrupt, or once every ms.This means that the actual system time can potentially be more than what a low-resolution function will return (forexample, if an interrupt actually occurs at 1.4 ticks, the system will still have measured only 1 tick as having elapsed).The problem becomes even greater with runtime measurement, because the system time must be measured twice. Eachmeasurement can potentially be up to 1 tick less than the actual time, so the difference between two measurementscould theoretically be inaccurate by up to two ticks.PPRTOS-2 113

USING A DIFFERENT TIMER TO GENERATE THE TICK-INTERRUPTS FOR <strong>IAR</strong> POWERPAC <strong>RTOS</strong>Relevant routinesOS_ InitHW()<strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> usually generates 1 interrupt per ms, making the timer-interrupt, or tick, normally equal to 1 ms.This is done by a timer initialized in the routine OS_InitHW(). If you have to use a different timer for your application,you must modify OS_InitHW() to initialize the appropriate timer. For details about initialization, read the commentsin <strong>RTOS</strong>Init.c.CHANGING THE TICK FREQUENCYRelevant definesOS_FSYSAs noted above, <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> usually generates 1 interrupt per ms. OS_FSYS defines the clock frequency ofyour system in Hz (times per second). The value of OS_FSYS is used for calculating the desired reload counter valuefor the system timer for 1000 interrupts/sec. The interrupt frequency is therefore normally 1 kHz.Different (lower or higher) interrupt rates are possible. If you choose an interrupt frequency different from 1 kHz, thevalue of the time variable OS_Time will no longer be equivalent to multiples of 1 ms. However, if you use a multipleof 1 ms as tick time, the basic time unit can be made 1 ms by using the (optional) configuration macro OS_CONFIG().The basic time unit does not have to be 1 ms; it might just as well be 100 µs or 10 ms or any other value. For mostapplications, 1 ms is an appropriate value.OS_CONFIG()OS_CONFIG() can be used for configuration of <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> in situations where the basic timer-interruptinterval (tick) is a multiple of 1 ms and the time values for delays still should use 1 ms as the time base. OS_CONFIG()tells <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> how many system time units expire per <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> tick and what the systemfrequency is.Examples4 The following will increment the time variable OS_Time by 1 per <strong>RTOS</strong> timer-interrupt. This is the default for <strong>IAR</strong><strong>PowerPac</strong> <strong>RTOS</strong>, so usage of OS_CONFIG() is not required.OS_CONFIG(8000000,8000); /* Configure OS : System-frequency, ticks/int */5 The following will increment the time variable OS_Time by 2 per <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> timer-interrupt.OS_CONFIG(8000000,16000); /* Configure OS : System-frequency, ticks/int */If, for example, the basic timer was initialized to 500 Hz, which would result in an <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> timer-interruptevery 2 ms, a call of OS_Delay(10) would result in a delay of 20 ms, because all timing values are interpreted asticks. A call of OS_CONFIG() with the parameter shown in example 2 would compensate for the difference, resultingin a delay of 10 ms when calling OS_Delay(10).STOP / HALT / IDLE modesMost CPUs support power-saving STOP, HALT, or IDLE modes. Using these types of modes is one possible way tosave power consumption during idle times. As long as the timer-interrupt will wake up the system with every <strong>IAR</strong><strong>PowerPac</strong> <strong>RTOS</strong> tick, or as long as other interrupts will activate tasks, these modes may be used for saving powerconsumption.If required, you may modify the OS_Idle() routine, which is part of the hardware-dependant module <strong>RTOS</strong>Init.c,to switch the CPU to power-saving mode during idle times. Refer to the CPU & Compiler Specific manual of embOSdocumentation for details about your processor.112<strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong>for ARM CoresPP<strong>RTOS</strong>-2

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

Saved successfully!

Ooh no, something went wrong!