| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → xPC Target |
| Contents | Index |
| Learn more about xPC Target |
| On this page… |
|---|
For registers in I/O space, use the xPC Target I/O read and write functions:
Read functions
uint32_T xpcInpDW(uint16_T port ); // read a 32 bit word uint16_T xpcInpW(uint16_T port ); // read a 16 bit word uint8_T xpcInpB(uint16_T port ); // read an 8 bit byte
Write functions
void xpcOutpDW(uint16_T port, uint32_T value ); // write 32 bits void xpcOutpW(uint16_T port, uint16_T value ); // write 16 bits void xpcOutpB(uint8_T port, uint8_T value ); // write a byte
The port address is the value returned in the BaseAddress array.
For registers in memory-mapped space, access them by dereferencing through a pointer that contains the virtual address returned by the xpcReserveMemoryRegion function. Because modern compilers have aggressive optimizers, you must declare the pointer to be volatile. Doing so ensures that the compiler does not optimize out reads and writes using that pointer. The following pseudocode illustrates this using two methods: structure and array.
Structure
struct bdregs {
volatile int reg1;
volatile int reg2;
etc.
};
struct bdregs *regs = pciInfo.VirtualAddress[1];
regs->reg1 = 0x1234; // Sets reg1 to that value
regs->reg2 = 0x56789abc;
etc.If your hardware uses registers with different lengths, it might be easier to use the structure method.
Array
#define REG1 0
#define REG2 1
etc.
volatile int *aregs = pciInfo.VirtualAddress[1];
aregs[REG1] = 0x1234;
aregs[REG2] = 0x56789abc;![]() | Passing Parameters | Creating Custom Drivers Using the xPC Target Driver Authoring Tool | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |