Skip to Main Content Skip to Search
Product Documentation

Processor-in-the-Loop (PIL) Simulation for Desktop Targets

Overview

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:

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

PIL Approaches

Model Block PIL

Use model block PIL to:

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:

  1. Right-click the Model block, and select ModelReference Parameters.

  2. When the software displays the Function Block Parameters: Model dialog box, set Simulation mode to Processor-in-the-loop (PIL) and click OK.

  3. Open the model block.

  4. Add a Target Preferences block to either model, and configure it for the target processor.

  5. Copy the Target Preferences block from one model to the other. The top-model and the model block now contain identical Target Preference blocks.

  6. 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.

  7. Save the changes to both models.

  8. 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.

For more information, see Numerical Equivalence Checking

Top-Model PIL

Use top-model PIL to:

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:

  1. 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.

  2. Open the Target Preferences block and select your processor from the list of processors.

  3. From the model window, select Simulation > Configuration Parameters.

  4. In Configuration Parameters, select Code Generation.

  5. Set System Target File to idelink_ert.tlc.

  6. From the list of panes under Code Generation, choose IDE Link.

  7. Set Build format to Project.

  8. Set Build action to Create_processor_in_the_loop_project.

  9. Click OK to close the Configuration Parameters dialog box.

Running the Top-Model PIL Application.  To create a PIL block, perform the following steps:

  1. In the model window menu, select Simulation > Processor-in-the-loop.

  2. 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.

PIL Block

Use the PIL block to:

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:

  1. Identify the algorithm blocks to cosimulate.

  2. 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.

  3. 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:

  1. From the model menu bar, select Simulation > Configuration Parameters. This action opens the Configuration Parameters dialog box.

  2. In the Configuration Parameters dialog box, select Code Generation.

  3. Set System Target File to idelink_ert.tlc.

  4. From the list of panes under Code Generation, choose IDE Link.

  5. Set Build format to Project.

  6. Set Build action to Create_processor_in_the_loop_project.

  7. 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:

  1. 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.

  2. 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.

Communications

Chose one of the following communication methods for transferring code and data during PIL simulations:

MethodSpeedComments
IDE DebuggerSlow
  • Supports PIL communications with an executable running an embedded target processor.

  • Supports the largest number of targets.

  • Requires a physical connection between host and target processor.

  • Only works with builds from IDE projects. Does not work with builds from makefiles.

TCP/IPFast
  • Supports PIL communications with an executable running on a Linux or Windows host.

  • Supports embedded targets running Linux, TI DSP/BIOS, and Wind River VxWorks.

  • Requires network connection between host and target processor.

  • Works with builds from IDE projects and from makefiles.

Serial Communication Interface (SCI)Fast
  • Supports PIL communications with an executable running an embedded target processor.

  • Supports only TI C28035 and C28335 microcontrollers.

  • Requires an SCI connection between host and target processor.

  • Works with builds from IDE projects and from makefiles.

TCP/IP

You can use TCP/IP for PIL communications with a hardware target running:

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:

TCP/IP does not work with the Subsystem PIL approach.

To enable and configure TCP/IP with PIL:

  1. Set up a PIL simulation according to the PIL approach you have chosen.

  2. 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');
  3. 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);
  4. 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.

  5. Open the Target Preferences block in your model, then set the Operating System parameter to an operating system.

      Note   You cannot use TCP/IP for PIL when the value of Operating System is None.

  6. Regenerate the code or PIL block.

To disable PIL communications over TCP/IP, enter:

setpref('MathWorks_Embedded_IDE_Link_PIL_Preferences','enabletcpip', false);

IDE Debugger

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.

Running Your PIL Application to Perform Simulation and Verification

After you add your PIL block to your model, click Simulation > Start to run the PIL simulation and view the results.

Definitions

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.

PIL Issues and Limitations

Consider the following issues when you work with PIL blocks.

Constraints

When using PIL in your models, keep the following constraints in mind:

Generic PIL Issues

Refer to PIL Feature Support and Limitations for general information about using the PIL block with embedded link products.

Simulink Coder grt.tlc-Based Targets Not Supported

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.

  


Related Products & Applications

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