Main Content

Create PIL Target Connectivity Configuration for MATLAB

Target Connectivity Configurations for PIL

Use target connectivity configurations and the target connectivity API to customize processor-in-the-loop (PIL) execution for your target environments.

Through a target connectivity configuration, you specify:

  • A target connectivity configuration name for a target connectivity API implementation.

  • Settings that define compatible MATLAB® code. For example, the code that is generated for a particular hardware implementation.

A PIL execution requires a target connectivity PIL API implementation that integrates third-party tools for:

  • Building the PIL application that runs on the target hardware

  • Downloading, starting, and stopping the application on the target

  • Communicating between MATLAB and the target

You can have many different connectivity configurations for PIL execution. Register a connectivity configuration with MATLAB by creating an rtwTargetInfo.m file and placing it on the MATLAB search path.

In a PIL execution, the software determines which of the available connectivity configurations to use. The software looks for a connectivity configuration that is compatible with the MATLAB code under test. If the software finds multiple or no compatible connectivity configurations, the software generates an error message with information about resolving the problem.

Create a Target Connectivity API Implementation

This diagram shows the components of the PIL target connectivity API.

You must provide implementations of the three API components:

  • Build API — Specify a toolchain approach for building generated code.

  • Launcher API — Control how MATLAB starts and stops the PIL executable.

  • Communications API — Customize connectivity between MATLAB and the PIL target. Embedded Coder® provides host-side support for TCP/IP and serial communications, which you can adapt for other protocols.

These steps outline how you create a target connectivity API implementation. The example code shown in the steps is taken from the ConnectivityConfig.m file used in Processor-in-the-Loop Execution from Command Line.

  1. Create a subclass of rtw.connectivity.Config.

    ConnectivityConfig < rtw.connectivity.Config

  2. In the subclass:

    • Instantiate rtw.connectivity.MakefileBuilder, which configures the build process.

      builder = rtw.connectivity.MakefileBuilder(componentArgs, ...
                      targetApplicationFramework, ...

    • Create a subclass of rtw.connectivity.Launcher, which downloads and executes the application using a third-party tool.

      launcher = mypil.Launcher(componentArgs, builder);

  3. Configure your rtiostream API implementation of the host-target communications channel.

    • For the target side, you must provide the driver code for communications, for example, code for TCP/IP or serial communications. To integrate this code into the build process, create a subclass of rtw.pil.RtIOStreamApplicationFramework.

    • For the host side, you can use a supplied library for TCP/IP or serial communications. Instantiate rtw.connectivity.RtIOStreamHostCommunicator, which loads and initializes the library that you specify.

      hostCommunicator = rtw.connectivity.RtIOStreamHostCommunicator(...
                              componentArgs, ...
                              launcher, ...

  4. If you require execution-time profiling for generated code, create a timer object that provides details of the hardware-specific timer and associated source files. See Specify Hardware Timer for MATLAB.

  5. If you require stack usage profiling for generated code, specify a driver implementation that obtains stack usage data from the target hardware. The driver must return the value of the stack register. If you do not specify a driver, the PIL simulation tries to use a default generic driver. See Implement Driver to Obtain Stack Usage Data During PIL Execution.

Register Target Connectivity Configuration

To register a target connectivity API implementation as a target connectivity configuration in MATLAB:

  1. Create or update an rtwTargetInfo.m file. In this file:

    • Create a target connectivity configuration object that specifies, for example, the configuration name for a target connectivity API implementation and compatible MATLAB code.

    • Invoke registerTargetInfo.

  2. Add the folder containing rtwTargetInfo.m to the search path and refresh the MATLAB Coder™ library registration information.

For more information, see rtw.connectivity.ConfigRegistry.

Verify Target Connectivity Configuration

To verify your target connectivity configuration early on and independently of your algorithm development and code generation, use the piltest function. With the function, you can run a suite of tests. The function:

  • Runs the MATLAB function and performs PIL executions.

  • Compares results and produces errors if it detects differences.

For an example, see PIL Execution of Code Generated for a Kalman Estimator.

See Also

| | | | | |

Related Topics