필터 지우기
필터 지우기

Simulink xPC C-function static variable issues

조회 수: 1 (최근 30일)
Istvan
Istvan 2011년 12월 12일
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

답변 (1개)

Kaustubha Govind
Kaustubha Govind 2011년 12월 12일
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
Istvan
Istvan 2011년 12월 13일
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 2011년 12월 13일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by