Main Content

Code interface packaging

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 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 static ert_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.

    • Select subsystem block parameter Function with separate data.

    • Use a subsystem that:

      • Has multiple ports that share 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.

      • Has output marked as a global signal.

      • For each instance contains identical blocks with different names or parameter settings.

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++. When Language is set to C++, this value is the default setting.

For a model configured with a service code interface, this parameter setting is not relevant and, therefore, is not supported.

Selecting C++ class enables the Multi-instance code error diagnostic parameter.

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 the Multi-instance code error diagnostic parameter to Warning or None, 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 than Auto, the code generator produces global data structures.

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyReusable function or C++ class
Safety precautionNo 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' if TargetLang is set to 'C++'

Version History

Introduced in R2014a