I want to develop a software that can restore the program after a power failure. I mean, if the device restart, I don't want it to execute from the beginning of the main function. What should I do to store the state of the program and how can I restore the program state after a power failure ? Thanks.