At command AT+CRONADD=p1,p2,p3… i populate this structure with some data…
At command AT+CRONLIST=1…i list the data from this structure
All works fine. Until i want to save this in flash memory and read it every time at : AT+CRONLIST=0
i use these code to write the data in the flash mem:
for (i=0; i<16; i++)
write = adl_flhWrite("CRON",i,sizeof(app_cronjob_set),(u8*) &Cron[i]);
And the reading part :
for (i=0; i<16;i++)
if ( adl_flhExist("CRON",i) > 0)
read = adl_flhRead("CRON",i,sizeof(app_cronjob_set), (u8*) &lstCron[i]);
I verified the returning values or adl_flhRead and adl_flhWrite …this values are ok…
but i`m obtaining some strange values:
DUMP (1,lstCron.var_set,6) = 55 55 55 55 55 55
and it should be = 01 00 01 00 00 01 - something like this
I did the same thing…at another part of my application…there i`m writing also a structure…and it works just fine…
I think i saw from where i get this problem…but i’m not sure how to solve this…
Besides reading flash with at+cronlist command…i read it with a cyclic timer at every 30 seconds.
and i saw with some traces that after 2 readings … every flash id has a size of 1 byte instead of 22 bytes …
Somehow the flash is overwritten with a byte value…but i don’t know exactly why is this happening…
Now i’m trying to limit the function called at 30 sec…to read just once… Because that’s all i need…in case of power failure…i don’t want to lose those values… and at power back to load those values back in RAM memory and start normal execution again…
Yes, that’s true…and isn’t the only function that in my opinion needs to take void* pointer parameters for data…but this is it…
I resolved my issues…the problem was that…somewhere in my app i periodically need to save in flash some paramaters from that structures that is modified by the application and in flash needs to be the last value …
I tried to write only to a member of the structure :
adl_flhWrite("CRON",i,sizeof(u8),(u8*) &flhCron[i].task_started);//update in flash
But this statement will write one byte at the starting adress of the structure and not on that specific member of the structure as i was expected…and this is why i cannot read succesfull my data…after such a writing…the structure in flash has only a byte written…
What the API is saying is what you are writing is a byte stream (ie, a series of u8s)
If it took a void* then it really wouldn’t know what was at the end of the pointer, but in this case its going to take the pointers and treat it as a stream of bytes. Its a common C idiom to serialize structures like this, however (not so relevant in this case) can be bad depending on the compiler and its byte packing.
What the API should be saying to you, the user, is that it will write any arbitrary data type that you should care to give it - just like malloc() returns a void* pointer because it allocates memory for any arbitrary data type.
Which is exactly the case!
The API neither knows nor cares anything about the data being passed to it - all it needs to know is where it starts, and how big it is.
I think you’re confusing the internal implementation with the interface to the user?