Convert non inlined s-function to inlined with wrapper

조회 수: 30 (최근 30일)
Dimitri
Dimitri 2026년 2월 11일 20:55
댓글: Dimitri 2026년 2월 12일 11:03
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
Dimitri
Dimitri 2026년 2월 12일 11:02
%function Outputs(block, system) Output
%assign outPtr = LibBlockOutputSignalAddr(0, "", "", 0)
%assign inPtr = LibBlockInputSignalAddr(0, "", "",0)
%assign numEls = LibBlockOutputSignalWidth(0)
times_two(%<inPtr>,%<outPtr>,%<numEls>);
%endfunction
Dimitri
Dimitri 2026년 2월 12일 11:03
Will be the better solution?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Target Language Compiler에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by