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 can represent periodic and aperiodic entry-point functions in a model by using a combination of two modeling styles: rate-based and, if you are using Embedded Coder®, export-function.
This table lists conditions that might prompt you to choose each modeling style.
Rate-Based Modeling Style Conditions | Export-Function Modeling Style Conditions |
---|---|
|
|
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 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.
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
If you are using Embedded Coder, 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.
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 (Embedded Coder), Configure Generated C Function Interface for Model Entry-Point Functions (Embedded Coder), and Interactively Configure C++ Interface (Embedded Coder).
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 (Embedded Coder)). 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:
- function for the first periodic ratemodel
_step0
- function for the second periodic ratemodel
_step1
- aperiodic function, wherefunction
is the name of the Inport block for a function-call subsystem or label of the signal line connecting the Inport and subsystemfunction
If you are using Embedded Coder, you can 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 (Embedded Coder)). 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 (Embedded Coder).
Related Topics
- Schedule Components to Avoid Data Dependency Issues
- Export-Function Models Overview
- Create Rate-Based Model
- Create an Export-Function Model
- Configure Generated C Function Interface for Model Entry-Point Functions (Embedded Coder)
- Configure C++ Class Interface for Rate-Based Models (Embedded Coder)
- Configure C++ Class Interface for Export-Function Models (Embedded Coder)
- Define Service Interfaces, Storage Classes, Memory Sections, and Function Templates for Software Architecture (Embedded Coder)