Well said! Just one thing I wanted to add:
> For instance, say I kept writing mystructs at MYBASE_ADDRESS + offset * > number of mystructs, and I needed them to be persistent across reboots. You might want to look at the LogRead/LogWrite interfaces as well (http://www.tinyos.net/tinyos-2.x/doc/html/tep103.html, 4.3 Logging). LogStorage is specifically designed for logging successive values. HTH, Michiel From: [email protected] [mailto:[email protected]] On Behalf Of Johny Mattsson Sent: donderdag 1 maart 2012 23:45 To: Max Cato Cc: [email protected] Subject: Re: [Tinyos-help] Using BlockWrite.write and BlockWrite.erase Hi Max, The BlockWrite interface is almost a direct mapping onto the way (most/all?) flash chips works at a driver-hardware interface level. Flash starts out with all bits set. The act of writing to the flash then unsets the bits necessary to achieve the desired result. The only way to set those bits again however, is through a block erase which sets all bits back to one. This is where the requirement to only write each block once between erases - writing the same block multiple times will typically lead to corrupt values (with some obvious exceptions where the new values can be achieved simply by unsetting more bits from the previous values). You don't mention what your "mystruct" really is used for, but based on the usage pattern you describe, you might be better off looking at ConfigStorage interface instead. It provides a significantly higher abstraction level, and can be used when you only want to update a part of your struct. If you still want/need to use BlockWrite, then yes, the approach of read-block, erase, write-modified-block is the way to do it. If you're updating values in flash very frequently, you should probably also give a bit of thought to wear-leveling, given flash memory has a limited amount of write/erase cycles. Cheers, /Johny On 2 March 2012 09:10, Max Cato <[email protected]> wrote: Hi, First off, thanks to the people who help out on this list! You guys are great :) I'm having a little difficulty understanding the BlockWrite interface. The documentation states that between power cycles, no block may be written to more than once. So, let's say I have a small struct at the beginning of my memory, defined as: struct mystruct { uint32_t myValue1; uint32_t myValue2; } mystruct; And I'm writing to MYBASE_ADDRESS. Does this mean that in order to do successive calls of BlockWrite.write(MYBASE_ADDRESS, &mystruct, sizeof(mystruct)) I have to first call BlockWrite.erase()? If so, this seems like a bad implementation-- what if I wanted to have more items written to the memory? For instance, say I kept writing mystructs at MYBASE_ADDRESS + offset * number of mystructs, and I needed them to be persistent across reboots. I would lose them to effect this one write. Would I first need to copy out all of the data I wanted to save, change mystruct (at whichever address I wanted to change), and then write the whole thing back? This also seems problematic. Could someone help me understand what is the "proper" way to go about this? Also, if someone could help me understand why only one write cycle is allowed between successive power cycles, I'd greatly appreciate it :) Thanks for your time! -Max _______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help -- Johny Mattsson Senior Software Engineer DiUS Computing Pty. Ltd. where ideas are engineered
_______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
