I am working on RM48L952 controller on the oscillator switching functionality. I have a clock (square wave) of 16MHz coming from an external oscillator and connected to the OSCIN pin of the controller. Normally, after power on my controller works on the external clock and when I manually disconnect the external clock it switches to the internal clock (confirmed by toggling an output pin and observed on DSO). This happens automatically. But now I want to ensure that when my external clock gets healthy again (not manually disconnected), I want to switch back to the external clock. In process of doing this, as per the Technical Reference Manual, I am supposed to clear the OSC_FAIL bit of the GLBSTAT register. But I have observed that it shows random behaviour, i.e at times I am able to clear it but the other times I get stuck in the while loop when I am waiting for that bit to get cleared.