If you can't read please download the document
Upload
meetbshah
View
75
Download
0
Embed Size (px)
Citation preview
uCOS IIRTOS
BY: Meet
Advantage/Disadvantage of Using RTOSAdvantageSplit application to multi tasks, simplify the design, easy to be understand, expend and maintenance Time latency is guaranteed Higher system reliability
DisadvantageMore RAM/ROM usage 2~5% CPU overhead
What is uCOS II?Micro-Controller Operating Systems, Version 2 A very small real-time kernel. Memory footprint is about 20KB for a fully functional kernel.
Feature of uC/OSIIPortable : Preemptive : portable C, minimum uC dependent ASM uC/OS-II is a fully preemptive real-time kernel ROMable & Scalable Multitasking : uC/OS-II can manage up to 64 tasks Deterministic : Execution time of all uC/OS-II functions and service are deterministic Deterministic : Each task requires its own different stack size Services : Mailboxes, Queues, Semaphores, fixed-sized memory partitions, time-related functions Int. can be nested up to 255 levels deep Robust and Reliable
Interrupt Management
Real Time Kernel on uCOS
Task statesC/OS-II is a multitasking operating system. Each task is an infinite loop and can be in any one of the following five states:
Dormant Ready Running Waiting Interrupt service routine
TermMultitaskingThe process of scheduling and switching the CPU between several tasks
TaskA simple program which thinks it has the CPU all to itself.
KernelThe part of the multitasking system responsible for the management of tasks and communication between tasks
Task SwitchKernel saves the current task's context (CPU registers) onto the current task's stack. Kernel load new task's context from the tasks stack of new task
TCBTask Control Block
SchedulerAlso called the dispatcher, is the part of the kernel which is responsible for determining which task will run next
Non-preemptive schedulingEach task is required to explicitly give up control of the CPU. (ex. System API Call) cooperative multitasking; tasks cooperate with each other to gain control of the CPU.
Preemptive Kernel In it, when an event makes a higher priority task ready to run, the current task is immediately suspended and the higher priority task is given control of the CPU Reentrancy A reentrant function is a function which can be used by more than one task without fear of data corruption.
uC/OS II OverviewExterna l IRQ TaskA TaskB { () { () {Task Scheduler
Task C()
IRQ1 IRQ2 IRQ3
Timer
}
}
}
MultiTasking Overview
OSTaskCreate
Create tasks with the given arguments. Tasks become ready after they are created. Task
An active entity which could do some computations. Priority, CPU registers, stack, text, housekeeping status. Task never return;int main (void) { OSInit(); OSTaskCreate(); OSTaskCreate(); OSStart(); return 0; // Never return }
Task Function
INT8U OSTaskCreate (void (*task)(void *pd), void *pdata, Private Data OS_STK *ptos, For Task INT8U prio)Priority of created task Note that OSTaskCreate can be called by main when OSStart is not invoked, but it can also be called in tasks when more task should be created at the run time Stack For Task
INT8U OSTaskCreateExt(void (*task)(void *pd),void *pdata,OS_STK *ptos,INT8U prio,INT16U id,OS_STK *pbos,INT32U stk_size,void *pext,INT16U opt)
task-Pointer to task's code. pdata-Pointer to optional data area; used to pass parameters to the task at start of execution. prio-The task's unique priority number; the lower the number the higher the priority. id-The task's identification number . stk_size-Size of the stack in number of elements. If OS_STK is set to INT8U, stk_size corresponds to the number of bytes available. If OS_STK is set to INT16U, stk_size contains the number of 16-bit entries available. Finally, if OS_STK is set to INT32U, stk_size contains the number of 32-bit entries available on the stack. pext-Pointer to a user-supplied Task Control Block (TCB) extension. opt-The lower 8 bits are reserved by C/OS-II. The upper 8 bits control application-specific options. Select an option by setting the corresponding bit(s).
W A IT IN G
O S T a s k D e l( )
O O O O O O O
S S S S S S S
M Q Q S T T T
B o x P o s t()O S P o s t() O S P o s tF ro n t() e m P o s t() O S a s k R e s u m eO ( S) i m e D l y R e s Ou mS im e T ic k ( ) O S
M B o x P e n d () Q P e n d () S e m T a s T e i (m ) T im P e n k S u s e D ly e D ly d () p e n d () () H M S M ()
O S T a s k C re a te () O S T a s k C re a te E x t()
D O R M A N T
R E A D Y
O S S ta rt() O S In t E x it ( ) O S _T A S K _S W ()
In t e r r u p t
R U N N IN GO S In t E x it ( )
IS R
O S T a s k D e l( ) T a s k is P r e e m p t e d O S T a s k D e l( )
Semaphore
Multiple concurrent threads of execution within an application must be able to
Synchronize their execution Coordinate mutually exclusive access to shared resources
RTOS provides a semaphore object and associated semaphore management services
Semaphore operations now defined as: wait(S)void wait(semaphoreS) { S.value--; if (S.value< 0) then { add this process to S.L; block(); } }
signal(S)void signal(semaphoreS) { S.value++; if (S.value