S-Function parameter generates unnecessary array

1 回表示 (過去 30 日間)
Michael Frena
Michael Frena 2020 年 1 月 31 日
コメント済み: Michael Frena 2020 年 2 月 13 日
Hi,
I am facing a problem with the c code generation of an S-Function:
I generated the S-Function with the legacy code tool. The only use of the S-Function is to insert a function call in the generated c-code. But as I need several calls to different functions, I am passing the respective name of the function as parameter event to the S-Function:
SFunction_Simulink.PNG
In the tlc file of the S-Function the Outputs function is defined like this to generated the function call:
%function Outputs(block, system) Output
%%
%assign event = LibBlockParameterString(P1)
%assign y1_ptr = LibBlockOutputSignalAddr(0, "", "", 0)
%%
%<event>( %<y1_ptr> );
%%
%endfunction
This way in the generated code appears always the function call passed as event e.g. dem_Call_Function1(dem_event_prefail);
Unfortuanetly also is generated for each call a uint16_t array of the size of the function call name which is not used at all, but just occupies space.
e.g. for dem_CallFunction1 there is generated:
uint16_t SFunction[18];
The array is initialized in the generated _data.c file like this:
{ 100U, 101U, 109U, 95U, 67U, 97U, 108U, 108U, 95U, 70U, 117U, 110U, 99U, 116U,
105U, 111U, 110U, 49U }
The question is now how could I avoid, that these useless arrays are getting generated?
  1 件のコメント
Michael Frena
Michael Frena 2020 年 2 月 13 日
I guess there is no way to avoid the generation.
What I did now to avoid the generation of the array is that I pass only an integer value to the S-function. And inside the TLC file this integer value is compared against an enumeration to select the correct Event-String.
This way only the integer value gets stored.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeTarget Language Compiler についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by