intro to vxworks rtos

28
Introduction to VxWorks RTOS Eli Carmi July 2007

Upload: elicarmi

Post on 22-Nov-2014

4.589 views

Category:

Documents


18 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Intro To Vxworks RTOS

Introduction to VxWorks RTOS

Eli Carmi

July 2007

Page 2: Intro To Vxworks RTOS

RTOS Tasks Synchronization Asynchronous Information

2

Introduction to VxWorks RTOS

Page 3: Intro To Vxworks RTOS

RTOS Real Time Multi Tasking Priority Scheduling Round-Robin Scheduling

3

RTOS - Real Time OS

Page 4: Intro To Vxworks RTOS

Control External Events Synchronous Event Asynchronous Event Independents Event

Speed Fast response Low overheads

Deterministic A late answer is a wrong answer

4

Real Time

Page 5: Intro To Vxworks RTOS

Sequence programming One task controlling all events in a Loop

5

Multi Tasking

FOREVER

{

if (Event1)

do Event1 action

if (Event2)

do Event2 action

}

Page 6: Intro To Vxworks RTOS

Multitasking Programming Task is “Waiting” on Event Task becomes “Ready” upon Event

6

Multi Tasking cont.

Task1

FOREVER

{

wait on Event1

do Event1 action

}

Task2

FOREVER

{

wait on Event2

do Event2 action

}

Task3

FOREVER

{

wait on Event3

do Event3 action

}

Page 7: Intro To Vxworks RTOS

Task in the system may have different Priority Preemptive Scheduling on Task Priority The Highest Priority Task ready to run is

allocated the CPU Equal Priority tasks won’t preempt each other Scheduling can occur by Synchronous or

Asynchronous Events No delay on Context Switch to the next Tick

7

Priority Scheduling

Page 8: Intro To Vxworks RTOS

Slicing Context Switch in each (predefined) time slice

period Round-Robin

All tasks in the same priority share the CPU

8

Round-Robin Scheduling

Page 9: Intro To Vxworks RTOS

Tasks Task States Task Create (t-name, t-id) TCB, Stack, errno… Context Switch

9

Tasks

Page 10: Intro To Vxworks RTOS

Delay Pended Ready Execute Suspend

10

Task States

Event TaskPended

TaskPended

TaskPended

Timer

Task Delay + Pended

TaskDelay

TaskDelay

Ready Taskexecute

Taskready

Taskready

Taskready

EventTask

PendedTask

Pended

Page 11: Intro To Vxworks RTOS

taskId = taskSpawn(name, Priority, Option, Stack, Entry, Arg1,… arg10 ) task Id Task name Priority Option Stack Entry Arg1,…arg10

11

Task Create

Page 12: Intro To Vxworks RTOS

TCB – Task Control Block Entry pointer Registers Status Errno …

Task Stack May be filled with 0xee

12

TCB

Page 13: Intro To Vxworks RTOS

13

Context Switch

New TCB CPU Old TCBCPU

Page 14: Intro To Vxworks RTOS

Synchronization Need for Synchronization Binary Semaphores Mutex Semaphores Message Queue

14

Synchronization

Page 15: Intro To Vxworks RTOS

Reentrancy & Shared Resource

Jobs Synchronization

15

Need for Synchronization

void func()

{

….

if (gResource.free)

{

gResource.free = FALSE;

gResource.xxx = …

}

….

}

….Action1

…. Action2

Page 16: Intro To Vxworks RTOS

Mostly for Synchronization Creates Semaphore for Event Waits for Event

Task call the semaphore take() action Task is blocked until Event Semaphore is given

Upon Event becomes available Task or ISR give() semaphore

16

Binary Semaphores

Page 17: Intro To Vxworks RTOS

SEM_ID semBCreate(option, InitState) SEM_ID Option InitState

Status semTake(semid, timeout) Status semGive(semid, timeout)

Status semid Timeout

Note: Counting Semaphores also available

17

Binary Semaphores (cont)

Page 18: Intro To Vxworks RTOS

Taking a Binary Semaphore

Giving a Binary Semaphore

18

Binary Semaphores (cont)

SemaphoreAvailable?

Task pends until sem is given or timeout

Task unpendssemTake()

return ERROR

No Timeout

Task continuesemTake()return OK

Task unpendssemTake()return OK

Yes Semaphore give

TaskPended?

SemaphoreMade available

No

Task at front ofqueue made ready,Semaphore remain

unavailable

Yes

Page 19: Intro To Vxworks RTOS

Mostly for Shared Resource Works like Semaphores, but with Ownership

Task which takes the mutex “owns” it This task is the only one that can give the mutex Mutex can be takes repeatedly ISR can not use Mutex

SEM_ID semMCreate(option) Option (SEM_INVERSION_SAFE,…)

Priority Inheritance Initial State is available

19

Mutex Semaphores

Page 20: Intro To Vxworks RTOS

Priority Inversion

Priority Inheritance

20

Mutex Semaphores (Cont)

execute

execute

execute

Low

Priority

High

Priority

Medium

Priority

semTak

Event

Event

semTak

Ready

Ready

PendPend

PendPend

Page 21: Intro To Vxworks RTOS

Msg_Q_ID msgQCreate (maxMsg, MaxMsgLen, Option) MSG_Q_ID maxMsg MaxMsgLen Option

21

Message Queue

Page 22: Intro To Vxworks RTOS

Status msgQSend(msgQId, buffer, nBytes, timeout, priority) Status msgQId buffer nBytes Timeout (WAIT_FOREVER, NO_WAIT, …) Priority (MSG_PRI_URGENT, MSG_PRI_NORMAL)

22

Message Queue (cont)

Page 23: Intro To Vxworks RTOS

Int msgQReceive(msgQId, buffer, MaxNBytes, timeout) Int –number of bytes reads or ERROR msgQId buffer nBytes Timeout (WAIT_FOREVER, NO_WAIT, …)

Note: Pipes are also available Built on top of message queue

23

Message Queue (cont)

Page 24: Intro To Vxworks RTOS

Asynchronous Interrupts & Exceptions ISR Timers

24

Asynchronous

Page 25: Intro To Vxworks RTOS

Interrupts Interrupts allow devices to notify the CPU on events Interrupt Levels Single Interrupt Stack allocate at startup

Exceptions Unplanned event generated by the CPU (divide by

0) Exceptions will generate an “internal” interrupt VxWorks installs exceptions handlers

intLock / intUnlock25

Interrupts & Exceptions

Page 26: Intro To Vxworks RTOS

ISR – Interrupt Service Routine NOT a Task

No TCB Can NOT be blocked (can’t use semTake, malloc

and IO routines like printf) Keep ISR short

Delay lower and equal Interrupts Delay all Tasks

Off-load work from ISR

26

ISR

Page 27: Intro To Vxworks RTOS

taskDelay() May “Drift”

System Clock tickGet() sysClkRateGet()

Watchdog WDOG_ID wdCreate() STATUS wdStart(wdid, delay, pRoutine, parameter) pRoutine is ISR

Note: Auxiliary Clock is also available

27

Timers

Page 28: Intro To Vxworks RTOS

Thank You

[email protected]