Simulink xPC C-function static variable issues
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
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
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.
Ver también
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!