Remove the use of memset in generated code
5 views (last 30 days)
Show older comments
Hello,
We need to remove the use of memset in the generated code because our platform does not suppor it (in fact, it does not support the lib string.h) and replace by another initialization.
We are generetanig code from an state machine (state flow) and memset is used only in the initialize service.
We are getting the following code:
void Mission_State_initialize(void)
{
rtmSetErrorStatus(Mission_State_M, (NULL));
{
Mission_State_B.Mission_State_Mode = Mission_State_Mode_Type_None;
}
(void) memset((void *)&Mission_State_DW, 0,
sizeof(DW_Mission_State_T));
Mission_State_DW.is_active_c1_Mission_State = 0U;
Mission_State_B.Mission_State_Mode = Mission_State_Mode_Type_None;
}
If it is not possible to replace memset by another code, we would like to keep the initializaiton for the rest of the variables.
NOTES:
- "Remove internal data zero initializiton" activalted lets the initialize servei empty (it ouwld be the last option).
- "Use memset to initialize floats and doubles to 0.0" has no impact in our generated code.
Do you have any idea how to do that?
Thanks in advacned.
Jesus.
3 Comments
Bruno Luong
on 3 Aug 2022
This is about how to make the same base code multi-platform compatible. There are many way to do it, including macro, have specific library/header, adapt make script, adapt build enviroment, etc...
The standard approach is NOT changing the base source code.
Answers (1)
Nicolas Schoonbroodt
on 5 Sep 2022
Hi Jesus,
We discussed this with you on a call, but I'm also adding this here for reference, if anyone came here because they have the same question.
One way to replace the call to memset (and some other functions) in the generated code by a custom inhouse memset variation is to use Code Replacement Libraries. Please refer to https://www.mathworks.com/help/ecoder/ug/quick-start-library-development-sc.html for an example (not focusing on memset, but the idea is the same)
Nicolas
0 Comments
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware 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!