Power Failure recovery - PIC24F target

savexp wrote on Friday, November 09, 2012:

Target microcontroller is PIC24F256GB210 and FreeRTOS is 7.2.0.   Currently developing the application using explorer 16 development board.
Our project has a power fail recovery scenario, where in we check the power failure using an external interrupt and leave behind a cookie if power fails.  On every reset we check for this cookie, if set then we go into power fail recovery mode and the application has to start again from its last known state.  I would like to know if there is any help guide or manuals or demo projects in freertos that can help me on what to do on the freertos kernel for this scenario?  Thanks.

rtel wrote on Friday, November 09, 2012:

In a word….no.

The stat of the system has several components:

1) The value of the CPU registers.
2) The value of the RAM - which holds the stack and register values for each task.
3) The value of the program counter.

If any of these change, and you cannot recover them, then you cannot get back to the exact same state.


richard_damon wrote on Sunday, November 11, 2012:

The PIC24 family has a reset status register to tell you the reason for the reset, and you could thus detect that you didn’t have a “power fail” but something less serious that perhaps some of the ram data might be recoverable (assuming you make sure the startup routine doesn’t kill their values by marking them properly.

You will not be able to just pickup where you stopped, as not enough information will be saved/preserved.

YOUR application will need to save the data needed to restart your application “in the middle”, as this is extremely application specific. If you really want to handle going through a power-down, you will need some form of non-volitile memory in the system to keep updated with the state to restart at.