Main Content

Multirate Modeling in Multitasking Mode (Bare Board, No OS)

This model shows the code generated for a multirate discrete-time model configured for a multitasking bare-board target (one with no operating system).

Open Example Model

Open the example model MultirateMultitaskingBareBoard.

open_system('MultirateMultitaskingBareBoard')

Explore Example Model

The model contains two sample times. Inport block 1 and Inport block 2 specify 1-second and 2-second sample times, respectively, which are enforced by the setting of model configuration parameter Periodic sample time constraint. The solver is set for multitasking operation, which means a rate transition block is required to ensure that data integrity is enforced when the 1-second task preempts the 2-second task. Proper rate transitions are always enforced by Simulink® and Simulink Coder™. This model specifies an explicit rate transition block. Alternatively, this block could be automatically inserted by Simulink setting model configuration parameter Automatically handle rate transition for data transfer.

The model is configured to display sample-time colors upon diagram update. To see them, after opening the model, update the diagram by pressing Ctrl+D. To display the legend, press Ctrl+J. Red represents the fastest discrete sample time in the model, green represents the second fastest, and yellow represents mixed sample times.

Data Transfer Assumptions

Basis of operation for data transfers between tasks:

  • Data transitions occur between a single reading task and a single writing task.

  • A read or write of a byte sized variable is atomic.

  • When two tasks interact through a data transition, only one of them can preempt the other.

  • For periodic tasks, the faster rate task has higher priority than the slower rate task; the faster rate task always preempts the slower rate task.

  • Tasks run on a single processor. Time slicing is not allowed.

  • Processes do not crash and restart (especially while data is being transferred between tasks)