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 Interface||Model Element or Pattern|
|Callable rate-based entry point||Block 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 point||Exported-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 point||Initialize Function block|
|Callable terminate function entry point||Terminate Function block|
|Call to target platform receiver service||In Bus Element or Inport block|
|Call to target platform sender service||Out 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 memory||Initialize Function and Terminate Function blocks or Simulink Function and Function Caller blocks|
|Reuse memory between a state variable and root-level output variable||Function loopback pattern that models state variable as a signal or Delay block that models state variable|
|Call to target platform timer service||Scoped 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 communication||Send 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 arguments||Parameter objects stored in the model workspace|
|Data for measurement||Signals (output port of a block), states (states on a block), and Datastore Memory blocks|
|Custom service interface||Custom 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.