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
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 code generator produces entry-point functions for these types of model functions.
|Type of Model Function||Model Source Name||Default Generated Function Name||Description|
|Exported function (requires Embedded Coder®)||For an exported-function model, the exported function for a subsystem.|
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 (
|Partition function||For a model partition, output and update code. Model configuration parameter Single output/update function is selected (the default).|
|Partition update function||For a model partition, output and update code in separate functions. Model configuration parameter Single output/update function is cleared.|
|Periodic multitasking function||For blocks in a rate-based model configured for multitasking, output and update code. The code generator produces a function for each sample period. Model configuration parameter Single output/update function is selected (the default).|
|Periodic multitasking update function||For blocks in a rate-based model configured for multitasking, output and update code in separate functions. The code generator produces output and update functions for each sample period. Model configuration parameter Single output/update function is cleared.|
|Periodic single-tasking function||For blocks in a rate-based model configured for single-tasking, output and update code. Model configuration parameter Single output/update function is selected (the default).|
|Periodic single-tasking update function||For blocks in a rate-based model configured for single-tasking, output and update code in separate functions. Model configuration parameter Single output/update function is cleared.|
If the model includes a Reset Function block, reset code generated. To reset conditions or state, call the function from the application code.
|Simulink Function||For an exported-function model, the exported function for a Simulink Function block.|
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).
If you have Embedded Coder software, to facilitate integration of external and generated code and achieve compliance with code standards and guidelines, you can configure how the code generator produces function interfaces from a model or subsystem.
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) to
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
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).
These limitations apply to customizations for generated C function interfaces:
You must select the model configuration parameter Single output/update function.
Multirate models are supported, but you must configure the models for single tasking.
You must configure root-level inports and outports to use the
Default storage class.
If you choose to customize a function interface, you must provide your own custom
main program. You cannot configure the function interface with the
rt_main.c that MathWorks® provides. Specifying a function interface configuration other than the
default creates a mismatch between the generated code and the default static
The code generator removes the data structure for the root inports of the model unless a subsystem implemented by a nonreusable function uses the value of one or more of the inports.
The code generator removes the data structure for the root outports of the model except when you enable MAT-file logging or if the sample time of one or more of the outports is not the fundamental base rate (including a constant rate).
If you copy a subsystem block to create a block in a new model or the same model, the function interface information from the original subsystem block is not copied to the new subsystem block.
If you have Stateflow®, for a Stateflow chart that uses a model root inport value or that calls a subsystem that uses a model root inport value, do one of the following to generate code:
Clear the Execute (enter) Chart At Initialization check box in the Stateflow chart.
Make the Stateflow function a nonreusable function.
Insert a Simulink® Signal Conversion block immediately after the root inport. In the Signal Conversion block parameters dialog box, select Exclude this block from 'Block reduction' optimization.
If a model root inport value connects to a Simscape™ conversion block, insert a Simulink Signal Conversion block between the root inport and the Simscape conversion block. In the Signal Conversion block parameters dialog box, select Exclude this block from 'Block reduction' optimization.
When building a referenced model that is configured with a function interface, do not use virtual buses as inputs or outputs to the referenced model. Use nonvirtual buses instead.
If the C function interface is not the default, the value is ignored for the model configuration parameter Pass fixed-size scalar root inputs by value for code generation. For more information, see Pass fixed-size scalar root inputs by value for code generation.