When my application crashes, a previously written variable will not be saved persistently.
I am currently implementing a checkpoint variable. It is supposed to show which checkpoint/section has been reached after a crash. With this I intend to find sections with code errors, which lead to crashes.
The variable is defined as global retain persistent. The first thing that happens when the program starts, is that this variable will be evaluated once and sent by CAN.
By now I have a method with which I can let my program crash. I used the method to test my checkpoint variable, if it is written properly after a crash.
Unfortunately, this is not the case. The last written and transmitted value is 5 segments old. So, the variable is written multiple times, in different segments, then is written a last time and then the program is being let crashed.
If I think about C/C++, what comes to my mind is the keyword 'volatile'.
There is only one task, so it will most likely not be a problem of multiprocessing.
I also added a loop with 1000 iterations for a test. It probably also doesn't have anything to do with code ordering/ optimization. (Notable is, this code is running on an operative system and is intended for diagnosis. So, it is not reasonable to wait 5ms after writing a checkpoint variable.)
Is it possible, that this variable is being written to a cache before it is being put into the flash?
Is it possible to make a variable 'volatile'? ('volatile' in the meaning like in C, being written to the RAM/Flash without cache optimization)
Is there another possible reason for my problem?
Is there a flush-method to actively write to the flash, without any cache?
Is there a bread crumb register to write to, which is more reasonable for my purpose?
Best regards and thanks in advance
I ran into similar problem, and according to what the codesys guy told me, the remain vars are written to retain file ON SHUTTING DOWN. This means that if your application crashes or on power cut it will not be able to store them. More importantly, it may lead to corrupted retain file (open in RW), similar like what happens with config file.
We decided to proceed with our own implementation of retain file, however we got no answer yet if it is possible to alter codesys's implementation of retain file.
Log in to post a comment.