www.gusucode.com > rtwdemos 工具箱matlab源码程序 > rtwdemos/rtwdemo_export_functions_script.m

    %% Exporting Functions
% A common modeling pattern is when you explicitly execute a collection of blocks 
% using Simulink Function blocks and function-call subsystems. Embedded Coder provides 
% intrinsic support for generating functions from Simulink Function blocks or 
% function-call subsystems without generating code for a scheduler.

%   Copyright 2014 The MathWorks, Inc.

%% Overview of Exporting Functions
%
% Often, you want to generate only the code for individual Simulink 
% Function blocks and function-call subsystems without generating its scheduling code.
% This concept is referred to as exporting functions. A common workflow involves
% creating a model containing the functions that you want to export. Then, you create
% a test harness model that schedules the execution of the functions in the 
% original model for simulation. You generate code only for the original model containing 
% the functions that you want to export.

%% Creating a Model with Functions That You Export
%
% The model from which functions are exported satisfies architectural constraints at 
% its root level.  The only blocks allowed at the root level are:
%
% * Inport
% * Outport
% * Function-Call Subsystem
% * Simulink Function
% * Goto
% * From
% * Merge 
% 
% When generating code, the Function-Call 
% Subsystem and Simulink Function blocks lead to the generation of functions.
% You must connect the function-call ports of function-call subsystems to
% root Inport blocks that are producing function-call lines.  When Simulink Function
% blocks' corresponding Function Caller blocks execute, Simulink Function blocks
% execute.
% 
% Use the model |rtwdemo_functions| to see how to construct a model from
% which you can export functions.  This model contains two function-call 
% subsystems and one Simulink Function block:
open_system('rtwdemo_functions')

%% Creating a Model Containing a Function Caller
% Use a Function Caller block to invoke a Simulink Function block. A Function
% Caller block can be in the same model as the Simulink Function block, or it can 
% be in a different model. There can be multiple Function Caller blocks
% invoking a Simulink Function block. You can also place the Function Caller block
% inside a function-call subsystem. During code generation, a function is exported
% from the function-call subsystem. The |rtwdemo_caller| model shows how to construct
% a model that exports a function-call subsystem containing a Function Caller block.
open_system('rtwdemo_caller')

%% Creating a Harness Model for Simulation
% When you export functions, the generated code does not include a scheduler.
% Simulink Function block is scheduled via the Function Caller block in "rtwdemo_caller|.
% A third model, |rtwdemo_export_functions|, provides function-call signals to
% the first two models, to schedule their contents. Use this third model for
% simulation, but not to generate code that you deploy.
open_system('rtwdemo_export_functions')


%%
% Close the models associated with the example
bdclose('rtwdemo_export_functions')
bdclose('rtwdemo_functions')
bdclose('rtwdemo_caller')