embedded systems os. reference materials the concise handbook of real- time systems timesys...

28
Embedded Systems OS

Upload: annis-mitchell

Post on 13-Dec-2015

229 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Embedded Systems

OS

Page 2: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Reference Materials• The Concise Handbook of

Real-Time Systems TimeSys Corporation

Page 3: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Real-time Embedded Systems

Embedded Systems

Real-time Systems

Real-time Embedded Systems

Page 4: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Real-time System

• Function correct

• time correct

Page 5: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Hard realtime vs. Soft real-time• Soft-realtime

– accept delayed response

• Hardware– Ensure response time

response time deadline

response time deadline

Hard realtime system may not be a fast system

Page 6: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

RTOSKey Features

• Reliability

• Predictability

• Performance (Fast , Small)

• Compactness (xMB ~ xxxKB)

• Scalability(Network, FS, IPC, GUI…)

Page 7: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Reliability of High Available System

Reliability Down Time / Year Applications

99.9% 1~9h Desktop System

99.99% 0~1h Enterprise Server

99.999%0~5min

Telecommunication Server

99.9999%0~31s

Telecommunication Switcher

Page 8: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Why using OS?

• Resource Management (Mem, IO, Time)

• Multi-task

• Reliable

• Standard System API

• Complex Applications

Page 9: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

What is Task?

Func_B(){

}

Task B

Func_A(){

}

Task Aint Func_XX(){ while(1) { do_work_1(); do_work_2(); } return TASK_DEAD;}task looks like a simple C function

Page 10: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

How Task is Running?

Func_B(){

}

Task B

Func_A(){

}

Task A

CPU

Page 11: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Static Task and Dynamic Task

Memory

Task ATask A

External Storage

Task D Task

C

Remote SystemRemote System

Task ETask F

LoaderLoader

Page 12: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

State of Threads/Tasks

Ready

Run

Blocked

Resource Obtained

Highest Priority Task

Request For Resource

Page 13: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Implementation Details

Task A Task B

TCB A TCB B

ISR (Software/Hardware)ISR (Software/Hardware)

1. Execute System Call2. Copy Registers into TCB3. Schedule

a) Update Task Statusb) Select Task with the

Highest Priority

ISR means Interrupt Service Routine

System_call()

System_call()

1

3

CPU PC

R0

R1

RN

PSR

2

4

Page 14: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

TCB (Task Control Block)

PC

R0

R1

RN

PSR

Task StatusTask Status

Task PriorityTask Priority

Page 15: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Semaphore

• Binary Semaphore

• Counting Semaphore

• Mutex Semaphore

Look like normal variable.Accessing (changing) its value is monitored by the OS

ValueValueAcquire(S)

Release(S)

SS

Page 16: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Binary Semaphore

1 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

Page 17: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Counting Semaphore

N 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

Page 18: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Mutex Semaphore

N0

Acquire()++Value

Acquire()set Value=1

Release()--Value

Release()--Value==0

Init() with value 0

Task Blocks when acquiring semaphore with non-zero valueOnly task who locked the semaphore can release it

Page 19: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

BufferBuffer

Use of Binary Semaphore

Task A

Pre-processing

Task B

Post-processing

0/1

Binary Semaphore

Acquire()set value=0blocks 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

Page 20: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

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

Page 21: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Use of Mutex Semaphore

N

Task_A(){ Acquire(S); Access_Share_Mem(); Release(S);}

Shared Memory

Task_B(){ Acquire(S); Access_Share_Mem(); Release(S);}

Page 22: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Task_B(){ Acquire(S); Access_Share_Mem(); Release(S);}

Use of Mutex Semaphore

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

Page 23: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Other Synchronization Methods

• Interrupt Locking– Enable Interrupt– Disable Interrupt

• Preemption Locking– Enable Scheduling– Disable Scheduling

Page 24: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

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

Page 25: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

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(); }

Page 26: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

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();}

Page 27: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

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

Page 28: Embedded Systems OS. Reference Materials The Concise Handbook of Real- Time Systems TimeSys Corporation

Soft Timer

Execution Start Time 1Execution

Start Time 1

Execution Start Time 2Execution

Start Time 2

Execution Start Time 3Execution

Start Time 3

Execution Start Time 3Execution

Start Time 3

WorkWork

Work

WorkWork

Work

WorkWork

Work

WorkWork

Work

RTC ISR

Run taskswhose start time has reached

Timer Counter(variable)

++