Forcing ownership of subsystem data to its self within a simulink model
1 view (last 30 days)
Show older comments
Hi all,
I have a bunch of matlab functions encapsulated in Simulink Matlab function blocks. These Matlab function blocks are part of a Simulink library.
I am code generating groups of these functions. Function packaging is set as reusable and file name is set to user specified so as to force groups of these functions to code generate as a subsystem (module).
I am using Simulink.Bus (structure) data types, placed in the Base workspace, set up as "Storage Class: Exported" and "HeaderFile: SubSystemName_types.h". I am using Simulink.Parameters set up as "Storage Class: Volatile(Custom)" and "Owner: SubSystemName" to try and force the subsystem to own its data.
This is not working and ownership of the subsystem data is with the model instead of the subsystem (module). I am running out of ideas in how to solve this.
Should I be using mpt.Parameters instead of Simulink.Parameters? Should I use a referenced model approach instead of simulink library approach? I am using Matlab 2016b.
Thanks Alex
0 Comments
Answers (1)
Mark McBroom
on 10 Dec 2017
Edited: Mark McBroom
on 10 Dec 2017
Data is owned at the model level, not the sub-system level. Referenced models will allow you to encapsulate parameters and state data ( BlockIO and DWork ) in code generated for the referenced model. To encapsulate parameters, they must be defined in model workspace of the referenced model, otherwise they will always be defined in the C code for the top level model. Nearly all features of mpt.Parameters are now available in Simulink.Parameters. Some other notes regarding Simulink.Parameter
1. set Optimization -> Signals and Parameters -> default parameter behavior = Inlined
2. storage class of "Auto" will result in parameters inlined in generated code
3. Other storage classes will result in a global variable being declared/defined the top level model if the parameter is defined in the base workspace. If defined in a model workspace, variable will be defined in the C code for that model.
See Also
Categories
Find more on Simulink Coder in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!