Xpc Target Driver Ug

  • View
    165

  • Download
    16

Embed Size (px)

Text of Xpc Target Driver Ug

xPC Target 4 Device Drivers

How to Contact MathWorks

Web Newsgroup www.mathworks.com/contact_TS.html Technical Supportwww.mathworks.com comp.soft-sys.matlab suggest@mathworks.com bugs@mathworks.com doc@mathworks.com service@mathworks.com info@mathworks.com

Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information

508-647-7000 (Phone) 508-647-7001 (Fax) The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098For contact information about worldwide offices, see the MathWorks Web site. xPC Target Device Drivers Guide COPYRIGHT 20072010 by The MathWorks, Inc.The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the governments needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to The MathWorks, Inc.

Trademarks

MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.Patents

MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for more information.

Revision History

March 2007 September 2007 March 2008 October 2008 March 2009 September 2009 March 2010 September 2010

Online Online Online Online Online Online Online Online

only only only only only only only only

New for Version 3.2 (Release 2007a) Updated for Version 3.3 (Release 2007b) Updated for Version 3.4 (Release 2008a) Updated for Version 4.0 (Release 2008b) Updated for Version 4.1 (Release 2009a) Updated for Version 4.2 (Release 2009b) Updated for Version 4.3 (Release 2010a) Updated for Version 4.4 (Release 2010b)

ContentsCustomizing xPC Target Drivers

1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xPC Target Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . When to Write Your Own Drivers . . . . . . . . . . . . . . . . . . . . Restrictions on Customizing xPC Target Drivers . . . . . . . . Expected Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Resources for Customizing xPC Target Drivers . . . . . . . . . What Makes Up an xPC Target Driver? . . . . . . . . . . . . . . . Before You Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Driver Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bus Types and Register Access . . . . . . . . . . . . . . . . . . . . . . Register Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Inlining xPC Target Drivers . . . . . . . . . . . . . . . . . . . . . . . . . Creating a Custom Driver . . . . . . . . . . . . . . . . . . . . . . . . . . Debugging Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 1-2 1-3 1-3 1-3 1-4 1-6 1-8 1-8 1-9 1-9 1-10 1-10 1-11 1-16

PCI Drivers

2PCI Bus Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PCI Configuration Space API . . . . . . . . . . . . . . . . . . . . . . . . Memory-Mapped Accesses . . . . . . . . . . . . . . . . . . . . . . . . . . I/O Port Accesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sample PCI Device Driver . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 2-2 2-3 2-6 2-6 2-8

v

ISA and PC/104 Drivers

3ISA and PC/104 Bus Considerations . . . . . . . . . . . . . . . . . Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . I/O Mapped . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Memory Mapped . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 3-2 3-2 3-3

Masking Drivers

4Creating Driver Subsystem Masks

..................

4-2 4-3 4-5 4-6 4-7

Driver Mask Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . Cross-Block Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . When You Are Done . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sample Driver Mask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Interrupt Support

5xPC Target Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interrupt Processing in the xPC Target Environment . . . . Adding Interrupt Support . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Guidelines for Creating Interrupt Functions . . . . . . . . . . . Filling in the Driver board Structure . . . . . . . . . . . . . . . . . 5-2 5-2 5-2 5-7 5-7 5-9 5-10

vi

Contents

Hook Function Prototypes Alphabetical List . . . . . . .

5-15

Custom xPC Target Driver Notes

6S-Function Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . mdlStart and mdlTerminate Considerations . . . . . . . . . DMA Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Passing Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Accessing Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . I/O Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Memory-Mapped Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 6-4 6-5 6-6 6-7 6-7 6-7

Creating Custom Drivers Using the xPC Target Driver Authoring Tool

7xPC Target Driver Authoring Tool . . . . . . . . . . . . . . . . . . Generating Custom Driver Templates . . . . . . . . . . . . . . . Using the xPC Target Driver Authoring Tool . . . . . . . . . . . Setting Up Driver Variables . . . . . . . . . . . . . . . . . . . . . . . . . Saving the Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . Reloading the Configuration . . . . . . . . . . . . . . . . . . . . . . . . Creating the C File Template . . . . . . . . . . . . . . . . . . . . . . . . Creating a C MEX File for the Driver . . . . . . . . . . . . . . . . . Customizing the Device Driver Mask . . . . . . . . . . . . . . . . . 7-2 7-4 7-4 7-4 7-7 7-8 7-8 7-8 7-9

vii

I/O Structures By Category

8I/O Structures Alphabetical List

9I/O Functions By Category

10Port I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PCI Configuration Information . . . . . . . . . . . . . . . . . . . . . Physical Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2 10-2 10-2 10-2 10-3

I/O Functions Alphabetical List

11

viii

Contents

1Customizing xPC Target Drivers Introduction on page 1-2 Before You Start on page 1-8 Creating a Custom Driver on page 1-11 Debugging Notes on page 1-16

1

Customizing xPC Target Drivers

IntroductionIn this section... xPC Target Drivers on page 1-2 When to Write Your Own Drivers on page 1-3 Restrictions on Customizing xPC Target Drivers on page 1-3 Expected Background on page 1-3 Resources for Customizing xPC Target Drivers on page 1-4 What Makes Up an xPC Target Driver? on page 1-6

xPC Target DriversThe xPC Target software provides device drivers for a variety of third-party boards. xPC Target users access these drivers as Simulink blocks from the xPC Target library (xpclib). If you have a board for which the xPC Target software does not supply a driver, you can write your own. This guide provides guidelines for writing custom xPC Target device drivers. The xPC Target driver library contains drivers that support third-party boards with many I/O capabilities and applications. This includes drivers for different types of I/O boards, including Analog-to-digital Digital-to-analog Audio Counters Shared memory There are also drivers that support particular protocols, including RS-232, RS-422, RS-485 GPIB CAN UDP ARINC 429 MIL-1553

1-2

Introduction

When to Write Your Own DriversConsider writing your own device drivers for the xPC Target block library if: No xPC Target driver exists for your I/O needs. You are unable