Configure and Run PIL Simulation
There are three ways of running SIL and PIL simulations. You can use:
The top model.
Model blocks.
SIL and PIL blocks that you create from subsystems.
Simulation with Top Model
To configure and run a top-model SIL or PIL simulation:
In the Simulink® Editor, open your model.
On the Apps tab, click SIL/PIL Manager.
In the Mode section, select SIL/PIL Simulation Only.
In the Prepare section, set System Under Test to
Top model
.In the SIL/PIL Mode field, select either
Software-in-the-Loop (SIL)
orProcessor-in-the-Loop (PIL)
. The option supports only ERT, GRT, or AUTOSAR system target files. See Model Configuration Parameters: Code Generation and Configure AUTOSAR Code Generation (AUTOSAR Blockset) for configuration information.To monitor component signals and state data and compare values from the model and SIL or PIL simulations:
For each signal that you want to log:
In the Simulink Editor, select the signal.
On the SIL/PIL tab, click Monitor Signals. From the gallery, select these options:
Log Selected Signals
Make Selected Signals Testpoints
Signal Logging
To log state data, from the Monitor Signals gallery, select State Logging.
If the Language configuration parameter is
C++
and Code interface packaging isC++ class
, in the Code Mappings editor, set the Data Visibility for the signals, states, and internal data model element categories topublic
.
If you are configuring a SIL simulation, specify the portable word sizes option. You can then switch seamlessly between the SIL and PIL modes. In the Configuration Parameters dialog box, select the Enable portable word sizes check box.
If required, configure:
In the Run section, in the Stop Time field, specify simulation time.
Click Run SIL/PIL.
At the end of the simulation, in the Results section, click Data Inspector to view simulation results.
Note
On a Windows® operating system, the Windows Firewall can potentially block a SIL or PIL simulation. To allow the simulation, use the Windows Security Alert dialog box. For example, in Windows 7, click Allow access.
You cannot:
Close the model while the simulation is running. To interrupt the simulation, in the Command Window, press Ctrl+C.
Alter the model during the simulation. You can move blocks and lines as long as it does not alter the behavior of the model.
You can run a top-model SIL or PIL simulation with the command sim(
.
The software supports the model
)sim
command option SrcWorkspace
for
the value 'base'
.
For a PIL simulation, you control the way code compiles and executes in the target environment through connectivity configurations.
Simulation with Model Blocks
To configure a Model block for a SIL or PIL simulation:
Open your model, for example,
SILModelBlock
:openExample('ecoder/SILPILVerificationExample', ... supportingFile='SILModelBlock.slx')
Right-click your Model block, for example,
Counter A
. In the context menu, select Block Parameters (ModelReference), which opens the Function Block Parameters dialog box.From the Simulation Mode drop-down list, select the required mode, for example,
Software-in-the-loop (SIL)
.From the Code interface drop-down list, specify the code that you want to test, for example,
Model reference
.Click OK. The software displays the simulation mode as a block label.
If you select
Top model
, the software displays the block label(SIL: Top)
.If you are configuring a SIL simulation, specify the portable word sizes option. You can then switch seamlessly between the SIL and PIL modes. In the Configuration Parameters dialog box, select the Enable portable word sizes check box.
On the Apps tab, click SIL/PIL Manager.
In the Mode section, select SIL/PIL Simulation Only.
In the Prepare section, set System Under Test to
Model blocks in SIL/PIL mode
.In the Top Model Mode field, select either
Normal
orAccelerator
.If required, configure:
Code execution profiling for your Model block, by configuring execution profiling for the top model.
In the Run section:
In the Stop Time field, specify simulation time.
If you want to avoid rebuilding code after the initial build, click Fast Restart. See Prevent Code Changes in Multiple Simulations.
Click Run SIL/PIL.
At the end of the simulation, in the Results section, click Data Inspector to view simulation results.
Note
On a Windows operating system, the Windows Firewall can potentially block a SIL or PIL simulation. To allow the simulation, use the Windows Security Alert dialog box. For example, in Windows 7, click Allow access.
For a PIL simulation, you control the way code compiles and executes in the target environment through connectivity configurations.
Simulation with Subsystem Blocks
You can use one of these workflows:
Simulink Test™ harness with the SIL/PIL Manager—If you have a model that contains subsystems, you can use Simulink Test and the SIL/PIL Manager to perform unit tests on code generated from the subsystems. This workflow tests the generated subsystem code as part of the code generated from the parent model. For workflow details, see Unit Test Subsystem Code with SIL/PIL Manager.
If this workflow does not support a subsystem, use the SIL or PIL block workflow as an alternative.
SIL or PIL block—Create a SIL or PIL block from the subsystem, and then run the block in an environment or test harness model that supplies test vectors or stimulus input. This workflow generates and tests new standalone code from the subsystem. For more information, see SIL or PIL Block Simulation.
For a PIL simulation, you control the way code compiles and executes in the target environment through connectivity configurations.
SIL or PIL Block Simulation
To create a SIL or PIL block from a subsystem and use this block to test the code generated from the subsystem:
From the Configuration Parameters > Code Generation > Verification > Advanced Parameters > Create block drop-down list, select either
SIL
orPIL
.If required, configure code execution profiling.
Click OK.
In your model window, right-click the subsystem that you want to simulate.
Select C/C++ Code > Build This Subsystem, which starts the subsystem build process that creates a SIL or PIL block for the generated subsystem code.
Add the generated block to an environment or test harness model that supplies test vectors or stimulus input.
Run simulations with the environment or test harness model.
Note
On a Windows operating system, the Windows Firewall can potentially block a SIL or PIL simulation. To allow the simulation, use the Windows Security Alert dialog box. For example, in Windows 7, click Allow access.
You cannot create a SIL or PIL block if you do one of the following:
Disable the
CreateSILPILBlock
property.Select a code coverage tool.
Create block appears dimmed.
Log Signals of a Component
SIL and PIL component outputs are available for observation and comparison with other simulation mode outputs. If you want to examine an internal signal, you can enable internal signal logging for top-model or Model block SIL or PIL. With signal logging, you can:
Collect signal logging outputs during SIL/PIL simulations, for example,
logsout
.Log the internal signals and the root-level outputs of a SIL/PIL component.
Manage the SIL/PIL signal logging settings with the Simulink Signal Logging Selector.
Use the Simulation Data Inspector to:
Observe streamed signals during normal, SIL, and PIL simulations.
Compare logged signals from normal, SIL, and PIL simulations.
To enable signal logging to the MATLAB® workspace and signal streaming to the Simulation Data Inspector during SIL or PIL simulations:
For each signal that you want to monitor:
In the Simulink Editor, select the signal.
On the SIL/PIL tab, click Monitor Signals. From the gallery, select these options:
Log Selected Signals
Make Selected Signals Testpoints
Signal Logging
If the Language configuration parameter is
C++
and Code interface packaging isC++ class
, in the Code Mappings editor, set the Data Visibility for the signals, states, and internal data model element categories topublic
.
You can use other methods to examine internal signals of the SIL or PIL component:
Manually route the signal to the top level.
Use global data stores to access internal signals:
Inside the component, connect a Data Store Write block to the required signal.
Outside the component, use a Data Store Read block to access the signal value.
Use MAT-file logging. Note that:
MAT-file logging does not support signal logging. If signal logging is enabled,
logsout
is generated but not stored in the MAT-file.For PIL, the target environment must support MAT-file logging.
For more information, see:
Prevent Code Changes in Multiple Simulations
Use Model block SIL/PIL or the SIL/PIL block with fast restart when you want to run multiple SIL or PIL simulations with:
Varying test vectors (parameter sets and input data).
Unchanged generated code, that is, none of the simulations regenerate or rebuild code after the initial build. For example, you want to avoid the incremental code generation that an initial value change can trigger.
For Model block SIL/PIL, you can also use one of these methods:
In your test harness model, in the Configuration Parameters dialog box, set Rebuild to
Never
. If the Model block Code interface parameter isModel reference
, the software does not rebuild the referenced model code. (If the Code interface parameter isTop model
, the software ignores the Rebuild setting.)Create a protected model and generate source or binary code. Then, insert the protected model in your test harness model. With this method, you can verify top-model code (with the standalone code interface) or model reference code.
For the alternative methods of running Model block SIL/PIL, the following table summarizes code generation behavior after the initial build.
SIL and PIL Approach | Code Generation Behavior After Initial Build | |
---|---|---|
Model block | Rebuild configuration parameter of test harness model set to
Never . |
|
Model block (protected model) | Source code from protected model. | You observe the same behavior except for feature 2. In this case, the component code makefile is run. The component code is recompiled and linked to produce new object code. |
Binary code from protected model. | You observe features 1–4. |
For more information, see:
Speed Up Testing
If your model has SIL/PIL blocks or Model blocks in SIL/PIL mode, you can speed up SIL/PIL testing by:
Running the top-model simulation in accelerator mode. This mode accelerates the simulation of model components that are not in SIL or PIL mode.
Turning on fast restart. After the first simulation, you can tune parameters and rerun simulations without model recompilation. The SIL/PIL Manager provides a Fast Restart button.
Note
The SIL and PIL simulation modes are not designed for the reduction of model simulation times. If you want to speed up the simulation of your model, use the rapid accelerator mode. For more information, see What Is Acceleration?.
Simulation with Function Calls
Use the Simulink Function block when you want to:
Generate code that makes a function-call to external code, for example, driver or legacy code.
Provide a subsystem that behaves like the external code in normal, SIL, or PIL simulations.
The example in Configure Calls to AUTOSAR NVRAM Manager Service (AUTOSAR Blockset) shows how you can configure client calls to Basic Software (BSW) NVRAM Manager (NvM) service interfaces from your AUTOSAR software component. In a simulation, Simulink implements the BSW NvM calls through Simulink Function and preconfigured Function Caller blocks. For the final system, you link function-call stubs with external BSW function code that runs in the AUTOSAR Runtime Environment (RTE).
For more information, see Simulink Function Blocks and Code Generation.
Related Topics
- SIL and PIL Simulations
- Choose a SIL or PIL Approach
- Create PIL Target Connectivity Configuration for Simulink
- Test Generated Code with SIL and PIL Simulations
- Configure Code Coverage with Third-Party Tools
- Create Execution-Time Profile for Generated Code
- View SIL and PIL Files in Code Generation Report
- SIL/PIL Manager Verification Workflow
- Run Simulations Programmatically
- Simulation Mode Override Behavior in Model Reference Hierarchy
- SIL and PIL Limitations