Remove the use of memset in generated code

20 views (last 30 days)
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
Jesus Alberto Calvo Portela
Hello Bruno.
Thanks for your answer.
We have already another memset for the platform.
The issue is that we run the same code (more or less) on windows also (non-regression tests) and for that memset is fine (we have to differnt compilation chains).
So, in fact, in that case we would need to include a macro in the generated code for the include and the calls.
Jesus.
P.S.: Making a "overwrite" of the platform memset for windows won't be trivial ...
Bruno Luong
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.

Sign in to comment.

Answers (1)

Nicolas Schoonbroodt
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

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!