fixed the DCF-LSS conflict
authorgroke6
Tue, 08 Jan 2008 10:47:10 +0100
changeset 349 1e6dd4ef46b9
parent 348 c50feb2bb590
child 350 e90113f7030b
fixed the DCF-LSS conflict
examples/TestMasterSlave/Master.c
include/data.h
include/dcf.h
include/objdictdef.h
src/dcf.c
src/lifegrd.c
src/states.c
--- a/examples/TestMasterSlave/Master.c	Fri Jan 04 17:50:06 2008 +0100
+++ b/examples/TestMasterSlave/Master.c	Tue Jan 08 10:47:10 2008 +0100
@@ -317,8 +317,6 @@
 	/* Ask slave node to go in stop mode */
 	masterSendNMTstateChange (&TestMaster_Data, 0, NMT_Stop_Node);
 	ConfigureLSSNode(&TestMaster_Data);
-#else
-	ConfigureSlaveNode(&TestMaster_Data, 0x02);
 #endif
 }
 
@@ -461,8 +459,8 @@
 void TestMaster_post_SlaveBootup(UNS8 nodeid)
 {
 	eprintf("TestMaster_post_SlaveBootup %x\n", nodeid);
-#ifdef CO_ENABLE_LSS
+
 	ConfigureSlaveNode(&TestMaster_Data, nodeid);
-#endif
-}
-
+
+}
+
--- a/include/data.h	Fri Jan 04 17:50:06 2008 +0100
+++ b/include/data.h	Tue Jan 08 10:47:10 2008 +0100
@@ -100,6 +100,7 @@
     const indextable* dcf_odentry;
 	UNS8* dcf_cursor;
 	UNS32 dcf_entries_count;
+	UNS8 dcf_request;
 	
 	/* EMCY */
 	e_errorState error_state;
@@ -237,6 +238,7 @@
     NULL,       /*dcf_odentry*/\
 	NULL,		/*dcf_cursor*/\
 	1,		/*dcf_entries_count*/\
+	0,		/* dcf_request*/\
 	\
 	/* EMCY */\
 	Error_free,                      /* error_state */\
--- a/include/dcf.h	Fri Jan 04 17:50:06 2008 +0100
+++ b/include/dcf.h	Tue Jan 08 10:47:10 2008 +0100
@@ -21,4 +21,4 @@
 */
 
 
-void send_consise_dcf(CO_Data* d, UNS8 nodeId);
+UNS8 send_consise_dcf(CO_Data* d, UNS8 nodeId);
--- a/include/objdictdef.h	Fri Jan 04 17:50:06 2008 +0100
+++ b/include/objdictdef.h	Tue Jan 08 10:47:10 2008 +0100
@@ -75,6 +75,7 @@
 #define RO     0x02
 
 #define TO_BE_SAVE  0x04
+#define DCF_TO_SEND 0x08
 
 /************************ STRUCTURES ****************************/
 /** This are some structs which are neccessary for creating the entries
--- a/src/dcf.c	Fri Jan 04 17:50:06 2008 +0100
+++ b/src/dcf.c	Tue Jan 08 10:47:10 2008 +0100
@@ -43,6 +43,8 @@
                                UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
 
 
+static void send_consise_dcf_loop(CO_Data* d,UNS8 nodeId);
+
 /**
 **
 **
@@ -60,9 +62,10 @@
     }
 
   closeSDOtransfer(d, nodeId, SDO_CLIENT);
-  send_consise_dcf(d,nodeId);
+  send_consise_dcf_loop(d,nodeId);
 }
 
+
 /**
 **
 **
@@ -71,7 +74,7 @@
 **
 ** @return
 */
-void send_consise_dcf(CO_Data* d,UNS8 nodeId)
+UNS8 send_consise_dcf(CO_Data* d,UNS8 nodeId)
 {
   /* Fetch DCF OD entry, if not already done */
   if(!d->dcf_odentry)
@@ -83,36 +86,56 @@
     if (errorCode != OD_SUCCESSFUL) goto DCF_finish;
   }
 
-  /* Loop on all DCF subindexes, corresponding to nodes ID */
-  while (nodeId < d->dcf_odentry->bSubCount){
-    UNS32 nb_entries;
+  UNS8 szData = d->dcf_odentry->pSubindex[nodeId].size;
+  /* if the entry for the nodeId is not empty. */
+  if(szData!=0){
+  	/* if the entry for the nodeId is already been processing, quit.*/
+  	if(d->dcf_odentry->pSubindex[nodeId].bAccessType & DCF_TO_SEND) return 1;
+  	
+  	d->dcf_odentry->pSubindex[nodeId].bAccessType|=DCF_TO_SEND;
+  	d->dcf_request++;
+  	if(d->dcf_request==1)
+  		send_consise_dcf_loop(d,nodeId);
+  	return 1;
+  }
+  
+  DCF_finish:
+  return 0;
+}
 
-    UNS8 szData = d->dcf_odentry->pSubindex[nodeId].size;
-    UNS8* dcfend;
+static void send_consise_dcf_loop(CO_Data* d,UNS8 nodeId)
+{
+  /* Loop on all DCF subindexes, corresponding to node ID until there is no request*/
+  //while (nodeId < d->dcf_odentry->bSubCount){
+  while (d->dcf_request>0){
+  	if(d->dcf_odentry->pSubindex[nodeId].bAccessType & DCF_TO_SEND){   	 
+  		UNS32 nb_entries;
+   		UNS8 szData = d->dcf_odentry->pSubindex[nodeId].size;
+   		UNS8* dcfend;
+      	 
+   		{
+	   		UNS8* dcf = *((UNS8**)d->dcf_odentry->pSubindex[nodeId].pObject);
+   			dcfend = dcf + szData;
+	   		if (!d->dcf_cursor){
+    	  		d->dcf_cursor = (UNS8*)dcf + 4;
+       			d->dcf_entries_count = 0;
+   			}
+   			nb_entries = UNS32_LE(*((UNS32*)dcf));
+   		}
 
-    {
-      UNS8* dcf = *((UNS8**)d->dcf_odentry->pSubindex[nodeId].pObject);
-      dcfend = dcf + szData;
-      if (!d->dcf_cursor){
-        d->dcf_cursor = (UNS8*)dcf + 4;
-        d->dcf_entries_count = 0;
-      }
-      nb_entries = UNS32_LE(*((UNS32*)dcf));
-    }
+    	/* condition on consise DCF string for NodeID, if big enough */
+    	if((UNS8*)d->dcf_cursor + 7 < (UNS8*)dcfend && d->dcf_entries_count < nb_entries){
+    	
+        	UNS16 target_Index;
+        	UNS8 target_Subindex;
+        	UNS32 target_Size;
 
-    /* condition on consise DCF string for NodeID, if big enough */
-    if((UNS8*)d->dcf_cursor + 7 < (UNS8*)dcfend && d->dcf_entries_count < nb_entries)
-      {
-        UNS16 target_Index;
-        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;
-
-        _writeNetworkDict(d, /* CO_Data* d*/
+        	/* 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;
+	
+    	    _writeNetworkDict(d, /* CO_Data* d*/
                                 nodeId, /* UNS8 nodeId*/
                                 target_Index, /* UNS16 index*/
                                 target_Subindex, /* UNS8 subindex*/
@@ -122,18 +145,35 @@
                                 CheckSDOAndContinue,/* SDOCallback_t
                                                       Callback*/
                                 0); /* no endianize*/
-        /* Push d->dcf_cursor to the end of data*/
+        	/* Push d->dcf_cursor to the end of data*/
 
-        d->dcf_cursor += target_Size;
-        d->dcf_entries_count++;
+        	d->dcf_cursor += target_Size;
+        	d->dcf_entries_count++;
 
-        /* send_consise_dcf will be called by CheckSDOAndContinue for next DCF entry*/
-        return;
-      }
-    nodeId++;
-    d->dcf_cursor = NULL;
+        	/* send_consise_dcf_loop will be called by CheckSDOAndContinue for next DCF entry*/
+        	return;
+      	}
+      	else
+      	{
+      		/* We have finished with the dcf entry. Change the flag, decrement the request
+      		 *  and execute the bootup callback. */
+      		d->dcf_odentry->pSubindex[nodeId].bAccessType&=~DCF_TO_SEND;
+      		d->dcf_request--;
+      		(*d->post_SlaveBootup)(nodeId);
+      	}
+ 	}
+ 	else
+   	{
+   		/* Check the next element*/
+   		//nodeId++;
+   		nodeId=(nodeId+1) % d->dcf_odentry->bSubCount;
+   		if(nodeId==d->dcf_odentry->bSubCount)nodeId=1;
+   		d->dcf_cursor = NULL;
+   	}
   }
- DCF_finish:
+  
+  //DCF_finish:
   /*  Switch Master to preOperational state */
-  (*d->preOperational)();
+ 
+  //(*d->preOperational)();
 }
--- a/src/lifegrd.c	Fri Jan 04 17:50:06 2008 +0100
+++ b/src/lifegrd.c	Tue Jan 08 10:47:10 2008 +0100
@@ -134,8 +134,10 @@
           */
           MSG_WAR(0x3100, "The NMT is a bootup from node : ", nodeId);
           
+          if(!send_consise_dcf(d,nodeId)){
              /* call post SlaveBootup with NodeId */
-		  (*d->post_SlaveBootup)(nodeId);
+		  	(*d->post_SlaveBootup)(nodeId);
+          }
         }
 
       if( d->NMTable[nodeId] != Unknown_state ) {
--- a/src/states.c	Fri Jan 04 17:50:06 2008 +0100
+++ b/src/states.c	Tue Jan 08 10:47:10 2008 +0100
@@ -185,8 +185,9 @@
 				switchCommunicationState(d, &newCommunicationState);
 				if (!(*(d->iam_a_slave)))
 				{
-					send_consise_dcf(d,0x01);
-                    /*(*d->preOperational)() will be called once dcf sent */
+					//send_consise_dcf(d,0x01);
+					masterSendNMTstateChange (d, 0, NMT_Reset_Node);
+                    (*d->preOperational)(); 
 				}
 				else 
 				{
@@ -266,13 +267,13 @@
 #endif
 
   if(offset){
-    /* Adjust COB-ID Client->Server (rx) only id already set to default value*/
-    if(*(UNS32*)d->objdict[offset].pSubindex[1].pObject == 0x600 + *d->bDeviceNodeId){
+    /* 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;
     }
-    /* Adjust COB-ID Server -> Client (tx) only id already set to default value*/
-    if(*(UNS32*)d->objdict[offset].pSubindex[2].pObject == 0x580 + *d->bDeviceNodeId){
+    /* 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;
     }
@@ -292,7 +293,7 @@
     UNS16 lastIndex = d->lastIndex->PDO_RCV;
     UNS32 cobID[] = {0x200, 0x300, 0x400, 0x500};
     if( offset ) while( (offset <= lastIndex) && (i < 4)) {
-      if(*(UNS32*)d->objdict[offset].pSubindex[1].pObject == cobID[i] + *d->bDeviceNodeId)
+      if((*(UNS32*)d->objdict[offset].pSubindex[1].pObject == cobID[i] + *d->bDeviceNodeId)||(*d->bDeviceNodeId==0xFF))
 	      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = cobID[i] + nodeId;
       i ++;
       offset ++;
@@ -306,7 +307,7 @@
     UNS32 cobID[] = {0x180, 0x280, 0x380, 0x480};
     i = 0;
     if( offset ) while ((offset <= lastIndex) && (i < 4)) {
-      if(*(UNS32*)d->objdict[offset].pSubindex[1].pObject == cobID[i] + *d->bDeviceNodeId)
+      if((*(UNS32*)d->objdict[offset].pSubindex[1].pObject == cobID[i] + *d->bDeviceNodeId)||(*d->bDeviceNodeId==0xFF))
 	      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = cobID[i] + nodeId;
       i ++;
       offset ++;
@@ -314,7 +315,7 @@
   }
 
   /* Update EMCY COB-ID if already set to default*/
-  if(*d->error_cobid == *d->bDeviceNodeId + 0x80)
+  if((*d->error_cobid == *d->bDeviceNodeId + 0x80)||(*d->bDeviceNodeId==0xFF))
     *d->error_cobid = nodeId + 0x80;
 
   /* bDeviceNodeId is defined in the object dictionary. */