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 timersAdditional InformationThe return value of OS_GetpCurrentTimer() is valid during execution of a timer callback function; otherwise it isundetermined. If only one callback function should be used for multiple timers, this function can be used for examiningthe timer that expired.The example below shows one usage of OS_GetpCurrentTimer(). In this version of <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong>, theextended timer structure and functions which come with embOS may be used to generate and use software timer withindividual parameter for the callback function.Example#include "<strong>RTOS</strong>.H"/********************************************************** Types*/typedef struct { /* Timer object with its own user data */OS_TIMER Timer;void* p<strong>User</strong>;} TIMER_EX;/********************************************************** Variables*/TIMER_EX Timer_<strong>User</strong>;int a;/********************************************************** Local Functions*/void CreateTimer(TIMER_EX* timer, OS_TIMERROUTINE* Callback, OS_UINT Timeout,void* p<strong>User</strong>) {timer->p<strong>User</strong> = p<strong>User</strong>;OS_CreateTimer((OS_TIMER*) timer, Callback, Timeout);}void cb(void) { /* Timer callback function for multiple timers */TIMER_EX* p = (TIMER_EX*)OS_GetpCurrentTimer();void* p<strong>User</strong> = p->p<strong>User</strong>; /* Examine user data */OS_RetriggerTimer(&p->Timer); /* Retrigger timer */}/********************************************************** main*/int main(void) {OS_InitKern(); /* Initialize OS */OS_InitHW(); /* Initialize Hardware for OS */CreateTimer(&Timer_<strong>User</strong>, cb, 100, &a);OS_Start(); /* Start multitasking */return 0;}OS_CREATETIMER_EX()DescriptionMacro that creates and starts an extended software-timer.Prototypevoid OS_CREATETIMER_EX (OS_TIMER_EX*pTimerEx,OS_TIMER_EX_ROUTINE* Callback,OS_TIMETimeoutvoid*pData);ParameterDescriptionpTimerExPointer to the OS_TIMER_EX data structure which contains the data of the timer.Table 30: OS_CREATETIMER_EX() parameter listPP<strong>RTOS</strong>-243

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

Saved successfully!

Ooh no, something went wrong!