Simulink xPC C-function static variable issues

1 visualización (últimos 30 días)
Istvan
Istvan el 12 de Dic. de 2011
Hello,
I am trying to implement a Simulink model for xPC, in which I need to call a C function. This C function has some static variables, so that it remembers the value from the last step at the new step (from last call to current call).
Now the problem:
It is one function. But I call it from TWO different Simulink S-function-creator blocks. I expected that two instances are created of this funcion's object, meaning the static variables in block 1 will not be mixed with those in block 2. But this is not the case.
Could anyone please give me some advice how to isolate these instances? I.e. I what to have two instances of my C code running, so that static variables are NOT mixed. The two blocks must work competely separately.
(Note: I ask for 2 blocks here, but the issue is valid for N blocks too, so I cannot just rename my C function, as I would end up having many C functions doing the same thing).
*********************************
---- C function ---- ..... int b; static int a[100]; ....
called from (with different inputs, not shown here) -- S-function-builder block 1 -- AND -- S-function-builder block 2 -- ...
************************************
Thank you for any advice. Istvan

Respuestas (1)

Kaustubha Govind
Kaustubha Govind el 12 de Dic. de 2011
I would recommend declaring D-Work vectors in your S-functions, and work with that memory from your C-function (ie. modify it to use a passed-in pointer which will be your DWork memory, rather than static variables).
  2 comentarios
Istvan
Istvan el 13 de Dic. de 2011
Thanks you for your answer.
Yes, I saw the D-Work vectors just about now, but I am not proficient in S-function writing, so I used the S-function-builder block. There, however, there is no way of using D-Work vectors...
Do you maybe nkow a good source of a --simple-- demo for a really minimalistic C S-function using D-Work vectors?
Thanks again -
Kaustubha Govind
Kaustubha Govind el 13 de Dic. de 2011
There's a lot of S-function demos in the documentation (type "sfundemos" to see them by classification). sfcndemo_sfunmem seems like a good beginner example.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by