Model Code Interfaces - MATLAB & Simulink (original) (raw)
To produce code that can interact with target platform services, the code generator must be aware of target platform 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 target platform receiver service by using a root-levelIn Bus Element or Inport block.
This table lists typical code interfaces and ways to represent them in a 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 usingFunction-Call Subsystem, function-callModel, Simulink Function, Message Triggered Subsystem, or 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 two blocks that exchange data and result in callable functions in generated code. A callable function is a generated entry-point that target environment software can call. |
Access target platform nonvolatile memory | Measurement service interface for persistent data, Initialize Function and Terminate Function blocks, orSimulink 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 orDelay block that models state variable |
Call to target platform timer service to get an absolute or elapsed time value | 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 (requires ), Discrete Time Integrator or Weighted Sample Time block. |
Message communication | Send block directly connected to a root-levelOutport 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), andDatastore Memory blocks |
Custom service interface | Custom blocks |
These topics provide more information for the different types of interfaces:
- Periodic and Aperiodic Function Interfaces
- Startup, Reset, and Shutdown Function Interfaces
- Data Interfaces
- Service Interfaces
- Message Communication Interfaces
- Client-Server Communication Interfaces
- Device Driver I/O 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, Modeling Guidelines, 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.