Simulink Coder generating C code with explicit function interface, not struct. Is it possible?

With Simulink a simple add funtion, and the Coder generating C code like this:
void myadd_step(void)
{
/* Outport: '<Root>/c' incorporates:
* Inport: '<Root>/a'
* Inport: '<Root>/b'
* Sum: '<S1>/Add'
*/
myadd_Y.c = myadd_U.a + myadd_U.b;
}
Can I with some configuration to make the generating code like this:
float my_add(float a, float b)
{
return a+b;
}
I know that Matlab Coder can do this, wondering if Simulink can do this also?

 採用された回答

Sebastian K
Sebastian K 2017 年 5 月 22 日

1 投票

Hi there,
It is possible to achieve this kind of function signature when generating code from a Simulink model, however you need to generate code using Embedded Coder instead of Simulink Coder. Using Simulink coder will give you a similar syntax, although it will not be the same.
In any case, the key is to create an "Atomic Subsystem" and do the calculation in there. Then, in the Subsystem Block Parameters, in the Code Generation tab, you should set "Function packaging" to "Reusable function" .
Please refer to Simulink documentation if you are not familiar with Subsystems.
I hope this helps.
Sebastian

1 件のコメント

Si Cheng
Si Cheng 2017 年 5 月 25 日
Sebastian, thanks for your helpful answer, really appreciate.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange代码生成 についてさらに検索

質問済み:

2017 年 5 月 20 日

編集済み:

2017 年 11 月 16 日

Community Treasure Hunt

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

Start Hunting!