Вы находитесь на странице: 1из 42

VxWorks Quick-Start

CMC Real Time Systems Group

Objectives
State essential characteristics operating system. of the VxWorks

Purposes of important VxWorks libraries.

Contents
VxWorks Facilities VxWorks Basics VxWorks Libraries

VxWorks Quick-Start
VxWorks Facilities

VxWorks Features
Real-time Kernel. POSIX Compatibility. I/O System along with lot of drivers. Local File System. TCP/IP Network Support. C++ Development Support. Shared Memory Object, Virtual Memory. Target Agent, Target Resident Tools. Board Support Packages (BSPs). Utility Libraries. Performance Evaluation Tools. VxWorks Simulator.

VxWorks RTOS
Memory Management

Device Support

Scheduling & System Clock Facilities

I/O system

Synchronization & Intertask Communication File Systems

Mutual Exclusion ...

Networking Support

Standard Images
Types of Images ROMable compressed ROMable uncompressed ROM resident Downloadable uncompressed VxWorks Tornado _ vxWorks_rom vxWorks.res_rom_nosym vxWorks VxWorks Standalone vxWorks.st_rom _ vxWorks.res_rom vxWorks.st Boot Program bootrom bootrom_uncmp bootrom_res _

Not all BSPs will support all of these images. Some BSPs support addititional images. Standalone VxWorks has a target shell and built-in symbol table. Network support is included but not initialized. The file target\h\make\rules.bsp has the make rules for building these images.

VxWorks Image Types


There are three classes of VxWorks images: Loadable images. ROM-based images - compressed/uncompressed. ROM-Resident images. Loadable images are loaded into RAM by boot code. Boot code is burned into ROM or Flash. Boot code is a stand-alone VxWorks application. ROM-based images load themselves into RAM from ROM or Flash. ROM-resident images execute out of ROM or Flash. Only the data segment of the VxWorks image is loaded into RAM.

VxWorks Quick-Start
VxWorks Basics

What is Real-Time?
Real-time denotes the ability of a control system to keep up with the system being controlled. A system is described as being deterministic if its response time is predictable. The lag time between the occurrence of an event and the response to that event is called latency. Deterministic performance is the key to real-time performance. Deterministic operation:
A late answer is a wrong answer.

Design Options

Unitasking Approach
One task controlling all the components in a loop.
arm() { for( ; ; ) { if (joint1 needs moving) moveJoint1(); if (joint2 needs moving) moveJoint2(); if (joint3 needs moving) moveJoint3(); . . } }

Multitasking Approach
Create a separate task to manipulate each joint:
joint() { for( ; ; ) { wait; /* Until this joint needs moving */ moveJoint(); } }

Each task alternates between ready and waiting. Vxworks allows a task to wait for:
A specified time delay An event (e.g. an interrupt)

VxWorks
VxWorks is a multitasking operating system optimized for real-time and embedded applications.
Low interrupt latency and context switching time. Low system call overhead. Scalable. Portable: well defined BSP.

VxWorks consists of core kernel facilities and peripheral facilities which depend on the kernel.
Loosely, kernel functions are those which can directly change the states of tasks.

Multitasking Kernel
Manages tasks. Transparently interleaves task execution, creating the appearance of many programs executing simultaneously and independently.

Process
A process is a single executable module that runs concurrently with other executable modules. For example, in Windows a word processor, an internet browser, and a data base, are separate processes and can run concurrently Processes are separate executable, loadable modules Each process has its own separate program space. Process A cannot read or write into process B's program space. Each process carries the same overhead in terms of bulk that an EXE requires.

Thread
A thread is a task that runs concurrently with other tasks within a single executable file Threads are memory efficient Threads share a common program space Thread task switching time is faster Threads are typically not loadable

Task
Task is a generic term that refers to an activity carried out by software that occurs independently from other activities in the system. Tasks are separate executing programs called Process. Tasks execute in the context of a single program (Process) called Thread. A task is an independent thread of execution, capable of executing in parallel with other threads of execution.

What is a VxWorks Task?


A task is a context of execution. It has:
a program counter (current location of execution). private copies of CPU registers. a stack for local variables, function arguments, and function call chain information.

It is often essential to organize an application into independent, though cooperating, programs; each of these programs while executing is called a task.

What is a VxWorks Task?


As VxWorks is a uniprocessor system, only one task is actually executing at any given time.
When a task is not executing, its context is stored in its Task Control Block (TCB) and stack. The TCB is the data structure which the kernel uses to represent and control the task.

Task Control Block Contains.


Tasks Program Counter. CPU Registers (Optionally floating point registers). A stack for dynamic variables. I/O assignments for standard input, output and error. A delay timer. A timeslice timer Signal handlers. Debugging and performance monitoring values.

Performance Optimizations
All tasks execute in the same address space:
RAM fooLib.c
static int x;

tTaskA fooSet(4)

text data bss

void fooSet (int arg) { x = arg; }

tTaskB fooSet(99)

All tasks execute at highest CPU privilege level.

Task State Transition Diagram


PENDED READY DELAYED

EXEC.

PENDED & SUSPENDED

SUSPENDED

DELAYED & SUSPENDED

Scheduling Policies
First-Come-First-Served (FCFS) Shortest Job First (SJF) Priority based Pre-emption Round-Robin (RR) Co-Operative

Pre-emptive Scheduling
A multi-tasking scheduling policy by which a higher priority task will preempt a lower priority task when the higher priority task has work to do

Round-Robin Scheduling
A multi-tasking scheduling policy in which all tasks are run in their turn for a fixed Time period, one after the other. When all tasks have run, the cycle is repeated.

Co-operative Scheduling
A group of tasks run cooperatively where each must voluntarily relinquish control so that other tasks can run. In other words A task will run forever, thus starving other tasks, unless it voluntarily gives up control. Control can be relinquished explicitly by a yield, pause, or suspend; or implicitly by waiting for an event.

Wind Task Scheduling


The Wind Kernel employs a priority-based, preemptive scheduling as the default algorithm. The Wind Kernel scheduling behaviour can be modified and can get round-robin scheduling or No preemptive scheduling. There are 256 priority levels. 0 is the highest & 255 is the lowest. Tasks are assigned a priority when created, however, while executing, a task can change its priority.

Preemptive Priority Scheduling


At any time, the highest priority task ready to run, runs! A higher priority task which is made ready preempts the executing task. Interrupts preempt any task.
Notes: On this board, INT 6 is the system clock, INT 3 is the network interrupt.

Context Switches
When one task stops executing and another task starts, a context switch has occurred. Context switches occur:
If a higher priority task becomes ready to run
made ready by executing task. made ready in an interrupt, or times out on a blocking call.

If the executing task makes a blocking kernel call (moving into a pended, delayed, or suspended state).

What happens:
CPU registers for outgoing task stored in its TCB. CPU registers for incoming task retrieved from its TCB.

Round-Robin Scheduling
To allow equal priority tasks to preempt each other time slicing must be turned on: kernelTimeSlice (ticks) if ticks = 0, time slicing is tuned off. Priority scheduling always takes precedence.
Round-Robin only applies to tasks of same priority.

Interrupt Service Routines


An ISR is a piece of code which is connected to a particular hardware interrupt. When the hardware interrupt occurs, the ISR runs. ISRs have an effective priority higher than any task. Whether and how ISRs can preempt each other is board dependent. An ISR has no permanent context; it is NOT a task.
An ISR may call only a limited set of VxWorks functions. Basic rule of thumb: If a routine could block, an ISR cannot call it.

Interrupt Service Routines

VxWorks Quick-Start
VxWorks Libraries

VxWorks Libraries / Modules


VxWorks routines are grouped into libraries (modules containing code and data). Many of these libraries are optional; VxWorks may be built with or without them. Each library has one or more header files. Examples:
Module taskLib semLib memPartLib sockLib Routine taskSpawn() semTake() malloc() sendto() Header files taskLib.h semLib.h stdlib.h sys\types.h, sys\socket.h, sockLib.h

Reference manual lists header files for each library.

taskLib
taskLib contains the kernel functions for creating, destroying, starting and stopping tasks. Example routines:
To create and start a new task:

int taskSpawn (name, priority, options, stackSize, entryPt, arg0, , arg9)


To delay the executing task for a certain number of system clock ticks:

STATUS taskDelay (ticks)

Task Management System Calls


Task Scheduler Controller Routines
kernelTimeSlice() Control Round-Robin Scheduling taskPrioritySet() Change the priority of task taskLock() Disable task rescheduling taskUnlock() Enable task rescheduling

Task Creation Routines


taskSpawn() Spawn (create & activate) a new task taskInit() Initialize a new task taskActivate() Activate an initialized task

Task Management System Calls


Task Option Routines
taskOptionsGet() - Examine task options. taskOptionsSet() - Set task options. VX_FP_TASK - Execute with the floating-point coprocessor. VX_NO_STACK_FILL - Do not fill stack with 0xee. VX_PRIVATE_ENV - Execute task with a private environment. VX_UNBREAKABLE - Disable breakpoints for the task.

Task Management System Calls


Task Name and ID Routines
taskName() Get the task name associated with a task ID taskNameToId()

Look up the task ID associated with a task name


taskIdSelf() Get the calling tasks ID taskIdVerify() Verify the existence of a specified task

Task Deletion Routines


exit() - Terminate the calling task and free memory taskDelete() - Terminate a specified task and free memory taskSafe() - Protect the calling task from deletion. taskUnsafe()- Undo a taskSafe( ) (make the calling task

Task Management System Calls


Task Control Routines
taskSuspend() - Suspend a task. taskResume() - Resume a task. taskRestart() - Restart a task. taskDelay() - Delay a task; delay units are ticks.

VxWorks System Tasks


Root Task (tUsrRoot).
First task executed by the kernel. Initializes the VxWorks facilities and spawns the system tasks.

Logging Task (tLogTask).


Logs system messages without performing I/O in current task context.

Exception Task (tExcTask).


Supports VxWorks exception handling package.

Network Task (tNetTask).


Handles task level functions required by VxWorks Network.

Target Agent Task (tWdbTask).


Services the requests from Tornado target server.

Optional Task (Tshell, Trlogin, tTelnetd, Tportmapd).

Thank You

Вам также может понравиться