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

Post on 26-Mar-2018

215 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

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

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

2

1. 1. System FunctionsSystem Functions

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

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

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

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

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

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

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

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

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

10

2. 2. Watchdog timer FunctionsWatchdog timer Functions

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

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

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

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

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

14

3. 3. Interrupt handling FunctionsInterrupt handling Functions

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

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

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

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

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

18

4. 4. Task Service functionsTask Service functions

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]

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

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

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

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

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

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

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

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

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

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 ...

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

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

30

SummarySummary

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

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

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

top related