lesson programming - devi ahilya · pdf filevxworks provides for round robin time sliced...

33
2008 Chapter-9 L10: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 1 REAL TIME OPERATING SYSTEM REAL TIME OPERATING SYSTEM PROGRAMMING PROGRAMMING - - I: I: µ µ µ µ µ µ C/OS C/OS - - II and II and VxWorks VxWorks Lesson Lesson - - 10: 10: VxWorks functions for system time, Watchdog timer, interrupts and Task servicing

Upload: ngonga

Post on 26-Mar-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

1

REAL TIME OPERATING SYSTEM REAL TIME OPERATING SYSTEM PROGRAMMINGPROGRAMMING--I: I: µµµµµµµµC/OSC/OS--II and II and

VxWorks VxWorks

LessonLesson--10: 10: VxWorks functions for system time, Watchdog timer, interrupts and Task

servicing

Page 2: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

2

1. 1. System FunctionsSystem Functions

Page 3: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

3

• sysClkDisable ( )− to disable the system clock interrupts • sysClkEnable ( )− to enable the system clock interrupts

System Clock Enable and DisableSystem Clock Enable and Disable

Page 4: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

4

• sysClkRateSet (TICK numTicks) sets the number of ticks per second •- sysClkRateSet (1000) will set the RTC tick after every 1/1000 second (1 ms)• sysClkRateGet ( ) returns the system ticks (System RTC interrupts) per second

Clock Rate Set and GetClock Rate Set and Get

Page 5: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

5

•Set function should be called in the main ( ) or start up FirstTask or as a starting function. • vxAbsTicks− 32-bit global integer variable • A variable, vxAbsTicks.lower that increases after each tick and vxAbsTicks. • A variable, vxAbsTicks.upper that increases after each 232 ticks.

VxAbsTicksVxAbsTicks

Page 6: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

6

TICK defines as follows. typedef struct (unsigned long lower;unsigned long upper;) TICKTICK vxAbsTicks;

TICKTICK

Page 7: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

7

• sysClkConnect ( ) connects a 'C' function to the system clock interrupts

Connect C functions and System Clock Connect C functions and System Clock InterruptsInterrupts

Page 8: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

8

• sysAuxClkDisable ( ) disables the system auxiliary clock interrupts and

• sysAuxClkEnable ( ) enables the system auxiliary clock interrupts

Auxiliary ClockAuxiliary Clock

Page 9: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

9

• kernelTimeSlice (int numTicks) controls the round robin scheduling and time slicing turns on and preemptive priority scheduling turns off • Refer Example in Section 9.3.3.2

Kernel Time Slice Setting for running Kernel Time Slice Setting for running tasks of equal prioritytasks of equal priority

Page 10: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

10

2. 2. Watchdog timer FunctionsWatchdog timer Functions

Page 11: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

11

Watchdog timer functionWatchdog timer function

� Watchdog timer− function, which once enabled for certain timeout period, then after the timeout the system executes a connected watchdog routine with the predefine parameters for that routine.

� If system is running without getting stuck up some where, then WDT is reset or restarted, else the routine will execute to handle the situation

Page 12: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

12

• WDOG_ID wdCreate ( ); − to create a watchdog timer control block. •wdtID = wdCreate ( ); −to creates a watchdog timer, wdtID• STATUS wdStart (wdtID, delayNumTicks, wdtRoutine, wdtParameter);− to start the created timer

WDT Create and WDT StartWDT Create and WDT Start

Page 13: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

13

•• wdtID wdtID defines the identity of the watchdog timerdefines the identity of the watchdog timer•• delayNumTicksdelayNumTicks−− to let the timer interrupts after the to let the timer interrupts after the delayNumTicksdelayNumTicks number of RTC interruptsnumber of RTC interrupts•• wdtRoutinewdtRoutine, , −− a function called on each timeout a function called on each timeout •• STATUS wdCancel (STATUS wdCancel (wdtIDwdtID) ) −− to cancel timer o cancel timer wdtIDwdtID

WDTWDT

Page 14: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

14

3. 3. Interrupt handling FunctionsInterrupt handling Functions

Page 15: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

15

• An interrupt vector address, ISR_VECTADDR does not auto-generate, that has to be defined by the intVectSet ( ) function.

Interrupt Handling FunctionsInterrupt Handling Functions

Page 16: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

16

Interrupt Handling FunctionsInterrupt Handling Functions

intVectSet ( ) Set the interrupt vector

intVecGet ( ) Get Interrupt Vector

intVecBaseGet ( ) Get interrupt vector base address

intContext ( ) Returns true when an ISR is calling function.

intLock ( ) Disables Interrupts

intUnLock ( ) Enables Interrupts

Page 17: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

17

Interrupt Handling FunctionsInterrupt Handling Functions

intVecBaseSet ( ) Set the interrupt vector

intLevelSet ( ) Sets the interrupt mask level of the process

intConnect ( ) Connects a 'C' function to the interrupt vector

intCount ( ) Counts number of interrupts nested together

Page 18: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

18

4. 4. Task Service functionsTask Service functions

Page 19: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

19

Task Service Functions Task Service Functions

� Each task divides into eight states [Four of these same as in µC/OS-II tasks]

Page 20: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

20

(b) Ready (waiting for running and CPU access in case scheduled by the scheduler but not waiting for a message through IPC) using taskActivate ( )

(a) Suspended (Idle state just after creation or state where execution is inhibited ) using taskSuspend ( )

Suspend and ReadySuspend and Ready

Page 21: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

21

(c) Pending (the task is blocked as it waits for a message from the IPC or from a resource; only then will the CPU be able to process further)

Task PendingTask Pending

Page 22: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

22

(d) Delayed (Sent to sleep for a certain time-interval) using taskDelay(e) Delayed + Suspended [Delayed and then suspended if is not preempted during the delay period] using taskSuspend ( )

Delayed and Delayed + SuspendedDelayed and Delayed + Suspended

Page 23: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

23

(f) Pended + Suspended [Pended and then suspended if the blocked state does not change].

Pended + SuspendedPended + Suspended

Page 24: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

24

(g) Pended + Delayed [Pended and then preempts after the delayed time-interval]. (h) Pended + Suspended + Delayed. [Pended and then suspended after the delayed time-interval].

Pended + DelayedPended + Delayed

Page 25: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

25

• unsigned int taskId = taskSpawn (name, priority, options, stacksize, main, arg0, arg1, ........., arg8, arg9); for task creating and activating (task spawning)• unsigned int taskIdSelf ( ); returns the identity of the calling task

Task SpawnTask Spawn

Page 26: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

26

• unsigned int [ ] listTasks = taskIdListGet ( ); will return the tasked list of all existing tasks needed in array, listTasks

Task ListTask List

Page 27: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

27

• taskIDVerify (taskId) verifies whether task, taskId exists • taskPriorityGet (taskId, &priority) - the task priority can be changed dynamically

Task Verify and Priority GetTask Verify and Priority Get

Page 28: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

28

• VX_PRIVATE_ENV −to execute the task in private environment (not public)•VX_NO_STACK_FILL− no filling of stack addresses each with the

hexadecimal bytes 0xEE at the task sawning

Task Options definable on spawning

Page 29: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

29

• VX_FP_TASK−to execute the task with the floating-point processing units (for greater precession)• VX_UNBREAKABLE−to disable the breakpoints at the task during

execution. [Breakpoints are inserted for help during debugging]

Task Options definable on spawning ...

Page 30: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

30

SummarySummary

Page 31: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

31

We learnt• VxWorks time-slice scheduling,

system clock and service, time delay and task, functions

• Watchdog timer and interrupt handling functions

Page 32: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

32

• VxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

• Eight states of a task

Page 33: Lesson PROGRAMMING - Devi Ahilya  · PDF fileVxWorks provides for round robin time sliced scheduling for equal priority tasks as well as preemptive scheduling

2008Chapter-9 L10: "Embedded Systems - Architecture,

Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc.

33

End of Lesson-6 on VxWorks functions for system time, Watchdog timer, interrupts and Task

servicing