Why does Simulink Accelerator not use all TLC methods even if I use the SS_OPTION_​USE_TLC_WI​TH_ACCELER​ATOR option in Real-Time Workshop 7.4 (R2009b)?

3 views (last 30 days)
I use an S-function block and have implemented an S-function and a TLC file in Real-Time Workshop 7.4 (R2009b).
In the TLC file I generate code for the methods:
* BlockTypeSetup
* InitializeConditions
* Start
* Outputs
* Terminate
If I build the model with the Rapid Accelerator, code is generated for all these methods. But if I build the model for the Accelerator, code is only generated for the methods:
* BlockTypeSetup
* Outputs

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Jun 2015
The observed is the expected behavior of Real-Time Workshop 7.4 (R2009b):
1) Rapid Accelerator: The TLC is being used
2) Accelerator without SS_OPTION_USE_TLC_WITH_ACCELERATOR: No TLC is used
3) Accelerator with SS_OPTION_USE_TLC_WITH_ACCELERATOR: Parts of the TLC are being used
* mdlOutputs()
* mdlUpdate()
* mdlDerivatives()
Read below for a more detailed description:
Look at the documentation for a "Process View" of "How the Simulink Engine Interacts with C S-Functions", at
<http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/f8-37326.html#f8-83424>
This section of the documentation is about S-Functions, but nearly everything in it applies equally well to all blocks, and to entire models. In Normal mode, running a Model method runs the corresponding Block method for each block in the model. For a subsystem, running a Block method runs the corresponding method for each block in the subsystem.
The Simulink Accelerator generates code for a C-MEX S-Function containing code for the simulation loop of the model. In Accelerator mode, methods in diagram "Model Initialization" run just as they do in Normal mode, but some methods in diagram "Simulation Loop" run differently. Model methods mdlOutputs(), mdlUpdate(), and mdlDerivatives() call the corresponding methods in the Accelerator S-Function, instead of calling the methods for each individual block.
As observed, the Accelerator S-Function does not include the optional mdlStart() and mdlInitializeConditions(). It does contain the required mdlInitializeSampleTimes() and mdlTerminate(), but they are empty functions that are never called. It contains the required mdlInitializeSize(), but it operates differently than in a typical S-Function, checking to see if the S-Function needs to be recreated, and verifying that DWork and BlockIO are the correct size.
If SS_OPTION_USE_TLC_WITH_ACCELERATOR is set in an S-Function, the Accelerator S-Function methods mdlOutputs(), mdlUpdate(), and mdlDerivatives() will contain code generated by the corresponding .tlc file, if it exists. Otherwise the Accelerator S-Function will have code to call the corresponding methods in
the .mex file for the S-Function.
Note that mdlDerivatives() exists only if the model has continuous states.
For both Accelerator and Normal mode, put the desired code for mdlStart() and mdlInitializeConditions() in the S-Function source file and build it into the .mex file
To use mdlStart() and mdlInitializeConditions() code generated by the .tlc file that inlines an S-Function, use Rapid Accelerator or a Real-Time Workshop Target.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2009b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!