Main Content

Host-Target Communication for Simulink PIL Simulation

This section provides information about using the rtiostream API for communication between your development computer and target hardware during a processor-in-the-loop (PIL) simulation.

Communications rtiostream API

The rtiostream API supports communications for the target connectivity API. Use the rtiostream API to implement a communication channel that enables data exchange between different processes.

PIL simulation requires a host-target communications channel. This communications channel comprises driver code that runs on the host and target. The rtiostream API defines the signature of target-side and host-side functions that this driver code must implement.

The API is independent of the physical layer that sends the data. Possible physical layers include RS232, Ethernet, or Controller Area Network (CAN).

A full rtiostream implementation requires both host-side and target-side drivers. Code generation software includes host-side drivers for the default TCP/IP implementation and a version for serial communications. To use:

  • The TCP/IP rtiostream communications channel, you must provide, or obtain from a third party, target-specific TCP/IP device drivers.

  • The serial communications channel, you must provide, or obtain from a third party, target-specific serial device drivers.

For other communication channels and platforms, the code generation software does not provide default implementations. You must provide both the host-side and the target-side drivers.

The rtiostream API comprises the following functions:

For information about:

Synchronize Host and Target

If you use the rtiostream API to implement the communications channel, the host and target must be synchronized, which prevents Simulink® from transmitting and receiving data before the target application is fully initialized.

To synchronize the host and target for TCP/IP rtiostream implementations, use the setInitCommsTimeout method from rtw.connectivity.RtIOStreamHostCommunicator. This approach works well for connection-oriented TCP/IP rtiostream implementations because Simulink automatically waits until the target server is running.

With other rtiostream implementations, for example, serial, the Simulink side of the rtiostream connection opens without waiting for the target to be fully initialized. In this case, you must make your Launcher implementation wait until the target application is fully initialized. Use one of the following approaches to synchronize your host and target:

  • Add a pause at the end of the Launcher implementation that makes the Launcher wait until target initialization is complete.

  • In the Launcher implementation, use third-party downloader or debugger APIs that wait until target initialization is complete.

  • Implement a handshaking mechanism in the Launcher / rtiostream implementation that confirms completion of target initialization.

Test an rtiostream Driver

Use a test suite to debug and verify the behavior of custom rtiostream interface implementations.

The test suite can help you to:

  • Reduce the time required for integrating custom hardware that does not have built-in rtiostream support.

  • Reduce the time required for testing custom rtiostream drivers.

  • Analyze the performance of custom rtiostream drivers.

The test suite consists of two parts. One part is an application that runs on the target hardware. The other part runs in MATLAB. For details, see rtiostreamtest.

Troubleshooting Host-Target Communication

To display communication I/O information in the Diagnostic Viewer during the PIL simulation, in the Command Window, enter:

set_param(model, 'SILPILVerboseOutput', 'on');

By default, the configuration parameter SILPILVerboseOutput is set to off.

If you run a SIL simulation with SILPILVerboseOutput set to on, the simulation displays I/O information for communication that occurs between Simulink and the target application that runs as a separate process on your development computer.

Word Addressable Target Hardware

In the Configuration Parameters dialog box, when you specify settings for Device vendor and Device type, you provide PIL simulations with memory addressing information about the target hardware.

For example, consider the case when Device vendor is set to Texas Instruments and Device type is set to C5000.

The settings specify that the target hardware uses 16-bit word addresses and big-endian word order. The rtiostream implementation operates with 16-bit words.

On the target hardware, if an rtIOStream function specifies a size of 1, then the target hardware must send or receive one 16-bit word (2 bytes). sizeof(char) and sizeof(short) return 1, which corresponds to one 16-bit word. The rtIOStream function expects the byte order within the word to be little-endian, that is, less significant bytes are transmitted before more significant bytes.

rtiostreamtest identifies the target hardware and handles data in terms of 16-bit words, for example, a byte value is transferred as a 16-bit word value.

See Also

| | | | | |

Related Topics