This example shows how the code generator removes unreachable (dead code) instances of the reset and disable functions from the generated code for ERT-based systems that include model referencing hierarchies. Optimizing the generated code to remove unreachable code is a requirement for safety-critical systems. This optimization also improves execution speed and reduces ROM consumption.
If a model contains blocks with states, the generated code contains reset and disable functions. If the model is not part of a conditionally executed system, such as an enabled subsystem, the code generator can remove the disable function because the generated code does not call it. If the model is not part of a conditionally executed system that can reset states when a control input enables it, the code generator can remove the reset function because the generated code does not call it.
A referenced model, rtwdemo_optionalDisableResetFunc_bot
, is in
rtwdemo_optionalDisableResetFunc_top
. The referenced model contains two
blocks with states, a Delay block and a Discrete-Time Integrator block.
Open the models. In the Command Window, type
rtwdemo_optionalDisableResetFunc_bot
and
rtwdemo_optionalDisableResetFunc_top
.
In your system temporary folder, create a temporary folder for the build and inspection process.
Build the model.
Open the rtwdemo_optionalDisableResetFunc_top.c
and
rtwdemo_optionalDisableResetFunc_bot.c
files.
The rtwdemo_optionalDisableResetFunc_bot.c
file contains these reset
and disable functions.
/* System reset for referenced model: 'rtwdemo_optionalDisableResetFunc_bot' */ void rtwdemo_optionalDisableResetFunc_bot_Reset (DW_rtwdemo_optionalDisableResetFunc_bot_f_T *localDW) { /* InitializeConditions for Delay: '<Root>/Delay' */ localDW->Delay_DSTATE = 0.0; /* InitializeConditions for DiscreteIntegrator: '<Root>/Discrete-Time Integrator' */ localDW->DiscreteTimeIntegrator_DSTATE = 3.0; } /* Disable for referenced model: 'rtwdemo_optionalDisableResetFunc_bot' */ void rtwdemo_optionalDisableResetFunc_bot_Disable(real_T *rty_Out1, DW_rtwdemo_optionalDisableResetFunc_bot_f_T *localDW) { /* Disable for DiscreteIntegrator: '<Root>/Discrete-Time Integrator' */ localDW->DiscreteTimeIntegrator_DSTATE = *rty_Out1; }
The rtwdemo_optionalDisableResetFunc_top_step
function does not call
the rtwdemo_optionalDisableResetFunc_bot_Disable
function because the
model is not part of a conditionally executed system. The
rtwdemo_optionalDisableResetFunc_top_step
function does not call the
rtwdemo_optionalDisableResetFunc_bot_Reset
function because the model
is not part of a conditionally executed system that can reset states when a control input
enables it.
Open the Model Configuration Parameters dialog box for
rtwdemo_optionalDisableResetFunc_bot
.
Select Remove Disable Function and Remove Reset Function.
Open the rtwdemo_optionalDisableResetFunc_bot.c
file. The code does
not contain the rtwdemo_optionalDisableResetFunc_bot_Reset
function or
the rtwdemo_optionalDisableResetFunc_bot_Disable
function.
Remove disable function | Remove reset function