Main Content

PIL Simulation Sequence

A processor-in-the-loop (PIL) simulation cross-compiles production source code, and then downloads and runs object code on your target hardware. The connectivity configuration that you create controls the way code is compiled and executed on the target. This table describes the sequence of stages in a PIL simulation.

StageDescription
1Start

For top-model PIL, on the Simulink® Editor toolbar, you select the Processor-in-the-Loop (PIL) mode, and then click the Run button.

For Model block PIL, you set the Simulation mode parameter of the Model block to Processor-in-the-loop (PIL), and then run a simulation of the harness model that contains the Model block.

For the PIL block, you run a simulation of the harness model that contains the PIL block.

2Validate target connectivityThe software verifies that a target connectivity configuration is registered for PIL. Otherwise, the software produces an error.
3Generate production source code and build object code for target

The generated source code is identical to the code that is produced when you run the slbuild command.

  • For top-model PIL or Model block PIL with block parameter Code interface set to Top model, the generated code is identical to the code produced when you run slbuild('model').

  • For Model block PIL with block parameter Code interface set to Model reference, the generated code is identical to the code produced when you run slbuild('model','ModelReferenceCoderTarget').

The software builds object code for the target by using the template makefile or toolchain that you specify.

4Create instances of PIL API components

The software instantiates your rtw.connectivity.Config class, which creates instances of rtw.connectivity.MakefileBuilder, rtw.connectivity.Launcher, rtw.pil.RtIOStreamApplicationFramework, and rtw.connectivity.RtIOStreamHostCommunicator.

5Generate PIL files

The generated PIL files are in the pil folder. At the end of the simulation, use the code generation report to view the files.

6Build target application

The software:

  • Uses your instance of rtw.connectivity.MakefileBuilder to build the target application.

  • Compiles the PIL interface file, xil_interface.c, and other PIL files into the target executable file. On a Windows® system, for example, this file is called modelName.exe. The object code, including the executable file, is in the pil folder.

  • If configured, produces the code generation report.

7Start target application

The software uses rtw.connectivity.Launcher to start the application on the target.

8Simulink engine interacts with PIL S-function

The Simulink engine interacts with the PIL S-function in the same way that it interacts with a C S-function.

From the host-side, the PIL S-function communicates with the target executable code through rtIOStream commands. On the target side, xil_interface executes generated code.

9Stop target application

The software uses rtw.connectivity.Launcher to stop the application on the target.

10End PIL simulation

For top-model PIL, at the end of the simulation, the software destroys the rtw.connectivity.Config instance.

For Model block PIL and PIL block, the block creates and owns the rtw.connectivity.Config instance, which is not destroyed at the end of the simulation. You can rerun the simulation, which now does not require the creation of another rtw.connectivity.Config instance. If you want to destroy the instance, close the parent model.

See Also

| | | |

Related Examples

More About