VxWorks6.9——设备驱动基本原理

介绍

        在理解了上一篇的两个知识点以后,本章将解释“驱动分类”的概念,还会讨论使用VxWorks设备驱动程序相关的关键概念——“VxBus驱动模型”。它提供了有关VxBus设备驱动程序生态系统的详细信息,包括:驱动相关的文件位置和目录结构(这个不会讨论);对VxBus的驱动方法解释,对VxBus设备驱动程序可用服务的描述(这个不会讨论);驱动程序运行时的生命周期。

        通过这么多年的学习,相信许多人都会有一个感觉:往往提到 “XXX原理”,那都是一大篇的文字,枯燥且乏味,狗看了都摇头。本文也是如此,建议浮躁的人直接划走,勿看!

驱动分类

        在正式内容开始之前,先引出“用于特定类型的设备驱动程序” 这个概念,并在这里做出解释。

        关于设备和管理它的驱动程序的最基本信息就是设备执行的功能。不同的设备有不同的功能、不同的用途。有的设备可以在磁盘上读写数据或长期存储数据;有的设备可以将文本和图形打印到纸上或输出到显示器上;还有其他控制机械手臂、笔等位置的设备。

        上面的提到的这些功能,可能就会有许多不同的设备执行类似的功能。例如,在视频上显示图形信息时,显示控制器可能是一个简单的VGA控制器,或者它可能是一个运行在PCI Express上的现代显示控制器,具有几兆字节的图形RAM缓冲区。然而,在每种情况下,底层设备的用途是相同的。

        VGA也好,现代显示控制器也罢,终归结底还是为了显示信息,这就是功能的相似性。出于这个原因,可以将设备驱动程序按照相似的功能,划分为不同的类。下面解释一些常见的类:

  • 串行设备驱动

        串行驱动程序是用来管理具有串行接口(如RS-232或RS-485)的设备的接口。这些设备连接到I/O子系统,并且还可以配置为VxWorks系统控制台。软件可以通过调用open()、read()、write()、ioctl()等方法来访问这些设备。

  • 存储设备驱动

        存储设备驱动程序管理:磁盘、磁带驱动器、闪存盘和板载闪存设备的接口。这些设备的一些特性是:当电源关闭时,存储内容保持不变;与RAM相比,数据访问速度较慢;这些设备的成本比RAM低;这些设备包括ATA磁盘、串行ATA磁盘、SCSI磁盘、USB闪存磁盘、软盘等等。

  • 网络设备驱动

        网络接口驱动程序用来管理网络硬件的接口。以太网是网络驱动程序支持的最常见的网络硬件类型,尽管这个类中也包括其他类型的网络硬件的驱动程序。
        以太网网络设备通常分为两个主要部分:媒体访问控制器(MAC)和物理层支持(PHY)。PHY设备驻留在称为媒体独立接口(MII)的总线类型上。

VxBus驱动方法解释

        现在开始进入本文的正题,为了使设备和驱动程序对VxWorks系统有用,必须有一种方法使应用程序、中间件、VxWorks内核模块能够访问设备并使设备执行某些功能。而在VxWorks框架内能做到这一点的最基本方法,就是使用VxBus驱动程序方法。简单来说,VxBus驱动程序方法是一个在系统内部公开的进入驱动程序的入口点,该驱动程序可供VxBus中的API使用。

在文档中对驱动方法进行表示

        现在做一个基本约定:将驱动程序方法表示为用大括号括起来并后跟圆括号的名称。例如:在{thisDriverMethod}()中。此语法将驱动程序方法及其所有部分引用为单个可调用项。

        驱动程序方法解析是由设备驱动程序的函数提供的。当应用程序、中间件或内核模块引用这个被调用的例程时,标准驱动程序方法语法会加上字符串func以获得func{thisDriverMethod}()。

        为了明确指定func{thisDriverMethod}()的参数和返回值,可调用例程被视为伪C函数并包含原型信息。例如:

驱动程序方法的组成部分 

        驱动程序方法定义了硬件设备要执行的一组操作,并提供了一个API,允许软件访问执行这些操作的硬件。在VxWorks VxBus框架中,驱动程序方法由一对数据组成:

  • 一个方法ID,该ID是一个数据值,为一个指针大小
  • 一个函数指针,可以通过该指针来执行底层定义的操作

调用驱动程序方法

        在引用驱动程序方法时需要某些宏。这些宏定义在以下目录中:

        需要调用驱动程序方法的应用程序可用的宏(带参宏)有: 

        METHOD_DECL( )                                它提供对驱动程序方法的正向引用。 

        DEVMETHOD_CALL( )                         以适合于传递给函数的形式提供方法ID。

        此外,vxbDevMethodRun( ) 函数用于调用已发布该方法的系统中的每个驱动程序中的特定驱动程序方法。此函数会遍历系统上的所有实例,并检查每个实例,查看它是否发布了指定的方法。如果一个给定的实例发布了指定的方法,vxbDevMethodRun( )就通过上面描述的两个带参宏调用func{driverMethod}( ),例如:

        但是这样遍历会存在一个问题,就是 vxbDevMethodRun( ) 的效率太低下了。我们希望可以像数组一样,通过下标直接引用。想要实现这个功能,就必须知道包含所需驱动程序方法的每个实例的设备ID

        vxbDevMethodGet( ) 函数就可以实现这个功能,当知道某个设备的ID后,并且明确我们想要的方法。如果方法存在,它会返回一个指向驱动程序中的函数指针,否则,返回NULL。实际调用如下:

驱动程序运行时的生命周期 

        这里将会描述VxWorks(VxBus)设备驱动程序的运行时生命周期,从VxWorks目标启动的点开始,到驱动程序不再与系统相关时结束。

驱动程序初始化队列

        官方提供的资料上,使用一张表来描述了初始化阶段,一共有五个阶段,如下:

早期启动阶段

        设备驱动程序在系统早期启动过程中不发挥任何作用。根据使用的处理器架构,CPU通常会在开机时跳转到一个指定的地址,并开始执行指令。这些指令通常来自ROM或FLASH等非易失性存储器。这些早期指令会初始化内存控制器和CPU,最终目的还是为了启动VxWorks内核。

sysHwInit(),PLB,硬件发现

        在VxWorks内核初始化过程的早期,会执行BSP中的sysHwInit()函数。在这里面,设备驱动程序才会被激活,下面分析一下函数套用关系。

        由BSP提供的sysHwInit()函数会执行一些早期初始化(一般还是CPU的初始化),然后调用hardWareInterFaceInit( )初始化硬件内存分配机制,需要包含INCLUDE_HWMEM_ALLOC组件。

        hardWareInterFaceInit() 又调用hardWareInterFaceBusInit( ),此时,系统的驱动程序通过向vxBus注册而被激活。

        第一个成为活跃的驱动程序之一的是处理器本地总线(PLB)的驱动程序。总线控制器驱动程序和PLB驱动程序,负责确定系统上存在哪些硬件。PLB硬件不包括对设备发现的支持,但是PLB驱动程序能够扫描一个BSP提供的表,其中包含关于直接连接到总线的设备的信息。对于每个表条目,PLB驱动程序都会通知VxWorks该设备的信息。

        通过这种方式,VxWorks可以发现直接连接到PLB的设备。然而,在这个时候,其他总线上的设备还不清楚,而这些设备将在初始化序列中被系统知道。这里涉及到一个设备与驱动的匹配机制,详细内容就不介绍了,简单来讲就是每个总线,都有一个特定的match函数。

驱动注册

        下一步,也是hardWareInterFaceBusInit( )的主要功能,是驱动程序和其他程序模块注册的过程。在此阶段,每个驱动程序调用一个注册函数:vxbDevRegister( ),它会通知VxWorks驱动程序可用,并提供有关驱动程序的所需信息。

        现在来回想一下,当PLB驱动程序被初始化时,它会发现直接连接到PLB的设备。而VxWorks是知道如何将给定的驱动程序与设备进行匹配的,因此,注册PLB驱动程序过程中,就可以让驱动程序和硬件相匹配,如此就形成了一个实例。

驱动第一阶段的初始化

        在实例形成以后,VxWorks检查由vxbDevRegister()函数提供的注册结构体,此结构体包含了驱动程序中的几个初始化入口点。第一个是devInstanceInit( )函数,第二个是devInstanceInit( )2函数。第三个是devInstanceConnect( )函数,如下图(名字是根据具体设备来变的,这里以FPGA网卡驱动为例):

        在VxBus初始化阶段1中调用devInstanceInit( )函数,是驱动程序初始化硬件的第一次机会。但是,由于目前没有任何类型的操作系统服务,因此对可以执行的操作内容有严重的限制。

启动内核

        在所有驱动程序都在VxWorks上注册后,hardWareInterFaceBusInit( )hardWareInterFaceInit( )这两个函数返回,后面由sysHwInit( )完成任何非VxBus驱动程序的初始化并返回。在sysHwInit( )完成后,将初始化VxWorks内核。VxBus初始化的下一阶段发生在sysHwInit( )2中。

驱动第二阶段初始化

        在sysHwInit( )2函数中,BSP会调用vxbDevInit( )函数。在该阶段中,将调用每个实例的设计实例:devInstanceInit2( )函数。此时,内核服务已初始化,并且驱动程序可以访问。但是,中间件服务(如网络MUX层)可能还是不可用。

驱动第三阶段初始化

        在sysHwInit( )2函数结尾,将创建一个任务,该任务会运行VxBus驱动程序初始化的第三个也是最后一个阶段。在这个阶段中,将调用devInstanceConnect( )函数。此阶段是用于需要很长时间来执行初始化的驱动程序,并且不适合为了等待驱动程序初始化而减缓系统启动时间。devInstanceConnect( )函数可以与其他系统模块和应用程序配置、启动同时执行。

总结

        写到这里也差不多了,内容已经很多了。如果你的工作会用的VxWorks,那么看过这篇文章后,不管能记住多少,但多多少少会让你对VxWorks实时系统有一定的了解。

        另外,本文没有去讨论驱动相关的文件位置和目录结构、对VxBus设备驱动程序的可用服务这两个点,因为一个是不重要,另一个是内容太多,一般是要用到了才会去查资料。当然,如果你对这两个点有想法,那么可以去阅读官方提供的资料。

        最后,对于本篇文章的重点,首先就是要理解驱动分类思想,要明白在系统级开发上为什么要进行驱动分类;另一个就是要知道系统对VxBus的初始化过程是怎样的,一共有几个阶段,每个阶段会做什么事。知道这些内容也就差不多了。

PART I: CORE TECHNOLOGIES 1 Overview ...................................................................................................... 3 1.1 Introduction ...................................................................................................................... 3 1.2 Kernel Architecture ......................................................................................................... 3 1.3 Related Documentation Resources .............................................................................. 4 1.4 VxWorks Configuration and Build .............................................................................. 5 2 VxWorks Configuration ............................................................................. 7 2.1 Introduction ...................................................................................................................... 7 2.2 About VxWorks Configuration ................................................................................... 7 2.2.1 Default Configuration and Images ................................................................. 8 2.2.2 Configuration With VxWorks Image Projects ............................................... 8 2.2.3 Configuration With VxWorks Source Build Projects ................................... 8 2.2.4 Configuration and Customization .................................................................. 8 2.2.5 Configuration Tools: Workbench and vxprj .................................................. 9 2.3 VxWorks Image Projects: VIPs .................................................................................... 9 2.3.1 VxWorks Components ...................................................................................... 10 Component Names .......................................................................................... 10 Basic VxWorks Components ............................................................................ 11 2.3.2 Device Driver Selection ................................................................................... 13 2.3.3 Component Bundles and Configuration Profiles ........................................ 14 2.3.4 VxWorks Component Reference .................................................................... 14 2.4 VxWorks Source Build Projects: VSBs ....................................................................... 14 2.4.1 Basic Operating System VSB Options ........................................................... 16 BSP-Specific Optimizations ............................................................................. 16 VxWorks Kernel Programmer's Guide, 6.9 iv Inconsistent Cache Mode Support .................................................................. 17 System Viewer Instrumentation Support ...................................................... 17 Real-Time Process Support .............................................................................. 17 Object Management Support ........................................................................... 17 Error Detection and Reporting Policy Hooks ............................................... 18 Task Switch Hook Support .............................................................................. 18 Task Create Hook Support ............................................................................... 18 CPU Power Management Support ................................................................. 19 Advanced Options ............................................................................................ 19 VxWorks BSP Validation Test Suite Support ................................................. 19 Symmetric Multiprocessor (SMP) Support ................................................... 19 SMP Determinism ............................................................................................. 19 MIPC Support .................................................................................................... 20 WRLOAD Support ............................................................................................ 20 Task-Specific Current Working Directory ...................................................... 20 Device Name Length ........................................................................................ 20 NFS V3 Server Optimization ........................................................................... 20 DOSFS Name Length Compatible .................................................................. 21 2.4.2 VSB Profiles ........................................................................................................ 21 2.4.3 Using VSB Projects to Create VxWorks Systems: Basic Steps .................... 21 2.4.4 Developing Kernel Applications for VSB Systems ..................................... 21 2.5 VxWorks Without Networking ..................................................................................... 22 2.6 Small-Footprint VxWorks Configuration ................................................................... 22 2.6.1 About Small-Footprint VxWorks .................................................................... 22 Kernel Facilities ................................................................................................. 22 Unsupported Facilities ..................................................................................... 23 BSPs ..................................................................................................................... 23 2.6.2 Configuring Small Footprint VxWorks .......................................................... 23 Small-Footprint VSB Profile and Options ...................................................... 24 VSB Options Specific to the Small-Footprint Profile .................................... 24 Small-Footprint VIP Profile and Components .............................................. 25 Optional Components for a Small Footprint VIP Project ............................ 25 2.6.3 Configuration and Build Steps for Small-Footprint VxWorks ................... 25 2.6.4 Writing Applications for Small-Footprint VxWorks .................................... 26 2.6.5 Example Application ........................................................................................ 26 2.6.6 Debugging Small-Footprint VxWorks ............................................................ 28 2.7 VxWorks Image Types ................................................................................................... 28 2.7.1 Default VxWorks Images ................................................................................ 29 2.7.2 VxWorks Images for Development and Production Systems ..................... 29 2.7.3 Boot Parameter Configuration for Standalone VxWorks Images .............. 30 2.8 Image Size Considerations ............................................................................................ 30 2.8.1 Boot Loader and Downloadable Image ......................................................... 30 2.8.2 Self-Booting Image ............................................................................................ 31 Contents v 3 Boot Loader ................................................................................................. 33 3.1 Introduction ...................................................................................................................... 33 3.2 Using a Default Boot Loader ......................................................................................... 34 3.3 Boot Loader Image Types ............................................................................................... 35 3.4 Boot Loader Shell ............................................................................................................ 35 3.4.1 Boot Loader Shell Commands ......................................................................... 36 3.5 Boot Parameters ............................................................................................................... 39 3.5.1 Displaying Current Boot Parameters ............................................................. 40 3.5.2 Description of Boot Parameters ...................................................................... 41 3.5.3 Changing Boot Parameters Interactively ....................................................... 44 3.6 Rebooting VxWorks ........................................................................................................ 45 3.7 Configuring and Building Boot Loaders .................................................................... 46 3.7.1 Boot Loader Profiles .......................................................................................... 46 3.7.2 Boot Loader Components ................................................................................ 47 3.7.3 Configuring Boot Parameters Statically ......................................................... 47 3.7.4 Enabling Networking for Non-Boot Interfaces ............................................. 48 3.7.5 Selecting a Boot Device ..................................................................................... 48 3.7.6 Reconfiguring Boot Loader Memory Layout for 32-Bit VxWorks ............. 50 Redefining the Boot Loader Link Address for Custom Boot Loaders ....... 50 Reconfiguring Memory Layout for a Persistent Memory Region ............. 51 3.7.7 Reconfiguring Boot Loader Memory Layout for 64-Bit VxWorks ............. 53 3.7.8 Building Boot Loaders ...................................................................................... 53 3.8 Installing Boot Loaders .................................................................................................. 53 3.9 Booting From a Network ............................................................................................... 53 3.10 Booting From a Target File System ............................................................................. 55 3.11 Booting From the Host File System Using TSFS ..................................................... 55 4 Kernel Applications .................................................................................... 57 4.1 Introduction ...................................................................................................................... 57 4.2 About Kernel Applications ........................................................................................... 58 4.3 Comparing Kernel Applications with RTP Applications ....................................... 59 4.4 C and C++ Libraries ........................................................................................................ 60 VxWorks Kernel Programmer's Guide, 6.9 vi 4.5 Kernel Application Structure ........................................................................................ 60 4.6 VxWorks Header Files .................................................................................................... 61 4.6.1 VxWorks Header File: vxWorks.h ................................................................... 61 4.6.2 Other VxWorks Header Files ........................................................................... 62 4.6.3 ANSI Header Files ............................................................................................ 62 4.6.4 ANSI C++ Header Files .................................................................................... 62 4.6.5 The -I Compiler Flag ......................................................................................... 62 4.6.6 VxWorks Nested Header Files ........................................................................ 62 4.6.7 VxWorks Private Header Files ........................................................................ 63 4.7 Custom Header Files ....................................................................................................... 63 4.8 Static Instantiation of Kernel Objects ......................................................................... 64 4.8.1 About Static Instantiation of Kernel Objects ................................................. 64 Kernel Objects That can be Instantiated Statically ....................................... 65 Static Instantiation and Code Size .................................................................. 65 Advantages of Static Instantiation .................................................................. 65 Applications and Static Instantiation ............................................................. 66 4.8.2 Scope Of Static Declarations ............................................................................ 66 4.8.3 Caveat With Regard to Macro Use .................................................................. 66 4.8.4 Static Instantiation of Tasks ............................................................................. 66 4.8.5 Static Instantiation Of Semaphores ................................................................ 67 4.8.6 Static Instantiation of Message Queues ......................................................... 68 4.8.7 Static Instantiation of Watchdog Timers ........................................................ 68 4.9 Boot-Time Hook Routine Facility ............................................................................... 69 Boot-Time Hook Routine Stubs and Components ....................................... 69 Using Boot-Time Hook Routine Stubs ........................................................... 70 4.10 Kernel Applications and Kernel Component Requirements ................................. 71 4.11 Building Kernel Application Modules ....................................................................... 71 4.12 Downloading Kernel Application Object Modules to a Target ............................. 72 4.13 Linking Kernel Application Object Modules with VxWorks ................................ 72 4.14 Configuring VxWorks to Run Applications Automatically ................................... 72 5 C++ Development ....................................................................................... 75 5.1 Introduction ...................................................................................................................... 75 5.2 Configuring VxWorks for C++ ..................................................................................... 76 5.3 C++ Header Files ............................................................................................................. 76 Contents vii 5.4 Spawning Tasks That Use C++ ..................................................................................... 76 5.5 Calls Between C and C++ Code .................................................................................... 77 5.6 C++ Compiler Caveats .................................................................................................... 77 5.7 Using C++ in Signal Handlers and ISRs ................................................................... 78 5.8 Downloadable Kernel Modules in C++ ..................................................................... 78 5.9 C++ Compiler Differences ............................................................................................ 78 5.9.1 Template Instantiation ...................................................................................... 78 5.9.2 Run-Time Type Information ............................................................................ 80 5.10 Namespaces ...................................................................................................................... 80 5.11 C++ Exception Handling ................................................................................................ 81 5.12 Standard Template Library (STL) ................................................................................ 81 5.13 C++ Demo Example ........................................................................................................ 81 6 Multitasking ................................................................................................. 83 6.1 Introduction ...................................................................................................................... 83 6.2 About Tasks and Multitasking ..................................................................................... 84 6.2.1 Task States and Transitions .............................................................................. 85 Tasks States and State Symbols ....................................................................... 85 Illustration of Basic Task State Transitions .................................................... 86 6.3 VxWorks System Tasks .................................................................................................. 87 Basic VxWorks Tasks ......................................................................................... 88 Tasks for Optional Components ..................................................................... 91 6.4 Task Scheduling .............................................................................................................. 93 6.4.1 Task Priorities .................................................................................................... 93 6.4.2 VxWorks Traditional Scheduler ...................................................................... 93 Priority-Based Preemptive Scheduling .......................................................... 94 Scheduling and the Ready Queue ................................................................. 94 Round-Robin Scheduling ................................................................................. 95 6.5 Task Creation and Management ................................................................................... 97 6.5.1 Task Creation and Activation .......................................................................... 97 Static instantiation of Tasks ............................................................................. 98 6.5.2 Task Names and IDs ......................................................................................... 98 Task Naming Rules ........................................................................................... 99 Task Name and ID Routines ............................................................................ 99 VxWorks Kernel Programmer's Guide, 6.9 viii 6.5.3 Inter-Process Communication With Public Tasks ......................................... 99 6.5.4 Task Creation Options ...................................................................................... 100 6.5.5 Task Stack ........................................................................................................... 102 Task Stack Protection ........................................................................................ 102 6.5.6 Task Information ............................................................................................... 103 6.5.7 Task Deletion and Deletion Safety .................................................................. 104 6.5.8 Task Execution Control ..................................................................................... 105 6.5.9 Task Scheduling Control .................................................................................. 106 6.5.10 Tasking Extensions: Using Hook Routines .................................................... 107 6.6 Task Error Status: errno .................................................................................................. 108 6.6.1 Layered Definitions of errno ........................................................................... 109 6.6.2 A Separate errno Value for Each Task ............................................................ 109 6.6.3 Error Return Convention ................................................................................. 109 6.6.4 Assignment of Error Status Values ................................................................. 110 6.7 Task Exception Handling ............................................................................................... 110 6.8 Shared Code and Reentrancy ........................................................................................ 111 6.8.1 Dynamic Stack Variables .................................................................................. 112 6.8.2 Guarded Global and Static Variables ............................................................. 112 6.8.3 Task-Specific Variables .................................................................................... 113 Thread-Local Variables: __thread Storage Class ........................................... 113 taskVarLib and Task Variables ........................................................................ 114 6.8.4 Multiple Tasks with the Same Main Routine ................................................ 114 7 Intertask and Interprocess Communication ............................................. 117 7.1 Introduction ...................................................................................................................... 117 7.2 About Intertask and Interprocess Communication .................................................. 118 7.3 Shared Data Structures ................................................................................................... 119 7.4 Interrupt Locks ............................................................................................................... 120 7.5 Task Locks ........................................................................................................................ 121 7.6 Semaphores ...................................................................................................................... 122 7.6.1 Inter-Process Communication With Public Semaphores ............................. 123 7.6.2 Semaphore Creation and Use .......................................................................... 123 Options for Scalable and Inline Semaphore Routines ................................ 125 Static Instantiation of Semaphores ................................................................. 125 Scalable and Inline Semaphore Take and Give Routines ........................... 126 Contents ix 7.6.3 Binary Semaphores ........................................................................................... 126 Mutual Exclusion .............................................................................................. 127 Synchronization ................................................................................................. 128 7.6.4 Mutual-Exclusion Semaphores ....................................................................... 129 Priority Inversion and Priority Inheritance ................................................... 129 Deletion Safety ................................................................................................... 132 Recursive Resource Access .............................................................................. 133 7.6.5 Counting Semaphores ...................................................................................... 134 7.6.6 Read/Write Semaphores ................................................................................. 134 Specification of Read or Write Mode .............................................................. 135 Precedence for Write Access Operations ....................................................... 136 Read/Write Semaphores and System Performance ..................................... 136 7.6.7 Special Semaphore Options ............................................................................. 136 Semaphore Timeout .......................................................................................... 136 Semaphores and Queueing .............................................................................. 137 Semaphores and VxWorks Events .................................................................. 137 7.7 Message Queues .............................................................................................................. 137 7.7.1 Inter-Process Communication With Public Message Queues ..................... 138 7.7.2 Message Creation and Use ............................................................................... 138 Static Instantiation of Message Queues ......................................................... 139 Message Queue Timeout .................................................................................. 139 Message Queue Urgent Messages .................................................................. 140 Message Queues and Queuing Options ........................................................ 140 7.7.3 Displaying Message Queue Attributes .......................................................... 141 7.7.4 Servers and Clients with Message Queues .................................................... 141 7.7.5 Message Queues and VxWorks Events .......................................................... 142 7.8 Pipes ................................................................................................................................... 142 7.8.1 Creating Pipes ................................................................................................... 142 7.8.2 Writing to Pipes from ISRs ............................................................................... 142 7.8.3 I/O Control Functions ...................................................................................... 143 7.9 VxWorks Events ............................................................................................................... 143 7.9.1 Configuring VxWorks for Events .................................................................... 144 7.9.2 About Event Flags and the Task Events Register ......................................... 144 7.9.3 Receiving Events ............................................................................................... 145 7.9.4 Sending Events .................................................................................................. 146 7.9.5 Inter-Process Communication With Events .................................................. 148 7.9.6 Events Routines ................................................................................................. 148 7.9.7 Code Example ................................................................................................... 149 7.9.8 Show Routines and Events .............................................................................. 149 VxWorks Kernel Programmer's Guide, 6.9 x 7.10 Inter-Process Communication With Public Objects ................................................. 149 Creating and Naming Public and Private Objects ....................................... 150 Example of Inter-process Communication With a Public Semaphore ...... 150 7.11 About VxWorks API Timeout Parameters .................................................................. 152 7.12 About Object Ownership and Resource Reclamation ............................................. 152 8 Signals, ISRs, and Watchdog Timers ........................................................ 155 8.1 Introduction ...................................................................................................................... 155 8.2 Signals .............................................................................................................................. 156 8.2.1 Configuring VxWorks for Signals .................................................................. 157 8.2.2 Basic Signal Routines ........................................................................................ 158 8.2.3 Queued Signal Routines .................................................................................. 159 8.2.4 Signal Events ...................................................................................................... 162 8.2.5 Signal Handlers ................................................................................................. 163 8.3 Interrupt Service Routines: ISRs ................................................................................. 166 8.3.1 Configuring VxWorks for ISRs ........................................................................ 166 Configuring the Interrupt Stack ...................................................................... 166 Adding Show Routine Support ....................................................................... 167 8.3.2 Writing ISRs ....................................................................................................... 167 Restrictions on ISRs ........................................................................................... 167 Facilities Available for ISRs .............................................................................. 169 Reserving High Interrupt Levels .................................................................... 170 8.3.3 System Clock ISR Modification ....................................................................... 171 8.3.4 Connecting ISRs to Interrupts ......................................................................... 171 8.3.5 Getting Information About ISRs ..................................................................... 172 8.3.6 Debugging ISRs ................................................................................................. 173 8.4 Watchdog Timers ............................................................................................................. 174 Static Instantiation of Watchdog Timers ........................................................ 175 8.4.1 Inter-Process Communication With Public Watchdog Timers ................... 176 9 POSIX Facilities .......................................................................................... 177 9.1 Introduction ...................................................................................................................... 178 9.2 Configuring VxWorks with POSIX Facilities ............................................................ 179 9.2.1 VxWorks Components for POSIX Facilities .................................................. 179 9.3 General POSIX Support ................................................................................................. 180 9.4 POSIX Header Files ........................................................................................................ 181 Contents xi 9.5 POSIX Namespace .......................................................................................................... 183 9.6 POSIX Clocks and Timers ............................................................................................. 183 9.7 POSIX Asynchronous I/O .............................................................................................. 186 9.8 POSIX Advisory File Locking ....................................................................................... 186 9.9 POSIX Page-Locking Interface ..................................................................................... 186 9.10 POSIX Threads ................................................................................................................ 187 9.10.1 POSIX Thread Attributes ................................................................................. 188 9.10.2 VxWorks-Specific Pthread Attributes ............................................................ 188 9.10.3 Specifying Attributes when Creating Pthreads ........................................... 189 9.10.4 POSIX Thread Creation and Management .................................................... 190 9.10.5 POSIX Thread Attribute Access ...................................................................... 190 9.10.6 POSIX Thread Private Data ............................................................................. 191 9.10.7 POSIX Thread Cancellation ............................................................................. 192 9.11 POSIX Thread Mutexes and Condition Variables .................................................... 193 9.11.1 Thread Mutexes ................................................................................................. 193 Protocol Mutex Attribute ................................................................................ 194 Priority Ceiling Mutex Attribute .................................................................... 195 9.11.2 Condition Variables .......................................................................................... 195 9.12 POSIX and VxWorks Scheduling ................................................................................. 196 9.12.1 Differences in POSIX and VxWorks Scheduling ........................................... 197 9.12.2 POSIX and VxWorks Priority Numbering ..................................................... 198 9.12.3 Default Scheduling Policy ................................................................................ 198 9.12.4 VxWorks Traditional Scheduler ...................................................................... 198 9.12.5 POSIX Threads Scheduler ................................................................................ 199 9.12.6 POSIX Scheduling Routines ............................................................................ 203 9.12.7 Getting Scheduling Parameters: Priority Limits and Time Slice ................ 204 9.13 POSIX Semaphores ......................................................................................................... 204 9.13.1 Comparison of POSIX and VxWorks Semaphores ....................................... 205 9.13.2 Using Unnamed Semaphores .......................................................................... 206 9.13.3 Using Named Semaphores .............................................................................. 208 9.14 POSIX Message Queues ................................................................................................. 211 9.14.1 Comparison of POSIX and VxWorks Message Queues ............................... 212 9.14.2 POSIX Message Queue Attributes .................................................................. 213 9.14.3 Displaying Message Queue Attributes .......................................................... 214 VxWorks Kernel Programmer's Guide, 6.9 xii 9.14.4 Communicating Through a Message Queue ................................................ 215 9.14.5 Notification of Message Arrival ..................................................................... 218 9.15 POSIX Signals .................................................................................................................. 222 9.16 POSIX Memory Management ....................................................................................... 222 10 Memory Management ................................................................................. 223 10.1 Introduction ...................................................................................................................... 223 10.2 32-Bit VxWorks Memory Layout ................................................................................. 224 10.2.1 Displaying Information About Memory Layout .......................................... 224 10.2.2 System Memory Map Without RTP Support ................................................ 224 10.2.3 System Memory Map with RTP Support ....................................................... 226 10.2.4 System RAM Autosizing .................................................................................. 228 10.2.5 Reserved Memory: User-Reserved Memory and Persistent Memory ...... 228 10.3 64-Bit VxWorks Memory Layout ................................................................................. 229 10.3.1 Displaying Information About Memory Layout .......................................... 230 10.3.2 Virtual Memory Regions .................................................................................. 230 Kernel System Virtual Memory Region ......................................................... 231 Kernel Virtual Memory Pool Region .............................................................. 232 Kernel Reserved Memory Region ................................................................... 232 Shared User Virtual Memory Region ............................................................. 232 RTP Private Virtual Memory Region .............................................................. 232 10.3.3 Global RAM Pool .............................................................................................. 233 10.3.4 Kernel Memory Map ........................................................................................ 233 Kernel System Memory .................................................................................... 235 Kernel Common Heap ...................................................................................... 235 DMA32 Heap ..................................................................................................... 235 User-Reserved Memory ................................................................................... 235 Persistent Memory ............................................................................................ 235 10.3.5 Reserved Memory Configuration: User-Reserved Memory and Persistent Memory .............................................................................................................. 236 10.3.6 System RAM Autosizing .................................................................................. 236 10.4 About VxWorks Memory Allocation Facilities ......................................................... 236 10.5 32-Bit VxWorks Heap and Memory Partition Management .................................. 237 10.5.1 Configuring the Kernel Heap and the Memory Partition Manager .......... 238 10.5.2 Basic Heap and Memory Partition Manager ................................................. 238 10.5.3 Full Heap and Memory Partition Manager ................................................... 238 10.6 64-Bit VxWorks Heap and Memory Partition Management .................................. 239 10.6.1 Kernel Common Heap ...................................................................................... 239 Contents xiii 10.6.2 Kernel Proximity Heap ..................................................................................... 240 10.6.3 DMA32 Heap ..................................................................................................... 240 10.7 SMP-Optimized Memory Allocation .......................................................................... 241 10.7.1 Configuration ..................................................................................................... 241 10.7.2 Usage scenarios ................................................................................................. 241 10.8 Memory Pools .................................................................................................................. 242 10.9 POSIX Memory Management ....................................................................................... 242 10.9.1 POSIX Memory Management APIs ................................................................ 243 10.9.2 POSIX Memory Mapping ................................................................................ 244 10.9.3 POSIX Memory Protection ............................................................................... 244 10.9.4 POSIX Memory Locking .................................................................................. 244 10.10 Memory Mapping Facilities .......................................................................................... 245 10.10.1 POSIX Memory-Mapped Files ........................................................................ 247 10.10.2 POSIX Shared Memory Objects ...................................................................... 247 10.10.3 Anonymous Memory Mapping ...................................................................... 247 10.10.4 Device Memory Objects ................................................................................... 248 10.10.5 Shared Data Regions ......................................................................................... 249 10.11 Virtual Memory Management ..................................................................................... 249 10.11.1 Configuring Virtual Memory Management .................................................. 250 10.11.2 Managing Virtual Memory Programmatically ............................................. 251 Modifying Page States ...................................................................................... 252 Making Memory Non-Writable ...................................................................... 253 Invalidating Memory Pages ............................................................................ 255 Locking TLB Entries .......................................................................................... 255 Page Size Optimization .................................................................................... 255 Setting Page States in ISRs ............................................................................... 256 10.11.3 Troubleshooting ................................................................................................. 256 10.12 Additional Memory Protection Features ................................................................... 257 10.12.1 Configuring VxWorks for Additional Memory Protection ......................... 257 10.12.2 Stack Overrun and Underrun Detection ........................................................ 258 10.12.3 Non-Executable Task Stack .............................................................................. 258 10.12.4 Text Segment Write Protection ........................................................................ 258 10.12.5 Exception Vector Table Write Protection ........................................................ 259 10.13 Memory Error Detection ................................................................................................ 259 10.13.1 Heap and Partition Memory Instrumentation .............................................. 259 10.13.2 Compiler Instrumentation: 32-Bit VxWorks .................................................. 264 VxWorks Kernel Programmer's Guide, 6.9 xiv 11 I/O System ................................................................................................... 269 11.1 Introduction ...................................................................................................................... 269 11.2 About the VxWorks I/O System ................................................................................... 270 Differences Between VxWorks and Host System I/O ................................. 270 11.3 Configuring VxWorks With I/O Facilities .................................................................. 271 11.4 I/O Devices, Named Files, and File Systems ............................................................ 272 11.5 Remote File System Access From VxWorks ............................................................... 273 NFS File System Access from VxWorks ......................................................... 273 Non-NFS Network File System Access from VxWorks WIth FTP or RSH 273 11.6 Basic I/O ............................................................................................................................ 275 11.6.1 File Descriptors .................................................................................................. 275 File Descriptor Table ......................................................................................... 276 11.6.2 Standard Input, Standard Output, and Standard Error .............................. 276 11.6.3 Standard I/O Redirection ................................................................................ 276 Issues with Standard I/O Redirection ........................................................... 277 11.6.4 Open and Close ................................................................................................. 278 11.6.5 Create and Remove ........................................................................................... 280 11.6.6 Read and Write .................................................................................................. 281 11.6.7 File Truncation ................................................................................................... 281 11.6.8 I/O Control ........................................................................................................ 282 11.6.9 Pending on Multiple File Descriptors with select( ) ..................................... 282 11.6.10 POSIX File System Routines ............................................................................ 284 11.7 Standard I/O ..................................................................................................................... 285 11.7.1 Configuring VxWorks With Standard I/O .................................................... 285 11.7.2 About printf( ), sprintf( ), and scanf( ) ............................................................ 286 11.7.3 About Standard I/O and Buffering ................................................................ 286 11.7.4 About Standard Input, Standard Output, and Standard Error .................. 287 11.8 Other Formatted I/O ....................................................................................................... 287 11.8.1 Output in Serial I/O Polled Mode: kprintf( ) ................................................ 287 Writing to User-Defined Storage Media With kprintf( ) and kputs( ) ....... 288 11.8.2 Additional Formatted I/O Routines ............................................................. 289 11.8.3 Message Logging ............................................................................................... 289 11.9 Asynchronous Input/Output ......................................................................................... 289 11.9.1 The POSIX AIO Routines ................................................................................. 290 Contents xv 11.9.2 AIO Control Block ............................................................................................. 291 11.9.3 Using AIO ........................................................................................................... 292 AIO with Periodic Checks for Completion ................................................... 292 Alternatives for Testing AIO Completion ..................................................... 294 12 Devices ........................................................................................................ 297 12.1 Introduction ...................................................................................................................... 297 12.2 About Devices in VxWorks ........................................................................................... 298 12.3 Serial I/O Devices: Terminal and Pseudo-Terminal Devices .................................. 299 tty Options .......................................................................................................... 299 12.3.1 Raw Mode and Line Mode .............................................................................. 300 12.3.2 tty Special Characters ....................................................................................... 300 12.3.3 I/O Control Functions ...................................................................................... 301 12.4 Pipe Devices ..................................................................................................................... 302 12.5 Pseudo I/O Device ........................................................................................................... 302 12.5.1 I/O Control Functions ...................................................................................... 303 12.6 Null Devices .................................................................................................................... 303 12.7 Block Devices ................................................................................................................... 303 12.7.1 XBD RAM Disk .................................................................................................. 305 12.7.2 SCSI Drivers ....................................................................................................... 306 Configuring SCSI Drivers ................................................................................ 306 Structure of the SCSI Subsystem ..................................................................... 307 Booting and Initialization ................................................................................ 308 Device-Specific Configuration Options ......................................................... 308 SCSI Configuration Examples ......................................................................... 310 Troubleshooting ................................................................................................. 312 12.8 Extended Block Device Facility: XBD ......................................................................... 313 12.8.1 XBD Disk Partition Manager ........................................................................... 313 12.8.2 XBD Block Device Wrapper ............................................................................. 314 12.8.3 XBD TRFS Component ..................................................................................... 314 12.9 PCMCIA ............................................................................................................................ 315 12.10 Peripheral Component Interconnect: PCI .................................................................. 315 12.11 Network File System (NFS) Devices ........................................................................... 315 12.11.1 I/O Control Functions for NFS Clients .......................................................... 316 12.12 Non-NFS Network Devices ........................................................................................... 317 VxWorks Kernel Programmer's Guide, 6.9 xvi 12.12.1 Creating Network Devices ............................................................................... 318 12.12.2 I/O Control Functions ...................................................................................... 318 12.13 Sockets ............................................................................................................................... 318 12.14 Internal I/O System Structure ....................................................................................... 319 12.14.1 Drivers ................................................................................................................ 321 The Driver Table and Installing Drivers ........................................................ 322 Example of Installing a Driver ........................................................................ 322 12.14.2 Devices ................................................................................................................ 323 The Device List and Adding Devices ............................................................. 323 Example of Adding Devices ............................................................................ 324 Deleting Devices ................................................................................................ 324 12.14.3 File Descriptors .................................................................................................. 327 File Descriptor Table ......................................................................................... 327 Example of Opening a File ............................................................................... 327 Example of Reading Data from the File ......................................................... 330 Example of Closing a File ................................................................................. 331 Implementing select( ) ...................................................................................... 331 Cache Coherency ............................................................................................... 334 13 Local File Systems ..................................................................................... 339 13.1 Introduction ...................................................................................................................... 339 13.2 File System Monitor ...................................................................................................... 341 Device Insertion Events .................................................................................... 342 XBD Name Mapping Facility .......................................................................... 343 13.3 Virtual Root File System: VRFS ................................................................................... 343 13.4 Highly Reliable File System: HRFS ............................................................................ 345 13.4.1 Configuring VxWorks for HRFS ..................................................................... 345 13.4.2 Configuring HRFS ............................................................................................ 346 13.4.3 Creating an HRFS File System ....................................................................... 347 Overview of HRFS File System Creation ....................................................... 347 HRFS File System Creation Steps ................................................................... 347 13.4.4 HRFS, ATA, and RAM Disk Examples .......................................................... 348 13.4.5 Optimizing HRFS Performance ...................................................................... 353 13.4.6 Transactional Operations and Commit Policies ......................................... 353 Automatic Commit Policy ............................................................................... 353 High-Speed Commit Policy ............................................................................. 354 Mandatory Commits ......................................................................................... 354 Rollbacks ............................................................................................................. 354 Programmatically Initiating Commits ........................................................... 354 13.4.7 File Access Time Stamps .................................................................................. 355 Contents xvii 13.4.8 Maximum Number of Files and Directories ................................................. 355 13.4.9 Working with Directories ................................................................................. 355 Creating Subdirectories .................................................................................... 355 Removing Subdirectories ................................................................................. 356 Reading Directory Entries ................................................................................ 356 13.4.10 Working with Files ............................................................................................ 356 File I/O Routines ............................................................................................... 356 File Linking and Unlinking ............................................................................. 356 File Permissions ................................................................................................. 357 13.4.11 I/O Control Functions Supported by HRFS ................................................. 357 13.4.12 Crash Recovery and Volume Consistency ..................................................... 358 Crash Recovery .................................................................................................. 358 Consistency Checking ...................................................................................... 358 13.4.13 File Management and Full Devices ................................................................ 358 13.5 MS-DOS-Compatible File System: dosFs .................................................................. 359 13.5.1 Configuring VxWorks for dosFs ..................................................................... 360 13.5.2 Configuring dosFs ............................................................................................ 361 13.5.3 Creating a dosFs File System ........................................................................... 362 Overview of dosFs File System Creation ....................................................... 362 dosFs File System Creation Steps ................................................................... 363 13.5.4 dosFs, ATA Disk, and RAM Disk Examples ................................................. 365 13.5.5 Optimizing dosFs Performance ...................................................................... 369 13.5.6 Working with Volumes and Disks .................................................................. 370 Accessing Volume Configuration Information ............................................. 370 Synchronizing Volumes .................................................................................... 370 13.5.7 Working with Directories ................................................................................. 370 Creating Subdirectories .................................................................................... 370 Removing Subdirectories ................................................................................. 371 Reading Directory Entries ................................................................................ 371 13.5.8 Working with Files ............................................................................................ 371 File I/O Routines ............................................................................................... 371 File Attributes .................................................................................................... 371 13.5.9 Disk Space Allocation Options ........................................................................ 373 Choosing an Allocation Method ..................................................................... 374 Using Cluster Group Allocation ..................................................................... 374 Using Absolutely Contiguous Allocation ...................................................... 374 13.5.10 Crash Recovery and Volume Consistency ..................................................... 376 13.5.11 I/O Control Functions Supported by dosFsLib ............................................ 376 13.5.12 Booting from a Local dosFs File System Using SCSI ................................... 378 13.6 Transaction-Based Reliable File System Support for dosFs: TRFS ....................... 380 VxWorks Kernel Programmer's Guide, 6.9 xviii 13.6.1 Configuring VxWorks With TRFS ................................................................... 380 13.6.2 Automatic Instantiation of TRFS .................................................................... 380 13.6.3 Formatting a Device for TRFS ......................................................................... 381 13.6.4 Using TRFS in Applications ............................................................................ 382 TRFS Code Examples ....................................................................................... 382 13.7 Raw File System: rawFs ................................................................................................. 383 13.7.1 Configuring VxWorks for rawFs ..................................................................... 383 13.7.2 Creating a rawFs File System .......................................................................... 383 13.7.3 Mounting rawFs Volumes ................................................................................ 384 13.7.4 rawFs File I/O ................................................................................................... 385 13.7.5 I/O Control Functions Supported by rawFsLib ........................................... 385 13.8 CD-ROM File System: cdromFs ................................................................................... 386 13.8.1 Configuring VxWorks for cdromFs ................................................................ 387 13.8.2 Creating and Using cdromFs ........................................................................... 387 13.8.3 I/O Control Functions Supported by cdromFsLib ...................................... 389 13.8.4 Version Numbers ............................................................................................... 390 13.9 Read-Only Memory File System: ROMFS ................................................................. 390 13.9.1 Configuring VxWorks with ROMFS ............................................................... 391 13.9.2 Adding a ROMFS Directory and File Content to VxWorks ........................ 391 13.9.3 Accessing Files in ROMFS ............................................................................... 392 13.9.4 Using ROMFS to Start Applications Automatically .................................... 392 13.10 Target Server File System: TSFS ................................................................................... 392 Socket Support ................................................................................................... 393 Error Handling .................................................................................................. 394 Configuring VxWorks for TSFS Use ............................................................... 394 Security Considerations ................................................................................... 394 Using the TSFS to Boot a Target ...................................................................... 395 14 Flash File System Support: TrueFFS ........................................................ 397 14.1 Introduction ...................................................................................................................... 397 14.2 Overview of Implementation Steps ............................................................................ 398 14.3 Creating a VxWorks System with TrueFFS ................................................................ 400 14.3.1 Selecting an MTD .............................................................................................. 400 14.3.2 Identifying the Socket Driver .......................................................................... 400 14.3.3 Configuring VxWorks with TrueFFS and File System ................................. 401 Including the Core TrueFFS Component ....................................................... 401 Including the MTD Component ...................................................................... 402 Contents xix Including the Translation Layer Component ................................................ 402 Including the Socket Driver ............................................................................. 403 Including the XBD Wrapper Component ...................................................... 403 Including File System Components ............................................................... 403 Including Utility Components ........................................................................ 403 14.3.4 Building the System .......................................................................................... 404 14.3.5 Formatting the Flash ......................................................................................... 404 Formatting With sysTffsFormat( ) .................................................................. 404 Formatting With tffsDevFormat( ) .................................................................. 405 14.3.6 Reserving a Region in Flash for a Boot Image .............................................. 406 Reserving a Fallow Region .............................................................................. 407 Writing the Boot Image to Flash ...................................................................... 408 14.3.7 Mounting the Drive .......................................................................................... 409 14.3.8 Creating a File System ...................................................................................... 409 14.3.9 Testing the Drive ............................................................................................... 410 14.4 Using TrueFFS Shell Commands ................................................................................. 410 14.5 Using TrueFFS With HRFS ............................................................................................
### 关于PCI开发板上移植VxWorks 6.9系统的指导 #### 移植准备阶段 对于在PCI开发板上的VxWorks 6.9移植工作,前期准备工作至关重要。这包括但不限于获取目标平台的相关文档和技术资料,了解其硬件架构特性以及接口定义等信息。此外还需要准备好必要的工具链环境用于编译适合该特定硬件的内核版本。 #### 配置与构建过程 针对具体的PCI开发板,在配置过程中需特别注意调整BSP(Baseboard Support Package)以匹配实际使用的处理器型号和其他外设资源。例如当涉及到ZYNQ系列器件时,则应参照相似案例中的设置方法来完成初步适配[^1]。在此基础上进一步优化内存管理策略、中断处理机制等方面的内容,确保最终生成的镜像文件能够稳定运行并发挥最佳性能表现。 #### 启动调试环节 一旦完成了上述步骤之后就可以尝试通过串口等方式加载新创建的操作系统映像到目标设备当中去,并按照既定流程执行初始化操作直至进入命令行界面为止。如果一切顺利的话应该可以看到类似于`->`这样的提示符等待用户输入指令;反之则可能遇到了某些潜在障碍需要逐一排查原因所在——比如波特率不一致可能导致通信失败等问题都应当被纳入考虑范围之内加以验证排除。 #### 替代方案考量 值得注意的是随着技术发展进步近年来也出现了不少可以作为替代品的选择对象之一便是“道系统”操作系统通用版(DeltaOS),它同样具备良好的实时性和可靠性特征而且兼容多种类型的中央处理器(CPU)[^2]。因此如果有条件的话不妨对比评估这两种不同产品的优劣差异从而做出更加明智合理的决策。 ```bash # 假设已经正确设置了环境变量和路径 $ cd $WIND_BASE/target/config/comppc # 进入对应目录下 $ mkdir myPciBoard # 创建新的项目文件夹 $ cp -r generic/* ./myPciBoard # 复制模板至新建工程中 $ cd myPciBoard # 切换到当前工作的子目录里边 $ configKernel # 执行菜单驱动式的交互程序来进行定制化选项设定... ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值