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

    %% Model Explicit Function Invocation with Atomic Subsystems
% Deploy embedded system code from Simulink(R) 
% models by partitioning a model into multiple atomic subsystems that you build
% separately. 
%
% Copyright 2010-2015 The MathWorks, Inc.
%% Atomic Subsystem Model 
% 
% Open the example model |rtwdemo_explicitinvocation_atomicsubsys|.  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_atomicsubsys_with_legend.png>>
%  
% This model partitions an algorithm into two atomic subsystems: |Rate1s| and
% |Rate2s|. Subsystem |Rate1s| is configured with a sample time of 1 second.  
% Subsystem |Rate2s| is configured with a sample time of 2 seconds. 
%
%% 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* cleared.
%
%% 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, single-tasking execution platform.
%
% For this example, the sample time legend shows implicit 
% rate grouping. Red represents the fastest discrete rate. Green represents 
% the second fastest discrete rate.
%
% Based on ratemonotonic scheduling, your application code 
% (execution framework) must transfer data between subsystems |Rate2s| and 
% |Rate1s| at a frequency of 2 seconds with the priority of 1 second. That is, 
% the generated function transfers data in the 1 second task every other time 
% prior to executing code for subsystem |Rate1s|.
%
% Your execution framework must schedule the generated function code 
% and handle the data transfers between them. This is an advantage for multirate 
% models because the generated code assumes no scheduling or data transfer 
% semantics. However, the execution framework must handle data transfers 
% explicitly.
%
%% Generate Code and Report
%
% Generate a single callable function for each subsystem without connections 
% between them. Multiple ways are available to generate code for a subsystem, 
% including from the subsystem context menu. For example, right-click a
% subsystem block and click *C/C++ Code > Build This Subsystem*. In the
% Build code for Subsystem dialog box, click *Build*.
%
% 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 
% subsystem. This code controls model code execution by  calling 
% entry-point function |Rate1s_step| or |Rate2s_step|. Use this file as a 
% starting point for coding your execution framework.
% * |Rate1s.c| and |Rate2s.c| contain entry points for the code that implements 
% subsystem |Rate1s| and |Rate2s|, respectively. This file includes the rate 
% and task scheduling code.
% * |Rate1s.h| and |Rate2s.h| declare model data structures and
% a public interface to subsystem entry points 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 file by adding directive 
% |#include rtwdemo_explicitinvocation_atomicsusys.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, |Rate1s|:
%
% * |rtU.In1| of type |real_T| with dimension of 1
% * |rtU.In2| of type |real_T| with dimension of 1
%
% Entry-point functions, |Rate1s|:
%
% * Initialize entry-point function, |void Rate1s_initialize(void)|. At startup,
% call this function once.
% * Output and update entry-point (step) function,
% |void Rate1s_step(void)|. Call this function periodically, every second.
% * Termination function, |void Rate1s_terminate(void)|. Call this function 
% once from your shutdown code.
%
% Output ports, |Rate1s|:
%
% * |rtY.Out1| of type |real_T| with dimension of 1
% * |rtY.Out2| of type |real_T| with dimension of 1
%
% Input ports, |Rate2s|:
%
% * |rtU.In1| of type |real_T| with dimension of 1
%
% Entry-point functions, |Rate2s|:
%
% * Initialize entry-point function, |void Rate2s_initialize(void)|. Call  
% this function once at startup.
% * Output and update entry-point (step),
% |void Rate2s_step(void)|. Call this function periodically, every 2 seconds.
% * Termination function, |void Rate2s_terminate(void)|. Call this function 
% once from your shutdown code.
%
% Output ports, |Rate2s|:
%
% * |rtY.Out1| of type |real_T| with dimension of 1
%
%% More About
%
% * <docid:ecoder_ug.bqnp4x_-1>
% * <docid:ecoder_ug.br54_tp>
% * <docid:ecoder_ug.f6010dfi4>