Hello there,
i’ve got FreeRTOS working, my only problem is my lost temperature-curves. My controller crashed randomly, probably because of unshielded wires to the roof. One evenening when i came home, all my recorded temperature values were lost.
To be honest, i don’t think there is a solution for my little problem right now. I’m working on it in free time. What i really need is a flash-memory that is working with power-loss, and i’m almost there.
I’ve implemented a memory-manager and tested it in memory. My next step is to transport it to flash-memory. It is not really difficult for me anymore, i’m sure it is working. Because i’m not comfortable with the current API of FreeRTOS You may have to do these steps on Your own.
Here is the goal:
auto list=flash_list_open(“buf_temp”);
flash_list_set_at(list, time, temp);
You can transport my heap one by one to flash-memory. The first interesting field in the header is the ‘used’-value. It is rapidly changing when filling memory and takes the first two blocks in flash-memory itself. Whenever changed, the new value is appended in both blocks until both blocks are full. Then the blocks are erased one after another, so there is always a reliable value.
When creating the maps of used and free blocks, the fastest option is to only store a group of 10 items in one block, and to append changes. There are two functions:
flash_alloc() and flash_free()
Because the created blocks need to be mapped, the only way is to overwrite existing entries. So there is the need of third function, and now it is getting funny somehow:
flash_flush()
Overwriting causes an update to be created in memory first. As soon as You call flash_flush() the update is stored in free space. I use a simple formula to move it around in free space and save the flash-chip. If there is power-loss, an update is found or not. Overwriting is repeated on power-loss, all data is reliable.
If You follow this simple concept, Your customers don’t need to buy batteries for backup anymore.
Best regards,
Sven