Sam Grove
/
canopen_slavenode
CANfestival - an open source CANopen framework
framework/src/nmtSlave.c@6:bc64031ac849, 2012-09-26 (annotated)
- Committer:
- sam_grove
- Date:
- Wed Sep 26 05:43:05 2012 +0000
- Revision:
- 6:bc64031ac849
- Parent:
- 0:6219434a0cb5
Change a typecast in can_mbed.cpp from unit8_t * to char * to fit the CANMessage constructor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove |
0:6219434a0cb5 | 1 | /* |
sam_grove |
0:6219434a0cb5 | 2 | This file is part of CanFestival, a library implementing CanOpen Stack. |
sam_grove |
0:6219434a0cb5 | 3 | |
sam_grove |
0:6219434a0cb5 | 4 | Copyright (C): Edouard TISSERANT and Francis DUPIN |
sam_grove |
0:6219434a0cb5 | 5 | |
sam_grove |
0:6219434a0cb5 | 6 | See COPYING file for copyrights details. |
sam_grove |
0:6219434a0cb5 | 7 | |
sam_grove |
0:6219434a0cb5 | 8 | This library is free software; you can redistribute it and/or |
sam_grove |
0:6219434a0cb5 | 9 | modify it under the terms of the GNU Lesser General Public |
sam_grove |
0:6219434a0cb5 | 10 | License as published by the Free Software Foundation; either |
sam_grove |
0:6219434a0cb5 | 11 | version 2.1 of the License, or (at your option) any later version. |
sam_grove |
0:6219434a0cb5 | 12 | |
sam_grove |
0:6219434a0cb5 | 13 | This library is distributed in the hope that it will be useful, |
sam_grove |
0:6219434a0cb5 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
sam_grove |
0:6219434a0cb5 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
sam_grove |
0:6219434a0cb5 | 16 | Lesser General Public License for more details. |
sam_grove |
0:6219434a0cb5 | 17 | |
sam_grove |
0:6219434a0cb5 | 18 | You should have received a copy of the GNU Lesser General Public |
sam_grove |
0:6219434a0cb5 | 19 | License along with this library; if not, write to the Free Software |
sam_grove |
0:6219434a0cb5 | 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
sam_grove |
0:6219434a0cb5 | 21 | USA |
sam_grove |
0:6219434a0cb5 | 22 | */ |
sam_grove |
0:6219434a0cb5 | 23 | /*! |
sam_grove |
0:6219434a0cb5 | 24 | ** @file nmtSlave.c |
sam_grove |
0:6219434a0cb5 | 25 | ** @author Edouard TISSERANT and Francis DUPIN |
sam_grove |
0:6219434a0cb5 | 26 | ** @date Tue Jun 5 08:50:53 2007 |
sam_grove |
0:6219434a0cb5 | 27 | ** |
sam_grove |
0:6219434a0cb5 | 28 | ** @brief |
sam_grove |
0:6219434a0cb5 | 29 | ** |
sam_grove |
0:6219434a0cb5 | 30 | ** |
sam_grove |
0:6219434a0cb5 | 31 | */ |
sam_grove |
0:6219434a0cb5 | 32 | #include "nmtSlave.h" |
sam_grove |
0:6219434a0cb5 | 33 | #include "states.h" |
sam_grove |
0:6219434a0cb5 | 34 | #include "canfestival.h" |
sam_grove |
0:6219434a0cb5 | 35 | #include "sysdep.h" |
sam_grove |
0:6219434a0cb5 | 36 | |
sam_grove |
0:6219434a0cb5 | 37 | /*! |
sam_grove |
0:6219434a0cb5 | 38 | ** put the slave in the state wanted by the master |
sam_grove |
0:6219434a0cb5 | 39 | ** |
sam_grove |
0:6219434a0cb5 | 40 | ** @param d |
sam_grove |
0:6219434a0cb5 | 41 | ** @param m |
sam_grove |
0:6219434a0cb5 | 42 | **/ |
sam_grove |
0:6219434a0cb5 | 43 | void proceedNMTstateChange(CO_Data* d, Message *m) |
sam_grove |
0:6219434a0cb5 | 44 | { |
sam_grove |
0:6219434a0cb5 | 45 | if( d->nodeState == Pre_operational || |
sam_grove |
0:6219434a0cb5 | 46 | d->nodeState == Operational || |
sam_grove |
0:6219434a0cb5 | 47 | d->nodeState == Stopped ) { |
sam_grove |
0:6219434a0cb5 | 48 | |
sam_grove |
0:6219434a0cb5 | 49 | MSG_WAR(0x3400, "NMT received. for node : ", (*m).data[1]); |
sam_grove |
0:6219434a0cb5 | 50 | |
sam_grove |
0:6219434a0cb5 | 51 | /* Check if this NMT-message is for this node */ |
sam_grove |
0:6219434a0cb5 | 52 | /* byte 1 = 0 : all the nodes are concerned (broadcast) */ |
sam_grove |
0:6219434a0cb5 | 53 | |
sam_grove |
0:6219434a0cb5 | 54 | if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == *d->bDeviceNodeId ) ){ |
sam_grove |
0:6219434a0cb5 | 55 | |
sam_grove |
0:6219434a0cb5 | 56 | switch( (*m).data[0]){ /* command specifier (cs) */ |
sam_grove |
0:6219434a0cb5 | 57 | case NMT_Start_Node: |
sam_grove |
0:6219434a0cb5 | 58 | if ( (d->nodeState == Pre_operational) || (d->nodeState == Stopped) ) |
sam_grove |
0:6219434a0cb5 | 59 | setState(d,Operational); |
sam_grove |
0:6219434a0cb5 | 60 | break; |
sam_grove |
0:6219434a0cb5 | 61 | |
sam_grove |
0:6219434a0cb5 | 62 | case NMT_Stop_Node: |
sam_grove |
0:6219434a0cb5 | 63 | if ( d->nodeState == Pre_operational || |
sam_grove |
0:6219434a0cb5 | 64 | d->nodeState == Operational ) |
sam_grove |
0:6219434a0cb5 | 65 | setState(d,Stopped); |
sam_grove |
0:6219434a0cb5 | 66 | break; |
sam_grove |
0:6219434a0cb5 | 67 | |
sam_grove |
0:6219434a0cb5 | 68 | case NMT_Enter_PreOperational: |
sam_grove |
0:6219434a0cb5 | 69 | if ( d->nodeState == Operational || |
sam_grove |
0:6219434a0cb5 | 70 | d->nodeState == Stopped ) |
sam_grove |
0:6219434a0cb5 | 71 | setState(d,Pre_operational); |
sam_grove |
0:6219434a0cb5 | 72 | break; |
sam_grove |
0:6219434a0cb5 | 73 | |
sam_grove |
0:6219434a0cb5 | 74 | case NMT_Reset_Node: |
sam_grove |
0:6219434a0cb5 | 75 | if(d->NMT_Slave_Node_Reset_Callback != NULL) |
sam_grove |
0:6219434a0cb5 | 76 | d->NMT_Slave_Node_Reset_Callback(d); |
sam_grove |
0:6219434a0cb5 | 77 | setState(d,Initialisation); |
sam_grove |
0:6219434a0cb5 | 78 | break; |
sam_grove |
0:6219434a0cb5 | 79 | |
sam_grove |
0:6219434a0cb5 | 80 | case NMT_Reset_Comunication: |
sam_grove |
0:6219434a0cb5 | 81 | { |
sam_grove |
0:6219434a0cb5 | 82 | UNS8 currentNodeId = getNodeId(d); |
sam_grove |
0:6219434a0cb5 | 83 | |
sam_grove |
0:6219434a0cb5 | 84 | if(d->NMT_Slave_Communications_Reset_Callback != NULL) |
sam_grove |
0:6219434a0cb5 | 85 | d->NMT_Slave_Communications_Reset_Callback(d); |
sam_grove |
0:6219434a0cb5 | 86 | #ifdef CO_ENABLE_LSS |
sam_grove |
0:6219434a0cb5 | 87 | // LSS changes NodeId here in case lss_transfer.nodeID doesn't |
sam_grove |
0:6219434a0cb5 | 88 | // match current getNodeId() |
sam_grove |
0:6219434a0cb5 | 89 | if(currentNodeId!=d->lss_transfer.nodeID) |
sam_grove |
0:6219434a0cb5 | 90 | currentNodeId = d->lss_transfer.nodeID; |
sam_grove |
0:6219434a0cb5 | 91 | #endif |
sam_grove |
0:6219434a0cb5 | 92 | |
sam_grove |
0:6219434a0cb5 | 93 | // clear old NodeId to make SetNodeId reinitializing |
sam_grove |
0:6219434a0cb5 | 94 | // SDO, EMCY and other COB Ids |
sam_grove |
0:6219434a0cb5 | 95 | *d->bDeviceNodeId = 0xFF; |
sam_grove |
0:6219434a0cb5 | 96 | |
sam_grove |
0:6219434a0cb5 | 97 | setNodeId(d, currentNodeId); |
sam_grove |
0:6219434a0cb5 | 98 | } |
sam_grove |
0:6219434a0cb5 | 99 | setState(d,Initialisation); |
sam_grove |
0:6219434a0cb5 | 100 | break; |
sam_grove |
0:6219434a0cb5 | 101 | |
sam_grove |
0:6219434a0cb5 | 102 | }/* end switch */ |
sam_grove |
0:6219434a0cb5 | 103 | |
sam_grove |
0:6219434a0cb5 | 104 | }/* end if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == |
sam_grove |
0:6219434a0cb5 | 105 | bDeviceNodeId ) ) */ |
sam_grove |
0:6219434a0cb5 | 106 | } |
sam_grove |
0:6219434a0cb5 | 107 | } |
sam_grove |
0:6219434a0cb5 | 108 | |
sam_grove |
0:6219434a0cb5 | 109 | |
sam_grove |
0:6219434a0cb5 | 110 | /*! |
sam_grove |
0:6219434a0cb5 | 111 | ** |
sam_grove |
0:6219434a0cb5 | 112 | ** |
sam_grove |
0:6219434a0cb5 | 113 | ** @param d |
sam_grove |
0:6219434a0cb5 | 114 | ** |
sam_grove |
0:6219434a0cb5 | 115 | ** @return |
sam_grove |
0:6219434a0cb5 | 116 | **/ |
sam_grove |
0:6219434a0cb5 | 117 | UNS8 slaveSendBootUp(CO_Data* d) |
sam_grove |
0:6219434a0cb5 | 118 | { |
sam_grove |
0:6219434a0cb5 | 119 | Message m; |
sam_grove |
0:6219434a0cb5 | 120 | |
sam_grove |
0:6219434a0cb5 | 121 | #ifdef CO_ENABLE_LSS |
sam_grove |
0:6219434a0cb5 | 122 | if(*d->bDeviceNodeId==0xFF)return 0; |
sam_grove |
0:6219434a0cb5 | 123 | #endif |
sam_grove |
0:6219434a0cb5 | 124 | |
sam_grove |
0:6219434a0cb5 | 125 | MSG_WAR(0x3407, "Send a Boot-Up msg ", 0); |
sam_grove |
0:6219434a0cb5 | 126 | |
sam_grove |
0:6219434a0cb5 | 127 | /* message configuration */ |
sam_grove |
0:6219434a0cb5 | 128 | { |
sam_grove |
0:6219434a0cb5 | 129 | UNS16 tmp = NODE_GUARD << 7 | *d->bDeviceNodeId; |
sam_grove |
0:6219434a0cb5 | 130 | m.cob_id = UNS16_LE(tmp); |
sam_grove |
0:6219434a0cb5 | 131 | } |
sam_grove |
0:6219434a0cb5 | 132 | m.rtr = NOT_A_REQUEST; |
sam_grove |
0:6219434a0cb5 | 133 | m.len = 1; |
sam_grove |
0:6219434a0cb5 | 134 | m.data[0] = 0x00; |
sam_grove |
0:6219434a0cb5 | 135 | |
sam_grove |
0:6219434a0cb5 | 136 | return canSend(d->canHandle,&m); |
sam_grove |
0:6219434a0cb5 | 137 | } |
sam_grove |
0:6219434a0cb5 | 138 |