How can I make the Subsystem block "function packaging" setting propagate to its inner subsystems in Simulink R2022b?

When 
- There is an atomic subsystem that is used multiple times inside of another atomic subsystem
- The parent subsystem is set to be a "Nonreusable function"
- The "Function packaging" option in instances of the atomic subsystem is set to "Auto"
The generated code still includes a "rt_sys_<model>" C file and header file where the code for this atomic subsystem is generated, despite the parent subsystem being set to be a "Nonreusable function." 
My expectation for this setting would be that if the function packaging is set to "Nonreusable function" that all subsystems below, which are set to "Auto" would follow that setting and the generated code would be contained within one C file, but this does not happen.
How can I make the subsystems below inherit the outer subsystem's "function packaging" setting?

 Accepted Answer

This is not possible with a setting in Simulink R2022b. When "Function packaging" is set to "Auto," Simulink determines the best packaging option for that subsystem.
A potential workaround at the moment is to write a script to programmatically propagate the setting of a Subsystem block to subsystems contained in it.
For example: 
model = 'your_model_name';
propagate_function_packaging(model);
function propagate_function_packaging(model)
open_system(model);
% Find all direct children of the model
children = find_system(model, 'MatchFilter',@Simulink.match.codeCompileVariants, 'SearchDepth', 1);
% Remove the parent itself from the list
children = setdiff(children, {model});
% Recursively process all children
for i = 1:length(children)
propagate_in_subsystem(children{i}, 'Auto');
end
end
function propagate_in_subsystem(current_block, parent_packaging)
if strcmp(get_param(current_block, 'BlockType'), 'SubSystem')
try
if strcmp(get_param(current_block, 'RTWSystemCode'), 'Auto')
set_param(current_block, 'RTWSystemCode', parent_packaging);
else
parent_packaging = get_param(current_block, 'RTWSystemCode');
end
catch e
warning(e.message);
end
end
% Find all direct children of the parent
children = find_system(current_block, 'MatchFilter',@Simulink.match.codeCompileVariants, 'SearchDepth', 1);
% Remove the parent itself from the list
children = setdiff(children, {current_block});
% Recursively process all child subsystems
for i = 1:length(children)
propagate_in_subsystem(children{i}, parent_packaging);
end
end

More Answers (0)

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!