User`s guide

Introduction
4-3
environment with a great deal of flexibility. This flexibility cannot always be
maintained when you use S-functions with the Real-Time Workshop. For
example,itis notpossibletoaccess theMATLABworkspacefromanS-function
that is used with the Real-Time Workshop. However, using the techniques
presentedin this chapter,you can createS-functions for mostapplications that
work with the generated code from the Real-Time Workshop.
Although S-functions provide a generic and flexible solution for implementing
complex algorithms in Simulink, they require significant m emory and
computation resources. Most often the additional resources are acceptable for
real-time ra pid prototyping systems. In many cases, though, additional
resources are unavailable in real-time embedded applications. You can
minimize memory and computational requirements by using the Target
Language Compiler technology provided with the Real-Time Workshop to
inline your S-functions.
Types of S-Functions
The implementation of S-functions changes based on your requirements. This
chapter discusses the typical problems that you may face and how to create
S-functions for applications that need to work with Simulink and the
Real-Time Workshop. These are some (informally defined) common situations:
1 “I’m not concerned with efficiency. I just want to write one version of my
algorithm and have it work in Simulink and the Real-Time Workshop
automatically.”
2 “I have a lot of hand-written code that I need to interface. I want to call my
functionfrom Simulinkand the Real-TimeWorkshopin an efficientmanner.
or said another way:
“I want to create a block for my blockset that will be distributed throughout
my organization. I’d like it to be very maintainable with efficient code. I’d
like my algorithm to exist in one place but work with both Simulink and the
Real-Time Workshop.”
3 “I want to implement a highly optimized algorithm in Simulink and the
Real-Time Workshop that looks like a built-in block and generates very
efficient code.”