Hi Faris,
Since Simulink works based on the discrete time steps, the continuous while loop causes the simulation to not being able to advance to the next step. This is what causes the freeze while simulation. To integrate such a function without freezing the simulation, you need to adapt your approach to fit within the Simulink simulation framework.
Since modifying the C++ code directly is not possible, consider wrapping the C++ code call in a MATLAB function that manages the execution flow to prevent the simulation from freezing. This approach might involve checking a condition and breaking the loop based on simulation time or another criterion that changes with each simulation step.
Another option could be to use state machines or timers to control the loop execution within the S-Function. It’s also important to ensure that the loop has proper exit conditions to prevent infinite looping.
You can find the documentation link for the S-functions at: https://www.mathworks.com/help/simulink/sfg/what-is-an-s-function.html#f6-54075
Hope this helps!