I am trying to create a level two s function with custom C, TLC, and a generator script. I am working with a legacy codebase that I cannot copy paste into this question. However, what I am trying to do shouldn't be too complicated. I want an s function to be able to take as input any bus type. Then, in C, I cast that input variable to (void *) and pass it into my C function in mdlOutputs. The existing code has a mask parameter where you manually type the type name into the sfunc and then use ssRegisterTypeFromParameter, and ssSetInputPortDataType to set the input type of the block. To be honest I do not know enough about matlab and simulink to be doing this, but I am pretty sure there should be a way to inherit a bus type. I don't understand why it asks for the input port width when I am telling it that it will inherit the input port type? I have tried using ssSetInputPortDataType(S, 0, DYNAMICALLY_TYPED); and including the required helper functions
void mdlSetDefaultPortDataTypes(SimStruct *S)
{
if (ssGetInputPortDataType(S, 0) == DYNAMICALLY_TYPED) {
ssSetInputPortDataType(S, 0, SS_UINT32 );//I chose uint32 randomly??
}
}
and
void mdlSetInputPortDataType(SimStruct *S, int_T port, DTypeId id)
{
ssSetInputPortDataType(S, port, id);
}
but I keep getting errors about my input/output dimension. And errors that mention type. It would be really helpful if someone could point me to a code example of a level 2 s function written in C that can take any user defined bus type as an input. Or if that code example doesn't exist, what are the required setup functions and parameters to do something like this? As a last question, I am making this model for a code base that is converted into C code before it is compiled which I think is why there is a custom TLC included in the generator script, but if anyone could explain why the TLC is necessary/what it is doing that would be very helpful as well.
Sorry I can't post more specific examples, and thanks for looking at the question!