How to automatically add some code content at any place in the code generated by simulink

1 view (last 30 days)
simulink code:
/* Const memory section */
/* Definition for custom storage class: Const */
const uint8_T SFCMM_ABSFunc_Active = 1U;/* Referenced by:
* '<S35>/Constant127'
* '<S35>/Constant90'
* '<S104>/Constant127'
* '<S104>/Constant90'
* '<S151>/Constant127'
* '<S151>/Constant90'
*/
const uint8_T SFCMM_AEBFuncConfig_Open = 1U;/* Referenced by: '<S9>/Constant15' */
const uint8_T SFCMM_AEBFuncSwitch_Open = 1U;/* Referenced by: '<S9>/Constant17' */
Object Code:
#define ASW_QM_COM_MODULE_START_SEC_CONST_UNSPECIFIED
#include "ASW_MemMap.h"
/* Const memory section */
/* Definition for custom storage class: Const */
const uint8_T SFCMM_ABSFunc_Active = 1U;/* Referenced by:
* '<S35>/Constant127'
* '<S35>/Constant90'
* '<S104>/Constant127'
* '<S104>/Constant90'
* '<S151>/Constant127'
* '<S151>/Constant90'
*/
const uint8_T SFCMM_AEBFuncConfig_Open = 1U;/* Referenced by: '<S9>/Constant15' */
const uint8_T SFCMM_AEBFuncSwitch_Open = 1U;/* Referenced by: '<S9>/Constant17' */
#define ASW_QM_COM_MODULE_STOP_SEC_CONST_UNSPECIFIED
include "ASW_MemMap.h"
how to add “#define ASW_QM_COM_MODULE_START_SEC_CONST_UNSPECIFIED #include "ASW_MemMap.h” and“#define ASW_QM_COM_MODULE_STOP_SEC_CONST_UNSPECIFIED include "ASW_MemMap.h"” in front of "/* Const memory section */ " and
behind "const uint8_T SFCMM_AEBFuncSwitch_Open = 1U;/* Referenced by: '<S9>/Constant17' */"

Answers (1)

Shivam
Shivam on 23 Apr 2024
Hi Phlips,
From the information provided, I understand that you want to add custom code to the code generated using Simulink Coder.
To achieve this, you can use the 'Model Source' block, where you can specify the code for the code generator to add near the top or bottom of the source file. The 'Model Source' block can be found in the "Simulink Coder -> Custom Code" library. You can double-click on the block and add your custom code in the "Top of Model Source" or "Bottom of Model Source" section.
Following code generation, you can open the generated source file and find the custom code statements near the top/bottom of the file, depending upon the section where you put the code.
You can refer to the following documentation to learn more about the 'Model Source' block:
I hope it helps.
  1 Comment
Phlips
Phlips on 23 Apr 2024
Maybe I didn't describe it very clearly。
For example.
I want to add code
“#define ASW_QM_COM_MODULE_START_SEC_CONST_UNSPECIFIED
#include "ASW_MemMap.h"”
before "/* Const memory section */.... code generration part"
code example
#define ASW_QM_COM_MODULE_START_SEC_CONST_UNSPECIFIED
#include "ASW_MemMap.h"
/* Const memory section */
/* Definition for custom storage class: Const */
const uint8_T SFCMM_ABSFunc_Active = 1U;/* Referenced by:
* '<S35>/Constant127'
I also want to add code
“#define BSW_START_SEC_DEFAULT_CALIB_32
#include "CAL_MemMap.h""”
before "/* Volatile memory section */
/* Definition for custom storage class: Volatile */
volatile real32_T SFCMM_AEBStatus_ActiveInhibit_Fps = 399.0F;/* Referenced by: '<S9>/Constant43' */.... code generration part"
code example
#define BSW_START_SEC_DEFAULT_CALIB_32
#include "CAL_MemMap.h"
/* Volatile memory section */
/* Definition for custom storage class: Volatile */
volatile real32_T SFCMM_AEBStatus_ActiveInhibit_Fps = 399.0F;/* Referenced by: '<S9>/Constant43' */
In brief,Add macro definition code to different data type definition intervals.How to implement manual add code to automatic generation
Add code sections manually 1:
#define ASW_QM_COM_MODULE_START_SEC_VAR_UNSPECIFIED
#include "ASW_MemMap.h"
Automatically generate code sections 2:
/* Exported block signals */
uint8_T SFCMM_AEBFuncSwitch_B; /* '<Root>/Inport10'
Add code sections manually 2:
#define BSW_START_SEC_DEFAULT_CALIB_32
include "CAL_MemMap.h"
Automatically generate code sections 2:
/* Volatile memory section */
/* Definition for custom storage class: Volatile */
volatile real32_T SFCMM_AEBStatus_ActiveInhibit_Fps = 399.0F;/* Referenced by: '<S9>/Constant43' */
How to implement manual add code to automatic generation

Sign in to comment.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!