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.

Basic conceptsThe active task may be delayed for or until a specified time; in this case it is put into the DELAY state (TS_DELAY)and the next highest priority task in the READY state is activated.The active task may also have to wait for an event (or semaphore, mailbox, or queue). If the event has not yet occurred,the task is put into the waiting state and the next highest priority task in the READY state is activated.A non-existent task is one that is not yet available to <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong>; it has either not been created yet or it hasbeen terminated.The following illustration shows all possible task states and transitions between them.Not existingCREATETASK()Terminate()TS_Ready Scheduler Active taskDelay()Wait for event,mailbox orsemaphoreTS_DELAYHow the OS gains controlWhen the CPU is reset, the special-function registers are set to their respective values. After reset, program executionbegins. The PC register is set to the start address defined by the start vector or start address (depending on the CPU).This start address is in a startup module shipped with the C compiler, and is part of the standard library.The startup code performs the following:● Loads the stack pointers with the default values, which is for most CPUsthe end of the defined stack segment(s)● Initializes all data segments to their respective values● Calls the main() routine.In a single-task-program, the main() routine is part of your program which takes control immediately after the Cstartup. <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> works with the standard C startup module without any modification. If there are anychanges required, they are documented in the startup file which is shipped with <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong>.The main() routine is still part of your application program. Basically, main() creates one or more tasks and thenstarts multitasking by calling OS_Start(). From then on, the scheduler controls which task is executed.The main() routine will not be interrupted by any of the created tasks, because those tasks are executed only after thecall to OS_Start(). It is therefore usually recommended to create all or most of your tasks here, as well as your controlstructures such as mailboxes and semaphores. A good practice is to write software in the form of modules which are(up to a point) reusable. These modules usually have an initialization routine, which creates the required task(s) and/orcontrol structures.PP<strong>RTOS</strong>-219

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

Saved successfully!

Ooh no, something went wrong!