|
From: Moritz S. <Mor...@in...> - 2010-10-12 07:41:25
|
Hi Sarah, whether memory needs to be aligned really depends on what you want to do. As memory can be accessed byte-wise you only need word-alignment when accessing the memory word-wise. As long as you have an byte-array and don't cast it, you _should_ be safe (The C compiler should use byte-access instead of word-access). Once you start casting you must make sure there your cast is aligned. E.g: "char buf[10]" is word aligned. If you do "(int *)&buf[1]" the result will have an unpredictable high byte (as far as I understood the manual - but it might as well just cause a reset). As you see this is rather a hardware then a software issue. And, as the msp430 hasn't got an interrupt to handle unaligned access, the OS hasn't even got a chance to do something. There are two ways to get something word aligned. Either you allocate an uint16_t array and cast it to char* or, if you use attributes: http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html Cheers Morty Am 12.10.2010 08:34, schrieb Sarah: > Hi all, > > Could someone tell me how memory access works in Contiki (with telosB/tmote sky platform)? Because this platform needs aligned memory. > How be sure that the memory is aligned... What is the reaction of the OS if the memory is not aligned (exception...)? > If I declare a table like this: buffer[256] , it can be unaligned? > > > Thanks for your help. > > Best regards, > > -- > Sarah > > > > > > -- Dipl.-Ing. Moritz 'Morty' Struebe (Wissenschaftlicher Mitarbeiter) Lehrstuhl für Informatik 4 (Verteilte Systeme und Betriebssysteme) Friedrich-Alexander-Universität Erlangen-Nürnberg Martensstr. 1 91058 Erlangen Tel : +49 9131 85-25419 Fax : +49 9131 85-28732 eMail : st...@in... WWW : http://www4.informatik.uni-erlangen.de/~morty |