Extraneous codegen function definition without associated type definition

3 views (last 30 days)
I have an extraneous function declaration and definition in my autocoded source code, which is not used internally or in the provided example script ert_main.c. The function argument has an undefined type, which causes build errors. If I delete the offending code below, I can build the code. However, I'd like to understand the casue so I can remove it programmatically in future autocoded source code.
In mdl_<name>.h
/* Model input signal initialize function */
void mdl_<name>_initialize_inputs(ExtU_mdl_<name>_T* mdl_<name>_U,
ExtU_mdl_<name>_T* mdl_<name>_U_init);
In mdl_<name>.c
/* Model Input Signal initialize function */
void mdl_<name>_initialize_inputs(ExtU_mdl_<name>_T* mdl_<name>_U, ExtU_mdl_<name>_T*
mdl_<name>_U_init)
{
memcpy( mdl_<name>_U, mdl_<name>_U_init, sizeof(ExtU_mdl_<name>_T));
}
I am using an ERT based build target, and the following config parameters.
set_param('GenCodeOnly','on');
set_param('HardwareBoard', 'None');
set_param('TargetLang', 'C');
set_param('CodeInterfacePackaging', 'Reusable function');
set_param('GenerateAllocFcn', 'off');
set_param('RootIOFormat','Individual arguments'); % Changes I/O for step(), constructor, etc
If I set 'RootIOFormat' to 'Structure reference' or 'Part of model data structure', the external input type ExtU_mdl_<name>_T is defined and this problem doesn't exist. I understand why the above code would be generated in those cases. However, it seems uneccessary in my use case. Is there a way to disable it that I am missing?

Answers (1)

Harsh
Harsh on 24 Feb 2025
Hi @Andrew,
The RootIOFormat parameter controls how root-level inputs and outputs are handled in the generated C code. It can have the following three settings:
  • Individual arguments: Passes each root-level model input and output value to the entry-point function as a separate argument.
  • Structure reference: Packs root-level model input into a struct, packs root-level model output into another struct and passes the structures to the entry-point function as arguments.
  • Part of model data structure: Packages root-level model input and output into the real-time model data structure rtModel.
In the “Individual arguments” setting, inputs/outputs are passed separately as real_T, no ExtU_<model>_T structure is created. Here’s the Simulink model configuration that I created:
1. Open Simulink and create a new model.
2. Add an Inport block (from Sources) and an Outport block (from Sinks). Connect the Inportdirectly to the Outport.
3. Set the system target file to “ert.tlc and solver as “fixed step”.
4. Set the following settings for the model-
Below is the code generated in the ExtraneousFunc.c(Model name is ExtraneousFuc).
set_param(modelName, 'GenCodeOnly', 'on');
set_param(modelName, 'HardwareBoard', 'None');
set_param(modelName, 'TargetLang', 'C');
set_param(modelName, 'CodeInterfacePackaging', 'Reusable function');
set_param(modelName, 'GenerateAllocFcn', 'off');
set_param(modelName, 'RootIOFormat', 'Individual arguments');
Below is the code generated in the ExtraneousFunc.c(Model name is ExtraneousFuc).
If you still observe an extraneous initialization function referencing ExtU_<model>_T” with the “Individual arguments” setting which leads to build errors, please provide your model or the steps to recreate the issue.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!