MATLAB: Does Real-Time Workshop 7.5 (R2010a), not generate a reusable function for the atomic subsystem with variable sized signal input or outputs

functionreusablesimulink codersize;variable

I have a model in which I have marked two identical subsystems as atomic and set to "Reusable Function" for Real-Time Workshop code generation. The input to these subsystems is a variable sized signal. However, I see in the generated code that the code is not generated as a reusable single function, but rather two functions are created. Why?

Best Answer

The ability to create a reusable function from a subsystem with variable signal inputs is not available when the maximum size for the variable signals is different between subsystems in Real-Time Workshop 7.5 (R2010a).
As a workaround, if you are able to force Simulink to see an equal maximum size for the variable sized signals, then the code generation may be able to create a reusable function for the subsystem. The attached examples ("No_reusable_function_generated", and "Force_reuse_var_signals") show how to do this with an extra switch which propagates the maximum size of the signal to the subsystem where the reusable function is desired.
"No_reusable_function_generated.mdl" is not able to generate the reusable function due to this mismatch in maximum variable signal size. "Force_reuse_var_signals.mdl" is able to propegate the same maximum sized signals to the subsystem forcing the same maximum size signal. Be sure to turn on Format -> Port/Signal Display -> Signal Dimensions to observe this behavior.