Flash storage – Wavetronix Click 500 (programmable controller) (CLK-500) - Developer Guide User Manual
Page 110
CHAPTER 10 • MEMORY MANAGEMENT 109
below 0x1000. You will notice by looking at the corresponding .map file that variables Mes-
sage1 through Message4, which are of type constant far char[], are actually placed within
this block.
Flash Storage
The user block can be used to store data and parameters in non-volatile flash memory.
However, not all of the 32 K bytes are available because it is reserved by the BIOS. About 8
K are available for use in a ping-pong double buffer scheme. This scheme prevents data loss
if power is lost while writing to flash.
The Click 500 library reserves 6 K of the 8 K for Click Supervisor and menu system support.
The remaining 2 K (2276) bytes are available for storing data and parameters.
The ClickflashRead and ClickflashWrite functions can be used to read and write data to this
2 K block. These functions are passed the following three parameters:
1 Pointer to SRAM memory containing data to flash.
2 Number of bytes to read/write.
3 An offset into the memory block from 0 to 2275.
It is recommended that you organize your data into structures. Multiple structures can be
stored at different offsets. The SRAM flashData structure in the following code block uses
almost the entire block because dataArray1 and dataArray2 use long variables and consume
2048 bytes alone. Consider limiting the size of variables in order to maximize use of the 2
K block.
struct
{
int messageIdx;
long dataArray1[256];
long dataArray2[256];
ClickUtilTime timeRecord;
} flashData;
A setup function can be used to load data from flash into SRAM. While doing so, it is im-
portant to check the validity of the data. For example, when the device boots for the first
time, the flashData.messageIdx is likely to be outside the bounds 0 and 3.