Main Content

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.

Use target.Emulator Object to Set Up Target Connectivity

Set Up PIL Connectivity by Using target Package 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:

  1. After creating the board description in a target.Board object, create a target.Emulator object.

    emulator = target.create('Emulator', ...
                             'Name', ‘Example Emulator Target’);

  2. Associate the object with the emulated target board. For example:

    emulator.Target = target.get('Board', 'ARM Cortex-A Emulator-Based Test Board');
  3. Specify a target.HostProcessExecutionTool, target.SystemCommandExecutionTool, or target.ExecutionService object 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;
  4. 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 and Set Up External Mode Connectivity Between Simulink and Target Hardware.

  5. Make board, connection, and emulator objects persist across MATLAB sessions.

    target.add([board, connection, emulator], 'UserInstall', true);

    board is the target.Board object that describes the emulated target board. connection is the target.TargetConnection object that specifies the connection between Simulink and your target hardware

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

See Also

| | |

Related Topics