Vxworks Application Programmer's Guide
Total Page:16
File Type:pdf, Size:1020Kb
VxWorks Application Programmer's Guide VxWorks® APPLICATION PROGRAMMER’S GUIDE 6.2 Copyright © 2005 Wind River Systems, Inc. All rights reserved. No part of this publication may be reproduced or transmitted in any form or by any means without the prior written permission of Wind River Systems, Inc. Wind River, the Wind River logo, Tornado, and VxWorks are registered trademarks of Wind River Systems, Inc. Any third-party trademarks referenced are the property of their respective owners. For further information regarding Wind River trademarks, please see: http://www.windriver.com/company/terms/trademark.html This product may include software licensed to Wind River by third parties. Relevant notices (if any) are provided in your product installation at the following location: installDir/product_name/3rd_party_licensor_notice.pdf. Wind River may refer to third-party documentation by listing publications or providing links to third-party Web sites for informational purposes. Wind River accepts no responsibility for the information provided in such third-party documentation. Corporate Headquarters Wind River Systems, Inc. 500 Wind River Way Alameda, CA 94501-1153 U.S.A. toll free (U.S.): (800) 545-WIND telephone: (510) 748-4100 facsimile: (510) 749-2010 For additional contact information, please visit the Wind River URL: http://www.windriver.com For information on how to contact Customer Support, please visit the following URL: http://www.windriver.com/support VxWorks Application Programmer’s Guide, 6.2 9 Oct 05 Part #: DOC-15673-ZD-00 Contents 1 Overview ............................................................................................... 1 1.1 Introduction ............................................................................................................. 1 1.2 Related Documentation Resources ..................................................................... 2 1.3 VxWorks Configuration and Build ..................................................................... 2 2 Applications and Processes ............................................................... 5 2.1 Introduction ............................................................................................................. 6 2.2 Configuring VxWorks For Real-time Processes ............................................... 8 2.3 Real-time Processes ................................................................................................ 10 2.3.1 Real-time Process Life-Cycle .................................................................. 12 2.3.2 Processes and Memory ............................................................................ 14 2.3.3 Processes and Tasks ................................................................................. 15 2.3.4 Processes, Inheritance, and Resource Reclamation ............................. 16 2.3.5 Processes and Environment Variables ................................................... 17 2.3.6 Processes and POSIX ............................................................................... 18 2.4 Developing VxWorks Applications .................................................................... 18 2.4.1 Application Structure .............................................................................. 18 iii VxWorks Application Programmer’s Guide, 6.2 2.4.2 VxWorks Header Files ............................................................................. 19 2.4.3 Applications, Processes, and Tasks ........................................................ 22 2.4.4 Applications and VxWorks Kernel Component Requirements ......... 23 2.4.5 Building Applications .............................................................................. 23 2.4.6 C++ Applications ..................................................................................... 24 2.4.7 Processes and Hook Routines ................................................................. 24 2.4.8 Application APIs, System Calls, and Library Routines ...................... 25 System Calls .............................................................................................. 25 VxWorks Libraries .................................................................................... 26 API Documentation ................................................................................. 26 2.4.9 POSIX ......................................................................................................... 26 2.5 Developing Application Libraries ...................................................................... 27 2.5.1 Library Initialization ................................................................................ 27 C++ Library Initialization ....................................................................... 28 Handling Initialization Failures ............................................................. 29 2.5.2 Library Termination ................................................................................. 29 Using atexit() for Termination Routines ............................................... 30 2.5.3 Developing Static Libraries ..................................................................... 30 2.5.4 Developing Shared Libraries .................................................................. 31 Configuring VxWorks for Shared Libraries .......................................... 35 Building Shared Libraries and Dynamic Applications ....................... 36 VxWorks Run-time C Library libc.so ..................................................... 50 Using Plug-Ins .......................................................................................... 51 Using readelf to Examine Dynamic ELF Files ...................................... 53 Getting Runtime Information About Shared Libraries ....................... 53 Debugging Shared Libraries ................................................................... 56 Working With Shared Libraries From a Windows Host ..................... 57 2.6 Creating and Managing Shared Data Regions ................................................. 59 2.6.1 Configuring VxWorks for Shared Data Regions .................................. 60 2.6.2 Creating Shared Data Regions ................................................................ 60 2.6.3 Accessing Shared Data Regions ............................................................. 61 iv Contents 2.6.4 Deleting Shared Data Regions ................................................................ 61 2.7 Executing Applications ......................................................................................... 62 2.7.1 Running Applications Interactively ...................................................... 63 Starting Applications ............................................................................... 63 Stopping Applications ............................................................................. 64 2.7.2 Running Applications Automatically ................................................... 64 Startup Facility Options .......................................................................... 65 Application Startup String Syntax ......................................................... 66 Specifying Applications with a Boot Loader Parameter .................... 67 Specifying Applications with a VxWorks Shell Script ........................ 69 Specifying Applications with a Startup Configuration Parameter ... 70 Starting Applications with Custom Startup Routines ........................ 70 2.7.3 Applications and Symbol Registration ................................................. 70 2.8 Bundling Applications with a VxWorks System using ROMFS .................. 71 2.8.1 Configuring VxWorks with ROMFS ...................................................... 72 2.8.2 Building a System With ROMFS and Applications ............................. 72 2.8.3 Accessing Files in ROMFS ...................................................................... 72 2.8.4 Using ROMFS to Start Applications Automatically ........................... 73 3 Multitasking .......................................................................................... 75 3.1 Introduction ............................................................................................................. 75 3.2 Tasks and Multitasking ......................................................................................... 76 3.2.1 Task State Transition ................................................................................ 77 3.2.2 Task Scheduling ........................................................................................ 80 Preemptive Priority Scheduling ............................................................. 81 Round-Robin Scheduling ........................................................................ 82 Preemption Locks ..................................................................................... 84 3.2.3 Task Control .............................................................................................. 84 Task Creation and Activation ................................................................. 84 Task Stack .................................................................................................. 85 Task Names and IDs ................................................................................ 86 v VxWorks Application Programmer’s Guide, 6.2 Task Options .............................................................................................. 88 Task Information .....................................................................................