www.gusucode.com > ecoder 案例源码程序 matlab代码 > ecoder/ModelExplicitFunctionInvocationExample.m
%% Model Explicit Function Invocation % This example shows how to deploy embedded system code from Simulink(R) models % by partitioning a model into multiple subsystems that you build separately. % Copyright 2010-2015 The MathWorks, Inc. %% Atomic Subsystem Model % % <<../singlerate.png>> % % The model partitions the one and two second rates by using atomic % subsystems. Sample times for the subsystems are set to 1s and 2s, % respectively. % % You generate code for each subsystem separately. Multiple ways are available % generating code for a subsystem, including from a subsystem context menu. % Generate a single callable function for each system without connections % between them. % % *Relevant Model Configuration Parameter Settings* % % * Set *Solver > Type* to |Fixed-step|. % * Set *Solver > Solver* to |discrete (no continuous states)|. % * Set *Solver > Fixed-step size (fundamental sample time)* to 1. % % *Interface* % % Entry-point functions: % % * Initialize function, % |rtwdemo_explicitinvocation_atomicsubsys_initialize|, called once % * Output (step) function, |rtwdemo_explicitinvocation_atomicsubsys_step|, % called periodically, every 1 second % * Termination function, % ||rtwdemo_explicitinvocation_atomicsubsys_terminate|, called once % % Inports: % % * |rtwdemo_explicitinvocation_at_U.In1_1s| of type |real_T| with % dimension 1 % * |rtwdemo_explicitinvocation_at_U.In2_2s| of type |real_T| with % dimension 1 % % Outports: % % * |rtwdemo_explicitinvocation_at_Y.Out1| of type |real_T| with % dimension 1 % * |rtwdemo_explicitinvocation_at_Y.Out2| of type |real_T| with % dimension 1 % % *Scheduling* % % For this model, assuming ratemonotonic scheduling, the application code % transfers data (2s) between the Rate2s and Rate1s systems at a frequency % of 2 seconds with the priority of 1s. That is, the function transfers data % in the 1s task every other time prior to executing system Rate1s. % % <<../singleratesampletimelegend.png>> % % External application code needs to schedule the generated function code % and handle data transfers between them. This is an advantage for multirate % models because the generated code assumes no scheduling or data transfer % semantics. A disadvantage is that the aplication code must handle data % transfers explicitly. %% Function-Call Subsystem Model % % <<../functioncallsubsystems.png>> % % An alternate way to model a system with subsystem builds in mind is to % model the subsystems and data transfers explicitly with function-call % subsystems. You can use function-call subsystems to model multirate systems % explicitly. % % This modeling pattern or style is referred to as export function % modeling. Simulink constrains the model to function-call subsystems at % the root level with the driving Inport block specifying the function % name. % % *Relevant Model Configuration Parameter Settings* % % * Set *Solver > Type* to |Fixed-step|. % * Set *Solver > Solver* to |discrete (no continuous states)|. % * Set *Solver > Fixed-step size (fundamental sample time)* to 1. % % *Interface* % % Entry-point functions: % % * Initialize function, % |rtwdemo_explicitinvocation_funccallsubsys_initialize|, called once % * Exported function, |CallEvery1s|, called at any time % * Exported function, |CallEvery2s|, called at any time % * Exported function, |CallEvery2sAt1sPriority|, called at any time % % Inports: % % * |rtU.In1_1s| of type |real_T| with dimension 1 % * |rtU.In2_2s| of type |real_T| with dimension 1 % % Outports: % % * |rtY.Out1| of type |real_T| with dimension 1 % * |rtY.Out2| of type |real_T| with dimension 1 % % *Scheduling* % % <<../functioncallsubsystemssampletimelegend.png>> % % External application code needs to schedule the generated function code % and handle data transfers between functions. Advantages of this approach include % the simplicity of the generated code and the level of you control you have % over the order of execution. A disadvantage is that you need to model % data transfers explicitly.