Main Content

Model Code Interfaces

The code generator must be aware of service interface requirements in order to produce code that can interact with target environment services. 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 target platform receiver service by using a root-level In Bus Element or Inport block.

This table lists typical code interfaces and ways to represent them in an application or component 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 exported-function entry pointExported-function model that defines functions by using Function-Call subsystem, function-call Model, Simulink Function, Message Triggered Subsystem, and S-Function blocks
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
Call to target platform data transfer service

Signal line that connects callable functions that exchange data

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
Call to target platform timer serviceScoped Simulink Function block (to represent service) and library block that includes a Function Caller block (to call the service) or, for a model configured with a service interface, Discrete Time Integrator or Weighted Sample Time block.
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 for Generated Code and Component Deployment Guidelines for Embedded Coder Support Package.

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