MATLAB Examples

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 rtwdemo_mrmtbb.


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 Periodic sample time constraint option on the Solver configuration page. 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 using the model configuration parameter Automatically handle rate transition for data transfer.

The model is configured to display sample-time colors upon diagram update. Red represents the fastest discrete sample time in the model, green represents the second fastest, and yellow represents mixed sample times. Click the yellow button to the right to update the diagram and show sample-time colors.

Data Transfer Assumptions

Basis of operation for data transfers between tasks:

  1. Data transitions occur between a single reading task and a single writing task.
  2. A read or write of a byte sized variable is atomic.
  3. When two tasks interact through a data transition, only one of them can preempt the other.
  4. 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.
  5. All tasks run on a single processor. Time slicing is not allowed.
  6. Processes do not crash/restart (especially while data is being transferred between tasks)