From 182650b55a1e47b5342f34273c9313445c973a7b Mon Sep 17 00:00:00 2001 From: etisserant Date: Wed, 4 Jun 2008 09:04:24 +0000 Subject: [PATCH] Fixed alignments problems on some 32bit target such as ARM or Xscale. --- src/dcf.c | 29 ++++++++++++++++++++++++----- src/pdo.c | 11 ++--------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/dcf.c b/src/dcf.c index ea63cfc..891efa8 100644 --- a/src/dcf.c +++ b/src/dcf.c @@ -130,10 +130,29 @@ static void send_consise_dcf_loop(CO_Data* d,UNS8 nodeId) UNS8 target_Subindex; UNS32 target_Size; - /* pointer to the DCF string for NodeID */ - target_Index = UNS16_LE(*((UNS16*)(d->dcf_cursor))); d->dcf_cursor += 2; - target_Subindex = *((UNS8*)((UNS8*)d->dcf_cursor++)); - target_Size = UNS32_LE(*((UNS32*)(d->dcf_cursor))); d->dcf_cursor += 4; + /* DCF data may not be 32/16b aligned, + * we cannot directly dereference d->dcf_cursor + * as UNS16 or UNS32 + * Do it byte per byte taking care on endianess*/ +#ifdef CANOPEN_BIG_ENDIAN + target_Index = *(d->dcf_cursor++) << 8 | + *(d->dcf_cursor++); +#else + memcpy(&target_Index, d->dcf_cursor,4); + d->dcf_cursor+=2; +#endif + + target_Subindex = *(d->dcf_cursor++); + +#ifdef CANOPEN_BIG_ENDIAN + target_Size = *(d->dcf_cursor++) << 24 | + *(d->dcf_cursor++) << 16 | + *(d->dcf_cursor++) << 8 | + *(d->dcf_cursor++); +#else + memcpy(&target_Size, d->dcf_cursor,4); + d->dcf_cursor+=4; +#endif _writeNetworkDict(d, /* CO_Data* d*/ nodeId, /* UNS8 nodeId*/ @@ -165,7 +184,7 @@ static void send_consise_dcf_loop(CO_Data* d,UNS8 nodeId) /* Check the next element*/ nodeId=(nodeId+1) % d->dcf_odentry->bSubCount; - if(nodeId==d->dcf_odentry->bSubCount)nodeId=1; + if(nodeId==0)nodeId=1; d->dcf_cursor = NULL; } diff --git a/src/pdo.c b/src/pdo.c index 9adff53..a8cdd59 100644 --- a/src/pdo.c +++ b/src/pdo.c @@ -630,15 +630,8 @@ _sendPDOevent (CO_Data * d, UNS8 isSyncEvent) /*Compare new and old PDO */ if (d->PDO_status[pdoNum].last_message.cob_id == pdo.cob_id && d->PDO_status[pdoNum].last_message.len == pdo.len && -#ifdef UNS64 - *(UNS64 *) (&d->PDO_status[pdoNum].last_message. - data[0]) == *(UNS64 *) (&pdo.data[0]) -#else /* don't ALLOW_64BIT_OPS */ - *(UNS32 *) (&d->PDO_status[pdoNum].last_message. - data[0]) == *(UNS32 *) (&pdo.data[0]) - && *(UNS32 *) (&d->PDO_status[pdoNum].last_message. - data[4]) == *(UNS32 *) (&pdo.data[4]) -#endif + memcmp(d->PDO_status[pdoNum].last_message.data, + pdo.data, 8) == 0 ) { /* No changes -> go to next pdo */ -- 2.39.2