Convert non inlined s-function to inlined with wrapper
17 views (last 30 days)
Show older comments
Hello!
I'm trying to reproduce the model described in this article: https://nl.mathworks.com/help/rtw/ug/write-wrapper-s-function-and-tlc-files.html#f53147
I've created the non inlined model. This model take an array of numbers and multuply by 2 each element.
The core function is the flowing:
static void mdlOutputs(SimStruct *S, int_T tid)
{
InputPtrsType uPtrs = ssGetInputPortSignalPtrs(S, 0);
uint8_T *y = (uint8_T *)ssGetOutputPortSignal(S, 0);
int_T width = ssGetOutputPortWidth(S, 0);
for (int_T i = 0; i < width; i++) {
y[i] = 2 * (*(uint8_T *)uPtrs[i]);
}
}
I've make a simple model and compile the *.c file with command:
mex times_two.c
The model is in the Noninlined.zip
Now; with the help of the article (https://nl.mathworks.com/help/rtw/ug/write-wrapper-s-function-and-tlc-files.html#f53147) I've created a wrapsfcn.tlc:
%%This code is the TLC file wrapsfcn.tlc 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 times_two(real_T u);"
%%
%function BlockTypeSetup(block, system) void
%openfile buffer
extern real_T times_two(real_T u); /* This line is placed in wrapper.h */
%closefile buffer
%<LibCacheFunctionPrototype(buffer)>
%endfunction %% BlockTypeSetup
%% Function: Outputs ===========================================================
%% Abstract:
%% y = times_two( u );
%%
%function Outputs(block, system) Output
/* %<Type> Block: %<Name> */
%assign u = LibBlockInputSignal( 0, "i", "", 0)
%assign y = LibBlockOutputSignal(0, "i", "", 0)
%% PROVIDE THE CALLING STATEMENT FOR "algorithm"
%% The following line is expanded and placed in mdlOutputs within wrapper.c
{
%assign u = LibBlockInputSignal( 0, "i", "", 0)
%assign y = LibBlockOutputSignal(0, "i", "", 0)
for (i = 0; i < %<LibBlockInputSignalWidth(0)>; i++) {
%<y> = times_two(%<u>);
}
}
%endfunction %% Outputs
and the file times_two.c:
#ifdef MATLAB_MEX_FILE
#include "tmwtypes.h"
#else
#include "rtwtypes.h"
#endif
real_T times_two(real_T u)
{
return(2.0 * u);
}
I've made a model (see Inlined.zip) but the Simulink didn't detect the function real_T times_two(real_T u)
Error in S-function 'inlined_wrapsfcn/S-Function': S-Function 'wrapsfcn' does not exist
From the article I don't understand what should be the exact content of the files wrapper.c and wrapper.h. It may be the reason why the inlined model didn't work.
Could you please explain me that steps I've missed?
5 Comments
Answers (0)
See Also
Categories
Find more on Target Language Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!