Multi-Instance usage of S-Functions (C code) in SIMULINK

1.8k views Asked by At

I have a legacy C function in my SIMULINK model that uses some static variables in its functions. The static variables are available globally. When I reference multiple instance of my model, I get error because my S-function is not configured for that. I am getting this error message because code generation doesn't allow this.

The error message I get is the following:

The S-Function block 'ECDCTRL/PULDESC/S-Function Builder' is not supported in multi-instance Normal mode because it does not declare that it supports multiple execution instances. If the S-Function satisfies the multiple execution instances requirements, you can declare this using the SimStruct function 'ssSupportsMultipleExecInstances' in the 'mdlSetWorkWidths' method.

I am using the (MYSFUNC)_Outputs_Wrapper.c file when I build it with the auto-generated code. How can I make sure that I can use my legacy C function when using multiple references of my model? SIMULINK website suggests using ssSupportsMultipleExecInstances(SimStruct *S, bool flag) method, but it is not correct as I am not using the SimStruct header files. What is the way around?

1

There are 1 answers

1
pmb On

Use DWork vectors instead of static variables. Quoting from here:

DWork vectors have several advantages:

Provide instance-specific storage for block variables
Eliminate static and global variables