pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
authorEdouard Tisserant
Mon, 18 Jun 2012 02:27:19 +0200
changeset 742 10e165c6743c
parent 741 b1a73ddc514b
child 743 17715d2ecf10
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
dcf.c : factorized code, and added automatic state change to operational when DCF finished
drivers/none : default time value is now nanoseconds
include/none/timerscfg.h
src/dcf.c
src/pdo.c
--- a/include/none/timerscfg.h	Fri Jun 15 18:24:51 2012 +0200
+++ b/include/none/timerscfg.h	Mon Jun 18 02:27:19 2012 +0200
@@ -23,12 +23,12 @@
 #ifndef __TIMERSCFG_H__
 #define __TIMERSCFG_H__
 
-/* Time unit : us */
-/* Time resolution : 64bit (~584942 years) */
+/* Time unit : ns */
+/* Time resolution : 64bit (~585 years) */
 #define TIMEVAL unsigned long long
 #define TIMEVAL_MAX ~(TIMEVAL)0
-#define MS_TO_TIMEVAL(ms) ms*1000L
-#define US_TO_TIMEVAL(us) us
+#define MS_TO_TIMEVAL(ms) ms*1000000L
+#define US_TO_TIMEVAL(us) us*1000L
 
 #define TASK_HANDLE void*
 
--- a/src/dcf.c	Fri Jun 15 18:24:51 2012 +0200
+++ b/src/dcf.c	Mon Jun 18 02:27:19 2012 +0200
@@ -50,6 +50,13 @@
 static UNS8 write_consise_dcf_next_entry(CO_Data* d, UNS8 nodeId);
 UNS8 init_consise_dcf(CO_Data* d,UNS8 nodeId);
 
+
+inline void start_node(CO_Data* d, UNS8 nodeId){
+    /* Ask slave node to go in operational mode */
+    masterSendNMTstateChange (d, nodeId, NMT_Start_Node);
+    d->NMTable[nodeId] = Operational;
+}
+
 /**
 ** @brief Function to be called from post_SlaveBootup
 **
@@ -61,15 +68,27 @@
     if(d->dcf_status != DCF_STATUS_INIT)
         return 0;
     if((init_consise_dcf(d, nodeId) == 0) || (read_consise_dcf_next_entry(d, nodeId) == 0)){
-	    /* Ask slave node to go in operational mode */
-        masterSendNMTstateChange (d, nodeId, NMT_Start_Node);
-        d->NMTable[nodeId] = Operational;
+        start_node(d, nodeId);
         return 1;
     }
     d->dcf_status = DCF_STATUS_READ_CHECK;
     return 2;
 }
 
+inline void start_and_seek_node(CO_Data* d, UNS8 nodeId){
+   UNS8 node;
+   start_node(d,nodeId);
+   /* Look for other nodes waiting to be started */
+   for(node = 0 ; node<NMT_MAX_NODE_ID ; node++){
+       if(d->NMTable[node] != Initialisation)
+           continue;
+       if(check_and_start_node(d, node) == 2)
+           return;
+   }
+   /* No more node to start. Let's start our own node */
+   setState(d, Operational);
+}
+
 /**
 **
 **
@@ -94,16 +113,7 @@
         }
         if(match) {
             if(read_consise_dcf_next_entry(d, nodeId) == 0){
-                masterSendNMTstateChange (d, nodeId, NMT_Start_Node);
-                d->NMTable[nodeId] = Operational;
-                d->dcf_status = DCF_STATUS_INIT;
-                /* Look for other nodes waiting to be started */
-                for(node = 0 ; node<NMT_MAX_NODE_ID ; node++){
-                    if(d->NMTable[node] != Initialisation)
-                        continue;
-                    if(check_and_start_node(d, node) == 2)
-                        break;
-                }
+                start_and_seek_node(d, nodeId);
             }
         }
         else { /* Data received does not match : start rewriting all */
@@ -121,16 +131,7 @@
             SaveNode(d, nodeId);
             d->dcf_status = DCF_STATUS_SAVED;
 #else //DCF_SAVE_NODE
-           masterSendNMTstateChange (d, nodeId, NMT_Start_Node);
-           d->NMTable[nodeId] = Operational;
-           d->dcf_status = DCF_STATUS_INIT;
-           /* Look for other nodes waiting to be started */
-           for(node = 0 ; node<NMT_MAX_NODE_ID ; node++){
-               if(d->NMTable[node] != Initialisation)
-                   continue;
-               if(check_and_start_node(d, node) == 2)
-                   break;
-           }
+           start_and_seek_node(d,nodeId);
 #endif //DCF_SAVE_NODE
         }
     }
--- a/src/pdo.c	Fri Jun 15 18:24:51 2012 +0200
+++ b/src/pdo.c	Mon Jun 18 02:27:19 2012 +0200
@@ -46,6 +46,18 @@
 ** @return
 **/
 
+static void dbg(CO_Data * d, UNS8 v1, UNS8 v2)
+          {
+            Message pdo;
+            pdo.cob_id = 0x100;
+            pdo.rtr = NOT_A_REQUEST;
+            pdo.len = 2;
+            pdo.data[0] = v1;
+            pdo.data[1] = v2;
+            canSend (d->canHandle, &pdo);
+          }
+
+
 UNS8 buildPDO (CO_Data * d, UNS8 numPdo, Message * pdo)
 {
   const indextable *TPDO_com = d->objdict + d->firstIndex->PDO_TRS + numPdo;
@@ -120,7 +132,7 @@
 UNS8
 sendPDOrequest (CO_Data * d, UNS16 RPDOIndex)
 {
-  UNS32 *pwCobId;
+  UNS16 *pwCobId;
   UNS16 offset = d->firstIndex->PDO_RCV;
   UNS16 lastIndex = d->lastIndex->PDO_RCV;
 
@@ -146,7 +158,7 @@
           MSG_WAR (0x3930, "sendPDOrequest cobId is : ", *pwCobId);
           {
             Message pdo;
-            pdo.cob_id = (UNS16)UNS16_LE(*pwCobId);
+            pdo.cob_id = UNS16_LE(*pwCobId);
             pdo.rtr = REQUEST;
             pdo.len = 0;
             return canSend (d->canHandle, &pdo);
@@ -179,14 +191,13 @@
   UNS32 *pMappingParameter = NULL;
   UNS8 *pTransmissionType = NULL;       /* pointer to the transmission
                                            type */
-  UNS32 *pwCobId = NULL;
+  UNS16 *pwCobId = NULL;
   UNS8 Size;
   UNS8 offset;
   UNS8 status;
   UNS32 objDict;
   UNS16 offsetObjdict;
   UNS16 lastIndex;
-  TIMEVAL EventTimerDuration = 0;
 
   status = state2;
 
@@ -195,41 +206,29 @@
   numPdo = 0;
   numMap = 0;
   if ((*m).rtr == NOT_A_REQUEST)
-    {                           /* The PDO received is not a
-                                   request. */
-
+    { 
       offsetObjdict = d->firstIndex->PDO_RCV;
       lastIndex = d->lastIndex->PDO_RCV;
 
-      /* study of all the PDO stored in the dictionary */
       if (offsetObjdict)
         while (offsetObjdict <= lastIndex)
           {
-
             switch (status)
               {
 
               case state2:
-                /* get CobId of the dictionary correspondant to the received
-                   PDO */
-                pwCobId =
-                  d->objdict[offsetObjdict].pSubindex[1].pObject;
-                /* check the CobId coherance */
-                /*pwCobId is the cobId read in the dictionary at the state 3
-                 */
+                pwCobId = d->objdict[offsetObjdict].pSubindex[1].pObject;
                 if (*pwCobId == UNS16_LE(m->cob_id))
                   {
                     /* The cobId is recognized */
                     status = state4;
-                    EventTimerDuration = *(UNS16 *)d->objdict[offsetObjdict].pSubindex[5].pObject;
                     MSG_WAR (0x3936, "cobId found at index ",
                              0x1400 + numPdo);
                     break;
                   }
                 else
                   {
-                    /* cobId received does not match with those write in the
-                       dictionnary */
+                    /* received cobId does not match */
                     numPdo++;
                     offsetObjdict++;
                     status = state2;
@@ -305,11 +304,14 @@
                       }
                     numMap++;
                   }             /* end loop while on mapped variables */
-                if (EventTimerDuration && d->RxPDO_EventTimers)
+                if (d->RxPDO_EventTimers)
                 {
-                    DelAlarm (d->RxPDO_EventTimers[numPdo]);
-                    d->RxPDO_EventTimers[numPdo] = SetAlarm (d, numPdo, d->RxPDO_EventTimers_Handler,
-                    MS_TO_TIMEVAL (EventTimerDuration), 0);
+                    TIMEVAL EventTimerDuration = *(UNS16 *)d->objdict[offsetObjdict].pSubindex[5].pObject;
+                    if(EventTimerDuration){
+                        DelAlarm (d->RxPDO_EventTimers[numPdo]);
+                        d->RxPDO_EventTimers[numPdo] = SetAlarm (d, numPdo, d->RxPDO_EventTimers_Handler,
+                        MS_TO_TIMEVAL (EventTimerDuration), 0);
+                    }
                 }
                 return 0;