If you are only using Retain variables in the IEC-Program, and you want to keep its values across a powerfail, Setting of the Powerfail Flag in the Policy function is enough.
This flag activates the "more advanced mechanism" as you call it, which has already been implemented in the RTS-kernel itself.
If you set the Powerfail flag, the PFI Interrupt service routine is installed by the RTS kernel. You should not install one yourself ! This PFI Handler uses the settings given in the Policy function to decide what to do. If the internal mechanism is used, it will call the hal_save_non_volatile () for you.
Also at startup time when the internal mechanism is used, the kernel will call the hal_non_volatile_init function for you.
I also read your reply in the thread "PowerFail doesn't work (saving/restoring remanent data)". This answers the question why your retains are not saved in case of a power fail. The retains area is initialised and restored before the IEC program is started. Redefining the PFI interrupt service routine after the program start event, means that in case of a powerfail not the original PFI service routine will be called, but your own. Result: the RTS internal mechanism implemented in the kernel is used to restore the data, and the mechanism you implemented yourself is used to save the data. This should be avoided. Again: Please comment out all Retain handling code you implemented yourself (including th entry in the CHIP.Ini file). Define only the Powerfail flag in the function RHICFGNonVolMemPolicy function. This should work in your case.
Please also note that using the reset button, does not generate a powerfail interrupt.