Main Content

Model Code Interfaces

To produce code that can interact between model elements , the code generator must be aware of interface requirements. The first step for doing that is to represent required interfaces in your top model by including specific model elements. For example, you can model an interface for reading data from a model element by using a root-level In Bus Element or Inport block.

This table lists typical code interfaces and ways to represent them in a top model.

Type of Code InterfaceModel Element or Pattern
Callable rate-based entry pointBlock in a rate-based model that is configured for single-tasking or multitasking execution or that is set up as a partition in the Simulink Schedule Editor
Callable initialize function entry pointInitialize Function block
Callable terminate function entry pointTerminate Function block
Call to target platform receiver serviceIn Bus Element or Inport block
Call to target platform sender serviceOut Bus Element or Outport block
Access target platform nonvolatile memoryInitialize Function and Terminate Function blocks or Simulink Function and Function Caller blocks
Reuse memory between a state variable and root-level output variableFunction loopback pattern that models state variable as a signal or Delay block that models state variable
Message communicationSend block directly connected to a root-level Outport block and Receive block directly connected to a root-level Inport block
Client-server communication Simulink Function and Function Caller blocks
Tunable parameters and parameter argumentsParameter objects stored in the model workspace
Data for measurementSignals (output port of a block), states (states on a block), and Datastore Memory blocks
Custom service interfaceCustom blocks

These topics provide more information for the different types of interfaces:

Modeling guidelines can be helpful depending on your deployment objective and how you configure code interfaces for the code generator. In some cases, you might need to create custom representations that involve creating custom blocks.

For information on modeling guidelines, see Modeling Guidelines and Block Usage.

For information on creating custom blocks, see Code Generation for Custom Blocks.