主要内容

Run external mode in a background thread

Force external mode engine in generated code to execute in background task

Model Configuration Pane: Hardware Implementation

Description

Add-On Required: This feature requires the MATLAB Coder Support Package for NVIDIA Jetson and NVIDIA DRIVE Platforms add-on.

Enable the Run external mode in a background thread parameter to force the external mode task in the generated code to execute in a background thread.

When external mode runs in the model thread, external mode executes after each execution step of the model and collects data at the base rate of the model. When model code consumes most of the thread execution time in each time step, external mode execution overruns into the next time step. This overrun delays the start of the next model execution step and degrades the real-time behavior of the deployed model.

You can configure external mode to run in a background thread. When external mode runs in a background thread, it executes in the time between the end of model code of one time step and the start of the next time step. By not blocking the model step, external mode can be used in systems that require real-time execution. This configuration enables direct observation of the deployed model on the hardware board as it would behave in standalone operation. This diagram shows the execution timing of external mode running in the foreground and background threads.

Comparison of External Mode running in the model thread and a background thread. When run with the model thread, the model and external mode thread can overrun into the next time step. When run using a background thread, the model and external mode threads execute independently.

When model code consumes most of the execution time for each time step, external mode in the background thread starves for execution time. Without the time to collect and transmit data from the hardware board to the host computer, data packets drop. This case results in gaps in the data logging.

To help avoid dropped data packets in deployed models where real-time execution takes priority over data logging, configure external mode to operate as a background task.

Note

Enabling the Run external mode in a background thread parameter is not recommended for models that use a very small time step or that might encounter task overruns. These situations can cause Simulink® to become unresponsive.

Settings

off (default) | on
off

Disables using a background thread for external mode execution.

on

Enables using a background thread for external mode execution.

Programmatic Use

You cannot set this parameter from the MATLAB® command line.

Version History

Introduced in R2020b