Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
authoretisserant
Fri, 25 Jan 2008 19:01:58 +0100
changeset 370 6fecf36df407
parent 369 8b67289d50b5
child 371 b13cfb3c6c16
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
src/emcy.c
src/lifegrd.c
src/lss.c
src/nmtMaster.c
src/nmtSlave.c
src/pdo.c
src/sdo.c
src/states.c
src/sync.c
--- a/src/emcy.c	Fri Jan 25 12:00:38 2008 +0100
+++ b/src/emcy.c	Fri Jan 25 19:01:58 2008 +0100
@@ -35,6 +35,7 @@
 #include <data.h>
 #include "emcy.h"
 #include "canfestival.h"
+#include "sysdep.h"
 
 
 
@@ -100,7 +101,7 @@
   
 	MSG_WAR(0x3051, "sendEMCY", 0);
   
-	m.cob_id = *d->error_cobid;
+	m.cob_id = UNS16_LE(*(UNS16*)d->error_cobid);
 	m.rtr = NOT_A_REQUEST;
 	m.len = 8;
 	m.data[0] = errCode & 0xFF;        /* LSB */
@@ -238,7 +239,7 @@
 	}
 	
 	/* post the received EMCY */
-	nodeID = m->cob_id & 0x7F;
+	nodeID = UNS16_LE(m->cob_id) & 0x7F;
 	errCode = m->data[0] | ((UNS16)m->data[1] << 8);
 	errReg = m->data[2];
 	(*d->post_emcy)(nodeID, errCode, errReg);
--- a/src/lifegrd.c	Fri Jan 25 12:00:38 2008 +0100
+++ b/src/lifegrd.c	Fri Jan 25 19:01:58 2008 +0100
@@ -36,6 +36,7 @@
 #include "lifegrd.h"
 #include "canfestival.h"
 #include "dcf.h"
+#include "sysdep.h"
 
 
 void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id);
@@ -101,7 +102,8 @@
       if (nodeId == *d->bDeviceNodeId )
         {
           Message msg;
-          msg.cob_id = *d->bDeviceNodeId + 0x700;
+          UNS16 tmp = *d->bDeviceNodeId + 0x700;
+          msg.cob_id = UNS16_LE(tmp);
           msg.len = (UNS8)0x01;
           msg.rtr = 0;
           msg.data[0] = d->nodeState;
@@ -177,8 +179,8 @@
       ** (decimal) and additionaly
       ** the node-id of this device.
       */
-
-      msg.cob_id = *d->bDeviceNodeId + 0x700;
+      UNS16 tmp = *d->bDeviceNodeId + 0x700;
+      msg.cob_id = UNS16_LE(tmp);
       msg.len = (UNS8)0x01;
       msg.rtr = 0;
       msg.data[0] = d->nodeState; /* No toggle for heartbeat !*/
--- a/src/lss.c	Fri Jan 25 12:00:38 2008 +0100
+++ b/src/lss.c	Fri Jan 25 19:01:58 2008 +0100
@@ -41,6 +41,7 @@
 #include "data.h"
 #include "lss.h"
 #include "canfestival.h"
+#include "sysdep.h"
 
 //#define LSS_TIMEOUT_MS	(TIMEVAL)1000  /* ms */
 //#define LSS_FS_TIMEOUT_MS	(TIMEVAL)100  /* ms */
@@ -280,7 +281,7 @@
   m.len = 8;
   m.rtr = NOT_A_REQUEST;
   m.data[0]=command;
-  m.cob_id=SLSS_ADRESS;
+  m.cob_id=UNS16_LE(SLSS_ADRESS);
   
   /* Tha data sent with the msg depends on the command */
   switch(command){
@@ -331,7 +332,7 @@
   m.len = 8;
   m.rtr = NOT_A_REQUEST;
   m.data[0]=command;
-  m.cob_id=MLSS_ADRESS;
+  m.cob_id=UNS16_LE(MLSS_ADRESS);
   
   /* Tha data sent with the msg depends on the command */	
   switch(command){
--- a/src/nmtMaster.c	Fri Jan 25 12:00:38 2008 +0100
+++ b/src/nmtMaster.c	Fri Jan 25 19:01:58 2008 +0100
@@ -32,6 +32,7 @@
 */
 #include "nmtMaster.h"
 #include "canfestival.h"
+#include "sysdep.h"
 
 /*!
 **
@@ -71,13 +72,14 @@
 {
   Message m;
 
-  MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId);
-
   /* message configuration */
-  m.cob_id = nodeId | (NODE_GUARD << 7);
+  UNS16 tmp = nodeId | (NODE_GUARD << 7); 
+  m.cob_id = UNS16_LE(tmp);
   m.rtr = REQUEST;
   m.len = 1;
 
+  MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId);
+
   return canSend(d->canHandle,&m);
 }
 
--- a/src/nmtSlave.c	Fri Jan 25 12:00:38 2008 +0100
+++ b/src/nmtSlave.c	Fri Jan 25 19:01:58 2008 +0100
@@ -33,6 +33,7 @@
 #include "nmtSlave.h"
 #include "states.h"
 #include "canfestival.h"
+#include "sysdep.h"
 
 /*!
 ** put the slave in the state wanted by the master
@@ -105,7 +106,10 @@
   MSG_WAR(0x3407, "Send a Boot-Up msg ", 0);
 
   /* message configuration */
-  m.cob_id = NODE_GUARD << 7 | *d->bDeviceNodeId;
+  {
+	  UNS16 tmp = NODE_GUARD << 7 | *d->bDeviceNodeId; 
+	  m.cob_id = UNS16_LE(tmp);
+  }
   m.rtr = NOT_A_REQUEST;
   m.len = 1;
   m.data[0] = 0x00;
--- a/src/pdo.c	Fri Jan 25 12:00:38 2008 +0100
+++ b/src/pdo.c	Fri Jan 25 19:01:58 2008 +0100
@@ -24,6 +24,7 @@
 #include "pdo.h"
 #include "objacces.h"
 #include "canfestival.h"
+#include "sysdep.h"
 
 /*!
 ** @file   pdo.c
@@ -54,7 +55,7 @@
 	UNS8 offset = 0x00;
 	const UNS8* pMappingCount = (UNS8*) TPDO_map->pSubindex[0].pObject;
 
-	pdo->cob_id = *(UNS32*)TPDO_com->pSubindex[1].pObject & 0x7FF;
+	pdo->cob_id = *(UNS16*)TPDO_com->pSubindex[1].pObject & UNS16_LE(0x7FF);
 	pdo->rtr = NOT_A_REQUEST;
 
 	MSG_WAR(0x3009, "  PDO CobId is : ", *(UNS32*)TPDO_com->pSubindex[1].pObject);
@@ -107,7 +108,7 @@
 **/
 UNS8 sendPDOrequest( CO_Data* d, UNS16 RPDOIndex )
 {
-  UNS32 * pwCobId;
+  UNS16 * pwCobId;
   UNS16 offset = d->firstIndex->PDO_RCV;
   UNS16 lastIndex = d->lastIndex->PDO_RCV;
 
@@ -121,7 +122,7 @@
     offset += RPDOIndex - 0x1400;  
     if (offset <= lastIndex) {
       /* get the CobId*/
-      pwCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject;
+      pwCobId = (UNS16*) d->objdict[offset].pSubindex[1].pObject;
 
       MSG_WAR(0x3930, "sendPDOrequest cobId is : ",*pwCobId);
       {
@@ -158,7 +159,7 @@
   UNS32 *    pMappingParameter = NULL;
   UNS8  *    pTransmissionType = NULL; /* pointer to the transmission
                                          type */
-  UNS32 *    pwCobId = NULL;
+  UNS16 *    pwCobId = NULL;
   UNS8       Size;
   UNS8       offset;
   UNS8       status;
@@ -168,7 +169,7 @@
   
   status = state2;
 
-  MSG_WAR(0x3935, "proceedPDO, cobID : ", ((*m).cob_id & 0x7ff));
+  MSG_WAR(0x3935, "proceedPDO, cobID : ", ((*m).cob_id & UNS16_LE(0x7ff)));
   offset = 0x00;
   numPdo = 0;
   numMap = 0;
@@ -187,7 +188,7 @@
         case state2:
           /* get CobId of the dictionary correspondant to the received
              PDO */
-          pwCobId = (UNS32*) d->objdict[offsetObjdict].pSubindex[1].pObject;
+          pwCobId = (UNS16*) d->objdict[offsetObjdict].pSubindex[1].pObject;
           /* check the CobId coherance */
           /*pwCobId is the cobId read in the dictionary at the state 3
             */
@@ -278,7 +279,7 @@
       case state1:/* check the CobId */
         /* get CobId of the dictionary which match to the received PDO
          */
-        pwCobId = (UNS32*) (d->objdict + offsetObjdict)->pSubindex[1].pObject;
+        pwCobId = (UNS16*) (d->objdict + offsetObjdict)->pSubindex[1].pObject;
         if ( *pwCobId == (*m).cob_id ) {
           status = state4;
           break;
--- a/src/sdo.c	Fri Jan 25 12:00:38 2008 +0100
+++ b/src/sdo.c	Fri Jan 25 19:01:58 2008 +0100
@@ -35,6 +35,7 @@
 #include "objacces.h"
 #include "sdo.h"
 #include "canfestival.h"
+#include "sysdep.h"
 
 /* Uncomment if your compiler does not support inline functions */
 #define NO_INLINE 
@@ -502,7 +503,7 @@
   UNS8 found = 0;
   Message m;
   UNS8 i;
-  UNS32 * pwCobId = NULL;
+  UNS16 * pwCobId = NULL;
   UNS8 * pwNodeId = NULL;
 
   MSG_WAR(0x3A38, "sendSDO",0);
@@ -551,7 +552,7 @@
       return 0xFF;
     }
     /* Second, read the cobid client->server */
-    pwCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject;
+    pwCobId = (UNS16*) d->objdict[offset].pSubindex[1].pObject;
   }
   /* message copy for sending */
   m.cob_id = *pwCobId;
@@ -619,7 +620,7 @@
   UNS8 subIndex;
   UNS32 abortCode;
   UNS8 i,j;
-  UNS32 *     pCobId = NULL;
+  UNS16 *pCobId = NULL;
   UNS16 offset;
   UNS16 lastIndex;
 
@@ -635,7 +636,7 @@
 	  MSG_ERR(0x1A61, "Subindex 1  not found at index ", 0x1200 + j);
 	  return 0xFF;
 	}
-      pCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject;
+      pCobId = (UNS16*) d->objdict[offset].pSubindex[1].pObject;
       if ( *pCobId == (*m).cob_id ) {
 	whoami = SDO_SERVER;
 	MSG_WAR(0x3A62, "proceedSDO. I am server. index : ", 0x1200 + j);
@@ -658,7 +659,7 @@
 	 return 0xFF;
        }
        /* a) Looking for the cobid received. */
-       pCobId = (UNS32*) d->objdict[offset].pSubindex[2].pObject;
+       pCobId = (UNS16*) d->objdict[offset].pSubindex[2].pObject;
        if (*pCobId == (*m).cob_id ) {
 	 /* b) cobid found, so reading the node id of the server. */
 	 pNodeId = (UNS8*) d->objdict[offset].pSubindex[3].pObject;
--- a/src/states.c	Fri Jan 25 12:00:38 2008 +0100
+++ b/src/states.c	Fri Jan 25 19:01:58 2008 +0100
@@ -37,6 +37,8 @@
 #ifdef CO_ENABLE_LSS
 #include "lss.h"
 #endif
+#include "sysdep.h"
+
 /** Prototypes for internals functions */
 /*!                                                                                                
 **                                                                                                 
@@ -67,10 +69,11 @@
 **/  
 void canDispatch(CO_Data* d, Message *m)
 {
-	 switch(m->cob_id >> 7)
+	UNS16 cob_id = UNS16_LE(m->cob_id);
+	 switch(cob_id >> 7)
 	{
 		case SYNC:		/* can be a SYNC or a EMCY message */
-			if(m->cob_id == 0x080)	/* SYNC */
+			if(cob_id == 0x080)	/* SYNC */
 			{
 				if(d->CurrentCommunicationState.csSYNC)
 					proceedSYNC(d);
@@ -107,11 +110,11 @@
 #ifdef CO_ENABLE_LSS
 		case LSS:
 			if (!d->CurrentCommunicationState.csLSS)break;
-			if ((*(d->iam_a_slave)) && m->cob_id==MLSS_ADRESS)
+			if ((*(d->iam_a_slave)) && cob_id==MLSS_ADRESS)
 			{
 				proceedLSS_Slave(d,m);
 			}
-			else if(!(*(d->iam_a_slave)) && m->cob_id==SLSS_ADRESS)
+			else if(!(*(d->iam_a_slave)) && cob_id==SLSS_ADRESS)
 			{
 				proceedLSS_Master(d,m);
 			}
@@ -270,12 +273,14 @@
     /* Adjust COB-ID Client->Server (rx) only id already set to default value or id not valid (id==0xFF)*/
     if((*(UNS32*)d->objdict[offset].pSubindex[1].pObject == 0x600 + *d->bDeviceNodeId)||(*d->bDeviceNodeId==0xFF)){
       /* cob_id_client = 0x600 + nodeId; */
-      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = 0x600 + nodeId;
+      UNS32 tmp = 0x600 + nodeId;
+      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = UNS32_LE(tmp);
     }
     /* Adjust COB-ID Server -> Client (tx) only id already set to default value or id not valid (id==0xFF)*/
     if((*(UNS32*)d->objdict[offset].pSubindex[2].pObject == 0x580 + *d->bDeviceNodeId)||(*d->bDeviceNodeId==0xFF)){
       /* cob_id_server = 0x580 + nodeId; */
-      *(UNS32*)d->objdict[offset].pSubindex[2].pObject = 0x580 + nodeId;
+        UNS32 tmp = 0x580 + nodeId;
+      *(UNS32*)d->objdict[offset].pSubindex[2].pObject = UNS32_LE(tmp);
     }
   }
 
--- a/src/sync.c	Fri Jan 25 12:00:38 2008 +0100
+++ b/src/sync.c	Fri Jan 25 19:01:58 2008 +0100
@@ -39,6 +39,7 @@
 #include "data.h"
 #include "sync.h"
 #include "canfestival.h"
+#include "sysdep.h"
 
 /* Prototypes for internals functions */
 
@@ -92,7 +93,7 @@
 		stopSYNC(d);
 	}
 	
-	if(*d->COB_ID_Sync & 0x40000000 && *d->Sync_Cycle_Period)
+	if(*d->COB_ID_Sync & UNS32_LE(0x40000000) && *d->Sync_Cycle_Period)
 	{
 		d->syncTimer = SetAlarm(
 				d,
@@ -130,7 +131,7 @@
   
   MSG_WAR(0x3001, "sendSYNC ", 0);
   
-  m.cob_id = *d->COB_ID_Sync & 0x1FFFFFFF;
+  m.cob_id = *(UNS16*)d->COB_ID_Sync;
   m.rtr = NOT_A_REQUEST;
   m.len = 0;