An entry point is a location in code where a transfer of program control (execution)
occurs. The main function (
main()) is the entry point to a C/C++
program and is called when the application starts executing. Calls to other functions, for
example from the
main function, provide entry points to function code.
Program control is transferred to the called function. The function code executes, and when
finished, returns control to the
main or other calling function.
When producing code for a model, the code generator defines a set of entry-point functions that you can call to execute the generated code. You can call the generated functions from external code or from a version of the generated main function that you modify.
The Code Interface Report section of the code generation report lists the entry-point functions that the code generator produces for a model. For more information, see Analyze the Generated Code Interface (Embedded Coder).
The type of entry-point functions that the code generator produces for a model and the calling interface for the functions depend on whether the model is:
Rate-based or is an export-function model
Configured for reusable, multi-instance code generation
Depending on the style and configuration of a model, the code generator produces one or more of these entry-point functions.
Initialization code for a model. At the start of the application code,
call the function once. Do not use this function to reset the
real-time model data structure (
Code for turning off a system. For ERT-based models, you can suppress generation of this function by clearing the model configuration parameter Terminate function required (Embedded Coder) (set by default).
For blocks in a rate-based model, output and update code. If you clear
the model configuration parameter Single output/update
function (selected by default), instead of producing a
|For an exported-function model, the exported function for a subsystem.|
|For an exported-function model, the exported function for a Simulink Function block.|
If the model includes a Reset Function block, reset code generated. To reset conditions or state, call the function from the application code.
|For a reference model, output and update code.|
|For an Async Interrupt block, interrupt service routine (ISR) code.|
|Shared utility||For shared utility functions, output code.|
By default, for top models, the code generator produces code that is not reusable or
reentrant. Entry-point functions have a
void-void interface. Code
communicates with other code by directly accessing global data structures that reside in
If your application requires reusable, multi-instance entry-point function code, you can configure the code generator to call each function (instance) with unique data. In this case, the code is reentrant.
You configure whether entry-point functions are reusable with the model configuration parameter Code interface packaging and related parameters. The parameter settings that you choose depend on factors such as configuration selections for the system target file, programming language, and argument interface.
By default, for GRT- and ERT-based system target files, the code generator produces single-instance C entry-point functions. The generated code:
Creates an execution function without arguments
Allocates memory statically (at compile time) for model data structures.
The default model configuration parameter settings for configuring single-instance entry-point function code are:
You can configure the code generator to produce reusable entry-point functions in C
for either a GRT- or ERT-based system target file. However, the function interfaces that
the code generator produces by default varies. Assuming that model configuration parameter
Language is set to
C and Code interface packaging is
Reusable function, the code generator produces this
entry-point function code for each system target file scenario.
|System Target File||Interface|
If you are using an ERT-based system target file and want to generate reusable, multi-instance C entry-point functions that are reentrant, consider:
Using dynamic memory allocation to initialize model data structures. Select Use dynamic memory allocation for model initialization (Embedded Coder).
Packing values of model root-level Inport blocks into a structure, packing values
of root-level Outport blocks into a second structure, and passing the structures to
the execution function as arguments by reference. Set Pass root-level I/O as (Embedded Coder) to
Packing values of model root-level Inport blocks and Output blocks into the
real-time model data structure and passing that structure to the execution function as
an argument by reference. Set Pass root-level I/O as (Embedded Coder)
Part of model data structure.
The C++ class interface encapsulates model data as class properties and entry-point
functions as class methods. That interface is available for use with ERT-based system
target files. To use the interface, set Language to
C++ and set Code interface packaging to
C++ class. You can:
Preview and customize the C++ class interface by clicking Configure C++ Class Interface (Embedded Coder). Customization means that you can generate code for integration with external code and verify that the code complies with coding standards.
Configure the visibility of class inheritance by specifying whether to generate
the block parameter structure as a public, private, or protected data member. Set
Parameter visibility (Embedded Coder)
Generate C++ interface code for model block parameters that meet code execution
speed or tunability requirements. The code can be noninlined or inlined access
methods. Set Parameter access (Embedded Coder) to
Generate C++ interface code for model root-level Inport and Outport blockset that meets code execution speed, data tunability, or data packaging requirements. The code can be one of these types of access methods.
|For Access Method Type||Set External I/O access (Embedded Coder) To|
Configure the visibility of class inheritance by specifying whether to generate
the root-level I/O structure as a public, private, or protected data member. Set External
I/O visibility (Embedded Coder) to
Depending on application requirements, such as integration or compliance with code standards, you might need to configure how the code generator produces declarations for entry-point functions. Embedded Coder® provides multiple configuration options.
Apply a default function naming rule to a category of functions across a model. For
example, a default naming rule can produce a
function for each rate in the
multi-rate model. In the Code Mappings editor, on the Function
Defaults tab, map a function category to a function customization template
that is defined to use the function naming rule (see Code Mappings Editor). You can override
the default naming of a function by changing the name on the
Functions tab (see Override Default Naming for Individual C Entry-Point Functions (Embedded Coder) or Override Default C Step Function Interface (Embedded Coder)).
Configure interfaces for individual entry-point functions. In the Code Mappings
editor, on the Functions tab, specify the names of individual
functions (see Override Default Naming for Individual C Entry-Point Functions (Embedded Coder)). For a
(execution) function, you
can customize the entire entry-point function interface (see Override Default C Step Function Interface (Embedded Coder)).
If your application requires that you configure the placement of entry-point functions in memory, for example, to optimize the generated code for specific hardware, you can apply a default memory section to a category of functions across a model. In the Code Mappings editor, map a function category to a function customization template that is defined to use a specific memory section. See Code Mappings Editor.
After generating code for a model, use the Code view to review the generated entry-point functions and, if applicable, variables representing external input and output ports.
#include statements to your external code that include the
generated header files that declare the model entry-point functions.
#include statement that includes the generated file
rtwtypes.h. This file provides type definitions,
#define statements, and enumerations.
Initialize target-specific data structures and hardware, such as ADCs or DACs.
If applicable, initialize data for each instance of a reusable model.
If applicable, write input data to generated variables that represent model Inport blocks.
Call the generated entry-point functions or set up use of the
If applicable, read data from generated variables that represent model Outport blocks.
For more information, see Deploy Generated Standalone Executable Programs To Target Hardware (Embedded Coder).