Main Content

Real-Time Execution in Run in Kernel Mode

The Run in Kernel mode is a higher-performance alternative to Real-Time Execution in Connected IO Mode. In Run in Kernel mode, you use Simulink® Coder™ to link generated algorithm code to I/O driver code generated from the I/O blocks. The resulting executable runs in operating system kernel mode on the development computer. The executable exchanges parameter data with Simulink through a shared memory interface.

  • Signal acquisition — You can capture and display signals from your real-time application while it is running. Signal data is retrieved from the real-time application and displayed in the same Simulink Scope blocks that you used for simulating your model.

  • Parameter tuning — You can change parameters in your Simulink block diagram and have the new parameters passed automatically to the real-time application. External mode changes parameters in your real-time application while it is running in real time.

The Run in Kernel mode executable is fully synchronized with the real-time clock. The main role of Simulink is to read and display simulation results returned from the executable.

Procedures related to real-time execution in run in kernel mode include:


Use a fixed-step solver in Run in Kernel mode.

In Run in Kernel mode, the real-time application and the I/O drivers run in the kernel mode process. Using the I/O drivers to communicate with the hardware, the application stores contiguous response data in memory accessible to Simulink until a data buffer is filled. When the buffer is filled, the real-time application continues to run while Simulink transfers the data to the MATLAB® environment through Simulink external mode. Transfer of data is less critical than maintaining deterministic real-time updates at the required sample interval. After model computations are finished, data transfer runs at a lower priority while the process waits for another interrupt to trigger the next model update.

Data captured within one buffer is contiguous. When a buffer of data has been transferred, the data is immediately plotted in a Simulink Scope block. You can save the data directly to a MAT-file by using data archiving in Simulink external mode.

With data archiving, you can save each buffer of data to its own MAT-file. The MAT-file names can be automatically incremented, enabling you to capture and store many data buffers. Although points within a buffer are contiguous, the time required to transfer data back to Simulink pauses data collection until the entire buffer has been transferred. This pause can result in lost sample points between data buffers.

Related Topics