src/states.c
changeset 343 118c1cabd0b0
parent 320 f82e758840bd
child 345 62d6b770a85f
equal deleted inserted replaced
342:66f007300c10 343:118c1cabd0b0
    32 #include "states.h"
    32 #include "states.h"
    33 #include "def.h"
    33 #include "def.h"
    34 #include "dcf.h"
    34 #include "dcf.h"
    35 #include "nmtSlave.h"
    35 #include "nmtSlave.h"
    36 #include "emcy.h"
    36 #include "emcy.h"
    37 
    37 #ifdef CO_ENABLE_LSS
       
    38 #include "lss.h"
       
    39 #endif
    38 /** Prototypes for internals functions */
    40 /** Prototypes for internals functions */
    39 /*!                                                                                                
    41 /*!                                                                                                
    40 **                                                                                                 
    42 **                                                                                                 
    41 **                                                                                                 
    43 **                                                                                                 
    42 ** @param d                                                                                        
    44 ** @param d                                                                                        
   100 		case NMT:
   102 		case NMT:
   101 			if (*(d->iam_a_slave))
   103 			if (*(d->iam_a_slave))
   102 			{
   104 			{
   103 				proceedNMTstateChange(d,m);
   105 				proceedNMTstateChange(d,m);
   104 			}
   106 			}
       
   107 #ifdef CO_ENABLE_LSS
       
   108 		case LSS:
       
   109 			if (!d->CurrentCommunicationState.csLSS)break;
       
   110 			if ((*(d->iam_a_slave)) && m->cob_id.w==MLSS_ADRESS)
       
   111 			{
       
   112 				proceedLSS_Slave(d,m);
       
   113 			}
       
   114 			else if(!(*(d->iam_a_slave)) && m->cob_id.w==SLSS_ADRESS)
       
   115 			{
       
   116 				proceedLSS_Master(d,m);
       
   117 			}
       
   118 			break;
       
   119 #endif
   105 	}
   120 	}
   106 }
   121 }
   107 
   122 
   108 #define StartOrStop(CommType, FuncStart, FuncStop) \
   123 #define StartOrStop(CommType, FuncStart, FuncStop) \
   109 	if(newCommunicationState->CommType && d->CurrentCommunicationState.CommType == 0){\
   124 	if(newCommunicationState->CommType && d->CurrentCommunicationState.CommType == 0){\
   129 	StartOrStop(csSYNC,	startSYNC(d),		stopSYNC(d))
   144 	StartOrStop(csSYNC,	startSYNC(d),		stopSYNC(d))
   130 	StartOrStop(csHeartbeat,	heartbeatInit(d),	heartbeatStop(d))
   145 	StartOrStop(csHeartbeat,	heartbeatInit(d),	heartbeatStop(d))
   131 	StartOrStop(csEmergency,	emergencyInit(d),	emergencyStop(d)) 
   146 	StartOrStop(csEmergency,	emergencyInit(d),	emergencyStop(d)) 
   132 	StartOrStop(csPDO,	PDOInit(d),	PDOStop(d))
   147 	StartOrStop(csPDO,	PDOInit(d),	PDOStop(d))
   133 	StartOrStop(csBoot_Up,	None,	slaveSendBootUp(d))
   148 	StartOrStop(csBoot_Up,	None,	slaveSendBootUp(d))
       
   149 #ifdef CO_ENABLE_LSS
       
   150 	StartOrStop(csLSS,	startLSS(d),	stopLSS(d))
       
   151 #endif
   134 }
   152 }
   135 
   153 
   136 /*!                                                                                                
   154 /*!                                                                                                
   137 **                                                                                                 
   155 **                                                                                                 
   138 **                                                                                                 
   156 **                                                                                                 
   145 {
   163 {
   146 	while(newState != d->nodeState){
   164 	while(newState != d->nodeState){
   147 		switch( newState ){
   165 		switch( newState ){
   148 			case Initialisation:
   166 			case Initialisation:
   149 			{
   167 			{
   150 				s_state_communication newCommunicationState = {1, 0, 0, 0, 0, 0};
   168 				s_state_communication newCommunicationState = {1, 0, 0, 0, 0, 0, 0};
   151 				/* This will force a second loop for the state switch */
   169 				/* This will force a second loop for the state switch */
   152 				d->nodeState = Initialisation;
   170 				d->nodeState = Initialisation;
   153 				newState = Pre_operational;
   171 				newState = Pre_operational;
   154 				switchCommunicationState(d, &newCommunicationState);
   172 				switchCommunicationState(d, &newCommunicationState);
   155 				/* call user app related state func. */
   173 				/* call user app related state func. */
   159 			break;
   177 			break;
   160 								
   178 								
   161 			case Pre_operational:
   179 			case Pre_operational:
   162 			{
   180 			{
   163 				
   181 				
   164 				s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 0};
   182 				s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 0, 1};
   165 				d->nodeState = Pre_operational;
   183 				d->nodeState = Pre_operational;
   166 				newState = Pre_operational;
   184 				newState = Pre_operational;
   167 				switchCommunicationState(d, &newCommunicationState);
   185 				switchCommunicationState(d, &newCommunicationState);
   168 				if (!(*(d->iam_a_slave)))
   186 				if (!(*(d->iam_a_slave)))
   169 				{
   187 				{
   178 			break;
   196 			break;
   179 								
   197 								
   180 			case Operational:
   198 			case Operational:
   181 			if(d->nodeState == Initialisation) return 0xFF;
   199 			if(d->nodeState == Initialisation) return 0xFF;
   182 			{
   200 			{
   183 				s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 1};
   201 				s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 1, 0};
   184 				d->nodeState = Operational;
   202 				d->nodeState = Operational;
   185 				newState = Operational;
   203 				newState = Operational;
   186 				switchCommunicationState(d, &newCommunicationState);
   204 				switchCommunicationState(d, &newCommunicationState);
   187 				(*d->operational)();
   205 				(*d->operational)();
   188 			}
   206 			}
   189 			break;
   207 			break;
   190 						
   208 						
   191 			case Stopped:
   209 			case Stopped:
   192 			if(d->nodeState == Initialisation) return 0xFF;
   210 			if(d->nodeState == Initialisation) return 0xFF;
   193 			{
   211 			{
   194 				s_state_communication newCommunicationState = {0, 0, 0, 0, 1, 0};
   212 				s_state_communication newCommunicationState = {0, 0, 0, 0, 1, 0, 1};
   195 				d->nodeState = Stopped;
   213 				d->nodeState = Stopped;
   196 				newState = Stopped;
   214 				newState = Stopped;
   197 				switchCommunicationState(d, &newCommunicationState);
   215 				switchCommunicationState(d, &newCommunicationState);
   198 				(*d->stopped)();
   216 				(*d->stopped)();
   199 			}
   217 			}
   200 			break;
   218 			break;
       
   219 #ifdef CO_ENABLE_LSS
       
   220 			case LssTimingDelay:
       
   221 			{
       
   222 				s_state_communication newCommunicationState = {0, 0, 0, 0, 0, 0, 0};
       
   223 				d->nodeState = LssTimingDelay;
       
   224 				newState = LssTimingDelay;
       
   225 				switchCommunicationState(d, &newCommunicationState);
       
   226 			}
       
   227 			break;
       
   228 #endif
   201 			
   229 			
   202 			default:
   230 			default:
   203 				return 0xFF;
   231 				return 0xFF;
   204 		}/* end switch case */
   232 		}/* end switch case */
   205 	
   233 	
   226 ** @param nodeId                                                                                   
   254 ** @param nodeId                                                                                   
   227 **/   
   255 **/   
   228 void setNodeId(CO_Data* d, UNS8 nodeId)
   256 void setNodeId(CO_Data* d, UNS8 nodeId)
   229 {
   257 {
   230   UNS16 offset = d->firstIndex->SDO_SVR;
   258   UNS16 offset = d->firstIndex->SDO_SVR;
       
   259   
       
   260 #ifdef CO_ENABLE_LSS
       
   261   if(nodeId==0xFF)
       
   262   {
       
   263   	*d->bDeviceNodeId = nodeId;
       
   264   	return;
       
   265   }
       
   266 #endif
       
   267 
   231   if(offset){
   268   if(offset){
   232     /* Adjust COB-ID Client->Server (rx) only id already set to default value*/
   269     /* Adjust COB-ID Client->Server (rx) only id already set to default value*/
   233     if(*(UNS32*)d->objdict[offset].pSubindex[1].pObject = 0x600 + *d->bDeviceNodeId){
   270     if(*(UNS32*)d->objdict[offset].pSubindex[1].pObject = 0x600 + *d->bDeviceNodeId){
   234       /* cob_id_client = 0x600 + nodeId; */
   271       /* cob_id_client = 0x600 + nodeId; */
   235       *(UNS32*)d->objdict[offset].pSubindex[1].pObject = 0x600 + nodeId;
   272       *(UNS32*)d->objdict[offset].pSubindex[1].pObject = 0x600 + nodeId;