Main Content

Periodic and Aperiodic Function Interfaces

Target environment software initiates execution of algorithm code generated for a top model (application or component) by calling generated execution entry-point functions. The execution entry-point functions that implement the top model behavior can be periodic or aperiodic. The entry-point function code that the code generator produces for a top model depends on the modeling styles and periodic rates represented in the model. You represent periodic and aperiodic entry-point functions in a model by using a combination of two modeling styles: rate-based and export-function.

This table lists conditions that might prompt you to choose each modeling style.

Rate-Based Modeling Style ConditionsExport-Function Modeling Style Conditions
  • Assumes rate monotonic scheduling.

  • Code generator produces a unique entry-point function for each rate represented in the model.

  • Sample time is design data. It is not an implementation consideration.

  • Can generate reusable code from multiple instances of a model.

  • A function represents the entry-point function for a server.

  • A function exchanges data with multiple other functions.

  • A function represents a periodic entry-point function that has a rate that is not a multiple of the fastest rate used by the top model.

  • A function represents a periodic entry-point function that other events also trigger.

  • Multiple functions represent periodic entry-point functions that are triggered at the same period.

If you want a top model to support multiple instantiation, you cannot model periodic functions as function-call subsystems. Use rate-based modeling.

For more information about modeling execution behavior, see Rate-Based Top Models and Export-Function Top Models. For guidelines on modeling execution behavior for component models, see cgsl_0401: Modeling styles for component deployment.

For options to configure the function prototype for generated periodic and aperiodic execution entry-point functions, see Periodic and Aperiodic Function Interface Configuration.

Rate-Based Top Models

A rate-based top model represents periodic entry-point functions by using unique periodic rates.

This example model shows a rate-based implementation of a component top model. The model implements periodic entry-point functions by using the rates 1 second and 2 seconds. An Initialize Function block initializes the component.

Example of rate-based modeling style

When you generate code for a rate-based top model, the C code contains rate-grouped step entry-point functions, one function for each discrete rate in the model. The target environment function scheduler calls the generated periodic step functions.

You can design a rate-based top model to represent periodic and aperiodic entry-point functions. For example, in the JMAAB-B type beta architecture, an asynchronous trigger entry-point function interacts with periodic rate-based entry-point functions.

Export-Function Top Models

You can represent an export-function top model as a function-call subsystem. For export-function models, the code generator produces code for independent functions that execute at a periodic rate or aperiodically in response to events. You can integrate the independent function code with other target environment software, including the function scheduler and other platform and custom services.

This example top model shows an export-function implementation of a component. The model uses three Function-Call Subsystem blocks, FC1_subsystem, FC1_subsystem, and FC3_subsystem, which have periodic rates to implement three periodic entry-point functions. Signal lines that connect the Function-Call Subsystem blocks, dsv1, dsv2, dsv3, and dsv4, represent data transfers.

Example of export-function model

When you generate code for an export-function implementation, the code includes a callable model entry-point function for each function represented in the top model. Unless you define and configure the interface otherwise, the code generator uses the name of the function-call subsystem input port as the name of the entry-point function. You can override the default naming by defining a function customization template in an Embedded Coder Dictionary and configuring the function name in the model code mappings.

You can control how the code generator packages the code for an export-function implementation. For example, by using subsystem block parameter Function packaging, you can specify whether the code generator inlines the function code for a subsystem or produces separate function code that passes I/O as global data. When inlined, the code generator uses the name of the function-call subsystem input port to name the entry-point function. When producing separate function code, the code generator names the function based on the settings of other parameters, such as File name options.

For more information, see Generate Component Source Code for Export to External Code Base, Configure Generated C Function Interface for Model Entry-Point Functions, and Interactively Configure C++ Interface.

Periodic and Aperiodic Function Interface Configuration

The code generator produces several types of entry-point functions for model functions (see Configure Generated C Function Interface for Model Entry-Point Functions). As an example, for a component model that includes two periodic function-call subsystems and an aperiodic function-call subsystem, the code generator produces three callable entry-point functions for initiating component execution:

  • model_step0 - function for the first periodic rate

  • model_step1 - function for the second periodic rate

  • function - aperiodic function, where function is the name of the Inport block for a function-call subsystem or label of the signal line connecting the Inport and subsystem

Customize the entry-point function prototypes to align with function calls initiated by the target environment function scheduler by applying one of these approaches:

  • For the model, in the Code Mappings editor or by using the code mappings programming interface, configure the function name and arguments for each model execution function individually.

  • Define a function customization template for execution functions in the Embedded Coder Dictionary (see Code Interface Definitions). Then, for the model, in the Code Mappings editor or by using the code mappings programming interface, configure the code generator to use that template for model execution functions.

For more information, see Configure Generated C Function Interface for Model Entry-Point Functions.

Related Topics