C S-Function to TLC conversion sytax help needed

11 views (last 30 days)
I need some help converting some simple C code from an S-Function to a TLC file, but I'm not familiar with the syntax enough to do so. I'm not even sure if it can be done or not.
Here's the C code:
/* Function: mdlOutputs =======================================================*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
union {real32_T x; uint8_T c[4];} sp;
real32_T *in;
uint8_T *out[4];
int_T i;
in = (real32_T *) ssGetInputPortSignal(S, 0);
sp.x = *in;
for (i=0; i<4; i++)
{
out[i] = (uint8_T *) ssGetOutputPortSignal(S, i);
*(out[i]) = sp.c[i];
}
}

Accepted Answer

Rich
Rich on 9 Feb 2012
Figured it out...
%%File : sfun_Single2FourBytes.tlc
%%Description:
Real-Time Workshop interface for S-function "sfun_Single2FourBytes.c"
%implements sfun_Single2FourBytes "C"
%function Outputs(block, system) Output
/* S-Function "sfun_Single2FourBytes" Block: %<Name> */
%assign in = LibBlockInputSignal(0, "", "", 0)
{
union {real32_T x; uint8_T c[4];} sp;
sp.x = %<in>;
%foreach i = 4
%assign out = LibBlockOutputSignal(i, "", "", 0)
%<out> = sp.c[%<i>];
%endforeach
}
%endfunction
%%[EOF] sfun_Single2FourBytes.tlc

More Answers (0)

Categories

Find more on Simulink Coder 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!