I'm trying to use the Simulink coder to codegen a fairly complex model into an S-Function block in order to improve the performance of the model. I can do this, but when I do, all of the states in the model vanish and become inaccessible from outside the S-Funcion. When I call Simulink.BlockDiagram.getInitialState() on the model with the generated S-Function block, it returns an empty array.
I have previously been able to access states inside generated S-Function blocks which were created for less complex models, so I know it should be possible. The states are (for the moment) just a bunch of Unit Delay blocks located inside a (non-Atomic) Subsystem. There are Reference Models in the model, but there are currently not any states in the Reference Models.
I've dug around in some of the codegen'd C-code, and the "Subsystem_sf.c" file actually calls "ssSetNumDiscStates(S, 0);", explicitly setting the number of discrete states to zero. This is dispite the same function actually initializing all of the variables for the states, which are currently set to "ImportedExternPointer". (I have tried other settings of the Code Generation Storage Class, and it does not appear to make any difference).
Any idea why my states are disappearing on me?