Create PIL Target Connectivity Configuration for Simulink - MATLAB & Simulink (original) (raw)

Target Connectivity Configurations for PIL

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

Through a target connectivity configuration, you specify:

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

You can have many different target connectivity configurations for PIL simulation. Register a connectivity configuration with Simulink by creating an sl_customization.m file and placing it on the MATLAB® search path.

When you run a PIL simulation, the software determines which of the available connectivity configurations to use. The software looks for a connectivity configuration that is compatible with the model 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.

Diagram shows components of PIL target connectivity API.

You must provide implementations of the three API components:

These steps outline how you create a target connectivity API implementation. The example code shown in the steps is taken from ConnectivityConfig.m in Configure Processor-In-The-Loop (PIL) for a Custom Target.

  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, ...
      exeExtension);
    • 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, 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, ...
      rtiostreamLib);
  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. For more information, see Specify Hardware Timer for Simulink.
  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. For more information, see Implement Driver to Obtain Stack Usage Data During PIL Simulation.

Note

Each time you modify a connectivity implementation, close and reopen the models to refresh them.

Register a Connectivity API Implementation

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

  1. Create or update an sl_customization.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 models.
    • Invoke registerTargetInfo.
  2. Add the folder containing sl_customization.m to the search path and refresh your customizations.
    addpath(slcustomizationpath);
    sl_refresh_customizations;

For more information, see rtw.connectivity.ConfigRegistry.

Verify Target Connectivity Configuration

To verify your target connectivity configuration early on and independently of your model development and code generation, use the supplied piltest function. With the function, you can run a suite of tests. In the tests, the function runs various normal, SIL, and PIL simulations. The function compares results and produces errors if it detects differences between simulation modes.

Target Connectivity API Examples

For step-by-step examples, see:

See Also

piltest | rtw.connectivity.Config | rtw.connectivity.ConfigRegistry | rtw.connectivity.Launcher | rtw.connectivity.MakefileBuilder | rtw.connectivity.RtIOStreamHostCommunicator | rtw.pil.RtIOStreamApplicationFramework

Topics