Main Content

model_reset

Generated C/C++ entry-point function that contains reset code for a Simulink model

Description

example

void model_reset(void) is a generated C or C++ entry-point function that executes reset code for a Simulink® model. If a model includes a Reset Function block, reset code is generated. To reset conditions or state, call the function from the application code.

The generated calling interface of the reset entry-point function for a model differs depending on the Language and Code interface packaging parameters. For more information, see Code interface packaging.

To preview and customize the name of the generated reset entry-point function an Embedded Coder® license is required. To preview the reset entry-point function, open the Code Mappings editor and click the Functions tab. To customize the function name, in the Function Name column click and edit the spreadsheet directly. To customize the function name and arguments, in the Function Preview column click the function hyperlink and configure the reset function from the opened dialogue box. To customize a function using a template (not supported for C++), in the Function Customization Template column select a template to apply to the function. For more information, see Configure Name and Arguments for Individual Step Functions, Interactively Configure C++ Interface, and Configure Default Code Generation for Functions.

To view the generated reset entry-point function, open the Code view or Code Generation Report and view the source code for your model. For more information see, Analyze Generated Data Code Interface Report.

Examples

collapse all

This example shows how to generate a nonreusable C reset entry-point function with Embedded Coder.

Examine Counter Model and Reset Function

Open the counter model and examine the subsystem Counter Subsystem. The counter is driven by a Discrete-Time Integrator block.

counterModel = "CounterECoderModel";
open_system(counterModel);

Simulate the model and observe how the subsystem increments the output. The simulation is set to run in paced mode to slow down the counting in this example.

sim(counterModel);

Generate C code from the model.

evalc("slbuild(counterModel,GenerateCodeOnly=true);");

Open the generated .c file and inspect the generated reset function CounterECoderModel_reset.

generatedCFile = fullfile(counterModel + "_ert_rtw",counterModel + ".c")
generatedCFile = 
"CounterECoderModel_ert_rtw/CounterECoderModel.c"

The reset function sets the value of the Discrete-Time Integrator block to 0.

coder.example.extractLines(generatedCFile,"CounterE_CounterSubsystem_reset(void)",...
      "/* End of Outputs for SubSystem: '<S1>/Reset Function' */",true,true);
void CounterE_CounterSubsystem_reset(void)
{
  /* Outputs for Atomic SubSystem: '<S1>/Reset Function' */
  /* StateWriter: '<S2>/State Writer' incorporates:
   *  Constant: '<S2>/Constant'
   */
  CounterECoderModel_DW.DiscreteTimeIntegrator_DSTATE = 0.0;

Use Tester Model to Test Counter Model and Reset Function

In this part of the example a tester model acts as a wrapper that references and feeds a revised version of the counter model. The tester model can invoke the functions of the counter model during simulation.

Open the tester model. The tester model feeds the counter activation trigger of the counter model, which runs together with the tester model throughout the simulation. The Reset Counter button of the tester model feeds the reset function of the counter model. Clicking this button resets the counter.

testerModel = "CounterTesterModel";
open_system(testerModel);

Simulate the tester model and observe the counting that it captures from the counter model.

sim(testerModel);

Click the Reset Counter button to invoke the reset entry point function. The counter is reset. You can click the Reset Counter button multiple times.

Input Arguments

collapse all

The reset entry-point C or C++ function provides an interface to the model reset code. By default, the generated function provides a void-void interface that does not have arguments.

Output Arguments

collapse all

The reset entry-point C or C++ function provides an interface to model reset code. By default, the generated function provides a void-void interface that does not have a return value.

Version History

Introduced before R2006a