MATLAB XPC TARGET 4 - DEVICE DRIVERS Podręcznik Użytkownika

Przeglądaj online lub pobierz Podręcznik Użytkownika dla Oprogramowanie MATLAB XPC TARGET 4 - DEVICE DRIVERS. MATLAB XPC TARGET 4 - DEVICE DRIVERS User`s guide Instrukcja obsługi

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 111
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów

Podsumowanie treści

Strona 1 - Device Drivers

xPC Target™ 4Device Drivers

Strona 2 - Natick, MA 01760-2098

1 Customizing xPC Target™ DriversIntroductionIn this section...“xPC Target Drivers” on page 1-2“When to Write Your Own Drivers” on page 1-3“Restrictio

Strona 3 - Revision History

xpcAllocPhysicalMemor yPurpose Allocate physical memoryPrototype void *xp cAllocPhysicalMemory(uint32_T numBytes)HeaderFilexpctarget.hArgumentsnumByte

Strona 4

xpcBusyWaitPurpose Wait for specified length of time in secondsPrototype void xpc BusyWait(real_T seconds)HeaderFilexpctarget.hArgumentssecondsLength

Strona 5 - Contents

xpcFreePhysicalMemor yPurpose Free physical memoryPrototype void xpc FreePhysicalMemory(const void * phys ical)HeaderFilexpctarget.hArgumentsphysicalF

Strona 6

xpcGetElapsedTimePurpose Return time since system bootPrototype real_T x pcGetElapsedTime(xpcTime *upTime)ArgumentsupTimePointer to an xpcTime structu

Strona 7 - Driver Authoring Tool

xpcGetPCIDeviceInfoPurpose Return information for PCI devicePrototype int32_T xpcGetPCIDeviceInfo (uint16_T v endorId, uint16_TdeviceId, uint16_T subV

Strona 8 - I/O Functions — By Category

xpcGetPCIDeviceInfousing only vendor ID and device ID, use XPC_NO_SUB for s ubDeviceIdand XPC_N O_SU B for subVen dor Id.This function returns 0 upon

Strona 9 - Customizing xPC Target

xpcInpB, xpcInpW, xpcInpDWPurpose I/O port input functions for byte, word, and double word accessesPrototype uint8_T xpcInpB(uint16_T port)uint16_T xp

Strona 10 - Introduction

xpcIsModelInitPurpose Return target application load statePrototype boolean_T xpcIsModelInit(vo id)HeaderFilexpctarget.hArgumentsnoneDescription The x

Strona 11

xpcOutpB, xpcOutpW, xpcOutpDWPurpose I/O port output functions for byte, word, and double word accessesPrototype void xpc OutpB(uint16_T port, uint8_T

Strona 12 - References

xpcReser veMemoryRegionPurpose Return virtual address that corresponds to physical address and markregion as readable/writablePrototype void * xpcRese

Strona 13 - MathWorks Consulting

IntroductionWhen to Write YourOwnDriversConsider writing your own device drivers for the xPC Target block library if:• No xPC Ta rge t driver exists f

Strona 14 - Third-Party Directory

xpcShowPCIDeviceInfoPurpose Display contents of PCIDevice structurePrototype void xpc ShowPCIDeviceInfo(xpcPCIDevice *pciInfo)ArgumentspciInfoPointer

Strona 15 - Mask initialization (M-file)

xpcSubtractTimePurpose Return differe n ce between two timesPrototype real_T x pcSubtractTime(xpcTime *time,const xpcTime *time2, const xpcTime *time1

Strona 16 - - Memory address mapped

1 Customizing xPC Target™ Drivers• Good C programming skills• Knowledge of how Sim u link simul ation works, for example, t he type an dorder of calls

Strona 17 - - Mask parameters

IntroductionSee...For...Developing S-Functions How to write MATLAB C-MEX S-functions (noninlined S-functions).Note the following references in this gu

Strona 18 - Inlining xPC Target Drivers

1 Customizing xPC Target™ DriversxPC Target Exported FunctionsThe xPC Target software provides kernel functions that y ou can use whenwriting your dev

Strona 19 - Creating a Custom Driver

IntroductionBlock maskUnderlying driver code (C-file)Mask editorMask initialization (M-file)Anatomy of an xPC Target™ Driver1-7

Strona 20

1 Customizing xPC Target™ DriversBefore You Star tIn this section...“Introduction” on page 1-8“Driver Types” on page 1-9“Bus Types and Register Access

Strona 21 - Creating a C ustom Driver

Before Yo u Start• Sele ct poll in g versus i nterrupt.• Specify the blocks for the drivers. Identify- Input and output ports- Mask parameters- Work v

Strona 22

1 Customizing xPC Target™ DriversBus AccessISA Board switches or jumpers usually select I/O port address and anymemory-mapped region.PCI The BIOS dete

Strona 23

Creating a C ustom DriverCreating a Custom DriverThe following is a generic procedure for how to create a custom device driver.For additional note s o

Strona 24 - Debugging Notes

How to Contact MathWorkswww.mathworks.comWebcomp.soft-sys.matlab Newsgroupwww.mathworks.com/contact_TS.html Technical [email protected] Pro

Strona 25 - PCI Drivers

1 Customizing xPC Target™ Drivers4 Open the Simulink Library Browser and create a new library, for example,your_company_namelib.mdl (see “Creating Blo

Strona 26 - PCI Bus Considerations

Creating a C ustom Driver7 Double-click the S-Function block and create a block mask (see Chapter 4,“Masking Drivers”).8 Save and close the S-Function

Strona 27 - PCI Configuration Space API

1 Customizing xPC Target™ DriversRename this file your_co mpany_namelib_xpcblocks. m and edit this file asfollows:• Setout.Library to your new library

Strona 28 - 2 PCI Drivers

Creating a C ustom Driverboards(1).VendorName = 'Co mmte ch';boards(1).DeviceType = 'Se rial Ports';e Save and close the file.f To

Strona 29

1 Customizing xPC Target™ DriversDebugging NotesWhile developing your custom driver, you can use pr intf statements in yourcode. This displays output

Strona 30

2PCI Drivers• “PCI Bus Co nsiderations” on page 2-2• “Sample PCI Device Driver” on page 2-8

Strona 31

2 PCI DriversPCI Bus ConsiderationsIn this section...“Introduction” on page 2-2“PCI Configuration Space API” on page 2-3“Memory-Mapped A ccesse s” on

Strona 32 - Sample PCI Device Driver

PCI Bus ConsiderationsYou can have the drivers locate PCI devices in one of the following ways:• If the system has one board of any one type, you can

Strona 33 - ISA and PC/104 Drivers

2 PCI DriversPCI Device InformationUse the xpcGetPCIDeviceInf o function to get information for a PCI device inyour system. The syntax for this functi

Strona 34 - 3 ISA and PC/104 Drivers

PCI Bus ConsiderationsSet...To ...Set slot = -1 Assume bus = 0 and call the xpcGetPCIDeviceInfofunction to find the first instance of the b oard.Set s

Strona 35 - Memory Mapped

Revision HistoryMarch 2007 Online only New for Version 3.2 (Release 2007a)September 2007 Online only Updated for Version 3.3 (Release 2007b)March 2008

Strona 36

2 PCI DriversvendorId = (uint16_T)0x1234;deviceId = (uint16_T)0x9876;subvendor = (uint16_T)0x5678;subdevice = (uint16_T)0x8765;/* Set subvendor and su

Strona 37 - Masking Drivers

PCI Bus Considerations• xpcInpB, xpcInpW, xp cInpDW — I/O port input functions for byte, word,anddoublewordaccesses•xpcOutpB, xpcOutpW, xpc Outp DW —

Strona 38 - 4 Masking Drivers

2 PCI DriversSample PCI Device DriverFor example PCI dev ice driv er code, seematlabroot\toolbox\rtw\targets\xpc\target\build\xpcblocks\dikpci1800.cTh

Strona 39 - Driver Mask Guidelines

3ISA and PC/104 Drivers

Strona 40

3 ISA and PC/104 DriversISA and PC/104 Bus ConsiderationsIn this section...“Introduction” on page 3-2“I/O Mapped” on page 3-2“Memory Mapped” on page 3

Strona 41 - Cross-Block Checking

ISA and PC/104 Bus Consid e rationsMemory MappedThe I/O and memory on the board is set via jumpers or sw itches. Driverscannot discoverthese addresses

Strona 42 - When You Are Done

3 ISA and PC/104 Drivers3-4

Strona 43 - Sample Driver Mask

4Masking Drivers• “Creating Driver Subsystem Masks” on page 4-2• “Driver M ask Guidelines” on page 4-3• “Cross-Block Checking” on page 4-5• “When You

Strona 44

4 Masking DriversCreating Driver Subsystem M asksThis chapter describes guidelines for creating a Simulink block user interface(mask) for the S-Functi

Strona 45

Driver Mask GuidelinesDriver Mask GuidelinesThis top ic lists guidel in es you sh ould follow when cre ati ng a ma sk for yourxPC Target driver. You s

Strona 47

4 Masking Drivers- Range checking for all parameters. For example, if you expect inputvalues from1 to 10, do not allow users to enter negative values,

Strona 48

Cross-Block CheckingCross-Block CheckingCross-block checking determines if multiple blocks are trying to access thesame hardware. You should include c

Strona 49 - Interrupt Support

4 Masking DriversWhen You Are DoneAfter you write the driver S-function and create the S-Function block, optionalblock mask, and MATLAB file for it, b

Strona 50 - 5 Interrupt Support

Sample Driver MaskSample Driver MaskThe following is the block mask for the Diamond MM-32 Analog Input block.If you were to create this mask as a new

Strona 51

4 Masking DriversNumber of channels:RangeSample time:Base address (for e xamp le 0x300):• In the Variable column, enter the parameter names. Be sure t

Strona 52

Sample Driver Mask3 Select the Initialization tab . The tab displays the dialog v ari ables youentered in the Parameters tab.4 In the Initialization c

Strona 53

4 Masking DriversThis example returns a string to display on the block with the variableport_label commands with which to label the input and output p

Strona 54

Sample Driver MaskAt InitF cn time, no variables in the mask exist yet. You cannot pass theminto theInitFcn. H ow ev er, in the function, you can get

Strona 56

5Interrupt Support• “xPC Target Interrupts” on page 5-2• “Addin g Interrupt Suppo rt” on page 5 -7• “Hook Function Prototypes — A lphabetical List” on

Strona 57 - 6 Save and close the file

ContentsCustomizing xPC Target Drivers1Introduction ... 1-2xPC Target Drivers... 1-2Wh

Strona 58

5 Interrupt SupportxPC Target InterruptsIn this section...“Introduction” on page 5-2“Interrupt Processing in the x PC Target Environment” on page 5-2I

Strona 59 - - Async IRQ Source block

xPC Target™ InterruptsThe following illustrates the flow of processing once a hardware interruptoccurs. This is background information to help you und

Strona 60

5 Interrupt SupportInterrupt occursCall PreHookFunction(if one exists)Did PreHookFunctionreturn a value ofXPC_RUN_ISR?Functioncall oninterrupt?Send wa

Strona 61

xPC Target™ InterruptsWhen a hardware interrupt occurs, the generated code uses the following stepsfor each device on this IRQ to determine which devi

Strona 62

5 Interrupt SupportNote The Allow preemption of function call subsystem check box hasno effect. Interrupts are never enabled when the function-call su

Strona 63 - • your_company_name_boardStop

Adding Interrupt SupportAdding Interrupt SupportIn this section...“Introduction” on page 5-7“Guidelines for Creating Interrupt Functions” on page 5-9“

Strona 64 - PostHook

5 Interrupt SupportFunction DescriptionStartRuns as the last item when starting a model, justbefore the model runs. It is typically used to turnon int

Strona 65

Adding Interrupt Support4 Copy the file sample_int.m toauniquefilenameinthefollowingdirectory:matlabroot\toolbox\rtw\targets\xpc\target\build\xpcblock

Strona 66 - See Also xpcPCIDevice

5 Interrupt Supportmatlabroot\toolbox\rtw\targets\xpc\target\build\xpcblocks\thirdpartydrivers\When modifying an existing hook file:• Change the nam e

Strona 67

Adding Interrupt Support• Depending on the bus type of your board, select a board structure of anexisting board that has the same bus type. The inform

Strona 68

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

Strona 69 - Custom xPC Target Driver

5 Interrupt Supportthat board with either two or four ID values, depending on the specifichardware. W hen calling the hook functions, the xPC Target k

Strona 70 - S-Function Guidelines

Adding Interrupt Support- PreHookFunctionPrototype:int __cdecl your_company_name_ boardPreHook(xpcPCIDevice *pciI nfo);- PostHookFunctionPrototype:voi

Strona 71

5 Interrupt Support• HookIncl udeFile — Interrupt handling file that contains thePreHookFunction, PostH ookF unction, StartFunction,andStopFunctionfun

Strona 72

Hook Function Prototypes — Alphabetical ListHook Function Prototypes — Alphabetical List• your_company_name_boardPostHook• your_company_name_boardPreH

Strona 73 - DMA Considerations

your_company_name_boardPostHookPurpose Run after return from interrupt service routine function-call subsystemor after sending wakeup call to model th

Strona 74 - Passing Parameters

your_company_name_boardPreHookPurpose Run just b efore the interrupt service routineSyntax int __cdecl your_company_name_boardPreHook(xpcPCIDevice*pci

Strona 75 - Accessing Registers

your_company_name_boardStar tPurpose Run as the last item in mdlStartSyntax void __cdecl your_company_name_boardStart(xpcPCIDevice*pciInfo);Argumentpc

Strona 76 - • Structure

your_company_name_boardStopPurpose Run at the beginning of mdlTerminateSyntax void __cdecl your_company_name_boardStop(xpcPCIDevice*pciInfo);Argumentp

Strona 77 - Using the xPC T arget

your_company_name_boardStop5-20

Strona 78

6Custom xPC Target DriverNotes• “S-Function Guidelines” on page 6-2• “mdlStart and mdlTerminate Considerations” on page 6-4• “DMA Considerations” on p

Strona 79

Hook Function Prototypes — Alphabetical List ... 5-15Custom xPC Target Driver Notes6S-Function Guidelines ... 6-2mdlStar

Strona 80 - Setting Up Driver Variables

6 Custom xPC Target™ Driver NotesS-Function GuidelinesYou implement xPC Target device driver blocks using Simulink S-functions.An S-function is a set

Strona 81 - 3 In the M ain tab, enter:

S-Function Guidelinesis also compiled with your application to run on the target PC. Because ofthe following reasons, you must conditionally compile c

Strona 82

6 Custom xPC Target™ Driver NotesmdlStart and mdlTerminate ConsiderationsWhen you load a target application onto a target PC, the driver executes them

Strona 83 - Saving the Configuration

DMA ConsiderationsDMA ConsiderationsIf your board directly accesses system RAM, such as a DMA controller, youmust allocate that memory using thexpcAll

Strona 84 - Creating the C File Template

6 Custom xPC Target™ Driver NotesPassing ParametersSee “Passing Parameters to S-Functions” in Developing S-Functions.6-6

Strona 85 - 3 Click the Build button

Accessing RegistersAccessing RegistersIn this section...“I/O Space” on page 6-7“Memory-Mapped Space” on page 6-7I/O SpaceFor registers in I/O space, u

Strona 86

6 Custom xPC Target™ Driver Notes• Structurestruct bdregs {volatile int reg1;volatile int reg2;etc.};struct bdregs *regs = pciInfo.Virtua lAdd ress[1]

Strona 87 - Category

7Creating Custom DriversUsing the xPC T argetDriver Authoring Tool• “xPC Target Driver Authoring Tool” on page 7-2• “Generating C ustom Driver Templat

Strona 88 - I/O Structures — By Catego ry

7 Creating Custom Drivers Using the xPC Target™ D river Authoring ToolxPC Tar get Driver Authoring ToolxPC Target Driver Authoring Tool helps you crea

Strona 89 - Alphabetical List

xPC Target™ Driver Authoring ToolNote The xPC Target Driver Authoring Tool creates custom driver templatesusing the Legacy Code Tool (LCT). You do not

Strona 90

I/O Structures — By Category8I/O Structures — Alphabetical List9I/O Functions — By Category10Port I/O ... 10-2

Strona 91

7 Creating Custom Drivers Using the xPC Target™ D river Authoring ToolGenerating Custom Driver Te mplatesIn this section...“Using the xPC Target Drive

Strona 92 - VirtAddress field

Generating Custom Driver TemplatesThe xPC Target Driver Authoring Tool is displayed.3 In the M ain tab, enter:• Driver name — The name for your driver

Strona 93

7 Creating Custom Drivers Using the xPC Target™ D river Authoring Tool• Size — E nter the maximum size number of storage locations to beallocated f or

Strona 94

Generating Custom Driver Templatesfunction argument that contains the size into the start, output and/orterminate functions along with the port/parame

Strona 95 - I/O Functions — By

7 Creating Custom Drivers Using the xPC Target™ D river Authoring ToolYou can iteratively change the configuration and resave the MAT-file a s oftenas

Strona 96 - Physical Memory

Generating Custom Driver TemplatesNote Use the xPC Target Driver Authoring Tool to build the C Mex file ifyou have not edited the C source code file (

Strona 97 - Miscellaneous

7 Creating Custom Drivers Using the xPC Target™ D river Authoring Tool7-10

Strona 98 - I/O Functions — By C atego ry

8I/O Structures — ByCategoryxpcPCIDeviceType definition for PCI configurationspace structurexpcTimeType definition of time structure

Strona 99 - I/O Functions —

8 I/O Structures — By Catego ry8-2

Strona 100

9I/O Structures —Alphabetical List

Strona 101

1Customizing xPC TargetDrivers• “Introduction” on page 1-2• “Before You Start” on page 1-8• “Creating a Custom Driver” on page 1-11• “Debugging Notes”

Strona 102 - Free specified m e mory

xpcPCIDevicePurpose Type definition for PCI configuration space structurePrototype typedef struct xpcPCIDe viceStruct{uint32_T BaseAddress[6];uint32_T

Strona 103 - Arguments

xpcPCIDeviceIndicates whether the board is I/O portmapped or memory-mapped. Values areone of t he fo ll owing. Verify this value inthe hardware manufa

Strona 104

xpcPCIDeviceof these addresses. Base addresses are filled in during the BIOSplug and play initialization, before the xPC Target kernel starts toexecut

Strona 105 - XPC_NO_SUB for s ubDeviceId

xpcTimePurpose Type definition of time structurePrototype typedef struct xpcTime6 4Struct{uint32_T NanoSecondsLo;uint32_T NanoSecondsHi;} xpcTime64;ty

Strona 106

xpcTime9-6

Strona 107

10I/O Functions — ByCategoryPort I/O (p. 10-2) I/O port input and output functionsfor byte, word and double wordaccessesPCI Confi gu ration Inform ati

Strona 108

10 I/O Functions — By C atego ryPor t I/OxpcInpB, xpcInpW, xpcInpDWI/O port input functions for byte,word, and double word accessesxpcOutpB, xpcOutpW,

Strona 109

MiscellaneousMiscellaneousxpcBusyWaitWait for specified length of time insecondsxpcIsModelInitReturn target application load state10-3

Strona 110 - See Also xpcGetPCIDeviceInfo

10 I/O Functions — By C atego ry10-4

Strona 111

11I/O Functions —Alphabetical List

Komentarze do niniejszej Instrukcji

Brak uwag