etisserant@0: /* nico@208: This file is part of CanFestival, a library implementing CanOpen nico@208: Stack. etisserant@0: nico@208: Copyright (C): Edouard TISSERANT and Francis DUPIN etisserant@0: nico@208: See COPYING file for copyrights details. etisserant@0: nico@208: This library is free software; you can redistribute it and/or nico@208: modify it under the terms of the GNU Lesser General Public nico@208: License as published by the Free Software Foundation; either nico@208: version 2.1 of the License, or (at your option) any later version. etisserant@0: nico@208: This library is distributed in the hope that it will be useful, nico@208: but WITHOUT ANY WARRANTY; without even the implied warranty of nico@208: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU nico@208: Lesser General Public License for more details. etisserant@0: nico@208: You should have received a copy of the GNU Lesser General Public nico@208: License along with this library; if not, write to the Free Software nico@208: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 nico@208: USA etisserant@0: */ nico@208: /*! nico@208: ** @file nmtMaster.c nico@208: ** @author Edouard TISSERANT and Francis DUPIN nico@208: ** @date Tue Jun 5 08:47:18 2007 nico@208: ** nico@208: ** @brief nico@208: ** nico@208: ** nico@208: */ etisserant@0: #include "nmtMaster.h" etisserant@149: #include "canfestival.h" etisserant@370: #include "sysdep.h" etisserant@0: nico@208: /*! nico@208: ** nico@208: ** nico@208: ** @param d nico@208: ** @param Node_ID nico@208: ** @param cs nico@208: ** nico@208: ** @return nico@208: **/ etisserant@0: UNS8 masterSendNMTstateChange(CO_Data* d, UNS8 Node_ID, UNS8 cs) etisserant@0: { etisserant@0: Message m; etisserant@0: etisserant@0: MSG_WAR(0x3501, "Send_NMT cs : ", cs); etisserant@0: MSG_WAR(0x3502, " to node : ", Node_ID); nico@215: /* message configuration */ etisserant@365: m.cob_id = 0x0000; /*(NMT) << 7*/ etisserant@0: m.rtr = NOT_A_REQUEST; etisserant@0: m.len = 2; etisserant@0: m.data[0] = cs; etisserant@0: m.data[1] = Node_ID; nico@208: etisserant@149: return canSend(d->canHandle,&m); etisserant@0: } etisserant@0: etisserant@0: nico@208: /*! nico@208: ** nico@208: ** nico@208: ** @param d nico@208: ** @param nodeId nico@208: ** nico@208: ** @return nico@208: **/ etisserant@0: UNS8 masterSendNMTnodeguard(CO_Data* d, UNS8 nodeId) etisserant@0: { etisserant@0: Message m; nico@208: etisserant@0: /* message configuration */ etisserant@370: UNS16 tmp = nodeId | (NODE_GUARD << 7); etisserant@370: m.cob_id = UNS16_LE(tmp); etisserant@0: m.rtr = REQUEST; edouard@597: m.len = 0; nico@208: etisserant@370: MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId); etisserant@370: etisserant@149: return canSend(d->canHandle,&m); etisserant@0: } etisserant@0: nico@208: /*! nico@208: ** nico@208: ** nico@208: ** @param d nico@208: ** @param nodeId nico@208: **/ etisserant@0: void masterRequestNodeState(CO_Data* d, UNS8 nodeId) etisserant@0: { nico@215: /* FIXME: should warn for bad toggle bit. */ etisserant@0: nico@215: /* NMTable configuration to indicate that the master is waiting nico@208: for a Node_Guard frame from the slave whose node_id is ID nico@208: */ nico@215: d->NMTable[nodeId] = Unknown_state; /* A state that does not exist nico@208: */ etisserant@0: nico@215: if (nodeId == 0) { /* NMT broadcast */ etisserant@0: UNS8 i = 0; etisserant@0: for (i = 0 ; i < NMT_MAX_NODE_ID ; i++) { etisserant@0: d->NMTable[i] = Unknown_state; etisserant@0: } etisserant@0: } etisserant@0: masterSendNMTnodeguard(d,nodeId); etisserant@0: } etisserant@0: