vxworks培训教程(10)
VxWorks开发教程(2024)
03
无线通信应用案例分 析
通过分析一个具体的无线通信应用案 例,展示如何在VxWorks系统中实现 无线通信功能,并提供一些优化和改 进的建议。
2024/1/28
35
08
图形界面开发与多媒体应用支 持
Chapter
2024/1/28
36
图形界面开发框架介绍
WindML
2024/1/28
29
设备驱动开发流程
01
需求分析
明确设备的功能需求、性能需求 和接口需求,为后续的设备驱动
开发提供基础。
03
编码实现
依据设计文档,使用C语言等编程 语言实现设备驱动的代码编写。
2024/1/28
02
设计阶段
根据需求分析结果,设计设备驱 动的整体架构、数据结构和函数
接口等。
04
测试与验证
2024/1/28
10
建立工程及源代码管理
创建新工程
在Workbench中,选择“File”->“New”>“VxWorks Project”,然后按照向导创建一个 新的VxWorks工程。
配置工程属性
在工程属性中,你可以设置编译选项、包含路径 、链接库等。确保这些配置与你的目标机和源代 码相匹配。
配的内存。
使用memPartAlloc和memPartFree函数:VxWorks提供了内存分区管理功能,可以 使用memPartAlloc函数从指定的内存分区中分配内存,使用memPartFree函数释放
内存到相应的分区。
2024/1/28
使用taskAlloc和taskFree函数:针对任务相关的内存分配,可以使用taskAlloc和 taskFree函数。这些函数会从任务的控制块中分配和释放内存。
Vxworks开发简明培训教程服务器应用
Vxworks开发简明培训教程服务器应用一、教学内容本教程服务器应用部分,主要针对VxWorks操作系统的服务器应用进行讲解。
教材涵盖的章节有:第三章网络编程,第四章服务器编程,第五章Web服务器开发。
具体内容如下:1. 第三章网络编程:介绍VxWorks操作系统中的网络编程基础,包括套接字编程、TCP/IP协议栈的使用等。
2. 第四章服务器编程:讲解如何在VxWorks中实现网络服务器,包括基于TCP和UDP的服务器编程。
3. 第五章Web服务器开发:介绍Web服务器的基本原理,以及在VxWorks中如何开发Web服务器。
二、教学目标1. 使学生掌握VxWorks操作系统的基本网络编程方法。
2. 培养学生具备在VxWorks中实现网络服务器的能力。
3. 让学生了解Web服务器的工作原理,并能在VxWorks中进行开发。
三、教学难点与重点1. 教学难点:VxWorks网络编程中的socket API,Web服务器开发中的HTTP协议处理。
2. 教学重点:服务器编程的基本方法,Web服务器的核心模块实现。
四、教具与学具准备1. 教具:多媒体教学设备,VxWorks操作系统安装光盘。
2. 学具:学生个人电脑,VxWorks操作系统安装文件,网络编程实践案例。
五、教学过程1. 引入实践情景:以企业实际需求为背景,讲解网络编程在服务器应用中的重要性。
2. 讲解第三章网络编程:通过示例代码,讲解VxWorks中的套接字编程方法。
3. 讲解第四章服务器编程:以TCP服务器为例,讲解服务器程序的实现过程。
4. 讲解第五章Web服务器开发:介绍Web服务器的工作原理,以及在VxWorks中实现Web服务器的方法。
5. 随堂练习:让学生根据所学内容,编写一个简单的网络服务器程序。
6. 例题讲解:分析并讲解典型的网络编程问题,如Socket编程中的粘包问题。
7. 课后作业:布置作业题目,要求学生完成一个基于VxWorks的Web服务器程序。
VxWorks操作系统基础(适合初学者阅读)2024新版
系统库(System Library)
提供一系列操作系统服务,如文件操作、网络协议栈等。
驱动程序(Device Drivers)
与硬件设备交互,实现对硬件设备的控制和管理。
内核组成及作用
内核组成及作用
01
内核的主要作用包括
02 管理系统资源,如CPU、内存、I/O设备等 。
06
VxWorks文件系统操作指南
文件系统类型及特点介绍
RAM-based File System
基于RAM的文件系统,读写速度快,但数据在 关机后丢失。
TrueFFS
Wind River特有的闪存文件系统,提供磨损均 衡和掉电保护功能。
ABCD
DOS File System (dosFs)
兼容MS-DOS的文件系统,支持FAT12、FAT16 和FAT32格式。
01
VxWorks操作系统概述
VxWorks操作系统定义
VxWorks是一款由美国风河公司( Wind River)开发的嵌入式实时操 作系统(RTOS),专为需要实时响 应和高可靠性的应用而设计。
VxWorks提供了丰富的中间件和开发 工具,支持多种处理器架构和硬件平 台,广泛应用于航空、航天、通信、 医疗、工业自动化等领域。
在ISR中处理完中断事件后, 需要及时清除中断标志,避 免重复处理。
中断优先级设置和嵌套处理
01
VxWorks支持多级中断优先级,高优先级的中断可以打断低优先 级的中断处理。
02
中断优先级可以通过配置文件或动态调整进行设置,以满 足不同应用场景的需求。
03
在处理中断时,如果发生更高优先级的中断请求, VxWorks会自动保存当前中断的上下文信息,并跳转到更 高优先级的中断处理程序中。处理完成后,再恢复之前中 断的上下文信息并继续执行。这种机制称为中断嵌套处理 。
实时嵌入式系统 VxWorks培训
1.5.3GDB--调试界面
1.5.4WindView--多任务观察界面
1.5.5程序编辑--Source Insight
开发环境的主要部件是宿主机(host)、目标机 (target) 典型的交叉平台系统代码(如实时嵌入式操作系统、系统 软件和应用软件)通常保存在ROM和NVRAM存 储设备中。 对嵌入式系统软件的升级就是利用特殊的设备 与/或特殊的方法重写EPROM中的程序或重写闪 存(flash)中的程序。
1.5 vxWorks及其开发环境
VxWorks 操作系统是美国WindRiver 公司于 1983 年设计开发的一种嵌入式实时操作系统 (RTOS),是嵌入式开发环境的关键组成部分。 vxWorks5.5开发环境为Tornado 2.2.1
1.5.1Tornado—安装目录
1.5.2Tornado--集成编译环境
1.1.1实时系统特性
实时系统必须产生正确的结果 实时系统的响应必须在预定的周期内完成 实时系统是具有确定性的。在这些实时系统中, 响应时间决定事件是有界的。一个确定的实时系 统意味着系统的每个部件都必须具有确定的行为, 使得整个系统是确定性的。
1.2嵌入式处理器
通用目的的处理器:它的设计非常丰富,可以 提供全部的特性和广泛的功能。但这些处理器 能源消耗大,产生的热量高,尺寸也大,其复 杂性也带来了制造成本的昂贵 嵌入式处理器:它是为完成特殊的应用而设计 的特殊目的的处理器 – 注重尺寸、能耗和价格的处理器 – 注重性能的处理器 – 注重性能、尺寸、能耗和价格的处理器
一、实时嵌入式系统 VxWorks 和Tornado开发环境
1.1实时嵌入式系统
嵌入式系统是设计完成复杂功能的硬 件和软件,并使其紧密耦合在一起的计算 机系统。术语嵌入式反映了这些系统通常 是更大系统中的一个完整的部分,称为嵌 入的系统。嵌入的系统中可以共存多个嵌 入式系统。
vxWorks BSP培训文档
vxWorks BSP 培训资料1BSP的概念1.1什么是BSP一个成熟的商用操作系统,其被广泛应用的必要条件之一就是能够支持众多的硬件平台,并实现应用程序的硬件无关性。
一般来说,这种无关性都是由操作系统来实现的。
但是,对于嵌入式系统来说,它没有像PC机那样所遵循的各种工业标准,各种嵌入式系统其具有的不同应用需求就决定了它一般都选用了各自定制的硬件环境,这种诸多变化硬件的环境就决定了无法完全由操作系统来实现上层软件与底层硬件之间的无关性。
因此当今的各种商用实时操作系统,都采用了分层的设计方法,它将系统中与硬件直接相关的一层软件独立出来,称之为Board Support Package即简称BSP。
顾名思义,这部分软件是针对某个单板而设计的,并且这一层软件对于用户(指开发者)也是开放的,用户可以根据不同的硬件需求对其作改动或二次开发,而操作系统本身仅仅提供了CPU内核的无关性。
1.2BSP的功能一个采用分层设计方法的典型系统,其结构如下(以UAS系统为例):图1 UAS软件总体框架BSP位于硬件平台与操作系统之间,用于对上层软件屏蔽各种硬件相关性。
BSP的主要功能在于配置系统硬件使其工作于正常的状态,完成硬件与软件之间的信息交互,为OS及上层应用程序提供一个与硬件无关的软件平台。
因此从执行角度来说,其可以分为两大部分:1)目标系统启动时的硬件初始化例程,只在系统启动过程中执行一次。
用于配置系统内硬件工作于指定状态。
2)目标板上控制各个硬件设备正常运行的设备驱动程序,由它来完成硬件与软件之间的信息交互。
其在整个软件系统中随着这种交互的发生而执行。
虽然通常BSP是为OS服务的,但实际上,BSP软件包中的部分程序对OS也并不是必须的,从这个角度,又可以将BSP 划分为两部分功能,1) 提供OS 运行所必须的硬件初始化例程及驱动程序,如单板最小系统BSP 等。
2) 为满足OS 之上的应用程序的需求而提供的一些外围设备的驱动程序,如网口,HDLC 控制器Driver 等,这些驱动程序一般需要应用程序通过OS 层与BSP 交互,当然可能还包括直接与应用程序交互的一些硬件驱动,如对各种控制信号的存取,自定义的驱动程序接口等,不经过OS 层。
vxworks培训教程(10)
vxworks培训教程(10)Wind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-1Chapter10Exceptions, Interrupts,and TimersException Handling and SignalsInterrupt Service RoutinesSystem Clock, Auxiliary Clock, Watchdog TimersWind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-2Exceptions, Interrupts, and Timers10.1Exception Handling and SignalsInterrupt Service RoutinesTimersException handlingUsing signalsInstalling user-de?ned signal handlerWind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-3Exception Handling Overview An exception is an unplanned event generated by theCPU. Examples include: trap or breakpoint instruction,divide by zero, ?oating point or integer over?ow, illegalinstruction, or address error.An exception will generate an “internal” interrupt.VxWorks installs exception handlers at system startup.These handlers will run on an exception and will try toinvoke a user-de?ned exception handler.A VxWorks exception handler communicates with auser tasks by sending a signal. The user-installedhandler will then run.Exceptions vary across CPU architectures. The help page for excLibcontains information about generic exception handling, while the page for excArchLib discusses architecture-speci?c routines.Wind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-4SignalsnormalCode(){........}mySignalHandler(){........}signal ? A signal is the software analog of an interrupt:A signal sent to a task indicates some asynchronous event has occurred.?There are 31 unique signals, each representing a different event.A task can attach a signal handler to take appropriate action when thesignal is received.Upon completion of signal handling, normal task execution is resumed(unless the signal corresponds to an exception).For more information on signals, see Advanced Programming in the UNIXEnvironment by Stevens.Wind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-5UNIX: UNIX vs. VxWorks Signals Signal is ignored if no handler is installed.“Automatic function restarting”Can install a handler to catch SIGKILL .No SIGCHLD ,SIGPIPE , or SIGURG .taskDelay() sets errno =EINTR and returns ERROR ifinterrupted by a signal.signalPend QReady QRunsignal-handler semTake(...,OrigDelay )“Automatic function restarting” describes behavior for a task whichcatches a signal while on the pend queue:1.Task receives a signal while pended.2.Task is removed from pend queue and made ready to run.3.When the task is the highest priority task on the Ready queue, it runs itssignal handler for the signal it caught.4.After running its signal handler, the task is returned to the pended state,with its originally speci?ed timeout.Wind River SystemsTornado Training Workshop ? Copyright Wind River Systems 10-6CaveatsSignals are not recommended for general intertaskcommunication. A signal:qMay be handled at too high a priority if it arrives during a priority inheritance.qDisrupts a task’s normal execution order. (It is better to create two tasks than to multiplex processing in one task via signals.)qCan cause reentrancy problems between a task running its signal handler and the same task running its normal code.q Can be used to tell a task to shut itself down.sigLib contains both POSIX and BSD UNIX interfaces.Do not mix them.Consider a task which enters a critical region by taking a mutexsemaphore guarding some shared resource. Suppose the task receives a signal while in the critical region. If the signal handler also attempts to take the mutex, it will succeed, and the resource may be corrupted.?Include signal.h or sigLib.h when programming with signals.To send a (non-exception) signal use the kill (tid, signo) function. Usesigqueue () to send queued signals.Wind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-7Registering a Signal Handler To register a signal handler:signal (signo, handler)signo Signal number.handlerRoutine to invoke when signal arrives (orSIG_IGN to ignore signal).Returns the previously installed signal handler, or SIG_ERR .The signal handler should be declared as:void sigHandler (int sig);/* signal number */? A VxWorks signal handler is passed not only the signal number but also two additional parameters. To access these additional parameters,declare your signal handler asvoid sigHandler(int sig,/* signal number */int code,/* additional code */struct sigcontext * pSigCtx);The code argument can be used to distinguish different exceptionswhich generate the same signal. See sigLib for the architecture speci?c codes. The pSigCtx argument points to saved context information for the task which received the signal. Its use is architecture dependent.? A third signal handler prototype is used for signals generated bysigqueue () and some routines in the POSIX Real-Time Extensions libraries. See sigLib for details.Wind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-8Signals and ExceptionsHardware exceptions include bus error, address error,divide by zero, ?oating point over?ow, etc..Some signals correspond to exceptions (e.g.,SIGSEGVcorresponds to a bus error on a 68k;SIGFPE correspondsto various arithmetical exceptions).myCode(){.......}bus error Task has SIGSEGV signal handler installed?Suspend task Log error messageraise signal ?When an executing task generates an exception: qIf the task has a signal handler installed to deal with that exception,VxWorks will raise the signal to that task.q If the task has no signal handler installed for that exception,VxWorks will suspend the task and log an error message to the console.The correspondence between signals and exceptions is architecturedependent. See sigLib .Wind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-9The Signal HandlerIf an exception signal handler returns:qThe offending task will be suspended.q A message will be logged to the console.Exception signal handlers typically call:q exit() to terminate the task, orq taskRestart() to restart the task, orq longjmp() to resume execution at location saved by setjmp().?For more information on setjmp()/longjmp(), see the onlinedocumentation or Advanced Programming in the UNIX Environment by Stevens.Signal handlers responding to asynchronously generated signals (sent byanother task or ISR) should return rather than exit non-locally with exit(),taskRestart(), or longjmp(). Such non-local exits, occurring in a signal handler called at an indeterminate point in the task’s execution,can leave shared resources (e.g., the system memory pool) corrupted.See also the reference entry for sigprocmask() for blocking signals during critical sections of a task’s execution.See the Exception Handling example in Appendix A.Wind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-10Exceptions, Interrupts, and Timers Exception Handling and Signals10.2Interrupt Service RoutinesTimersISR BasicsISR RestrictionsInterruptsInterrupts allow devices to notify the CPU that someevent has occurred.A user-de?ned routine can be installed to execute when an interrupt arrives.This routine runs at interrupt time. It is not a task.On-board timers are a common source of interrupts.Using them requires understanding interrupts.Tornado Training Workshop? Copyright Wind River Systems10-11Wind River SystemsDevice DriversUse interrupts for asynchronous I/O.Are beyond the scope of this course.For more information:intArchLib To install user de?ned ISR’s.Board Support Package Board-speci?c interrupt handling.Programmers Guide Architecture speci?c interrupt info.Tornado User’s Guide System mode debugging info.BSP Porting Kit Optional product for writing BSP’s.VxWorks Device Write VMEbus and VxWorksDriver Workshop standard device drivers.Tornado BSP BSP-speci?c interrupt issues, suchTraining Workshop as interrupt controllers and busses.Tornado Training Workshop? Copyright Wind River Systems10-12Wind River SystemsWind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-13Interrupt Handling Example (68k)save registers Interrupt ServiceRoutine (ISR)restore registerscall routine REThandlervectornumber hardware handler:Interrupt Vector TablemyISR (){..}.User ISR ?When an interrupt occurs:1.Switch to a dedicated interrupt stack (except for x86, R6000, CPU-32,MC68060, MC68000, and MC68010 which take interrupts on task stacks.).2.In handler wrapper routine, save volatile registers and errno .3.Call user-de?ned interrupt handler from handler wrapper.4.On return from handler, restore values previously saved and returnfrom interrupt level. May result in a reschedule of the previously executing task if a higher priority task was made ready to run.User-de?ned interrupt handler code can be installed by intConnect().Wind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-14Interrupt Handling Example (PowerPC) Exception Vector T able0x500External Exception Handler 0123456...Interrupt Table Exception Vector Interrupt Number User ISR #1User ISR #2...The PowerPC has a single external interrupt pin. A BSP may support an external interrupt controller to support nested interrupts. For details,see excArchLib and VxWorks Programmer’s Guide appendix on PowerPC.The number of entries in the interrupt table is dependent on which interrupt controller(s) your BSP supports. ISRs may be chained for a given BSP .The VxWorks external exception handler:qsaves CPU registers qreads interrupt number from interrupt controller qsequentially calls all chained interrupts at that number qcommunicates to interrupt controller that ISR is complete q restores CPU registers and returnsWind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-15Displaying the Interrupt Vector Table To show the interrupt vector table from the Browser,choose Vector Table in the selector box (Windows), orclick on the Interrupt button (UNIX).Not all CPU architectures support an interrupt vector table.This screenshot displays a portion of the interrupt vector table on amv162 BSP (MC68040 CPU). Interrupt numbers 144, 146, 148, 150, 152,154, 156, and 158 are mapped by this BSP to interrupts from the board’s Z8530 serial communications controller. The highlighted entry, 156, has installed handler _z8530IntRd, the receive ISR for this serial device.?Note that the same handler is also installed at number 148, because theZ8530 has two ports, each with its own installed ISRs. If the table we see _z8530IntRd at number 148 (SCC 1, channel B), and 156 (SCC 1,channel A). The interrupt mapping for this BSP is done set in mv162.h ,sysSerial.c ,sysScsi.c , and sysLib.c .Wind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-16Interrupts and PrioritiesInterrupt Interrupt Interrupt ...Task Task Task ...Execution Order Controlled by Hardware A b s o l u t e S y s t e m -W i d e P r i o r i t y Execution Order Controlled by Kernel Task Priority Interrupt Level (Programmable)(Hard Wired)?Interrupts preempt even highest priority task.Wind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-17Interrupt StackMost architectures use a single dedicated interruptstack.Interrupt stack is allocated at system start-up.The interrupt stack size is controlled by the macroINT_STACK_SIZE;default value de?ned in con?gAll.h .Must be large enough for worst-case nesting.Interrupt Stackint level 2int level 3int level 5x86, CPU-32, R6000, MC68060, MC68000, and MC68010 are CPU’swhich use tasks’ stacks for processing interrupts. Consequently, each task’s stack must have enough extra space to handle the worst-case nesting of interrupts.Use checkStack() or the Browser to check task stacks for stackcrashes.Interrupt stacks may be checked manually; on many architectures, the variables vxIntStackBase (where the stack starts) and vxIntStackEnd (towards which the stack grows) identify the ends of the interrupt stack region. Dump memory from vxIntStackEnd to vxIntStackBase. Thelocation where the 0xee bytes stop indicates the high water mark of ISR stack usage.Wind River Systems Tornado Training Workshop ? Copyright Wind River Systems 10-18ISR RestrictionsNo tasks can run until ISR has completed.ISR’s are restricted from using some VxWorks facilities.In particular, they can’t block:qCan’t call semTake().qCan’t call malloc() (uses semaphores).q Can’t call I/O system routines (e.g.,printf()).?The Programmer’s Gui de gives a list of routines which arecallable at interrupt time.The one I/O system call which can be made from an ISR is write( ) to apipe.ISR GuidelinesKeep ISR’s short, because ISR’s:q Delay lower and equal priority interrupts.q Delay all tasks.q Can be hard to debug.Avoid using ?oating-point operations in an ISR.q They may be slow.q User must call fppSave() and fppRestore().Try to off-load as much work as possible to some task:q Work which is longer in duration.q Work which is less critical.Tornado Training Workshop? Copyright Wind River Systems10-19Wind River Systems。
第十课_VxWorks讲解
VxWorks_rom 的压缩形式
BootRom
压缩方式的映象,生成的时候编译器会把除掉romlnit.s 和bootInit.c之外的目标文件压缩并“汇编”成一个 bootrom.Z.s,最后和romInit.o,bootInit.o, version.o进行链接,生成bootrom映像
要全部拷贝到ram中,并必须要进行解压缩的工作。而这 些工作基本上都是在bootInit.c中进行的。
2010年4月的VxWorks 653
面向安全关键级别,航空电子设备市场,如波音787 基于Power Architecture架构(PowerPC)以及intel架构;严格的
两级时间与空间调度;文件系统具有电源故障安全保护功能
6
课程大纲
VxWorks简介 VxWorks映像 Wind 内核 VxWorks内存管理及其他 VxWorks开发环境
VxWorks 6.0的航向标
对MMU、CACHE和大物理地址的抽象化
4
支持多核的6.7版本
支持多核
非对称式多重处理(asymmetric multiprocessing; AMP)
对称式多重处理(symmetric multiprocessing; SMP)
降低功率消耗 multicore-aware工具
BootRom类型映像 VxWorks类型
8
BootRom类型映像
最小化、专用的VxWorks引导映像,实现最少的系统 初始化
用于启动装载VxWorks映像 功能类似于PC机的BIOS
BootRom运行时建立起多任务环境
usrRoot任务、网络任务、TFFS任务和FTP任务等
VxWorks基础培训
SHELL
EDIT DEBUGGER
Project
Browser
Windview
WDB
The WDB (Wind DeBug) protocol specifies how the target server (on the host) communicates with the target agent (on the target).
在VxWorks中,任务有几种状态 :就绪 (READY)、阻塞(PEND)、睡眠 (DELAY)、挂起(SUSPEND)及它们的 组合DELAY+S、PEND+S、PEND+T、 PEND+S+T、State+I。
任务状态转换
• Wind微内核的状态迁移表如下图所示:
Wind内核的任务调度
• 多任务处理需要一个调度法则对CPU准备运行的
基于优先级的抢占式调度与轮转调度算法相结合调度示意图
抢占上锁
• Wind的调度器可以通过tasklock( )和
taskUnlock( )对一个任务锁定或允许抢先调 度。当一个任务通过调用taskLock( )来锁定 抢先调度,在任务的运行期间就避免了高 优先级的任务的抢占。
VxWorks任务编程接口
删除安全
• 互斥中的另一个问题涉及到任务的删除。删除一
个在临界资源中的正在执行的任务往往会带来严 重的错误。
• 互斥信号量提供了一个SEM_DELETE_SAFE的参
数使得每个semTake()都含有taskSafe(),且每 个semGive()都含有taskUnsafe()。通过这个方法, 一个持有信号量的任务就可以得到删除保护。
共享内存访问互斥
vxworks培训讲稿(嵌入式系统)
第一部分 VxWorks & Tornado Overview第一章 绪论VxWorks是一种嵌入式的实时操作系统,所谓嵌入式系统就是用户自己开发设计板子,板子上通常有一颗CPU,VxWorks支持32位的CPU,包括Intel公司的x86、Motorola公司的68k和PowerPC、MIPS、ARM、Intel公司的i960、Hitachi公司的SH。
我们设计的这块板子通常没有软件的自开发能力,所以我们需要一台通用机来辅助开发,这台通用机可以是PC或工作站,我们称辅助我们软件开发的通用机为宿主机(Host),用户自己开发的板子为目标机(Target)。
宿主机上要有一个集成开发环境(IDE)来辅助我们的软件开发,这套集成开发环境可以运行在Windows95/NT或 UNIX下,包括交叉编译器(Cross Compiler)和交叉调试器(Cross Debugger),所谓交叉编译器就是在宿主机上编译生成可以在目标机上运行的代码IMAGE,交叉调试器就是通过宿主机和目标机之间的某种耦合方式实现前后台调试。
我们称宿主机上的这套集成开发环境为Tornado,编译生成的目标机上的可执行代码IMAGE为VxWorks。
在系统安装的时候,集成调试环境和VxWorks的原材料(一些obj文件)都安装到宿主机上,编译生成的在目标机上运行的IMAGE内包含操作系统。
下面我们分别来介绍这两部分内容。
第二章 VxWorks第一节 IMAGE的结构VxWorks的IMAGE有三个层次、四个部分。
其RTOS内核是wind kernel,这个内核有两个特点:1.w ind kernel是一个微内核,这个特点导致VxWorks有许多的Components2.w ind kernel对外设不做假设。
所谓对外设不做假设是指操作系统不假设用户开发的板子上是否有总线以及有什麽样的总线,也不假设内存的大小及内存如何定位,不假设I/O 及有多少I/O。
精Vxworks教程
06 VxWorks内存管 理编程实践
动态内存分配策略
分段内存管理
将内存划分为不同大小的段,根据需求动态分配和释 放内存段。
内存池管理
创建多个内存池,每个内存池管理特定大小的内存块 ,提高内存分配效率。
自定义内存分配器
根据应用需求,实现自定义的内存分配器,以满足特 定场景下的内存管理需求。
内存泄漏检测工具使用
优化内存使用技巧
减少全局变量使用
尽量避免使用全局变量,以减少内存占用和 提高程序可维护性。
合理使用指针和引用
在传递数据时,尽量使用指针和引用而非直 接传递数据,以降低内存消耗。
及时释放不再使用的内存
在程序运行过程中,及时释放不再使用的内 存资源,避免造成不必要的内存浪费。
使用内存对齐和压缩技术
合理利用内存对齐和压缩技术,提高内存使 用效率并降低内存碎片化的风险。
01
根据目标硬件平台和开发需求选择合适的编译器,如GNU
Compiler Collection (GCC) 或 Wind River Diab Compiler。
设置编译器选项
02
在Workbench中配置编译器的选项,如优化级别、警告级别、
语言标准等。
编译项目
03
使用选定的编译器对项目进行编译,生成可在目标硬件上运行
同步与互斥机制实现
互斥锁
条件变量
互斥锁是一种用于实现互斥访问共享 资源的同步机制。在VxWorks中,互 斥锁通过`mutexCreate()`函数创建, 并通过`mutexLock()`和 `mutexUnlock()`函数进行锁的获取 和释放。当一个任务获取了互斥锁时 ,其他试图获取该锁的任务将被阻塞 ,直到锁被释放。
VxWorks入门
嵌入式实时操作系统VxWorks入门VxWorks操作系统是美国WindRiver公司于1983年设计开发的一种嵌入式实时操作系统(RTOS),它以其良好的可靠性和卓越的实时性被广泛地应用在通信、军事、航空、航天等高精尖技术及实时性要求极高的领域中,如卫星通讯、军事演习、弹道制导、飞机导航等。
在美国的F-16、FA-18 战斗机、B-2隐形轰炸机和爱国者导弹上,甚至连1997年4月在火星表面登陆的火星探测器上也使用到了VxWorks。
VxWorks原先对中国区禁止销售,自解禁以来,在我们的军事、通信、工业控制等领域得到了非常广泛的应用。
嵌入式系统的调试方法一般为通过PC(宿主机)上的集成开发环境交叉编译针对特定电路板(目标机)的程序,然后将程序通过目标板的JTAG、串口或网口等途径下载到目标板上运行。
如图1。
因此,为了构造一个嵌入式系统的学习环境,拥有一块包含CPU、存储器及I/O电路(构造计算机系统)的目标电路板往往是必要的。
虽然许多集成开发环境附带模拟软件,但仅限于指令集的模拟,均无法模拟物理的目标机硬件平台,因而在其上只能进行应用程序的象征性模拟开发。
但是,并非所有人都能拥有一块物理的电路板。
在这种情况下,我们如何构造一个模拟的开发环境,其学习效果就如同拥有完全真实的电路板一样呢? 本文试图解答此问题,主体内容包括四个方面:1.利用VMware等软件模拟真实的目标机;2.构建VMware虚拟PC上VxWorks BSP,建立Bootrom和OS映像;3.修改Tornado相关设置,连接宿主机与目标机,建立调试通道;4.写一个简单的应用程序并下载到目标系统运行。
图1 嵌入式系统的调试本章工作的最终目标为:(1)VxWorks在VMware启动成功并顺利运行,如图2;图2 在VMware中运行的VxWorks(2)可在Tornado上针对目标板编译程序并进行调试,如图3。
图3 与目标机建立调试通道的Tornado1. 模拟目标机PC也具有目标机的所有特点,实际上,我们可以把PC作为嵌入式系统的目标机,从而构造如图4所示的开发模型:图4 PC作为目标机很遗憾,这种方法实际上非常麻烦,同时开动两台PC进行调试将使你和你的室友饱受折磨,既然他如此地热切于游戏和上网。
Vxworks学习资料整理
Vxworks学习资料整理Vxworks学习资料整理 (1)1 基于硬盘启动的Vxworks环境搭建 (3)2 Vxworks引导盘制作 (6)2.1 通过DOS加载VxWorks方法 (6)2.2 Bootrom三种类型 (7)2.3 VxWorks映象 (7)2.4 Bootrom.sys最快制作方法 (8)2.5 从网络引导 (8)2.6 从本地硬盘引导 (9)2.7 制作bootrom文件 (9)2.8 Bootrom编译步骤 (11)2.9 用BSP生成Bootable工程(即我们的程序文件) (12)2.10 FTP Server下载VxWorks (14)3 Tornado调试环境的建立 (17)3.1.1 配置文件config.h (17)3.1.2 网络连接 (18)6 从主机搭接(attach)到目标机 (21)7.1.3 串口连接 (21)4 4.Config.h文件注释说明 (22)4.1 启动行说明 #define DEFAULT_BOOT_LINE \: (22)4.2 Config.h 文件说明 (23)4.3 启动参数结构体 BOOT_PARAMS (35)4.4 booting过程介绍,比较详细 (39)5 sysClkRateGet();返回系统时钟每秒的tick数量, tick详解 (43)6 中断应用设计要点 (44)7 驱动程序设计 (49)8 缩短vxworks的启动时间 (52)9 调试篇 (55)10 驱动编程步骤 (55)10.1 将驱动程序增加到“系统驱动程序列表”中 (55)10.2 将设备增加到“系统设备列表”中 (55)10.3 打开设备,得到文件描述符 (55)10.4 SELECT机制的使用 (56)10.4.1 select( )函数翻译 (58)11 VxWorks系统的网络驱动(END) (60)12 VXworks操作系统中信号量用于多任务同步与互斥的讨论 (62)12.1 二进制信号量实现互斥和同步 (64)12.1.1 互斥的实现: (64)12.1.2 同步的实现: (65)12.2 互斥信号量 (67)13 Tornado的文件目说明录 (68)14 Shell 内置命令说明 (72)14.1 任务管理 (72)14.2 任务状态信息 (72)14.3 系统修改和调试 (73)14.4 对象命令( WindSh Commands for Object Display ) (73)14.5 WindShell and Browser, Shell 命令 (74)15 驱动篇 (82)16 中断篇 (83)16.1 中断服务程序ISR编写注意事项 (83)16.2 中断号与中断向量的转换 (84)16.3 安装中断服务程序 intConnect() (84)16.4 调试中断服务程序方法 (84)17mkboot批处理命令详细解释 (84)18 MakeFile 说明 (86)19 VxWorks5.4中的输入输出重定向 (89)19.1 vxworks屏幕输出, 一般来说用printf都是串口/shell输出,串口输出就可以到屏幕上了? (89)19.2 20.2 VxWorks中针对X86开发时标准输入输出的重定向? (90)20 怎样加入外部.o文件? (93)21 如何在Vxworks中使用 cd ,pwd , ls 命令:启用File System and Disk Utilities 组件(INCLUDE_DISK_UTIL),可在shell下用pwd/cd/ls等命令 (94)22 Error: image is larger than 524288 bytes (94)23 proxyArpDefaultOn()未定义解决方法? (95)24 如何将VxWorks的系统定时间隔或系统Ticks设置为1ms (95)25 read/write、fread/fwrite、fopen/open有什么区别 (96)26 快速启动 (100)27 启动时报ATA0a和硬盘启动相关问题 (100)28 如何安装USB2.2新版本及编译USB驱动? (101)29 WindML、图形界面相关问题 (102)29.1 WindML,ugldemo出错? (102)29.2 5101 VxWorks黑屏问题? (102)29.3 添加ugldemo.c后,编译报undefined reference to “ugltextdraw”错误一大堆? (103)29.4 WindML 中文字库显示? (103)30 VxWork6.8相关问题 (105)30.1 ELF和bin文件的区别? (105)30.2 diab和GNU的区别? (106)31 No such file or directory错误? (108)专业术语:WTX协议:(Wind River Tool eXchange): 用于开发机内部Tornado工具与Target Server 之间通信.WDB协议:(Wind DeBug): 用于主机Target Server与目标机之间的通信.1基于硬盘启动的Vxworks环境搭建VxWorks操作系统是美国WindRiver公司于1983年设计开发的一种嵌入式实时操作系统(RTOS)。
CP_1_上海创景_vxworks培训课程
vxworks培训课程
课程目标:
通过该课程,帮助学员了解基础理论,快速掌握工具套件的基本使用,以及常用使用技巧。
课程对象:
软件开发人员,具备软件开发以及嵌入式应用的基础知识。
授课讲师:
上海创景计算机系统有限公司工具培训讲师。
授课场所要求:
培训教室,投影仪,以及白板。
课时安排:
培训课程共提供20个课时的内容;一个课时45分钟。
1)标准课程:
3天时间,两天半讲授前15个课时内容,最后半天进行课程考核以及提问讨论。
课程结业:
通过相关考试,颁发相应的工具使用培训结业证书。
vxworks基础培训课件
学习交流PPT
1
实时嵌入式系统
• 嵌入式系统:
• 由CPU控制,即自带CPU • 相对于常见的pc而言,不对用户提供开发环境,用户与系统交互的唯一接
口就是系统提供给用户的应用; • 提供功能通常带有针对性,大多为专用系统; • 手机,医疗设备,微波炉,mp3……
• 实时嵌入式系统:
• 后者顾名思义,应用模块可以以静态链接的方式编译至VxWorks镜像工程 中,还可以在VxWorks运行之后,通过网络将将应用模块(.out格式)下 载到目标板,并与VxWorks镜像进行链接。在单独对某个模块进行调试时, 我们常常会用到这种动态链接的方法。
学习交流PPT
8
VxSim的HelloWorld(一)
号量、 消息队列、内存分配、看门狗计时器、堆栈使用情况、 目标 CPU使用率、对象模块结 构和符号表以及每个任务的详细信息。
• WindShell:
• 提供从宿主机到目标机之间的一个命令 shell。 • 允许用户调用内存中的应用程序模块或是 VxWorks模块中的任何例程。
• WindView:
• 非常出色的系统可视诊断和分析工具。可非常容易地观察各任务,中断程序之间的相互作用。
学习交流PPT
9
VxSim的HelloWorld(二)
• 选择 A BSP(板级支持包)在下拉菜单中选择simpc
• 打开文件usrAppInit.c(它的函数usrAppInit是应用的入口点),添加Hello World打印语句,保存文件。
学习交流PPT
10
VxSim的HelloWorld(三)
• 交叉编译:在某一体系结构的宿主机上为另一体系结构的 目标板编译可运行的目标代码。即编译与运行不在同一地 方。
VxWorks 开发简明培训教程Manual
TAO-TAO-LE板级功能测试程序暨VxWorks开发简明培训教程朱海涛2003年11月关于本手册本手册读者须具有基本的Windows操作经验,并且已经参加过03年八月份的培训:“Tornado集成开发环境的操作及基于PowerPC/VxWorks的编程实例”。
没有参加过该次培训的读者,请到/report/jicheng.doc下载相关文档学习,本手册第一章也将对之做一简单复习。
此外,读者最好具有在Windows下架设简单FTP服务的经验。
本手册第一章会简单涉及这些内容。
读者应该仔细阅读本手册后再操作,你碰到的问题很可能是由于疏忽了本手册的某些细节而造成的,以避免浪费不必要的时间。
欢迎指正对本手册的纰漏,提出宝贵意见。
mailto:zhuht@几个关键名词:Host(开发主机):即你的PC机,上面装有用于开发的Tornado,并架设了FTP服务器。
Target(目标机):VxWorks运行的PowerPC,我们目前使用MVME5100。
第一章 PowerPC及VxWorks的配置本章是对培训:“Tornado集成开发环境的操作及基于PowerPC/VxWorks的编程实例”的简单复习。
如果你已对其中内容熟悉,可以跳过本章。
以下的操作都是针对MVME5100而言的。
关于MVME5100的安装设置,请参考其Datasheet:MVME5100 Single Board Computer Installation and Use。
Step 1.准备10M(或100M)网线、串口线(注:串口线必须一端为RJ45接口,另一端为RS232- 9pin接口)各一根。
网线一端接到PowerPC的LAN1口,另一端接到HUB或Switch上;串口线的RJ45端接到PowerPC的DEBUG口,另一端接到自己PC上的RS232口。
如图1 -图 1 - 1注:请勿将串口线的RJ45口接到PowerPC的LAN1口,将网线接到了PowerPC的DEBUG口。
VxWorks开发简明培训教程Manual
VxWorks开发简明培训教程ManualVxWorks是美国Wind River Systems开发的一款实时操作系统,常被使用在嵌入式系统中,其广泛的应用领域包括航空航天,自动驾驶,医疗设备等。
为了更好地了解VxWorks的开发及应用,在这里针对其开发进行简明培训教程。
1. 环境准备在使用VxWorks进行开发之前,需要先进行相关环境的准备。
首先是设备的准备,需要一块支持VxWorks的开发板。
其次是软件的准备,可以从Wind River Systems官网上下载VxWorks开发软件。
2. 创建项目在进行VxWorks开发前,需要创建一个新的项目。
在Eclipse或者Wind River Workbench中,可以通过点击New Project来创建新的项目。
在这一步中,需要选择合适的CPU类型和操作系统类型,以及选择开发板的型号。
3. 创建任务在VxWorks操作系统中,任务是一个非常重要的概念。
任务可以看做是一个运行在操作系统上的程序,可以控制任务的创建和销毁。
通过在代码中调用taskSpawn函数可以创建一个新的任务,该函数包含任务名称、任务优先级、任务属性、栈大小等参数。
4. 任务管理在VxWorks中,可以通过taskDelete和taskSuspend等函数来分别删除或者挂起一个任务。
在对任务进行管理时,需要注意任务的优先级和业务流程,确保任务的执行顺序和执行时间。
5. 中断处理在嵌入式系统中,中断是一个非常重要的概念。
VxWorks 提供了中断处理机制,可以在中断的发生时进行处理。
通过对中断处理函数进行编写,可以实现对中断信号的处理和相应,从而保证系统的稳定性和安全性。
6. IO操作在嵌入式系统中,IO操作是必不可少的一部分。
VxWorks 提供了相关的函数,可以对设备进行读写操作。
比如,通过open函数打开设备,通过read函数读取设备数据,通过write 函数将数据写入设备。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-1Chapter10Exceptions, Interrupts,and TimersException Handling and SignalsInterrupt Service RoutinesSystem Clock, Auxiliary Clock, Watchdog TimersWind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-2Exceptions, Interrupts, and Timers10.1Exception Handling and SignalsInterrupt Service RoutinesTimersException handlingUsing signalsInstalling user-defined signal handlerWind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-3Exception Handling Overview•An exception is an unplanned event generated by theCPU. Examples include: trap or breakpoint instruction,divide by zero, floating point or integer overflow, illegalinstruction, or address error.•An exception will generate an “internal” interrupt.•VxWorks installs exception handlers at system startup.These handlers will run on an exception and will try toinvoke a user-defined exception handler.• A VxWorks exception handler communicates with auser tasks by sending a signal. The user-installedhandler will then run.•Exceptions vary across CPU architectures. The help page for excLibcontains information about generic exception handling, while the page for excArchLib discusses architecture-specific routines.Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-4SignalsnormalCode(){........}mySignalHandler(){........}signal • A signal is the software analog of an interrupt:• A signal sent to a task indicates some asynchronous event has occurred.•There are 31 unique signals, each representing a different event.• A task can attach a signal handler to take appropriate action when thesignal is received.•Upon completion of signal handling, normal task execution is resumed(unless the signal corresponds to an exception).•For more information on signals, see Advanced Programming in the UNIXEnvironment by Stevens.Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-5UNIX: UNIX vs. VxWorks Signals•Signal is ignored if no handler is installed.•“Automatic function restarting”•Can install a handler to catch SIGKILL .•No SIGCHLD ,SIGPIPE , or SIGURG .•taskDelay() sets errno =EINTR and returns ERROR ifinterrupted by a signal.signalPend QReady QRunsignal-handler semTake(...,OrigDelay )•“Automatic function restarting” describes behavior for a task whichcatches a signal while on the pend queue:1.Task receives a signal while pended.2.Task is removed from pend queue and made ready to run.3.When the task is the highest priority task on the Ready queue, it runs itssignal handler for the signal it caught.4.After running its signal handler, the task is returned to the pended state,with its originally specified timeout.Wind River SystemsTornado Training Workshop © Copyright Wind River Systems 10-6Caveats•Signals are not recommended for general intertaskcommunication. A signal:qMay be handled at too high a priority if it arrives during a priority inheritance.qDisrupts a task’s normal execution order. (It is better to create two tasks than to multiplex processing in one task via signals.)qCan cause reentrancy problems between a task running its signal handler and the same task running its normal code.q Can be used to tell a task to shut itself down.•sigLib contains both POSIX and BSD UNIX interfaces.Do not mix them.•Consider a task which enters a critical region by taking a mutexsemaphore guarding some shared resource. Suppose the task receives a signal while in the critical region. If the signal handler also attempts to take the mutex, it will succeed, and the resource may be corrupted.•Include signal.h or sigLib.h when programming with signals.•To send a (non-exception) signal use the kill (tid, signo) function. Usesigqueue () to send queued signals.Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-7Registering a Signal Handler•To register a signal handler:signal (signo, handler)signo Signal number.handlerRoutine to invoke when signal arrives (orSIG_IGN to ignore signal).Returns the previously installed signal handler, or SIG_ERR .•The signal handler should be declared as:void sigHandler (int sig);/* signal number */• A VxWorks signal handler is passed not only the signal number but alsotwo additional parameters. To access these additional parameters,declare your signal handler asvoid sigHandler(int sig,/* signal number */int code,/* additional code */struct sigcontext * pSigCtx);The code argument can be used to distinguish different exceptionswhich generate the same signal. See sigLib for the architecture specific codes. The pSigCtx argument points to saved context information for the task which received the signal. Its use is architecture dependent.• A third signal handler prototype is used for signals generated bysigqueue () and some routines in the POSIX Real-Time Extensions libraries. See sigLib for details.Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-8Signals and Exceptions•Hardware exceptions include bus error, address error,divide by zero, floating point overflow, etc..•Some signals correspond to exceptions (e.g.,SIGSEGVcorresponds to a bus error on a 68k;SIGFPE correspondsto various arithmetical exceptions).myCode(){.......}bus error Task has SIGSEGV signal handler installed?Suspend task Log error messageraise signal •When an executing task generates an exception:qIf the task has a signal handler installed to deal with that exception,VxWorks will raise the signal to that task.q If the task has no signal handler installed for that exception,VxWorks will suspend the task and log an error message to the console.•The correspondence between signals and exceptions is architecturedependent. See sigLib .Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-9The Signal Handler•If an exception signal handler returns:qThe offending task will be suspended.q A message will be logged to the console.•Exception signal handlers typically call:q exit() to terminate the task, orq taskRestart() to restart the task, orq longjmp() to resume execution at location saved by setjmp().•For more information on setjmp()/longjmp(), see the onlinedocumentation or Advanced Programming in the UNIX Environment by Stevens.•Signal handlers responding to asynchronously generated signals (sent byanother task or ISR) should return rather than exit non-locally with exit(),taskRestart(), or longjmp(). Such non-local exits, occurring in a signal handler called at an indeterminate point in the task’s execution,can leave shared resources (e.g., the system memory pool) corrupted.See also the reference entry for sigprocmask() for blocking signals during critical sections of a task’s execution.•See the Exception Handling example in Appendix A.Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-10Exceptions, Interrupts, and TimersException Handling and Signals10.2Interrupt Service RoutinesTimersISR BasicsISR RestrictionsInterrupts•Interrupts allow devices to notify the CPU that someevent has occurred.• A user-defined routine can be installed to execute when an interrupt arrives.•This routine runs at interrupt time. It is not a task.•On-board timers are a common source of interrupts.Using them requires understanding interrupts.Tornado Training Workshop© Copyright Wind River Systems10-11Wind River SystemsDevice Drivers•Use interrupts for asynchronous I/O.•Are beyond the scope of this course.•For more information:intArchLib To install user defined ISR’s.Board Support Package Board-specific interrupt handling.Programmers Guide Architecture specific interrupt info.Tornado User’s Guide System mode debugging info.BSP Porting Kit Optional product for writing BSP’s.VxWorks Device Write VMEbus and VxWorksDriver Workshop standard device drivers.Tornado BSP BSP-specific interrupt issues, suchTraining Workshop as interrupt controllers and busses.Tornado Training Workshop© Copyright Wind River Systems10-12Wind River SystemsWind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-13Interrupt Handling Example (68k)save registers Interrupt ServiceRoutine (ISR)restore registerscall routine REThandlervectornumber hardware handler:Interrupt Vector TablemyISR (){..}.User ISR •When an interrupt occurs:1.Switch to a dedicated interrupt stack (except for x86, R6000, CPU-32,MC68060, MC68000, and MC68010 which take interrupts on task stacks.).2.In handler wrapper routine, save volatile registers and errno .3.Call user-defined interrupt handler from handler wrapper.4.On return from handler, restore values previously saved and returnfrom interrupt level. May result in a reschedule of the previously executing task if a higher priority task was made ready to run.•User-defined interrupt handler code can be installed by intConnect().Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-14Interrupt Handling Example (PowerPC)Exception Vector Table0x500External Exception Handler 0123456...Interrupt Table Exception Vector Interrupt Number User ISR #1User ISR #2...•The PowerPC has a single external interrupt pin. A BSP may support an external interrupt controller to support nested interrupts. For details,see excArchLib and VxWorks Programmer’s Guide appendix on PowerPC.•The number of entries in the interrupt table is dependent on which interrupt controller(s) your BSP supports. ISRs may be chained for a given BSP .•The VxWorks external exception handler:qsaves CPU registers qreads interrupt number from interrupt controller qsequentially calls all chained interrupts at that number qcommunicates to interrupt controller that ISR is complete q restores CPU registers and returnsWind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-15Displaying the Interrupt Vector Table•To show the interrupt vector table from the Browser,choose Vector Table in the selector box (Windows), orclick on the Interrupt button (UNIX).•Not all CPU architectures support an interrupt vector table.•This screenshot displays a portion of the interrupt vector table on amv162 BSP (MC68040 CPU). Interrupt numbers 144, 146, 148, 150, 152,154, 156, and 158 are mapped by this BSP to interrupts from the board’s Z8530 serial communications controller. The highlighted entry, 156, has installed handler _z8530IntRd, the receive ISR for this serial device.•Note that the same handler is also installed at number 148, because theZ8530 has two ports, each with its own installed ISRs. If the table we see _z8530IntRd at number 148 (SCC 1, channel B), and 156 (SCC 1,channel A). The interrupt mapping for this BSP is done set in mv162.h ,sysSerial.c ,sysScsi.c , and sysLib.c .Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-16Interrupts and PrioritiesInterrupt Interrupt Interrupt ...Task Task Task ...Execution Order Controlled by Hardware A b s o l u t e S y s t e m -W i d e P r i o r i t y Execution Order Controlled by Kernel Task Priority Interrupt Level (Programmable)(Hard Wired)•Interrupts preempt even highest priority task.Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-17Interrupt Stack•Most architectures use a single dedicated interruptstack.•Interrupt stack is allocated at system start-up.•The interrupt stack size is controlled by the macroINT_STACK_SIZE;default value defined in configAll.h .•Must be large enough for worst-case nesting.Interrupt Stackint level 2int level 3int level 5•x86, CPU-32, R6000, MC68060, MC68000, and MC68010 are CPU’swhich use tasks’ stacks for processing interrupts. Consequently, each task’s stack must have enough extra space to handle the worst-case nesting of interrupts.•Use checkStack() or the Browser to check task stacks for stack crashes.Interrupt stacks may be checked manually; on many architectures, the variables vxIntStackBase (where the stack starts) and vxIntStackEnd (towards which the stack grows) identify the ends of the interrupt stack region. Dump memory from vxIntStackEnd to vxIntStackBase. Thelocation where the 0xee bytes stop indicates the high water mark of ISR stack usage.Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-18ISR Restrictions•No tasks can run until ISR has completed.•ISR’s are restricted from using some VxWorks facilities.In particular, they can’t block:qCan’t call semTake().qCan’t call malloc() (uses semaphores).q Can’t call I/O system routines (e.g.,printf()).•The Programmer’s Guide gives a list of routines which arecallable at interrupt time.•The one I/O system call which can be made from an ISR is write( ) to apipe.ISR Guidelines•Keep ISR’s short, because ISR’s:q Delay lower and equal priority interrupts.q Delay all tasks.q Can be hard to debug.•Avoid using floating-point operations in an ISR.q They may be slow.q User must call fppSave() and fppRestore().•Try to off-load as much work as possible to some task:q Work which is longer in duration.q Work which is less critical.Tornado Training Workshop© Copyright Wind River Systems10-19Wind River SystemsTypical ISR•Reads and writes memory-mapped I/O registers.•Communicates information to a task by:q Writing to memory.q Making non-blocking writes to a message queue.q Giving a binary semaphore.Tornado Training Workshop© Copyright Wind River Systems10-20Wind River SystemsWind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-21Debugging ISR’s•To log diagnostic information to the console at interrupttime:logMsg (“foo =%d\n”, foo, 0, 0, 0, 0, 0);Sends a request to tLogTask to do a printf() for us.•Similar to printf(), with the following caveats:qArguments must be 4 bytes.q Format string plus 6 additional arguments.•Use a debugging strategy which provides system-leveldebugging:qWDB agent.q Emulator.•Related logLib routines:logFdSetSet file descriptor for logging output (default is the console).logFdAdd Add file descriptor for logging output.•In system mode, CrossWind can be used with the WDB agent or anemulator to obtain diagnostic information.•Debug as much code as possible from task level before executing frominterrupt level.Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-22Exceptions at Interrupt Time•Cause a trap to the boot ROM’s.•Logged messages will not be printed.•Boot ROM program will display an exceptiondescription on reboot.•An exception occurring in an ISR will generate a warmreboot.•Can use sprintf() to print diagnostic information tomemory not overwritten on reboot, if necessary.•During a cold reboot, RAM is zeroed to avoid parity errors the first timememory is read. This step is skipped on a warm reboot.•If you are unsure how your architecture responds to a particularexception in an ISR, execute code causing that exception from interrupt level (e.g. in a watchdog; see the Timers section of this chapter) and check memory after the reboot. The typical architecture-specificmemory maps in the Programmer’s Guide may be of use as a starting point in deciding where to sprintf diagnostic information.Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-23Exceptions, Interrupts, and TimersException Handling and SignalsInterrupt Service Routines10.3TimersSystem clock interrupt service routineWatchdog timersAuxiliary clockWind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-24Timers•On-board timers interrupt the CPU periodically.•Timers allow user-defined routines to be executed atperiodic intervals, which is useful for:qPolling hardware.qChecking for system errors.q Aborting an untimely operation.•VxWorks supplies a generic interface to manipulate twotimers:qSystem clock.q Auxiliary clock (if available).•If your board has other timers, you may write additional drivers tomanipulate them.Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-25System Clock•System clock ISR performs book-keeping:qIncrements the tick count (use tickGet() to examine the count).qUpdates delays and timeouts.q Checks for round-robin rescheduling.•These operations may cause a reschedule.•Default clock rate is 60hz.sysClkRateSet (freq)Sets the clock rate.int sysClkRateGet()Returns the clock rate.•sysClkRateSet() should only be called at system start-up.• The global variable vxAbsTicks is a 64-bit count which rolls over exactlyonce each 264 ticks of the system clock:typedef struct{ULONG lower;ULONG upper;} TICK;TICK vxAbsTicks;vxAbsTicks.lower rolls over exactly once every 232 ticks; when thishappens,vxAbsTicks.upper is incremented by 1.The tickGet() function returns vxAbsTicks.lower .Watchdog Timers•User interface to the system clock.•Allows a C routine to execute after a specified timedelay.•Upon expiration of delay, connected routine runs.q As part of system clock ISR.q Subject to ISR restrictions.Tornado Training Workshop© Copyright Wind River Systems10-26Wind River SystemsWind River SystemsTornado Training Workshop © Copyright Wind River Systems 10-27Creating Watchdog Timers•To create a watchdog timer:WDOG_ID wdCreate ()Returns watchdog id, or NULL on error.•To start (or restart) a watchdog timer:STATUS wdStart (wdId, delay, pRoutine,parameter)wdIdWatchdog id, returned from wdCreate().delayNumber of ticks to delay.pRoutineRoutine to call when delay has expired.parameter Argument to pass to routine.•wdStart()will cause the watchdog routine to run once when thespecified delay expires. To get periodic execution, the watchdog routine must call wdStart() to restart itself.•Only the most recent wdStart()on a watchdog timer will run: to runmultiple watchdog ISR’s, you must use multiple watchdog timers.•WDOG_ID defined in wdLib.h.Using Watchdogs•To use watchdogs for periodic code execution:wdId = wdCreate();wdStart (wdId, DELAY_PERIOD, myWdIsr, 0);void myWdIsr(int param){doit (param);wdStart (wdId, DELAY_PERIOD, myWdIsr, param);}•The doit() routine might:q Poll some hardware device.q Unblock some task.q Check if system errors are present.Tornado Training Workshop© Copyright Wind River Systems10-28Wind River SystemsWind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-29Missed DeadlinesTo recover from a missed deadline:WDOG_ID wdId;void foo(void){wdId = wdCreate();/* Must finish each cycle in under 10 seconds */FOREVER{wdStart (wdId, DELAY_10_SEC, fooISR, 0);fooDoWork();}}void fooISR (int param){/* Handle missed deadline */...}•The above code demonstrates a technique for recovering from misseddeadlines. The fooDoWork( )must run every 10 seconds. If it takes less than 10 seconds, the watchdog is restarted (and fooISR() is not called).If fooDoWork( ) ever takes longer than 10 seconds, our watchdog routine fooISR( ) is called to handle the emergency.Wind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-30Stopping Watchdogs•To cancel a previously started watchdog:STATUS wdCancel (wdId)•To deallocate a watchdog timer (and cancel anyprevious start):STATUS wdDelete (wdId)•Cancelling a watchdog that has already expired is a no-op.Watchdog Browser•After creating, but prior to activating the watchdog, the Browser provides minimal information:•After activating the watchdog, more useful information is provided:Tornado Training Workshop© Copyright Wind River Systems10-31Wind River SystemsPolling Issues•Can poll at task time or interrupt time.q Interrupt time polling is more reliable.q Task time polling has a smaller impact on the rest ofthe system.•To poll at task time, there are two options:q taskDelay() : faster, but may “drift”.q wdStart() +semGive(): more robust.Tornado Training Workshop© Copyright Wind River Systems10-32Wind River SystemsPolling Caveats•The following code is accurate only if the system clockrate is a multiple of 15hz:void myWdISR (){wdStart (myWdId, sysClkRateGet()/15, myWdISR, 0);pollMyDevice();}•Do not set the system clock rate too high, because there is OS overhead in each clock tick.•Use auxiliary clock to poll at high speeds.Tornado Training Workshop© Copyright Wind River Systems10-33Wind River SystemsWind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-34Auxiliary Clock•For high speed polling, use the auxiliary clock.•Precludes using spy , which also uses the auxiliary clock.•Some routines to manipulate auxiliary clock:sysAuxClkConnect()Connect ISR to Aux clock.sysAuxClkRateSet()Set Aux clock rate.sysAuxClkEnable()Start Aux clock.sysAuxClkDisable()Stop Aux clock.•Some boards do not have an auxiliary clock.•The maximum and minimum rates for the auxiliary clock are given inconfig.h.•Using signals for exception handling:q signal()q exit()q taskRestart()q longjmp()•Interrupt Service Routines have a limited context:q No Blockingq No I/O system callsTornado Training Workshop© Copyright Wind River Systems10-35Wind River SystemsWind River Systems Tornado Training Workshop © Copyright Wind River Systems 10-36•Polling with timers:low speedhigh speed aux clock wd timertaskDelay, orinterrupt time task timewd timer + semGive。