How to avoid generated block i/o structure in case of generating Code from a level 2 S-Function?

1 view (last 30 days)
Hello all,
i´m trying to write an level 2 S function for a dynamic saturation block, that uses special intrinsic functions of my compiler within codegeneartion.
Firstly i wrote the level 2 Sfunction:
function dynamicIQsat_block(block)
setup(block);
%endfunction
%%Function: setup ===================================================
function setup(block)
% Register number of ports
block.NumInputPorts = 3;
block.NumOutputPorts = 1;
% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Override input port properties
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DirectFeedthrough = 1;
block.InputPort(2).Dimensions = 1;
block.InputPort(2).DirectFeedthrough = 1;
block.InputPort(3).Dimensions = 1;
block.InputPort(3).DirectFeedthrough = 1;
% Override output port properties
block.OutputPort(1).Dimensions = 1;
% Register parameters
block.NumDialogPrms = 0;
% Register sample times
% [-1, 0] : Inherited sample time
block.SampleTimes = [-1, 0];
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('Outputs', @Outputs); % Required
%end setup
%%Function: Outputs ===================================================
function Outputs(block)
if block.InputPort(1).Data < block.InputPort(2).Data
block.OutputPort(1).Data = block.InputPort(1).Data;
elseif block.InputPort(3).Data > block.InputPort(2).Data
block.OutputPort(1).Data = block.InputPort(3).Data;
else
block.OutputPort(1).Data = block.InputPort(2).Data;
end
This is working as expected. After writing the level 2 S-Function, i added an .tlc file to inline this level2 S-Function:
%implements "dynamicIQsat_block" "C"
%%Function Outputs
%function Outputs(block, system) Output
/* %<Type> Block: %<Name> */
/* dynamic Saturate with using _iqsat function of iqmath bib */
%assign rollVars = ["U", "Y"]
%roll idx = RollRegions, lcv = RollThreshold, block,"Roller", rollVars
%%Assignment of the Block ports to named Variablles
%assign u1 = LibBlockInputSignal(0, "", lcv, idx)
%assign u2 = LibBlockInputSignal(1, "", lcv, idx)
%assign u3 = LibBlockInputSignal(2, "", lcv, idx)
%assign y = LibBlockOutputSignal(0, "", lcv, idx)
%%This Code is ploted to the c-file
%<y> = __IQsat(%<u2>,%<u1>,%<u3>);
%endroll
%endfunction
After this i´m able to generate code inlined from the S-Function. This works fine, but a little thing is bad. To interface the from the S-Function generated code, a structure named "Block signals (auto storage)" is used:
/* Block signals (auto storage) */
32 typedef struct {
33 int32_T Sum1; /* '<S1>/Sum1' */
34 int32_T Sum4; /* '<S1>/Sum4' */
35 };
This is bad because the controller now has to save the inputs and outputs in this structure and than load it again as parameters of the generated function. Is it possible to avoid this inefficient interfacing? In case ist is, how it can be avoided?

Answers (0)

Community Treasure Hunt

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

Start Hunting!