How to remove 'sl_padding' fields in the generated code using Simulink Coder in MATLAB R2022b?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 9 Apr. 2025
Beantwortet: MathWorks Support Team
am 10 Apr. 2025
I am generating code for a top model using Simulink Coder in MATLAB R2022b. When using "rtwsfcn.tlc," I noticed extra "sl_padding" fields in the generated code, specifically in the *_types.h file. Please refer to the following code snippets for more details:
Using rtwsfcn.tlc:
typedef struct {
boolean_T EN[2];
uint8_T sl_padding0[2]; -> padding here
real32_T Value[2];
int32_T Time[2];
uint8_T sl_padding1[4]; -> padding here
} EN_Value_Time2;
Using a custom TLC:
typedef struct {
boolean_T EN[2];
real32_T Value[2];
int32_T Time[2];
} EN_Value_Time2;
How to avoid having "sl_padding" in the generated code using "rtwsfcn.tlc" target?
Akzeptierte Antwort
MathWorks Support Team
am 10 Apr. 2025
For the "rtwsfcn" target, we currently do not support the absence of paddings in the generated code. This limitation arises from how buses (structs in code) are interpreted in Simulink. Simulink requires padding to ensure safety when copying elements, which helps prevent crashes or incorrect results.
In this case, you might benefit from using model references or a protected model for the low-level model. You can then generate code for the top model with the referenced model. In that case, there is no need to work with S-Functions or TLC, which will eliminate the "sl_padding" fields. For more information, please refer to the MATLAB Answers post on using reference models instead of S-Functions for target code generation.
Another alternative is to utilize a Functional Mockup Unit (FMU) for the low-level model and import that into Simulink to generate code. Please note that this workflow is supported starting from MATLAB R2024a. You can learn more about FMU on the FMU importing documentation page.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!