I have a processor that is powered by a mains 5V power from a wall adapter, and has a short term battery backup.
I need the processor to turn on automatically and immediately when 5V mains supply is present. 5V power, processor turns on.
But, if mains power is removed, the processor needs to stay powered from the battery, save to memory, and then it can assert a signal saying it is ready to turn off, which should then turn off the power.
Power can then not turn on again until the 5V mains supply is present again.
How can this be possible to do, without it entering an unstable state where the processor tries to turn off and then can't hold it off and turns back on in a loop...