Local pointer rtM for embedded coder in ert_main.c
Show older comments
Hi,
Setup:
- Simulink Model
- Generate C-Code for real-time target by embedded coder
- Generate example main
In the example main the RT_MODEL rtM_ is defined with a file-wide scope as well as a pointer to rtM_ (rtMPtr).
static RT_MODEL rtM_;
static RT_MODEL *const rtMPtr = &rtM_; /* Real-time model */
static DW rtDW; /* Observable states */
static ExtU rtU; /* External inputs */
static ExtY rtY; /* External outputs */
In the main function of the example main, there is the definition of the pointer rtM=rtMPtr at function scope.
int_T main(int_T argc, const char *argv[])
{
RT_MODEL *const rtM = rtMPtr;
/* Unused arguments */
(void)(argc);
(void)(argv);
/* Pack model data into RTM */
rtM->dwork = &rtDW;
rtM->inputs = &rtU;
rtM->outputs = &rtY;
/* Initialize model */
codgen_initialize(rtM);
What is the reasoning behind the usage of the pointer rtM instead of using rtMPtr directly?
I'd also appreciate some guidance on best practices to use the generated code in a non-trivial codebase (e.g. not an empty main). As soon as the codebase is not just one file (e.g. rt_OneStep is in a different c file) I have to pass arround pointers to variables that are defined on a file scope in different files which seems like a code smell to me. Since there is so much documentation regarding the embedded coder it seems like I am missing some useful pages.
Answers (1)
Tobias Schindler
on 14 Jan 2021
0 votes
Categories
Find more on Texas Instruments C2000 Processors 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!