User`s guide

4 Guidelines for Writing C MEX S-Functions
4-16
placing calls toyourS-function in the generatedcode. This is the wrapsfcn.tlc
file that inlines wrapsfcn.c:
%% File : wrapsfcn.tlc
%% Abstract:
%% Example inlined tlc file for S-function wrapsfcn.c
%%
%implements “wrapsfcn” “C”
%% Function: BlockTypeSetup ====================================================
%% Abstract:
%% Create function prototype in model.h as:
%% “extern real_T my_alg(real_T u);”
%%
%function BlockTypeSetup(block, system) void
%openfile buffer
extern real_T my_alg(real_T u);
%closefile buffer
%<LibCacheFunctionPrototype(buffer)>
%endfunction %% BlockTypeSetup
%% Function: Outputs ===========================================================
%% Abstract:
%% y = my_alg( u );
%%
%function Outputs(block, system) Output
/* %<Type> Block: %<Name> */
%assign u = LibBlockInputSignal(0, ““, ““, 0)
%assign y = LibBlockOutputSignal(0, ““, ““, 0)
%% PROVIDE THE CALLING STATEMENT FOR “algorithm”
%<y> = my_alg(%<u>);
%endfunction %% Outputs
The first section of this code directs the Real-Ti me Workshop to inlin e the
wrapsfcn S-function block and generate the code in C:
%implements "wrapsfcn" "C"
Thenexttask istotell theReal-TimeWorkshop thatthe routine,my_alg,needs
to be declared external in the generated
wrapper.h file for any wrapsfcn
S-function blocks in the model. You only need to do this o nce for all wrapsfcn
S-functionblocks,sousetheBlockTypeSetup function.Inthisfunction,youtell
theTargetLanguageCompilertocreateabufferandcachethe
my_alg as
extern in the wrapper.h generated header file.
This line is placed in
wrapper.h.
This line is expanded
andplacedin
MdlOutputs within
wrapper.c
.