src/states.c
author Edouard Tisserant
Fri, 23 Mar 2018 15:45:52 +0100
changeset 803 cb315e75b3bd
parent 750 bfb63ff7106e
permissions -rw-r--r--
Fixed trailing -lrtdm added by configure with Xenomai
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    22
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    23
** @file   states.c
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    24
** @author Edouard TISSERANT and Francis DUPIN
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    25
** @date   Tue Jun  5 09:32:32 2007
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    26
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    27
** @brief
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    28
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    29
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    30
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
    32
#include "data.h"
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
    33
#include "sysdep.h"
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
    34
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    35
/** Prototypes for internals functions */
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    36
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    37
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    38
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    39
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    40
** @param newCommunicationState                                                                    
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    41
**/     
53
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    42
void switchCommunicationState(CO_Data* d, 
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    43
	s_state_communication *newCommunicationState);
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    44
	
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    45
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    46
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    47
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    48
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    49
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    50
** @return                                                                                         
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    51
**/    
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
e_nodeState getState(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
  return d->nodeState;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    57
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    58
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    59
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    60
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    61
** @param m                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    62
**/  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
void canDispatch(CO_Data* d, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
{
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
    65
	UNS16 cob_id = UNS16_LE(m->cob_id);
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
    66
	 switch(cob_id >> 7)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
	{
284
24bf3d692993 Implemented EMCY objects.
luis
parents: 263
diff changeset
    68
		case SYNC:		/* can be a SYNC or a EMCY message */
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
    69
			if(cob_id == 0x080)	/* SYNC */
284
24bf3d692993 Implemented EMCY objects.
luis
parents: 263
diff changeset
    70
			{
24bf3d692993 Implemented EMCY objects.
luis
parents: 263
diff changeset
    71
				if(d->CurrentCommunicationState.csSYNC)
24bf3d692993 Implemented EMCY objects.
luis
parents: 263
diff changeset
    72
					proceedSYNC(d);
24bf3d692993 Implemented EMCY objects.
luis
parents: 263
diff changeset
    73
			} else 		/* EMCY */
24bf3d692993 Implemented EMCY objects.
luis
parents: 263
diff changeset
    74
				if(d->CurrentCommunicationState.csEmergency)
24bf3d692993 Implemented EMCY objects.
luis
parents: 263
diff changeset
    75
					proceedEMCY(d,m);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
			break;
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    77
		/* case TIME_STAMP: */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
		case PDO1tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
		case PDO1rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
		case PDO2tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
		case PDO2rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
		case PDO3tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
		case PDO3rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
		case PDO4tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
		case PDO4rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
			if (d->CurrentCommunicationState.csPDO)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
				proceedPDO(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
		case SDOtx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
		case SDOrx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
			if (d->CurrentCommunicationState.csSDO)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
				proceedSDO(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
		case NODE_GUARD:
750
bfb63ff7106e Implementation of a basic working node-guarding
mwildbolz
parents: 746
diff changeset
    95
			if (d->CurrentCommunicationState.csLifeGuard)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
				proceedNODE_GUARD(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
		case NMT:
88
b6e0b91d073a pointer bogue for *(d->iam_a_slave)
frdupin
parents: 71
diff changeset
    99
			if (*(d->iam_a_slave))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
			{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
				proceedNMTstateChange(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
			}
668
ba53613e94e4 Added some fixes from Jaroslav Fojtik submitted on sourceforge bug tracker:
Mongo
parents: 517
diff changeset
   103
            break;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   104
#ifdef CO_ENABLE_LSS
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   105
		case LSS:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   106
			if (!d->CurrentCommunicationState.csLSS)break;
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
   107
			if ((*(d->iam_a_slave)) && cob_id==MLSS_ADRESS)
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   108
			{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   109
				proceedLSS_Slave(d,m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   110
			}
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
   111
			else if(!(*(d->iam_a_slave)) && cob_id==SLSS_ADRESS)
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   112
			{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   113
				proceedLSS_Master(d,m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   114
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   115
			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   116
#endif
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
#define StartOrStop(CommType, FuncStart, FuncStop) \
291
6165554cbfe9 Some tricks in communication services status struct (states.c) and in sync.c to fit with Beremiz generated node code.
etisserant
parents: 284
diff changeset
   121
	if(newCommunicationState->CommType && d->CurrentCommunicationState.CommType == 0){\
195
1510dd61ead0 Added debug level opt in configure and re-enabled debug macros.
etisserant
parents: 183
diff changeset
   122
		MSG_WAR(0x9999,#FuncStart, 9999);\
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
		d->CurrentCommunicationState.CommType = 1;\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
		FuncStart;\
291
6165554cbfe9 Some tricks in communication services status struct (states.c) and in sync.c to fit with Beremiz generated node code.
etisserant
parents: 284
diff changeset
   125
	}else if(!newCommunicationState->CommType && d->CurrentCommunicationState.CommType == 1){\
195
1510dd61ead0 Added debug level opt in configure and re-enabled debug macros.
etisserant
parents: 183
diff changeset
   126
		MSG_WAR(0x9999,#FuncStop, 9999);\
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
		d->CurrentCommunicationState.CommType = 0;\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
		FuncStop;\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
#define None
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   131
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   132
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   133
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   134
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   135
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   136
** @param newCommunicationState                                                                    
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   137
**/  	
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
void switchCommunicationState(CO_Data* d, s_state_communication *newCommunicationState)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 378
diff changeset
   140
#ifdef CO_ENABLE_LSS
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 378
diff changeset
   141
	StartOrStop(csLSS,	startLSS(d),	stopLSS(d))
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 378
diff changeset
   142
#endif
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
	StartOrStop(csSDO,	None,		resetSDO(d))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
	StartOrStop(csSYNC,	startSYNC(d),		stopSYNC(d))
750
bfb63ff7106e Implementation of a basic working node-guarding
mwildbolz
parents: 746
diff changeset
   145
	StartOrStop(csLifeGuard,	lifeGuardInit(d),	lifeGuardStop(d))
284
24bf3d692993 Implemented EMCY objects.
luis
parents: 263
diff changeset
   146
	StartOrStop(csEmergency,	emergencyInit(d),	emergencyStop(d)) 
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 215
diff changeset
   147
	StartOrStop(csPDO,	PDOInit(d),	PDOStop(d))
14
1fbdf88163b3 d?placement de l'envoi du bootup
dejoigny
parents: 0
diff changeset
   148
	StartOrStop(csBoot_Up,	None,	slaveSendBootUp(d))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   151
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   152
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   153
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   154
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   155
** @param newState                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   156
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   157
** @return                                                                                         
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   158
**/  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
UNS8 setState(CO_Data* d, e_nodeState newState)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
{
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   161
	if(newState != d->nodeState){
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
		switch( newState ){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
			case Initialisation:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
			{
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   165
				s_state_communication newCommunicationState = {1, 0, 0, 0, 0, 0, 0};
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
				d->nodeState = Initialisation;
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   167
				switchCommunicationState(d, &newCommunicationState);
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   168
				/* call user app init callback now. */
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   169
				/* d->initialisation MUST NOT CALL SetState */
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   170
				(*d->initialisation)(d);				
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   171
			}
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   172
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   173
			/* Automatic transition - No break statement ! */
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   174
			/* Transition from Initialisation to Pre_operational */
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   175
			/* is automatic as defined in DS301. */
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   176
			/* App don't have to call SetState(d, Pre_operational) */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
								
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
			case Pre_operational:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
			{
178
01d81faa3350 Add concise DCF support
greg
parents: 152
diff changeset
   180
				
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   181
				s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 0, 1};
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
				d->nodeState = Pre_operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
				switchCommunicationState(d, &newCommunicationState);
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   184
                (*d->preOperational)(d);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
								
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
			case Operational:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
			if(d->nodeState == Initialisation) return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
			{
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   191
				s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 1, 0};
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
				d->nodeState = Operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
				newState = Operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
				switchCommunicationState(d, &newCommunicationState);
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   195
				(*d->operational)(d);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
						
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
			case Stopped:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
			if(d->nodeState == Initialisation) return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
			{
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   202
				s_state_communication newCommunicationState = {0, 0, 0, 0, 1, 0, 1};
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
				d->nodeState = Stopped;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
				newState = Stopped;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
				switchCommunicationState(d, &newCommunicationState);
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   206
				(*d->stopped)(d);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
			break;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 378
diff changeset
   209
			default:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 378
diff changeset
   210
				return 0xFF;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 378
diff changeset
   211
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   212
		}/* end switch case */
94
bdf4c86be6b2 Removed all non-supported and uncontrolled source code. Please refer to CVS version "Before_..." to see old code.
etisserant
parents: 88
diff changeset
   213
	
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
	}
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   215
	/* d->nodeState contains the final state */
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   216
	/* may not be the requested state */
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   217
    return d->nodeState;  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   220
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   221
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   222
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   223
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   224
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   225
** @return                                                                                         
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   226
**/ 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
UNS8 getNodeId(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
  return *d->bDeviceNodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   232
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   233
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   234
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   235
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   236
** @param nodeId                                                                                   
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   237
**/   
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
void setNodeId(CO_Data* d, UNS8 nodeId)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
  UNS16 offset = d->firstIndex->SDO_SVR;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   241
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   242
#ifdef CO_ENABLE_LSS
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 378
diff changeset
   243
  d->lss_transfer.nodeID=nodeId;
517
003679edc437 FastScan review
groke6
parents: 447
diff changeset
   244
  if(nodeId==0xFF){
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   245
  	*d->bDeviceNodeId = nodeId;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   246
  	return;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   247
  }
517
003679edc437 FastScan review
groke6
parents: 447
diff changeset
   248
  else
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   249
#endif
517
003679edc437 FastScan review
groke6
parents: 447
diff changeset
   250
  if(!(nodeId>0 && nodeId<=127)){
003679edc437 FastScan review
groke6
parents: 447
diff changeset
   251
	  MSG_WAR(0x2D01, "Invalid NodeID",nodeId);
003679edc437 FastScan review
groke6
parents: 447
diff changeset
   252
	  return;
003679edc437 FastScan review
groke6
parents: 447
diff changeset
   253
  }
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 320
diff changeset
   254
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
  if(offset){
349
1e6dd4ef46b9 fixed the DCF-LSS conflict
groke6
parents: 345
diff changeset
   256
    /* Adjust COB-ID Client->Server (rx) only id already set to default value or id not valid (id==0xFF)*/
1e6dd4ef46b9 fixed the DCF-LSS conflict
groke6
parents: 345
diff changeset
   257
    if((*(UNS32*)d->objdict[offset].pSubindex[1].pObject == 0x600 + *d->bDeviceNodeId)||(*d->bDeviceNodeId==0xFF)){
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   258
      /* cob_id_client = 0x600 + nodeId; */
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 446
diff changeset
   259
      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = 0x600 + nodeId;
303
340348f0193f Now, SetNodeId will change 1200h SDO server params to new defaul values only if already set to appropriate default values.
etisserant
parents: 291
diff changeset
   260
    }
349
1e6dd4ef46b9 fixed the DCF-LSS conflict
groke6
parents: 345
diff changeset
   261
    /* Adjust COB-ID Server -> Client (tx) only id already set to default value or id not valid (id==0xFF)*/
1e6dd4ef46b9 fixed the DCF-LSS conflict
groke6
parents: 345
diff changeset
   262
    if((*(UNS32*)d->objdict[offset].pSubindex[2].pObject == 0x580 + *d->bDeviceNodeId)||(*d->bDeviceNodeId==0xFF)){
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   263
      /* cob_id_server = 0x580 + nodeId; */
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 446
diff changeset
   264
      *(UNS32*)d->objdict[offset].pSubindex[2].pObject = 0x580 + nodeId;
303
340348f0193f Now, SetNodeId will change 1200h SDO server params to new defaul values only if already set to appropriate default values.
etisserant
parents: 291
diff changeset
   265
    }
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   268
  /* 
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   269
   	Initialize the server(s) SDO parameters
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   270
  	Remember that only one SDO server is allowed, defined at index 0x1200	
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   271
 		
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   272
  	Initialize the client(s) SDO parameters 	
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   273
  	Nothing to initialize (no default values required by the DS 401)	
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   274
  	Initialize the receive PDO communication parameters. Only for 0x1400 to 0x1403 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   275
  */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
    UNS8 i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
    UNS16 offset = d->firstIndex->PDO_RCV;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
    UNS16 lastIndex = d->lastIndex->PDO_RCV;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
    UNS32 cobID[] = {0x200, 0x300, 0x400, 0x500};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
    if( offset ) while( (offset <= lastIndex) && (i < 4)) {
349
1e6dd4ef46b9 fixed the DCF-LSS conflict
groke6
parents: 345
diff changeset
   282
      if((*(UNS32*)d->objdict[offset].pSubindex[1].pObject == cobID[i] + *d->bDeviceNodeId)||(*d->bDeviceNodeId==0xFF))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
	      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = cobID[i] + nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
      i ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
      offset ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
  }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   288
  /* ** Initialize the transmit PDO communication parameters. Only for 0x1800 to 0x1803 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
    UNS8 i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
    UNS16 offset = d->firstIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
    UNS16 lastIndex = d->lastIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
    UNS32 cobID[] = {0x180, 0x280, 0x380, 0x480};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
    i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
    if( offset ) while ((offset <= lastIndex) && (i < 4)) {
349
1e6dd4ef46b9 fixed the DCF-LSS conflict
groke6
parents: 345
diff changeset
   296
      if((*(UNS32*)d->objdict[offset].pSubindex[1].pObject == cobID[i] + *d->bDeviceNodeId)||(*d->bDeviceNodeId==0xFF))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
	      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = cobID[i] + nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
      i ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
      offset ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
  }
314
68e83c3ffbb5 Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents: 303
diff changeset
   302
68e83c3ffbb5 Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents: 303
diff changeset
   303
  /* Update EMCY COB-ID if already set to default*/
349
1e6dd4ef46b9 fixed the DCF-LSS conflict
groke6
parents: 345
diff changeset
   304
  if((*d->error_cobid == *d->bDeviceNodeId + 0x80)||(*d->bDeviceNodeId==0xFF))
314
68e83c3ffbb5 Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents: 303
diff changeset
   305
    *d->error_cobid = nodeId + 0x80;
68e83c3ffbb5 Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents: 303
diff changeset
   306
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   307
  /* bDeviceNodeId is defined in the object dictionary. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
  *d->bDeviceNodeId = nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
}
149
fe50ada8020b Changes in the API:
etisserant
parents: 94
diff changeset
   310
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   311
void _initialisation(CO_Data* d){}
746
3e16d9a121b8 Master now sends NMT_Reset only from default preOperational application callback
Edouard Tisserant
parents: 668
diff changeset
   312
void _preOperational(CO_Data* d){
3e16d9a121b8 Master now sends NMT_Reset only from default preOperational application callback
Edouard Tisserant
parents: 668
diff changeset
   313
    if (!(*(d->iam_a_slave)))
3e16d9a121b8 Master now sends NMT_Reset only from default preOperational application callback
Edouard Tisserant
parents: 668
diff changeset
   314
    {
3e16d9a121b8 Master now sends NMT_Reset only from default preOperational application callback
Edouard Tisserant
parents: 668
diff changeset
   315
        masterSendNMTstateChange (d, 0, NMT_Reset_Node);
3e16d9a121b8 Master now sends NMT_Reset only from default preOperational application callback
Edouard Tisserant
parents: 668
diff changeset
   316
    }
3e16d9a121b8 Master now sends NMT_Reset only from default preOperational application callback
Edouard Tisserant
parents: 668
diff changeset
   317
}
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   318
void _operational(CO_Data* d){}
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   319
void _stopped(CO_Data* d){}