www.gusucode.com > simulinkcoder 案例源码程序 matlab代码 > simulinkcoder/MultirtMdlngInMultitskngModeBareBoardNoOSExample.m
%% 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|. % Copyright 2015 The MathWorks, Inc. open_system('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 *Automatically handle data transfers % between tasks* option on the *Solver* configuration page. % % 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: % % # 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. % # All tasks run on a single processor. Time slicing is not allowed. % # Processes do not crash/restart (especially while data is being transferred % between tasks)