Someone once told me naming was everything.Fred wrote:When we get told to go to sleep, we need to turn off clocks and so on and so forth and set a flag and disable the main loop, possibly by changing while(TRUE) to while(allSystemsAreGo) where the value of that condition is dependent on clock and sleep states etc.

Not trying to micro manage the shit out of you but...
while(allSystemsAreGo) -> Not so good variable naming.
while(awake) -> better
while(!sleeping) -> better still?