C caller block: parse the function with no parameters and return values (usage of external functions inside)
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Roy Mathew
on 30 Sep 2020
Edited: Roy Mathew
on 1 Oct 2020
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 Comments
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!