A few lines of watch dog code that will monitor the status of the while loop and if it doesn't respond, reset the unit to a known state.