1

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?

tanascius
  • 53,078
  • 22
  • 114
  • 136
ha9u63a7
  • 6,233
  • 16
  • 73
  • 108
  • 1
    You have a general problem with static variables and multiple instances. Consider using DWork vectors in your SFunction instead. – pmb Dec 09 '13 at 11:58
  • Could you clarify a bit more? I am not familiar with it. – ha9u63a7 Dec 09 '13 at 12:00

1 Answers1

3

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
pmb
  • 866
  • 7
  • 24
  • Thanks! A colleague of mine came up with a SIMULINk based solution and replace the S-function block. phew!! – ha9u63a7 Dec 09 '13 at 16:06