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.
Set Up PIL Connectivity by Using Target Framework 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.
Use target.Emulator
Object to Set Up Target Connectivity
This example shows how to use a target.Emulator
object to set up target connectivity.
Create a board object to use with the emulator.
emulatorBoard = target.create("Board", ... Name="ARM Cortex-A Emulator-Based Test Board");
Create a target.Emulator
object and associate it with the emulated target board.
emulatorTarget = target.create("Emulator", ... Name="Example Emulator Target"); emulatorTarget.Target = emulatorBoard;
Create a target.HostProcessExecutionTool
object.
hostProcLaunchTool = target.create("HostProcessExecutionTool"); hostProcLaunchTool.Name = "Emulator Host Process Execution Tool";
Create a target.Command
object. Set the String
property of the object to the command for starting the emulator.
emulatorCommand = target.create("Command", ... String="pathToEmulatorApplication");
Specify the arguments of the command object as the configuration options for opening the emulator from command line.
emulatorCommand.Arguments = [ "-flag1","value1", ... "-flag2","value2", ... "-flagN","valueN"];
Specify the start command of the target.HostProcessExecutionTool
object as the emulator command, and specify the launch tool of the emulator object as the host process execution tool.
hostProcLaunchTool.StartCommand = emulatorCommand; emulatorTarget.LaunchTool = hostProcLaunchTool;
Create a target.TargetConnection
object to specify a connection between the host machine and the emulated target.
emulatorConnection = target.create( "TargetConnection", ... Name = "Emulator Connection", ... Target = emulatorBoard, ... CommunicationType = "TCPChannel", ... IPAddress = "localhost", ... Port = "17725");
Make board, connection, and emulator objects persist across MATLAB sessions.
addedObjs = target.add([emulatorBoard , emulatorConnection , emulatorTarget],UserInstall=true);
"target.add" summary: Objects added to internal database, which will persist across MATLAB sessions: target.Board "ARM Cortex-A Emulator-Based Test Board" target.Emulator "Example Emulator Target" target.HostProcessExecutionTool "Emulator Host Process Execution Tool" target.TCPChannel "Emulator Connection TCPChannel" target.TargetConnection "Emulator Connection" Objects not added because they already exist: target.Board "ARM Cortex-A Emulator-Based Test Board"
emulatorBoard
is the target.Board
object that describes the emulated target board. emulatorConnection
is the target.TargetConnection
object that specifies the connection between Simulink and your target hardware, emulatorTarget
.
To select the emulator for the model, set the HardwareBoard
configuration 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:
To remove the added target objects, enter:
target.remove(addedObjs);
"target.remove" summary: Objects removed from internal database: target.Board "ARM Cortex-A Emulator-Based Test Board" target.Emulator "Example Emulator Target" target.HostProcessExecutionTool "Emulator Host Process Execution Tool" target.TCPChannel "Emulator Connection TCPChannel" target.TargetConnection "Emulator Connection"
See Also
target.Emulator
| target.Board
| target.add
| target.create