Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop Embedded Coder   

PIL Simulation Support and Limitations

PIL Simulation Support

Top-model and Model block processor-in-the-loop (PIL) simulation modes are Real-Time Workshop Embedded Coder features. You can also use top-model and Model block PIL with Embedded IDE Link software specific to AltiumTASKING.

The PIL block works with the general Embedded IDE Link product. For more details on the differences between top-model PIL, Model block PIL and the PIL block, see Choosing a PIL Simulation Approach.

The following tables describe feature support for top-model PIL, Model block PIL and the PIL block. "Yes" indicates a supported feature.

This is not a complete list of supported features, but provides information on selected features of interest for PIL, especially unsupported features and limitations.

Feature Support Top-Model PILModel Block PIL ModePIL Block
Testing of deployment object codeYesYesYes
Target Connectivity APIYesYesNo

Code Source Support

Code Source Code InterfaceTop-Model PILModel Block PIL ModePIL Block
Top modelStandaloneYesNoYes
Atomic subsystem StandaloneNoNoYes
Virtual subsystemStandaloneNoNoYes, but recommend atomic subsystem. See Algebraic Loop Issues.
Model blockModel reference Real-Time Workshop targetNo, but you can include Model blocks inside your top model.Yes. See Cannot Use Multirate Model Block PIL Inside Conditionally Executed SubsystemNo, but you can include Model blocks inside your model.
Enabled/
Triggered subsystem
StandaloneNoNoYes
Export Functions subsystemExport Functions NoNoNo
Legacy codeCustomSee Custom Code Interfaces.See Custom Code Interfaces.See Custom Code Interfaces.
Embedded MATLAB CoderEmbedded MATLAB CoderSee Custom Code Interfaces.See Custom Code Interfaces.See Custom Code Interfaces.

For more information on code interfaces, see PIL Code Interfaces.

Custom Code Interfaces

The MathWorks does not provide direct PIL support for code interfaces such as legacy code and Embedded MATLAB Coder. However, you can incorporate these interfaces into Simulink as an S-function (for example, using the Legacy Code Tool, S-Function Builder, or hand-written code), and then verify them using PIL.

PIL Does Not Check Real-Time Workshop Error Status

PIL does not check the Real-Time Workshop error status of the generated code under test. This error status flags exceptional conditions during execution of the generated code.

The Real-Time Workshop error status can also be set by blocks in the model (for example, custom blocks developed by a user). It is a limitation that PIL cannot check this error status and report back errors.

Cannot Use Multirate Model Block PIL Inside Conditionally Executed Subsystem

You see an error if you place your Model block (in processor-in-the-loop (PIL) simulation mode) in a conditionally executed subsystem and the referenced model is multirate (that is, has multiple sample times). Single rate referenced models (with only a single sample time) are not affected.

Block Support

Blocks Top-Model PILModel Block PIL ModePIL Block
Model blockYes, you can include Model blocks inside your top model.YesYes, you can include Model blocks inside your subsystem or model.
Signal Processing BlocksetYesYesYes
Video and Image Processing Blockset™YesYesYes
Embedded MATLAB blockYesYesYes
Driver blocks Yes, but not recommended.Yes, but not recommended.Yes, but not recommended.
To File blocks NoNoNo
To Workspace blocksNoNoNo
Merge blocksYes.Yes. Cannot connect PIL outputs to Merge blocks. See Merge Block Issue.Yes. Cannot connect PIL outputs to Merge blocks. See Merge Block Issue.
Stop blockNo. PIL ignores the Stop Simulation block and continues simulating.No. PIL ignores the Stop Simulation block and continues simulating.No. PIL ignores the Stop Simulation block and continues simulating.

Run-Time Display Limitation

Scope blocks, and all types of run-time display, such as the display of port values and signal values, have no effect when you specify them in models executing in PIL mode. The result during simulation is the same as if the constructs did not exist.

Merge Block Issue

If you connect PIL outputs to a Merge block, you see an error because S-function memory is not reusable.

The signal from 'mpil_enabled/Subsystem' output port 1 is
required to be persistent, hence this signal cannot be
connected to a Merge block.

Other Top-Model PIL Limitations

PIL does not support Callbacks (model or block ) InitFcn, StartFcn, StopFcn.

Configuration Parameters Support

Configuration Parameters Top-Model PILModel Block PIL ModePIL Block
ERT-based system target fileYesYesYes
AUTOSAR system target fileNoYes, but see AUTOSAR Support.No
GRT-based system target fileNoNoNo
GRT compatible call interfaceNo; see Missing Code Interface Description File Errors.No; see Missing Code Interface Description File Errors.No; see Missing Code Interface Description File Errors.
Function Prototype ControlYesYesYes
Reusable code format Yes, but see the special cases in Imported Data Definitions.N/AYes, but see the special cases in Imported Data Definitions.
Target Function LibraryYesYesYes
C++ No; see Missing Code Interface Description File Errors.No; see Missing Code Interface Description File Errors.No; see Missing Code Interface Description File Errors.
Generate ASAP2 fileYesYesYes
Generate example main N/AN/AN/A
MAT-file logging NoNoNo
Signal loggingYes, but only for signals connected to root-level inports and outports.No, but see Verifying Signals with PIL Testing.No, but see Verifying Signals with PIL Testing.
'Simplified' model initializationYesNoYes
Single output/updateYes, but see Algebraic Loop Issues.Yes, but see Algebraic Loop Issues.Yes, but see Algebraic Loop Issues.
Configuration set referenceYesYesDepends on the use of the Embedded IDE Link product.

Missing Code Interface Description File Errors

PIL requires a code interface description file, which is generated during the code generation process for the component under test. If the code interface description file is missing, PIL simulation cannot proceed and you see an error reporting that the file does not exist. This error can occur if you select these unsupported options in your configuration parameters:

Make sure that you have not selected these options.

AUTOSAR Support

PIL does supports testing components of AUTOSAR models that are modeled as model reference components. These model reference components are implemented as standard model reference Real-Time Workshop targets and do not contain any special AUTOSAR behavior.

For example, you can simulate a top-level AUTOSAR model containing PIL components, or you can create a second top-level model for testing of individual components.

Algebraic Loop Issues

For more information on algebraic loops, see:

There are three ways that PIL simulation can introduce algebraic loops that do not exist for a normal simulation:

Algebraic Loops Caused by Code Generation for a Virtual Subsystem.   If you generate code for a virtual subsystem, the Real-Time Workshop software treats the subsystem as atomic and generates the code accordingly. The resulting code can change the execution behavior of your model, for example, by applying algebraic loops, and introduce inconsistencies to the simulation behavior.

Declare virtual subsystems as atomic subsystems to ensure consistent simulation and execution behavior for your model.

See Creating Subsystems in the Real-Time Workshop documentation.

Algebraic Loops Caused by "Single output/update function".   The "single output/update function" in Real-Time Workshop optimization can introduce algebraic loops because it introduces direct feedthrough via a combined output and update function.

This option is not compatible with the Minimize algebraic loop occurrences option (in the Subsystem Parameters dialog box and Model Referencing pane of the Configuration Parameters dialog box). This option allows Real-Time Workshop to remove algebraic loops by partitioning generated code appropriately between output and update functions to avoid direct feedthrough.

Algebraic Loops Caused by PIL Scheduling Limitations.   The S-function scheduling mechanism that the software uses to execute the PIL component has the following limitations:

These limitations mean that PIL can introduce algebraic loops that do not exist in normal simulation, and you might get incorrect results. If this happens, you see a warning or error about the introduced algebraic loop and PIL results may differ from simulation results. You will not see or warning or error if the algebraic loop setting is "none" in the Configuration Parameters dialog box (under Diagnostics on the Solver pane).

A workaround is to break the algebraic loop by inserting a Unit Delay block so that the algebraic loop does not occur. Then, you can use PIL successfully.

I/O Support

I/O Top-Model PILModel Block PIL ModePIL Block
Tunable parameters (Model reference arguments)N/AYes, except for tunable structure parameters. See Tunable Parameters and PIL.N/A
Tunable parameters (Workspace variables)NoYes, except for tunable structure parameters. See Tunable Parameters and PIL.No
Virtual busesNoYesYes, but some limitations at PIL component boundary; see PIL Block Virtual Bus Support Limitations.
Nonvirtual buses Yes, but see Top-Model PIL Bus Limitations.YesYes
MUX/DEMUXNoYesYes, but see PIL Block MUX Support Limitations.
Vector/2D/
Multidimensional
YesYesYes
Complex dataYesYesYes
Fixed-point dataYesYesYes
Complex fixed-point dataYesYesYes
Fixed-point data type override Not at PIL component boundary. See Fixed-Point Tool Data Type OverrideNot at PIL component boundary. See Fixed-Point Tool Data Type Override.Not at PIL component boundary. See Fixed-Point Tool Data Type Override.
Goto/From I/ON/AN/AGoto / From blocks must not cross the PIL component boundary. You can use Goto / From blocks to route buried signals up to top-level Inports and Outports inside the PIL component.
Global data store I/OYes. See Global Data Store Support and Imported Data Definitions.Yes. See Global Data Store Support and Imported Data Definitions.Yes. See Global Data Store Support and Imported Data Definitions.
Local data store I/ONo. See Imported Data Definitions.No. See Imported Data Definitions.No. See Imported Data Definitions.
Non-port-based sample timesYesYesYes
Continuous sample timesNot at PIL component boundary.NoNot at PIL component boundary.
Outputs with constant sample timeYesNoYes
Non-auto-storage classes for data (such as signals, parameters, data stores)Yes. See Imported Data Definitions.Yes. See Imported Data Definitions.Yes. See Imported Data Definitions.
Simulink data objects YesYesYes
Simulink numeric type and
alias type
YesYesYes
Simulink enumerated dataYesYesYes
Custom storage classes Yes, but see Imported Data Definitions, and Unsupported Custom Storage Classes.Yes, but see Imported Data Definitions, and Unsupported Custom Storage Classes.Yes, but see Imported Data Definitions, and Unsupported Custom Storage Classes.
Variable-size signalsNo. See Variable-Size Signals and PIL.No. See Variable-Size Signals and PIL.No. See Variable-Size Signals and PIL.

Tunable Parameters and PIL

You can tune parameters during a Model block PIL mode simulation exactly as you do in Normal simulation mode.

For more information, see Global Tunable Parameters and Using Model Arguments in the Simulink model reference documentation.

Tunable Parameters Limitation.   You cannot tune parameters during PIL simulation if the parameters have an associated storage class that applies "static" scope or the "const" keyword (for example, Custom, Const, or ConstVolatile). Parameter changes are ignored.

If the storage class also specifies that the parameter is imported, then you must manually define and initialize the value of the parameter. See Imported Data Definitions).

Global Data Store Support

PIL supports global data stores. PIL components that access global data stores must be single rate. You see an error if your PIL component has multiple sample times and accesses global data stores. To avoid the error, either remove accesses to global data stores or make the component single rate.

Imported Data Definitions

You can use signals, parameters, data stores, etc., that specify storage classes with imported data definitions.

Model Block PIL.   The PIL application automatically defines storage for imported data associated with:

A PIL limitation is that PIL does not define storage for other imported data storage. You must define the storage through custom code included by the component under test or through the PIL rtw.pil.RtIOStreamApplicationFramework API. For example, the PIL application does not define imported data storage for data associated with:

Top-Model PIL and PIL Block.  

The PIL application automatically defines storage for imported data associated with:

A PIL limitation is that it does not define storage for other imported data storage. You must define the storage through custom code included by the component under test or through the PIL rtw.pil.RtIOStreamApplicationFramework API. For example, the PIL application does not define imported data storage for data associated with:

Top-Model PIL and the PIL block can produce errors if you select the Real-Time Workshop option Generate reusable code, and either:

If either of these conditions are met then PIL produces an error similar to the following:

Parameter "t_pil_lib_alg/t_pil_lib_alg/Unit Delay:Dialog:X0"
is not defined in the code associated with the PIL component,
and is therefore not supported for PIL.
Please change the parameter's storage class and / or the 
code generation configuration settings so that the parameter
becomes defined in the code associated with the PIL component.

Unsupported Custom Storage Classes

PIL does not support the following non-addressable custom storage classes:

PIL also does not support signals and parameters with imported grouped custom storage classes.

Unsupported Implementation Errors

You may see errors like the following if you are using a signal or parameter implementation that PIL does not support:

The following data interfaces have 
implementations that are not supported by PIL.

data interfaces may be inports, outports or parameters.

This error message has the following possible causes:

The following example illustrates a model that causes this error due to changing the output port signal's data type.

Variable-Size Signals and PIL

PIL treats variable-size signals at the I/O boundary of the PIL component as fixed-size signals which can lead to errors during propagation of signal sizes. To avoid such errors, use only fixed-size signals at the I/O boundary of the PIL component.

Fixed-Point Tool Data Type Override

PIL does not support signals with data types overridden by the Fixed-Point Tool Data type override parameter at the PIL component boundary.

You may see an exception message like the following:

Simulink.DataType object 'real_T' is not in scope
from 'mpil_mtrig_no_ic_preread/TmpSFcnForModelReference_unitInTopMdl'.
 This error message is related to a hidden S-Function block. 

There is no resolution for this issue.

Top-Model PIL Bus Limitations

The software does not support grounded or unconnected signals at the outputs of a top model.

You must enable the strict bus mode for top-model PIL:

  1. In the model window, select Simulation > Configuration Parameters > Diagnostics > Connectivity.

  2. Set Mux blocks used to create bus signals to error.

PIL Block Virtual Bus Support Limitations

The PIL block supports virtual buses except for the following cases:

To avoid these limitations, use nonvirtual buses at the PIL component boundary.

PIL Block MUX Support Limitations

The PIL block supports mux signals, except mixed data-type mux signals that expand into individual signals during a right-click subsystem build. You see an error for unsupported cases.

Hardware Implementation Support

Hardware Implementation Real-Time Workshop Embedded CoderEmbedded IDE Link
Different host and target data-type sizeNot at PIL component boundary. See Hardware Implementation Settings.Not at PIL component boundary. See Hardware Implementation Settings.
Word-addressable targetsNoYes
Multiword data type word order different to target byte orderNoYes
MultiwordNoNo
Size of target 'long' > 32 bitsNoNo

Hardware Implementation Settings

PIL requires that, in the Simulink Configuration Parameters dialog box, you correctly configure the Hardware Implementation settings for the target environment.

Specify byte ordering for non-8-bit targets.

For more information, see the following sections:

Host/Target Data Type Size Mismatch.   PIL supports only data types that have the same size on the host and the target at the PIL I/O boundary.

The data types used at the PIL I/O boundary are restricted based on the following rule: PIL supports the data type only if the data-type size on the host (Simulink) is the same as the data-type size on the target.

Examples of unsupported data types are:

To resolve issues with Simulink data types that have different sizes on the host and target, do not use them at the PIL I/O boundary. Instead, use a Simulink data type that maps directly onto a target data type. This resolution is more efficient.

Data Type Size Mismatch Issues (Real-Time Workshop Embedded Coder).   PIL mode makes the following assumptions about the target environment:

To resolve issues with Simulink data types that have different sizes on the host and target, do not use them at the PIL I/O boundary. Instead, use a Simulink data type that maps directly onto a target data type. This resolution is more efficient.

Some known violations with predefined hardware implementation settings are:

Data Type Size Mismatch Issues (Embedded IDE Link).   The Embedded IDE Link product registers the following information about the target environment to Simulink:

This allows PIL to support target environments with unusual hardware characteristics.

PIL can detect data types used at the PIL component boundary that have a host/target data type size mismatch. In such cases, an error indicates that an unsupported data type is being used. This avoids unexpected data transfer errors during simulation.

To resolve issues with Simulink data types that have different sizes on the host and target, do not use them at the PIL I/O boundary. Instead, use a Simulink data type that maps directly onto a target data type. This resolution is more efficient.

Some target compilers allow the sizes of target data types to be changed from their default size. For example, an IEEE double data type is most likely 8 bytes by default, but an optimization option may be provided to treat it as a 4 byte IEEE single precision type instead. The registration of target data type sizes done by the Embedded IDE Link product is typically statically defined to match the compiler's default data type size, and therefore does not support changing the data type size from that default size.

To resolve this issue, either:

Other Feature Support

Other Features Top-Model PILModel Block PIL ModePIL Block
Multiplatform support (such as Linux®)YesYesDepends on the use of the Embedded IDE Link product.
Execution profilingDepends on PIL configuration.Depends on PIL configuration.Yes (if Embedded IDE Link product support)
Stack profilingDepends on PIL configuration.Depends on PIL configuration.Yes (if Embedded IDE Link product support)
C code coverage reportDepends on PIL configuration.Depends on PIL configuration.Yes (if Embedded IDE Link product support)

PIL Block Limitations

Out of Date PIL Application

The PIL block indicates that the PIL application executable is out of date only when the PIL block detects that new code has been generated for the PIL algorithm under test.

No indication that the PIL application executable is out of date is given under the following circumstances:

  1. A component of the PIL application executable, such as a C library, is updated after generating code for the PIL algorithm. In this case, click the PIL block Build button to bring the PIL application executable up to date. You do not need to regenerate code for the PIL algorithm.

  2. A model referenced by the PIL algorithm is rebuilt after generating code for the PIL algorithm. In this case, regenerate code for the PIL algorithm and then click the PIL block Build button to bring the PIL application executable up to date.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS