Code Generation for Custom Blocks
An S-function is a computer language description of a Simulink® block written in MATLAB®, C, C++, or Fortran. You can develop an S-function to represent external code using a programming interface that interacts with the Simulink engine. Use this S-function with the code generator to produce code. Start with S-Functions and Code Generation.
For simpler alternative approaches for interfacing between generated and external code, see External Code Import.
|Represent model or subsystem as generated S-function code
- S-Functions and Code Generation
Use S-functions to extend Simulink support for simulation and code generation.
- Build Integrated Code Within the Simulink Environment
Add support files and control model code generation and builds within the Simulink Environment.
- Write Noninlined S-Function
Implement your algorithm according to the S-function API by writing a C or C++ MEX S-function.
- Write Wrapper S-Function and TLC Files
Create S-functions that serve as wrappers for existing code.
- Write Fully Inlined S-Functions
Inline your algorithm in the TLC file for code generation.
- Write Fully Inlined S-Functions with mdlRTW Routine
mdlRTWcallback method in an inlined S-function.
- S-Functions for Multirate Multitasking Environments
Explains how to handle rate-grouped tasks in multirate, port-based sample time S-functions.
- Use S-Function Target for Model or Subsystem
Use a shared library generated from a model or subsystem that you can load dynamically into another application.
Legacy Code Tool
- Import Calls to External Code into Generated Code with Legacy Code Tool
Import calls to external code for utility functions, lookup tables, filters, and device drivers into the Simulink environment for simulation and code generation.
- Legacy Code Tool Examples
Learn how to use the Legacy Code Tool to generate fully inlined C MEX S-functions for legacy or custom code.