This code is most useful for implementing non-volatile arrays,
...
...
@@ -57,7 +57,7 @@ double *arrayInFlash;
to declare an array of doubles named "arrayInFlash".
The asterisk ( * ) before the array name is important.
The scope of the array is determined by where the declaration is made.
If outside of any function, the scope is global (all functions can see the array), while if it is inside a function, it will be seen only within that function , and others to which it is passed in the function argument list.
If outside of any function, the scope is global (all functions can see the array), while if it is inside a function, it will be seen only within that function , and others to which it is passed in function argument lists.
The second step is to specify where and how big the array is.
This is done using a macro:
...
...
@@ -91,14 +91,16 @@ as doing so defeats the non-volatility property of flash.
Valid datatypes for arrays in flash using this library include structs and typedefs, in addition to the predefined C datatypes. Structs appear to default to multiples of flash words, so the programmer's attention to alignment issues does not appear to be neccessary.
Some limitations: the sizeof operator on any array in flash will always return 4 (=flashBytesPerWord). Also, C string functions like strcpy and strlen do not always work as one would expect to manipulate the arrays in flash, 'tho memcpy and strcpy do work to copy the contents out of flash, and memcpy does work to copy into flash if the number of bytes is a multple of flashBytesPerWord. I recommend using macros (ie. #define) or variables to declare the number of array elements as the sketch cannot easily figure out by itself how big a flash array has been declared after the declaration.
Some limitations: the sizeof() operator on any array in flash will always return 4 (=flashBytesPerWord).
Also, C string functions like strcpy() and strlen() do not always work as one would expect to manipulate the arrays in flash, 'tho memcpy() and strcpy() do work to copy the contents out of flash, and memcpy() does work to copy into flash if the number of bytes is a multple of flashBytesPerWord.
I recommend using macros (ie. #define) or variables to declare the number of array elements as the sketch cannot easily figure out by itself how big a flash array has been declared after the declaration.
If you want more control over the details of the declarations in flash,