Download presentation
Presentation is loading. Please wait.
Published byAnnis Mitchell Modified over 9 years ago
1
Embedded Systems OS
2
Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation
3
Real-time Embedded Systems Embedded Systems Real-time Systems Real-time Embedded Systems
4
Real-time System Function correct time correct
5
Hard realtime vs. Soft real-time Soft-realtime –accept delayed response Hardware –Ensure response time response time deadline Hard realtime system may not be a fast system
6
RTOS Key Features Reliability Predictability Performance (Fast, Small) Compactness (xMB ~ xxxKB) Scalability(Network, FS, IPC, GUI…)
7
Reliability of High Available System ReliabilityDown Time / YearApplications 99.9% 1~9h Desktop System 99.99% 0~1h Enterprise Server 99.999% 0~5min Telecommunication Server 99.9999% 0~31s Telecommunication Switcher
8
Why using OS? Resource Management (Mem, IO, Time) Multi-task Reliable Standard System API Complex Applications
9
What is Task? Func_B() { } Task B Func_A() { } Task A int Func_XX() { while(1) { do_work_1(); do_work_2(); } return TASK_DEAD; } task looks like a simple C function
10
How Task is Running? Func_B() { } Task B Func_A() { } Task A CPU
11
Static Task and Dynamic Task Memory Task A External Storage Task D Task C Remote System Task E Task F Loader
12
State of Threads/Tasks Ready Run Blocked Resource Obtained Highest Priority Task Request For Resource
13
Implementation Details Task ATask B TCB ATCB B ISR (Software/Hardware) 1.Execute System Call 2.Copy Registers into TCB 3.Schedule a)Update Task Status b)Select Task with the Highest Priority ISR means Interrupt Service Routine System_call() 1 3 CPU PC R0 R1 RN … … PSR 2 4
14
TCB (Task Control Block) PC R0 R1 RN … … PSR Task Status Task Priority
15
Semaphore Binary Semaphore Counting Semaphore Mutex Semaphore Look like normal variable. Accessing (changing) its value is monitored by the OS Value Acquire(S) Release(S) S
16
Binary Semaphore 1 1 0 0 Acquire() set Value=0 Release() set Value=1 Task Blocks when acquiring semaphore with value 0 Any task can release semaphore (can be release more than once) Init() with value 1 Init with value 0
17
Counting Semaphore N N 0 0 Acquire() - -Value Acquire() --Value==0 Task Blocks when acquiring semaphore with value 0 Any task can release semaphore (can be release more than once) Release() ++Value Release() ++Value Init() with value N Init() with Value 0
18
Mutex Semaphore N N 0 0 Acquire() ++Value Acquire() set Value=1 Release() --Value Release() --Value==0 Init() with value 0 Task Blocks when acquiring semaphore with non-zero value Only task who locked the semaphore can release it
19
Buffer Use of Binary Semaphore Task A Pre-processing Task B Post-processing 0/1 Binary Semaphore Acquire() set value=0 blocks at value==0 Release() set value=1 Task A won’t be blocked on it, Task A can be ISR B blocks itself until obtain the data
20
Use of Counting Semaphore Task A Pre-processing Task B Post-processing N Counting Semaphore Acquire() value— blocks at value==0 Release() value++ Task A won’t be blocked on it, it can be ISR Task A issue batch of semaphores after pre-processing and block itself. then task B continue data processing
21
Use of Mutex Semaphore N N Task_A() { Acquire(S); Access_Share_Mem(); Release(S); } Shared Memory Task_B() { Acquire(S); Access_Share_Mem(); Release(S); }
22
Task_B() { Acquire(S); Access_Share_Mem(); Release(S); } Use of Mutex Semaphore N N Task_A() { Acquire(S); Access_Share_Mem(); Func_X(); Release(S); } Func_X() { Acquire(S); Access_Share_Mem(); Func_Y(); Release(S); } Func_Y() { Acquire(S); Access_Share_Mem(); Release(S); } Shared Memory Same Task won’t block itself when try locking the same lock
23
Other Synchronization Methods Interrupt Locking –Enable Interrupt –Disable Interrupt Preemption Locking –Enable Scheduling –Disable Scheduling
24
Use of Interrupt Locking ISR() { Access_Share_Mem(); } Shared Memory Task_B() { Disable_IRQ(); Access_Share_Mem(); Enable_IRQ(); Data Processing } IRQ disable time should be very short Need to add protection code to avoid access conflict of shared memory
25
Use of Interrupt Locking (1) ISR_1() { Access_Share_Mem(); } Shared Memory 1 Task_B() { } Shared Memory 2 Shared Memory N ISR_2() { Access_Share_Mem(); } ISR_N() { Access_Share_Mem(); } … …
26
Use of Interrupt Locking (2) Task_B() { for (i=1; i<=N; i++) { Disable_IRQ(); Access_Memory(i); enable_IRQ(); Data_Proc(); } ISR_1() { Access_Share_Mem(); } Shared Memory 1 Shared Memory 2 Shared Memory N ISR_2() { Access_Share_Mem(); } ISR_N() { Access_Share_Mem(); } … …
27
Use of Preemption Locking Task_A() { Disable_Sched(); Access_Share_Mem(); Enable_Sched(); Data Processing } Shared Memory Task_B() { Disable_Sched(); Access_Share_Mem(); Enable_Sched(); Data Processing } Scheduler disable time should be very short
28
Soft Timer Execution Start Time 1 Execution Start Time 2 Execution Start Time 3 Work RTC ISR Run tasks whose start time has reached Timer Counter (variable) Timer Counter (variable) ++
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.