Main Content

Periodic and Aperiodic Function Interfaces

A target platform initiates execution of a component by calling execution entry-point functions generated for the model. The execution entry-point functions that implement component behavior can be periodic or aperiodic. The code that the code generator produces for a component 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 function-call- (export-function) based.

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

Rate-Based Modeling Style ConditionsFunction-Call Based 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 component.

  • 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 component 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 Components and Function-Call-Based Components.

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 Components

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

This example model shows a rate-based implementation of a component. 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 component model, the C code contains rate-grouped step entry-point functions, one function for each discrete rate in the model. The platform function scheduler calls the generated periodic step functions.

You can design a rate-based component 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.

Function-Call-Based Components

You can represent a function-call- (export-function) based component as a function-call subsystem. For function-call-based 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 platform code, including the function scheduler and other platform services.

This example model shows a function-call-based 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 a function-call-based 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 callable 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 a function-call-based 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, 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 platform 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