Main Content

model_step

Generated C/C++ entry-point function that contains execution code for each step in a Simulink model

Description

example

void model_step(void) is an execution function that contains the output and update code for the blocks in a Simulink® model.

void model_step_N(void) is an execution function with a task identifier that contains the output and update code for the blocks in a Simulink model.

The step entry-point function computes the current values of the blocks. If logging is enabled, the step function updates logging variables. By design, the step function is called at the interrupt level from rt_OneStep (invoked as a timer ISR). The rt_OneStep function calls the model_step function to execute processing for one clock period of the model. For a more information, see rt_OneStep and Scheduling Considerations (Embedded Coder).

If the model has a finite stop time, the step function signals the end of execution when the current time equals the stop time. Otherwise, if one or more of these conditions are true, the step function does not check the current time against the stop time and the program runs indefinitely:

  • The model stop time is set to inf.

  • Logging is disabled.

  • Parameter Terminate function required is not selected.

The generated calling interface of the step entry-point function for a model differs depending on these parameters:

  1. To generate a step entry-point function, select the Single output/update function parameter. If you clear this parameter, model_output and model_update entry-point functions are generated in place of the step function.

  2. To generate a single step function with configurable arguments, clear the Treat each discrete rate as a separate task parameter. To generate separate step functions based on timing requirements, select this parameter. For more information, see Treat each discrete rate as a separate task.

    • Parameter Value: Off (single rate or multirate single-tasking model)

      Function Prototype: void model_step(void);

    • Parameter Value: On (multirate multi-tasking model)

      Function Prototype: void model_step_N (void); (N is a task identifier)

  3. To change the generated calling interface, set the Language and Code interface packaging parameters. For more information, see Code interface packaging.

To preview and customize the name and arguments of the generated C or C++ step entry-point function an Embedded Coder® license is required. To preview a step 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 step function from the opened dialog box. To customize a function using a template, 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 (Embedded Coder), Interactively Configure C++ Interface (Embedded Coder), and Configure Default Code Generation for Functions (Embedded Coder).

To view the generated step 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 (Embedded Coder).

Examples

collapse all

This example shows the basic workflow for how to configure, customize, generate, and examine a step entry-point function.

  1. Open a model.

  2. Select a coder. In the Apps gallery, click Simulink Coder or Embedded Coder.

  3. Set model configuration parameters Single output/update function, Treat each discrete rate as a separate task, Language, and Code interface packaging.

  4. (Embedded Coder only) Customize the function. Using Embedded Coder, you can customize the name and arguments of the step entry-point function.

    • Open the Code Mappings editor.

    • Click on the Functions tab.

    • Customize the name and arguments. In the Function Preview column, click the function hyperlink to open the Configure C Step Function Interface dialog box. Configure the name and arguments.

  5. Generate code.

  6. Examine the generated code. In the Code view, verify the generated step function appears with the expected name and parameters.

Input Arguments

collapse all

The step entry-point C or C++ function provides an interface to the model execution code. By default, the generated function provides a void-void interface that does not have arguments. To configure the input arguments for a C step function, use the Code Mappings Editor – C. To configure the input arguments for a C++ step function, use the Code Mappings – C++ Editor (Embedded Coder).

Output Arguments

collapse all

The step entry-point C or C++ function provides an interface to the model execution code. By default, the generated function provides a void-void interface that does not have arguments. To configure the output arguments for a C step function, use the Code Mappings Editor – C. To configure the output arguments for a C++ step function, use the Code Mappings – C++ Editor (Embedded Coder).

Version History

Introduced before R2006a