Download MATLAB SIMULINK 7 - DEVELOPING S-FUNCTIONS User`s guide
Transcript
Introduction Fully Inlined S-Functions A fully inlined S-function builds your algorithm (block) into Simulink and the Real-Time Workshop in a manner that is indistinguishable from a built-in block. Typically, a fully inlined S-function requires you to implement your algorithm twice: once for Simulink (C-MEX S-function) and once for the Real-Time Workshop (TLC file). The complexity of the TLC file depends on the complexity of your algorithm and the level of efficiency you’re trying to achieve in the generated code. TLC files vary from simple to complex in structure. Basic Files Required for Implementation This section briefly describes what files and functions you’ll need to create noninlined, wrapper, and fully inlined S-functions. • Noninlined S-functions require the C-MEX S-function source code (sfunction.c). • Wrapper S-functions that inline a call to your algorithm (your C function) require an sfunction.tlc file. • Fully inlined S-functions require an sfunction.tlc file. Fully inlined S-functions produce the optimal code for a parameterized S-function. This is an S-function that operates in a specific mode dependent upon fixed S-function parameter(s) that do not change during model execution. For a given operating mode, the sfunction.tlc specifies the exact code that will be generated to implement the algorithm for that mode. For example, the direct-index lookup table S-function at the end of this chapter contains two operating modes — one for evenly spaced x-data and one for unevenly spaced x-data. - Fully inlined S-functions using the mdlRTW S-function routine require the placement of the mdlRTW routine in your S-function MEX-file, sfunction.c. The mdlRTW routine lets you place information in model.rtw, which is the file that is processed by the Target Language Compiler prior to executing sfunction.tlc when generating code. This is useful in two situations: when you want to rename tunable parameters in your generated code, and when you want to introduce nontunable parameters into your TLC file. For S-functions to work correctly in the Simulink environment, a certain amount of overhead code is necessary. When the Real-Time Workshop generates code from models that contain S-functions (without sfunction.tlc 4-5