www.gusucode.com > ecoder 案例源码程序 matlab代码 > ecoder/ModelExplicitFunctionInvocationWithFuncCallSubsysExample.m

    %% Model Explicit Function Invocation with Function-Call Subsystems 
% Deploy embedded system code from Simulink(R) 
% models by partitioning a model into function-call subsystems that you build
% separately. 
%
% Copyright 2010-2015 The MathWorks, Inc.
%% Function-Call Subsystem Model 
% 
% Open the example model |rtwdemo_explicitinvocation_funccallsubsys|.  The model is 
% configured to display color-coded sample times with annotations. To see them,
% after opening the model, update the diagram by pressing *Ctrl+D*.  
% To display the legend, press *Ctrl+J*.
%
% <<../rtwdemo_explicitinvocation_funccallsubsys_with_legend.png>>
%  
% This model partitions an algorithm into three function-call subsystems: 
% |Rate1s|, |Rate2s|, and |DataBuffer|. Use function-call subsystems 
% to model multirate systems explicitly.
% 
% Subsystems |Rate1s| and |DataBuffer| use a sample time of 1 second.  
% Subsystem |Rate2s| usea a sample time of 2 seconds. 
%
% This model design is referred to as export function modeling. Simulink 
% constrains the model to function-call subsystems at the root level.  
% The driving Inport block specifies the function name.
%
%% Relevant Model Configuration Parameter Settings
%
% * *Solver > Type* set to |Fixed-step|.
% * *Solver > Solver* set to |discrete (no continuous states)|.
% * *Solver > Treat each discrete rate as a separate task* selected. 
% Simulink applies multitasking execution because the model uses 
% multiple sample rates.
%
%% Scheduling
%
% Simulink(R) simulates the model based on the model configuration. Simulink
% propagates and uses the Inport block sample times to order block execution
% based on a single-core, multitasking execution platform.
%
% In the sample time legend, red identifies the fastest discrete rate. Magenta 
% identifies rates inherited from exported functions, indicating their execution is 
% outside the context of Simulink scheduling.
%
% Your execution framework must schedule the generated function code 
% and transfer data between functions.
%
% Your execution framework needs to schedule the generated function code 
% and handle data transfers between functions. The 
% generated code is simple and you control the order of execution.
%
%% Generate Code and Report
%
% Generate code and a code generation report. The example model generates 
% a report.
%
%% Review Generated Code
%
% From the code generation report, review the generated code.
%
% * |ert_main.c| is an example main program (execution framework) for the 
% model. This code shows how to call the exported functions. The code also
% shows how to initialize, execute, and terminate the generated code.
% * |rtwdemo_explicitinvocation_funccallsubsys.c| calls the initialization 
% function and exported functions for subsystems |Rate1s|, |Rate2s|, and 
% |DataBuffer|.
% * |rtwdemo_explicitinvocation_funccallsubsys.h| declares model data structures 
% and a public interface to the exported entry point functions and data structures.
% * |rtwtypes.h| defines data types, structures, and macros that 
% the generated code requires.
%
%% Code Interface
%
% Open and review the Code Interface Report. Use the information in that report
% to write the interface code for your execution framework:
% 
% # Include the generated header files by adding directives 
% |#include Rate1s.h|, |#include DataBuffer.h|, and |#include Rate2s.h|.
% # Write input data to the generated code for model Inport blocks.
% # Call the generated entry-point functions.
% # Read data from the generated code for model Outport blocks.
%
% Input ports:
%
% * |rtU.In1_1s| of type |real_T| with dimension of 1
% * |rtU.In2_2s| of type |real_T| with dimension of 1
%
% Entry-point functions:
%
% * Initialize entry-point function, 
% |void rtwdemo_explicitinvocation_funccallsubsys_initialize(void)|. At  
% startup, call this function once.
% * Exported function, |void CallEvery1s(void)|. Call this function as needed.
% * Exported function, |void CallEvery1s(void)|. Call this function as needed.
% * Exported function, |void CallEvery2sAt1sPriority(void)|. Call this function 
% as needed.
%
% Output ports:
%
% * |rtY.Out1| of type |real_T| with dimension of 1
% * |rtY.Out2| of type |real_T| with dimension of 1
%
%% More About
%
% * <docid:ecoder_ug.bqnrwky-1>
% * <docid:ecoder_ug.br54_tp>
% * <docid:ecoder_ug.f6010dfi4>