How to pass pointer arguments in Simulink for auto-generated code?

20 ビュー (過去 30 日間)
Sourabh
Sourabh 2022 年 8 月 18 日
回答済み: Rajanya 2025 年 2 月 3 日 11:40
The Simulink code generator generates call by reference functions but uses global variables. I need to make a reusable susbsystem which can accept different data store inputs similar to a call by reference implementation in C. How should I proceed?
Referenced subsystem block
Referenced subsystem call

回答 (1 件)

Rajanya
Rajanya 2025 年 2 月 3 日 11:40
You can determine how the code should be generated for subsystem blocks by the 'Function Packaging' parameter, which is, by default, set to 'Auto' for Simulink to automatically determine the packaging.
Making the subsystem reference 'Atomic' (which tells Simulink to treat the block as a single unit while generating code) and changing the 'Function Packaging' parameter to 'Reusable' results in the generation of reusable functions with call by reference implementations.
The packaging can be set to 'Reusable' from Block Parameters of the subsystem > Check 'Treat as atomic unit' > Code Generation > Function Packaging > Reusable function.
The below sample model shows how to change the packaging and also the code generated for the model step function as a result -
The subsystem used in the reference -
Code generated -
Here, it can be seen that the 'exampleModel_SubsystemReference' can be reused and the data store variable is passed to the function via call by reference as the second parameter from the model step ('exampleModel_step').
You can refer to the following documentation to learn more about function packaging -https://www.mathworks.com/help/rtw/ug/reusing-functions-in-generated-code.html
Hope this answers your question! Thanks!

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by