]> rtime.felk.cvut.cz Git - CanFestival-3.git/commitdiff
Fixed alignments problems on some 32bit target such as ARM or Xscale.
authoretisserant <etisserant>
Wed, 4 Jun 2008 09:04:24 +0000 (09:04 +0000)
committeretisserant <etisserant>
Wed, 4 Jun 2008 09:04:24 +0000 (09:04 +0000)
src/dcf.c
src/pdo.c

index ea63cfc9bf92d10e79b05b3092353b7e659faabb..891efa8d601070b358a0eb45e6c8d1fb32bcdeae 100644 (file)
--- 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;
 
   }
index 9adff5386871b080020c37591d1f0cde85d09e95..a8cdd591a708f35d5574b80a9d567f4cfd3f1437 100644 (file)
--- 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 */