| Contents | Index |
| On this page… |
|---|
Running Your PIL Application to Perform Simulation and Verification |
Processor-in-the-loop (PIL) requires an Embedded Coder license.
Verification consists broadly of running generated code on a processor and verifying that the code does what you intend. Embedded Coder provides processor-in-the-loop (PIL) simulation to meet this need. PIL compares the numeric output of your model under simulation with the numeric output of your model running as an executable on a target processor.
With PIL, you run your generated code on a target processor or instruction set simulator. To verify your generated code, you compare the output of model simulation modes, such as Normal or Accelerator, with the output of the generated code running on the processor. You can switch between simulation and PIL modes. This flexibility allows you to verify the generated code by executing the model as compiled code in the target environment. You can model and test your embedded software component in Simulink and then reuse your regression test suites across simulation and compiled object code. This process avoids the time-consuming process of leaving the Simulink software environment to run tests again on object code compiled for the production hardware.
Embedded Coder supports the following PIL approaches:
Model block PIL
Top-model PIL
PIL block
When you use makefiles with PIL, use the "model block PIL" approach. With makefiles, the other two approaches, "top-model PIL" and "PIL block", and are not supported.
For more information about PIL, see Numerical Equivalence Checking
Processor-in-the-loop (PIL) builds and uses a MEX function to run the PIL simulation block. Before using PIL, set up a compiler for MATLAB to build the MEX files. Run the command |mex -setup| to select a compiler configuration. For more information, read Building MEX-Files
Use model block PIL to:
Verify code generated for referenced models (model reference code interface).
Provide a test harness model (or a system model) to generate test vector or stimulus inputs.
Switch a model block between normal, SIL, or PIL simulation modes.
To perform a model block PIL simulation, start with a top-model that contains a model block. The top-model serves as a test harness, providing inputs and outputs for the model block. The model block references the model you plan to run on a target processor. During PIL simulation, the referenced model runs on the target processor.
For more information about using the model block, see Model, Model Variants and Referencing a Model.
By default, your MathWorks software uses the IDE debugger for PIL communications with the target processor. To achieve faster communications, consider using one alternatives presented in Communications.
To use model block PIL:
Right-click the Model block, and select ModelReference Parameters.
When the software displays the Function Block Parameters: Model dialog box, set Simulation mode to Processor-in-the-loop (PIL) and click OK.
Open the model block.
Add a Target Preferences block to either model, and configure it for the target processor.
Copy the Target Preferences block from one model to the other. The top-model and the model block now contain identical Target Preference blocks.
In the referenced model (model block) Configuration Parameters (Ctrl+E), under Code Generation > IDE Link, set Build action set to Archive_library. This action avoids a warning when you start the simulation.
Save the changes to both models.
In the top-model menu bar, select Simulation > Start. This action builds the referenced model in the model block, downloads it to your target processor, and runs the PIL simulation.
Note In the top-model Configuration Parameters (Ctrl+E), under Code Generation > IDE Link, leave Build action set to Build_and_execute. Do not change Build action to Create_Processor_In_the_Loop_Project. |
For more information, see Numerical Equivalence Checking
Use top-model PIL to:
Verify code generated for a top-model (standalone code interface).
Load test vectors or stimulus inputs from the MATLAB workspace.
Switch the entire model between normal and SIL or PIL simulation modes.
For more information, see Numerical Equivalence Checking
Setting Model Configuration Parameters to Generate the PIL Application. Configure your model to generate the PIL executable from your model:
Add a Target Preferences block in to your model. The Target Preferences block is located in the Simulink library browser under Simulink Coder > Desktop Targets.
Open the Target Preferences block and select your processor from the list of processors.
From the model window, select Simulation > Configuration Parameters.
In Configuration Parameters, select Code Generation.
Set System Target File to idelink_ert.tlc.
From the list of panes under Code Generation, choose IDE Link.
Set Build format to Project.
Set Build action to Create_processor_in_the_loop_project.
Click OK to close the Configuration Parameters dialog box.
Running the Top-Model PIL Application. To create a PIL block, perform the following steps:
In the model window menu, select Simulation > Processor-in-the-loop.
In the model toolbar, click the Start simulation button.
A new model window opens and the new PIL model block appears in it. The third-party IDE compiles and links the PIL executable file. Follow the progress of the build process in the MATLAB command window.
Use the PIL block to:
Verify code generated for a top-model (standalone code interface) or subsystem (right-click build standalone code interface).
Represent a component running in SIL or PIL mode. The test harness model or a system model provides test vector or stimulus inputs.
For more information, see Numerical Equivalence Checking.
Preparing Your Model to Generate a PIL Block. Start with a model that contains the algorithm blocks you want to verify on the processor as compiled object code. To create a PIL application and PIL block from your algorithm subsystem, follow these steps:
Identify the algorithm blocks to cosimulate.
Convert those blocks into an unmasked subsystem in your model.
For information about how to convert your process to a subsystem, refer to Creating Subsystems in Using Simulink or in the online Help system.
Open the newly created subsystem and copy a Target Preferences block to it. The Target Preferences block is located in the Simulink library browser under Simulink Coder > Desktop Targets.
Open the Target Preferences block and select your processor from the list of processors.
Setting Model Configuration Parameters to Generate the PIL Application. After you create your subsystem, set the Configuration Parameters for your model to enable the model to generate a PIL block.
Configure your model to enable it to generate PIL algorithm code and a PIL block from your subsystem:
From the model menu bar, select Simulation > Configuration Parameters. This action opens the Configuration Parameters dialog box.
In the Configuration Parameters dialog box, select Code Generation.
Set System Target File to idelink_ert.tlc.
From the list of panes under Code Generation, choose IDE Link.
Set Build format to Project.
Set Build action to Create_processor_in_the_loop_project.
Click OK to close the Configuration Parameters dialog box.
Creating the PIL Block from a Subsystem. To create a PIL block, perform the following steps:
Right-click the masked subsystem in your model and select Code Generation > Build Subsystem from the context menu.
A new model window opens and the new PIL block appears in it. The third-party IDE compiles and links the PIL executable file.
This step builds the PIL algorithm object code and a PIL block that corresponds to the subsystem, with the same inputs and outputs. Follow the progress of the build process in the MATLAB command window.
Copy the new PIL block from the new model to your model. To simulate the subsystem processes concurrently, place it parallel to your masked subsystem. Otherwise, replace the subsystem with the PIL block.
To see a PIL block in a parallel masked subsystem, search the product help for Getting Started with Application Development and select the demo that matches your IDE.
Note Models can have multiple PIL blocks for different subsystems. They cannot have more than one PIL block for the same subsystem. Including multiple PIL blocks for the same subsystem causes errors and inaccurate results. |
Chose one of the following communication methods for transferring code and data during PIL simulations:
| Method | Speed | Comments |
|---|---|---|
| IDE Debugger | Slow |
|
| TCP/IP | Fast |
|
| Serial Communication Interface (SCI) | Fast |
|
You can use TCP/IP for PIL communications with a hardware target running:
Linux
Microsoft Windows
Using TCP/IP for PIL communications is typically faster than using a debugger, particularly for large data sets, such as with video and audio applications.
You can use TCP/IP with the following PIL approaches:
Top-model PIL
Model block PIL
TCP/IP does not work with the Subsystem PIL approach.
To enable and configure TCP/IP with PIL:
Set up a PIL simulation according to the PIL approach you have chosen.
At the MATLAB command line, use setpref to specify the IP address of the PIL server (servername).
If you are running the PIL server on a remote target, specify the IP address of the target processor. For example:
setpref('MathWorks_Embedded_IDE_Link_PIL_Preferences','servername','144.212.109.114');If you are running PIL server locally, on your host Windows or Linux system, enter 'localhost' instead of an IP address:
setpref('MathWorks_Embedded_IDE_Link_PIL_Preferences','servername','localhost');Specify the TCP/IP port number to use for PIL data communication. Use one of the free ports in your system. For example:
setpref('MathWorks_Embedded_IDE_Link_PIL_Preferences','portnum', 17025);Enable PIL communications over TCP/IP:
setpref('MathWorks_Embedded_IDE_Link_PIL_Preferences','enabletcpip', true);To disable PIL communications over TCP/IP, change the value to false. This action automatically enables PIL communications over an IDE debugger, if an IDE is available.
Open the Target Preferences block in your model, then set the Operating System parameter to an operating system.
Regenerate the code or PIL block.
To disable PIL communications over TCP/IP, enter:
setpref('MathWorks_Embedded_IDE_Link_PIL_Preferences','enabletcpip', false);To enable PIL communications over an IDE debugger, disable PIL communications over TCP/IP and SCI by entering the following commands:
setpref('MathWorks_Embedded_IDE_Link_PIL_Preferences','enabletcpip',false);
setpref('MathWorks_Embedded_IDE_Link_PIL_Preferences','enableserial',false);Then regenerate the code or PIL block.
Using IDE debugger for PIL communication only works when you build your code from IDE projects. Using IDE debugger for PIL communication does not work with builds from makefiles.
After you add your PIL block to your model, click Simulation > Start to run the PIL simulation and view the results.
PIL Algorithm
The algorithmic code, which corresponds to a subsystem or portion of a model, to test during the PIL simulation. The PIL algorithm is in compiled object form to enable verification at the object level.
PIL Application
The executable application that runs on the processor platform. Your coder product creates a PIL application by augmenting your algorithmic code with the PIL execution framework. The PIL execution framework code compiles as part of your embedded application.
The PIL execution framework code includes the string.h header file so that the PIL application can use the memcpy function. The PIL application uses memcpy to exchange data between the Simulink model and the simulation processor.
PIL Block
When you build a subsystem from a model for PIL, the process creates a PIL block optimized for PIL simulation. When you run the simulation, the PIL block acts as the interface between the model and the PIL application running on the processor. The PIL block inherits the signal names and shape from the source subsystem in your model, as shown in the following example. Inheritance is convenient for copying the PIL block into the model to replace the original subsystem for simulation.

Consider the following issues when you work with PIL blocks.
When using PIL in your models, keep the following constraints in mind:
Models can have multiple PIL blocks for different subsystems. They cannot have more than one PIL block for the same subsystem. Including multiple PIL blocks for the same subsystem causes errors and inaccurate results.
A model can contain a single model block running PIL mode.
A model can contain a subsystem PIL block or a model block in PIL mode, but not both.
Refer to PIL Feature Support and Limitations for general information about using the PIL block with embedded link products.
PIL does not support grt.tlc system target files.
To use PIL, set System target file in the Configuration Parameters > Code Generation pane to idelink_ert.tlc.
![]() | Verification Code Generated for Desktop Targets | Working with Eclipse IDE | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |