How to call a function that uses a function pointer argument from Simulink?

27 ビュー (過去 30 日間)
WJKIM
WJKIM 2024 年 1 月 12 日
コメント済み: Benjamin Thompson 2024 年 1 月 27 日
I want to load the following C code function as the C -Caller in the simulink.
There is no build error, but I can't find the function in the Function name.
I think, it can't recognize Void (*func) (CONST IF_AppDiagStatus_t), one of the argument of the function. (Use of function pointer)
Is there a way to solve this?
********************************************************************************************************************************************
void IF_AppDiagSetFuncForGetDiagStatus(void(*func)(CONST IF_AppDiagStatus_t), CONST App_ID_e appID)
{
if (appID < APP_ID_END)
{
appDiagGetFunc[appID].getDiagStatusFunc = func;
}
}
  2 件のコメント
madhan ravi
madhan ravi 2024 年 1 月 12 日
Did you try the suggested actions?
WJKIM
WJKIM 2024 年 1 月 12 日
It doesn't seem to be associated with SUGESTED ACTIONS.
The functions mentioned in SUGESTED ACTIONS are different from the functions I mentioned.
The function name is similar, so it can be confusing.
IF_AppDiagSetFuncForGetDiagStatus
IF_AppDiagUpdateDiagStatus

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

回答 (1 件)

Benjamin Thompson
Benjamin Thompson 2024 年 1 月 21 日
Simulink only supports certain data types as inputs to blocks: integers, double, single, busses, enumerations, or arrays of those basic types. How would Simulink know how to pass a memory address pointer to your block as an input? If your C code defines an array of C functions in appDiagGetFunc, can your block use an integer input for appID? Then Simulink can pass an integer to the C Caller block to select which function in appDiagGetFunc to call.
  2 件のコメント
WJKIM
WJKIM 2024 年 1 月 26 日
Thank you for answer.
How would Simulink know how to pass a memory address pointer to your block as an input?
> Actually, it is main point of my question how to pass memory address.
So, i requested the Mathworks support about this issue.
Then, Mathworks support reply was as follow.
"The C Caller block does not support code of type void pointer. Please refer to the answers below for cases similar to yours. In these cases, we recommend using the C Function block instead of the C Caller block. a video explaining how to use it can be found at the link below.
- Using the C Function Block to Integrate Custom Code in Simulink
If your C code defines an array of C functions in appDiagGetFunc, can your block use an integer input for appID?
> Yes, the appID defined in c code can be used.
Benjamin Thompson
Benjamin Thompson 2024 年 1 月 27 日
If your question has been answered please accept it. If you would like more help with the problem please provide more information and the Community can suggest different approaches.

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

カテゴリ

Help Center および File ExchangeNonlinear Operators についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by