User`s guide
4 Guidelines for Writing C MEX S-Functions
4-2
Introduction
This chapter describes how to create S-functions that work seamlessly with
both Simulink and the Real-Time Workshop. It begins with basic concepts and
concludes with an example of how to create a highly optimized direct-index
lookup table S-function block.
This chapter assumes that you understand these concepts:
• Level 2 S-functions
• Target Language Compiler (TLC)
• The basics o f how the Real-Time Workshop creates generated code
See The Target Language Compiler Reference Guide,andThe Real-Time
Workshop User’s Guide for more information about these subjects.
A note on t erminology: when this chapter refers actions performed by the
Target Language Compiler, including parsing, caching, creating buffers, etc.,
the name Target Language Compiler is spelled out fully. When referring to
code written in the Target Language Compiler syntax, t his chapter uses the
abbreviation TLC.
Note The guidelines presented in this chapter are for Real-Time Workshop
users. E ven if you do not currently use the Real-Time Workshop, we
recommend that you follow the guidelines presented in this chapter when
writing S -functions, especially if y ou are cre ating general-purpose S-functions.
Classes of Problems Solved by S-Functions
S-functions help solve various kinds of problems you may face when working
with Simulink and the Real-Time Workshop (RTW). These problem s include:
• Extending t he se t o f algorithms (blo cks ) provided by Simulink and RTW
• Interfacing legacy (hand-written) C-code w ith Simulink and RTW
• Generating highly optimized C-code for embedded systems
S-functions and S-functi on routines form an application program interfa ce
(API) that allows you to i m p leme n t generic algorithms in the Simulink