How to call user-defined C function having return and arguments with GetSet storage class

1 回表示 (過去 30 日間)
Shijo
Shijo 2024 年 2 月 15 日
編集済み: Shijo 2024 年 2 月 20 日
I am developing a Stateflow model where I need to call user defined C functions. The function prototype could be as follows
uint8 getset_Func(uint8 arg1, uint8 arg2, uint8 *arg3);
I have defined signal FuncCall with sorage class as GetSet and function header file is added in the code generation option.
I have added the option GetFunction as getset_$N and SetFunction option is empty.
But I am not able to use the signal in the stateflow. I have tried to use as var = FuncCall(temp1, temp2, &temp3);
This is giving error Unresolved function 'FuncCall'
How can I pass the arguments and return the result at the same time using GetSet storage class.

回答 (1 件)

Mark McBroom
Mark McBroom 2024 年 2 月 17 日
編集済み: Mark McBroom 2024 年 2 月 17 日
You should use coder.ceval() to call external C code from Stateflow. https://www.mathworks.com/help/simulink/slref/coder.ceval.html
You would write code similar to the folloiwng but substituting the name of your .c and .h files.
arg1 = uint8(4);
arg2 = uint8(5)
arg3 = uint8(6);
var = uint8(8);
coder.updateBuildInfo('addSourceFiles','foo.c');
coder.cinclude('foo.h');
var = coder.ceval("getset_Func", arg1, arg2, arg3 );
  1 件のコメント
Shijo
Shijo 2024 年 2 月 19 日
編集済み: Shijo 2024 年 2 月 20 日
Hi,
I am getting error while building the model
"Unresolved function 'coder.ceval in xx"
"Unresolved function 'coder.cinclude' in"
"Unresolved function 'coder.updateBuildInfo' in"
I ahve attached the screenshot
My objective is to create an input signal to the stateflow chart and the signal storage class as GetSet. So that the respective C function call should be invoked.

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

カテゴリ

Help Center および File ExchangeComplex Logic についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by