Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
nmtSlave.c
00001 /* 00002 This file is part of CanFestival, a library implementing CanOpen Stack. 00003 00004 Copyright (C): Edouard TISSERANT and Francis DUPIN 00005 00006 See COPYING file for copyrights details. 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 USA 00022 */ 00023 /*! 00024 ** @file nmtSlave.c 00025 ** @author Edouard TISSERANT and Francis DUPIN 00026 ** @date Tue Jun 5 08:50:53 2007 00027 ** 00028 ** @brief 00029 ** 00030 ** 00031 */ 00032 #include "nmtSlave.h" 00033 #include "states.h" 00034 #include "canfestival.h" 00035 #include "sysdep.h" 00036 00037 /*! 00038 ** put the slave in the state wanted by the master 00039 ** 00040 ** @param d 00041 ** @param m 00042 **/ 00043 void proceedNMTstateChange(CO_Data* d, Message *m) 00044 { 00045 if( d->nodeState == Pre_operational || 00046 d->nodeState == Operational || 00047 d->nodeState == Stopped ) { 00048 00049 MSG_WAR(0x3400, "NMT received. for node : ", (*m).data[1]); 00050 00051 /* Check if this NMT-message is for this node */ 00052 /* byte 1 = 0 : all the nodes are concerned (broadcast) */ 00053 00054 if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == *d->bDeviceNodeId ) ){ 00055 00056 switch( (*m).data[0]){ /* command specifier (cs) */ 00057 case NMT_Start_Node: 00058 if ( (d->nodeState == Pre_operational) || (d->nodeState == Stopped) ) 00059 setState(d,Operational); 00060 break; 00061 00062 case NMT_Stop_Node: 00063 if ( d->nodeState == Pre_operational || 00064 d->nodeState == Operational ) 00065 setState(d,Stopped); 00066 break; 00067 00068 case NMT_Enter_PreOperational: 00069 if ( d->nodeState == Operational || 00070 d->nodeState == Stopped ) 00071 setState(d,Pre_operational); 00072 break; 00073 00074 case NMT_Reset_Node: 00075 if(d->NMT_Slave_Node_Reset_Callback != NULL) 00076 d->NMT_Slave_Node_Reset_Callback(d); 00077 setState(d,Initialisation); 00078 break; 00079 00080 case NMT_Reset_Comunication: 00081 { 00082 UNS8 currentNodeId = getNodeId(d); 00083 00084 if(d->NMT_Slave_Communications_Reset_Callback != NULL) 00085 d->NMT_Slave_Communications_Reset_Callback(d); 00086 #ifdef CO_ENABLE_LSS 00087 // LSS changes NodeId here in case lss_transfer.nodeID doesn't 00088 // match current getNodeId() 00089 if(currentNodeId!=d->lss_transfer.nodeID) 00090 currentNodeId = d->lss_transfer.nodeID; 00091 #endif 00092 00093 // clear old NodeId to make SetNodeId reinitializing 00094 // SDO, EMCY and other COB Ids 00095 *d->bDeviceNodeId = 0xFF; 00096 00097 setNodeId(d, currentNodeId); 00098 } 00099 setState(d,Initialisation); 00100 break; 00101 00102 }/* end switch */ 00103 00104 }/* end if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == 00105 bDeviceNodeId ) ) */ 00106 } 00107 } 00108 00109 00110 /*! 00111 ** 00112 ** 00113 ** @param d 00114 ** 00115 ** @return 00116 **/ 00117 UNS8 slaveSendBootUp(CO_Data* d) 00118 { 00119 Message m; 00120 00121 #ifdef CO_ENABLE_LSS 00122 if(*d->bDeviceNodeId==0xFF)return 0; 00123 #endif 00124 00125 MSG_WAR(0x3407, "Send a Boot-Up msg ", 0); 00126 00127 /* message configuration */ 00128 { 00129 UNS16 tmp = NODE_GUARD << 7 | *d->bDeviceNodeId; 00130 m.cob_id = UNS16_LE(tmp); 00131 } 00132 m.rtr = NOT_A_REQUEST; 00133 m.len = 1; 00134 m.data[0] = 0x00; 00135 00136 return canSend(d->canHandle,&m); 00137 } 00138
Generated on Tue Jul 12 2022 17:24:12 by
1.7.2