Target Language Compiler | ![]() ![]() |
Generate Code Using a Wrapper
To create a wrapper for external function my_alg.c
, you need to construct a TLC file that embodies its calling function, wrapsfcn.c
. The TLC file must generate C code that provides
double u
.
my_alg()
in the outputs section of the code.
To create a wrapper for my_alg()
, do the following:
change_wrapsfcn.tlc
in your editor, and add lines of code where comments indicate to create a workable wrapper.
wrapsfcn.tlc
. It must have the same name as the S-function block that uses it or the TLC won't be called to inline code.
If you had any problems building the application:
set_param()
command as specified above.
wrapsfcn.tlc
.
As a last resort, look at wrapsfcn.tlc
in the solutions/tlc_solution
directory, also listed below:
%% File : wrapsfcn.tlc %% Abstract: %% Example tlc file for S-function wrapsfcn.c %% %% Copyright 1994-2001 The MathWorks, Inc. %% %% $ Revision: 1.3 $ %implements "wrapsfcn" "C" %% Function: BlockTypeSetup ================================ %% Abstract: %% Create function prototype in model.h as: %% "extern double my_alg(double u);" %% %function BlockTypeSetup(block, system) void %openfile buffer %% ASSIGNMENT: PROVIDE ONE LINE OF CODE AS A FUNCTION PROTOTYPE %% FOR "my_alg" AS DESCRIBED IN THE WRAPPER TLC ASSIGNMENTextern double my_alg(double 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 "wrapfcn"%<y> = my_alg( %<u> );
%endfunction %% Outputs
Look at the highlighted lines. Did you declare my_alg()
as extern double
? Did you call my_alg()
with the proper input and output? Correct any mistakes you may have made and build the model again.
![]() | Generate Code Without a Wrapper | Code Generation Architecture | ![]() |