Nested Bus as S-Function input
6 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156228/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156229/image.png)
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
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!