C caller block: parse the function with no parameters and return values (usage of external functions inside)
5 次查看(过去 30 天)
显示 更早的评论
I was wondering whether it is possible to simulate the C function in Simulink using the C caller block if the C function does not have direct parameters and return-values?
The "Read-in" of the function parameters and "Write-out" of the function return values are happened via the call of external read/write functions inside of the main C function body.
Example (body of C_function.c file)
#include "Read_Write_function_declarations.h"
void Main_C_function (void)
{
uint8 value1, value2;
(void)Read_value1(&value1); /* this read-in function is declared in the abovementioned header-file */
value2 = value1 * 2 + 15u;
(void)Write_value2(value2); /* this write-out function is declared in the abovementioned header-file */
}
In the C caller block I would like to parse the Main_C_function and simulate it by providing the input to "value1" and displaying the calculated "value2". Unfortunately the C caller block after the parsing (Main_C_function selected) does not have any input/output ports available for connection in the Simulink. Probably it is due to the missing function parameters and return values.
The question is whether there is a way around to parse such function so that the parameters "value1" and "value2" are appeared as ports in the C caller block for connection?
The example above is just an overview of the current problem. In the reality the function is more complicated. I haven't compiled the example C file so some compilation mistakes/warnings could be possible.
0 个评论
回答(1 个)
Roy Mathew
2020-9-30
编辑:Roy Mathew
2020-10-1
You can do this in R2020b. See the documentation page for the parameter that enables this setting:Enable custom code globals as function interface.
There is some more information on this page as well: https://www.mathworks.com/help/simulink/ug/integrate-ccode-ccaller.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!