| Writing S-Functions | ![]() |
Creating Code-Reuse-Compatible S-Functions
The code reuse feature of the Real-Time Workshop generates code for a subsystem in the form of a function that is invoked wherever the subsystem occurs in the model (see Nonvirtual Subsystem Code Generation Options in the online Real-Time Workshop documentation). If a subsystem contains S-functions, the S-functions must be compatible with the code reuse feature. Otherwise, the Real-Time Workshop may not generate reusable code from the subsystem or may generate incorrect code.
If you want your S-function to support the subsystem code reuse feature, you must ensure that the S-function meets the following requirements:
BlockInstanceData function.
mdlStart and not before.
mdlSetWorkWidths. (It must not use ssWriteRTWParameters in its mdlRTW function for this purpose.)
In addition to meeting the preceding requirements, your S-function must set the SS_OPTION_WORKS_WITH_CODE_REUSE flag (see ssSetOptions). This flag assures RTW that your S-function meets the requirements for subsystem code reuse.
| The Direct-Index Lookup Table Example | S-Function Callback Methods | ![]() |