]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
fix uin16_t alignment bug for the msp430
authormmaroti <mmaroti>
Sat, 13 Feb 2010 22:50:09 +0000 (22:50 +0000)
committermmaroti <mmaroti>
Sat, 13 Feb 2010 22:50:09 +0000 (22:50 +0000)
Committed on the Free edition of March Hare Software CVSNT Server.
Upgrade to CVS Suite for more features and support:
http://march-hare.com/cvsnt/

tos/lib/diagmsg/DiagMsgP.nc

index 371063c063a698c2c374fe0fc113b775d0a1420f..85fab069180f4f196eb0148a4c03d134bc4562ca 100644 (file)
@@ -178,26 +178,32 @@ implementation
                return ret;
        }
 
-#define IMPLEMENT(NAME, TYPE, TYPE2) \
-       async command void DiagMsg.NAME(TYPE value) \
-       { \
-               int8_t start = allocate(sizeof(TYPE), TYPE2); \
-               if( start >= 0 ) \
-                       *(TYPE*)((uint8_t*) &(recording->data) + start) = value; \
-       } \
-       async command void DiagMsg.NAME##s(const TYPE *value, uint8_t len) \
-       { \
-               int8_t start; \
-               if( len > 15 ) len = 15; \
-               start = allocate(sizeof(TYPE)*len + 1, TYPE_ARRAY); \
-               if( start >= 0 ) \
-               { \
-                       ((uint8_t*) &(recording->data))[start++] = (TYPE2 << 4) + len; \
-                       while( len-- != 0 ) \
-                               ((TYPE*)((uint8_t*) &(recording->data) + start))[len] = value[len]; \
-               } \
+       void copyData(uint8_t size, uint8_t type2, const void* data)
+       {
+               int8_t start = allocate(size, type2);
+               if( start >= 0 )
+                       memcpy(&(recording->data[start]), data, size);
        }
 
+       void copyArray(uint8_t size, uint8_t type2, const void* data, uint8_t len)
+       {
+               int8_t start;
+
+               if( len > 15 )
+                       len = 15;
+
+               start = allocate(size*len + 1, TYPE_ARRAY);
+               if( start >= 0 )
+               {
+                       recording->data[start] = (type2 << 4) + len;
+                       memcpy(&(recording->data[start + 1]), data, size*len);
+               }
+       }
+       
+#define IMPLEMENT(NAME, TYPE, TYPE2) \
+       async command void DiagMsg.NAME(TYPE value) { copyData(sizeof(TYPE), TYPE2, &value); } \
+       async command void DiagMsg.NAME##s(const TYPE *value, uint8_t len) { copyArray(sizeof(TYPE), TYPE2, value, len); }
+
        IMPLEMENT(int8, int8_t, TYPE_INT8)
        IMPLEMENT(uint8, uint8_t, TYPE_UINT8)
        IMPLEMENT(hex8, uint8_t, TYPE_HEX8)