Global Variables in Simulink with Multiple Instances

I'm modeling a company's product in Simulink, and have written a C SFunction that runs the firmware successfully. The firmware is compiled from many header/source files, and makes extensive use of global variables. This is fine for single instances, but when I run simulations with more than 1 instance of my custom block there are problems. I believe this is because the global variables are being shared between the blocks. I know DWork vectors are the way around this, but I'm also trying to modify the firmware as little as possible. Does anyone know if Simulink runs single-threaded or multi-threaded (or if I can force it to run single threaded)?. Then I could just load the globals from DWork vectors before each call in mdlOutputs, then update the DWorks after.

댓글 수: 1

I tried this and it did not work. What does work is compiling 2 MEX-files with different names but identical source code so that the globals are not the same. This is a little cumbersome, but the firmware is such that the globals are there to stay. Any suggestions for a cleaner solution?

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기

질문:

2016년 6월 7일

댓글:

2016년 6월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by