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
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.
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
ConnectivityConfig.m file used in Processor-in-the-Loop Execution From Command Line.
Create a subclass of
ConnectivityConfig < rtw.connectivity.Config
In the subclass:
configures the build
builder = rtw.connectivity.MakefileBuilder(componentArgs, ... targetApplicationFramework, ... exeExtension);
Create a subclass of
downloads and executes the application using a
launcher = mypil.Launcher(componentArgs, builder);
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
For the host side, you can use a supplied library for TCP/IP or serial communications.
which loads and initializes the library that you
hostCommunicator = rtw.connectivity.RtIOStreamHostCommunicator(... componentArgs, ... launcher, ... rtiostreamLib);
If you require execution-time profiling of generated code, create a timer object that provides details of the hardware-specific timer and associated source files. See Specify Hardware Timer.
To register a target connectivity API implementation as a target connectivity configuration in MATLAB:
Create or update an
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.
Add the folder containing
the search path and refresh the MATLAB
Coder™ library registration
For more information, see
To verify your target connectivity configuration early on and
independently of your algorithm development and code generation, use
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.