Code interface packaging (component) - Package generated code interface as reusable or nonreusable functions or as a
C++ class - MATLAB ([original](http://www.mathworks.com/help/rtw/ref/codeinterfacepackaging.html)) ([raw](?raw))
Main Content
Package generated code interface as reusable or nonreusable functions or as a C++ class
Model Configuration Pane: Code Generation / Interface
Description
The Code interface packaging (component) parameter specifies how the code generator packages generated C or C++ interface code.
Settings
Nonreusable function
(default) | Reusable function
| C++ class
Nonreusable function
Generates nonreusable code. The code generator allocates model data structures statically. Generated entry-point functions access the data structures directly.
This is the default setting when Language is set to C
.
Reusable function
Generates reusable, multi-instance code that is reentrant.
- The generated
_`model`_.c
source file contains an allocation function that dynamically allocates model data for each instance of the model. - The generated code passes the real-time model data structure in, by reference, as an argument to entry-point functions.
- The code generator exports the real-time model data structure in the
_`model`_.h
header file.
Selecting Reusable function
:
- Enables the Multi-instance code error diagnostic parameter.
- Does not change the code generated for function-call subsystems.
If the System target file parameter is set to an ERT-based system target file:
- This
Reusable function
setting is not supported if the model is configured with a service code interface. - Selecting
Reusable function
enables parameters Use dynamic memory allocation for model initialization and Pass root-level I/O as.- Use Use dynamic memory allocation for model initialization to control whether to generate an allocation function.
- Use Pass root-level I/O as to control how root-level input and output arguments are passed to the reusable model entry-point functions. You can include the arguments in the real-time model data structure that is passed to the functions, pass the arguments individually, or pass the arguments as references to input and output structures.
- You can select
Reusable function
when generating a staticert_main.c
module, if you do the following:- Select the Use dynamic memory allocation for model initialization parameter.
- Set the Pass root-level I/O as parameter to
Part of model data structure
.
- You cannot select
Reusable function
if you:- Customize the
model_step
function prototype of a model that passes root-level I/O as a structure reference or part of the model data structure. - Use a subsystem that:
* Has subsystem block parameter Function packaging configured asNonreusable function
and parameter Function with separate data enabled.
* Has multiple ports that share a source.
* Has a port that is used by multiple instances of the subsystem and has different sample times, data types, complexity, frame status, or dimensions across the instances.
* Assigns a global storage class to an output signal.
* For each instance contains identical blocks with different names or parameter settings.
- Customize the
C++ class
Generates a C++ class interface for the model. The generated interface encapsulates required model data into C++ class attributes and model entry point functions into C++ class methods.
To enable this value, set the Language parameter to C++
. WhenLanguage is set toC++
, this value is the default setting.
For a model configured with a service code interface, this parameter setting is not relevant and thus is not supported.
Selecting C++ class
enables theMulti-instance code error diagnostic parameter.
You cannot select C++ class
if you use a subsystem with the block parameterFunction packaging configured asNonreusable function
and the parameter**Function with separate data** enabled.
Tips
- The code generator exports entry-point functions in
_`model`_.h
. To call the entry-point functions from user-written code, add an#include_`model`_.h
directive to the code. - When you select
Reusable function
, the code generator generates a pointer to the real-time model object (_`model`__M
). - When you select
Reusable function
and set theMulti-instance code error diagnostic parameter toWarning
orNone
, the code generator might generate code that compiles but is not reentrant. For example, if a signal, a DWork structure, or parameter data has a storage class other thanAuto
, the code generator produces global data structures.
Recommended Settings
Application | Setting |
---|---|
Debugging | No impact |
Traceability | No impact |
Efficiency | Reusable function or C++ class |
Safety precaution | No impact |
Programmatic Use
Parameter: CodeInterfacePackaging | |
---|---|
Type: character vector | |
Value: 'C++ class' | 'Nonreusable function' | 'Reusable function' |
Default: 'Nonreusable function' if TargetLang is set to'C'; 'C++ class' ifTargetLang is set to 'C++' |
Version History
Introduced in R2014a
See Also
Code interface packaging (subcomponent) | model_step
Topics
- Model Configuration Parameters: Code Generation Interface
- Configure Generated C Function Interface for Model Entry-Point Functions
- Generate Reentrant Code from Top Models
- Combine Code Generated for Multiple Models or Multiple Instances of a Model
- Generate C++ Class Interface to Model or Subsystem Code
- Interactively Configure C++ Interface (Embedded Coder)
- Generate Reentrant Code from Subsystems
- S-Functions for Code Reuse
- Static Main Function Module (Embedded Coder)
- Configure Generated C Function Interface for Model Entry-Point Functions (Embedded Coder)
- Generate Modular Function Code for Nonvirtual Subsystems (Embedded Coder)
- Generate Component Source Code for Export to External Code Base (Embedded Coder)