How to generate C code with Simulink functions (global) and main reusable function from stateflow

4 次查看(过去 30 天)
Hello,
I encounter a problem with code generation (embeded coder) on a simulink that contains a stateflow chart.
The stateflow chart is the main process to be generated in code, reusable function because instantiated after integration.
The stateflow chart uses simulink functions inside chart to share some function inside the chart.
I wanted also to use some simulink function inside another simulink function (to be accessible in standalone function after generation). To do so, the simulink function has to be higher in hierarchy and global, so I moved the required simulink function in the simulink at a higher level (root of the code generation)
After doing this, the code generation is no more possible because the generation cannot be in "reusable function" at the same time of having global simulink function.
As a result I am blocked to do properly what I wanted.
Is there a way to to such a thing in a good way ? (i.e : share simulink function with stateflow shart, other simulink functions and be accessible outside chart as standalone functions ? )

回答(1 个)

Altaïr
Altaïr 2025-6-6
Simulink functions can be defined at various levels in the model hierarchy. For global accessibility, defining the function at the model's top level works best. However, a limitation exists where global Simulink functions cannot be directly called from Stateflow charts configured as reusable functions, as noted in the documentation:
To work around this while maintaining chart reusability, consider creating a local Simulink function within the Stateflow chart that calls the global function via a Function Caller block. For example, a global function named sumFunc can be accessed inside a local function localSumFunc using this approach:
This method supports code generation. For more details on reusing Simulink functions in Stateflow:
web(fullfile(docroot, 'stateflow/ug/simulink-functions-in-stateflow.html'))

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by