Define Custom Emulator for Target Connectivity
Before you can run processor-in-the-loop (PIL) or XCP-based external mode simulations, you must set up connectivity between Simulink® and your target hardware. The target connectivity enables the simulation to:
Build the target application.
Download, start, and stop the application on the target hardware.
Support communication between Simulink and the target hardware.
If you want to run the simulations on an emulator, use the
target.Emulator class to define the emulator for MATLAB®. Then, you can use the definition to set up target connectivity between
Simulink and the emulator.
target.Emulator Object to Set Up Target Connectivity
Set Up PIL Connectivity by Using target Package (Embedded Coder) and Set Up External Mode Connectivity Between Simulink and Target Hardware provide workflows for setting up target connectivity. These steps show how you can adapt the workflows to run the simulations on an emulator:
After creating the board description in a
target.Boardobject, create a
emulator = target.create('Emulator', ... 'Name', ‘Example Emulator Target’);
Associate the object with the emulated target board. For example:
emulator.Target = target.get('Board', 'ARM Cortex-A Emulator-Based Test Board');
target.ExecutionServiceobject that contains the command for starting the emulator. For example:
hostprocesslaunchtool = target.create("HostProcessExecutionTool"); hostprocesslaunchtool.Name = "Emulator Host Process Execution Tool"; command = target.create("Command"); command.String = "pathToEmulatorApplication"; % Configuration options for opening emulator from command line command.Arguments = ["-flag1", "value1" ... "-flag2", "value2" ... "-flagN", "valueN"]; hostprocesslaunchtool.StartCommand = command; emulator.LaunchTool = hostprocesslaunchtool;
Create the communication interface, specify the communication protocol, and create the connection between Simulink and the emulator. See Set Up PIL Connectivity by Using target Package (Embedded Coder) and Set Up External Mode Connectivity Between Simulink and Target Hardware.
Make board, connection, and emulator objects persist across MATLAB sessions.
target.add([board, connection, emulator], 'UserInstall', true);
target.Boardobject that describes the emulated target board.
target.TargetConnectionobject that specifies the connection between Simulink and your target hardware
To select the emulator for the model, set the
HardwareBoardconfiguration parameter to the board name. For example:
set_param(model, 'HardwareBoard', board.Name);
You can now run PIL or external mode simulations on the emulator. For more information, see: