Fixed alignments problems on some 32bit target such as ARM or Xscale.
authoretisserant
Wed, 04 Jun 2008 11:04:24 +0200
changeset 474 09c8c4b6c7df
parent 473 8cecdb44533e
child 475 4b63ea646964
Fixed alignments problems on some 32bit target such as ARM or Xscale.
src/dcf.c
src/pdo.c
--- a/src/dcf.c	Wed Jun 04 11:03:11 2008 +0200
+++ b/src/dcf.c	Wed Jun 04 11:04:24 2008 +0200
@@ -130,10 +130,29 @@
         	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 @@
  	
    	/* 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;
 
   }
--- a/src/pdo.c	Wed Jun 04 11:03:11 2008 +0200
+++ b/src/pdo.c	Wed Jun 04 11:04:24 2008 +0200
@@ -630,15 +630,8 @@
                   /*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 */