Nested Bus as S-Function input

3 Ansichten (letzte 30 Tage)
Guilherme T Silva
Guilherme T Silva am 8 Sep. 2016
Hi,
I'm trying to compile some legacy code as a s-function, and I'd like to pass a struct as input. I created a bus that replicates that struct and imports its definition from the legacy header file. One of the fields of that struct is a pointer to an array of structs.
I configured the s-function to accept a bus as input:
%
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, INPUT_0_WIDTH);
ssSetInputPortComplexSignal(S, 0, COMPLEX_NO);
ssSetInputPortDirectFeedThrough(S, 0, 1);
ssSetInputPortRequiredContiguous(S, 0, 1);
ssSetBusInputAsStruct(S, 0, IN_0_BUS_BASED);
ssSetInputPortBusMode(S, 0, SL_BUS_MODE);
Then I'm allocating memory for the struct:
%
static void mdlStart(SimStruct *S)
{
int_T *busInfo = (int_T *)malloc(sizeof(PARAM_EST_SETUP_TYPE) + 3*sizeof(DIGITAL_FILTER_BIQUAD_COEFF_TYPE));
ssSetUserData(S, busInfo);
}
Note that I added 3*sizeof(DIGITAL_FILTER_BIQUAD_COEFF_TYPE) to the malloc call in order to allocate memory for the struct array that is referenced inside PARAM_EST_SETUP_TYPE.
Finally, when I try to execute that S-Function Simulink crashes due to memory access violation. What am I doing wrong?
I'm sending my sfunction.c code attached.
Thanks,
Guilherme

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by