From ad0ad7a973011655478e41bc58032deb4676e021 Mon Sep 17 00:00:00 2001 From: mmaroti Date: Sat, 13 Feb 2010 22:50:09 +0000 Subject: [PATCH] fix uin16_t alignment bug for the msp430 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 | 42 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/tos/lib/diagmsg/DiagMsgP.nc b/tos/lib/diagmsg/DiagMsgP.nc index 371063c0..85fab069 100644 --- a/tos/lib/diagmsg/DiagMsgP.nc +++ b/tos/lib/diagmsg/DiagMsgP.nc @@ -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) -- 2.39.2