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.

Task routinesIntroductionA task that should run under <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> needs a task control block (TCB), a stack, and a normal routinewritten in C. The following rules apply to task routines:●●●●●The task routine cannot take parameters.The task routine must never be called directly from your application.The task routine must not return.The task routine should be implemented as an endless loop, or it must terminate itself (see examples below).The task routine needs to be started from the scheduler, after the task is created and OS_Start() is called.Example of task routine as an endless loop:/* Example of a task routine as an endless loop */void Task1(void) {while(1) {DoSomething() /* Do something */OS_Delay(1); /* Give other tasks a chance */}}Example of task routine that terminates itself/* Example of a task routine that terminates */void Task2(void) {char DoSomeMore;do {DoSomeMore = DoSomethingElse() /* Do something */OS_Delay(1); /* Give other tasks a chance */} while(DoSomeMore);OS_Terminate(0); /* Terminate yourself */}There are different ways to create a task; <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> offers a simple macro that makes this easy and whichis fully sufficient in most cases. However, if you are dynamically creating and deleting tasks, a routine is availableallowing "fine-tuning" of all parameters. For most applications, at least initially, using the macro as in the sample startproject works fine.PP<strong>RTOS</strong>-2 25

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

Saved successfully!

Ooh no, something went wrong!