Can_open_slavenode

Dependencies:   mbed

Committer:
sam_grove
Date:
Mon May 30 07:14:41 2011 +0000
Revision:
0:6219434a0cb5
Initial public release of slave node framework port

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:6219434a0cb5 1 /*
sam_grove 0:6219434a0cb5 2 This file is part of CanFestival, a library implementing CanOpen
sam_grove 0:6219434a0cb5 3 Stack.
sam_grove 0:6219434a0cb5 4
sam_grove 0:6219434a0cb5 5 Copyright (C): Edouard TISSERANT and Francis DUPIN
sam_grove 0:6219434a0cb5 6
sam_grove 0:6219434a0cb5 7 See COPYING file for copyrights details.
sam_grove 0:6219434a0cb5 8
sam_grove 0:6219434a0cb5 9 This library is free software; you can redistribute it and/or
sam_grove 0:6219434a0cb5 10 modify it under the terms of the GNU Lesser General Public
sam_grove 0:6219434a0cb5 11 License as published by the Free Software Foundation; either
sam_grove 0:6219434a0cb5 12 version 2.1 of the License, or (at your option) any later version.
sam_grove 0:6219434a0cb5 13
sam_grove 0:6219434a0cb5 14 This library is distributed in the hope that it will be useful,
sam_grove 0:6219434a0cb5 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
sam_grove 0:6219434a0cb5 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
sam_grove 0:6219434a0cb5 17 Lesser General Public License for more details.
sam_grove 0:6219434a0cb5 18
sam_grove 0:6219434a0cb5 19 You should have received a copy of the GNU Lesser General Public
sam_grove 0:6219434a0cb5 20 License along with this library; if not, write to the Free Software
sam_grove 0:6219434a0cb5 21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
sam_grove 0:6219434a0cb5 22 USA
sam_grove 0:6219434a0cb5 23 */
sam_grove 0:6219434a0cb5 24 /*!
sam_grove 0:6219434a0cb5 25 ** @file nmtMaster.c
sam_grove 0:6219434a0cb5 26 ** @author Edouard TISSERANT and Francis DUPIN
sam_grove 0:6219434a0cb5 27 ** @date Tue Jun 5 08:47:18 2007
sam_grove 0:6219434a0cb5 28 **
sam_grove 0:6219434a0cb5 29 ** @brief
sam_grove 0:6219434a0cb5 30 **
sam_grove 0:6219434a0cb5 31 **
sam_grove 0:6219434a0cb5 32 */
sam_grove 0:6219434a0cb5 33 #include "nmtMaster.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 **
sam_grove 0:6219434a0cb5 39 **
sam_grove 0:6219434a0cb5 40 ** @param d
sam_grove 0:6219434a0cb5 41 ** @param Node_ID
sam_grove 0:6219434a0cb5 42 ** @param cs
sam_grove 0:6219434a0cb5 43 **
sam_grove 0:6219434a0cb5 44 ** @return
sam_grove 0:6219434a0cb5 45 **/
sam_grove 0:6219434a0cb5 46 UNS8 masterSendNMTstateChange(CO_Data* d, UNS8 Node_ID, UNS8 cs)
sam_grove 0:6219434a0cb5 47 {
sam_grove 0:6219434a0cb5 48 Message m;
sam_grove 0:6219434a0cb5 49
sam_grove 0:6219434a0cb5 50 MSG_WAR(0x3501, "Send_NMT cs : ", cs);
sam_grove 0:6219434a0cb5 51 MSG_WAR(0x3502, " to node : ", Node_ID);
sam_grove 0:6219434a0cb5 52 /* message configuration */
sam_grove 0:6219434a0cb5 53 m.cob_id = 0x0000; /*(NMT) << 7*/
sam_grove 0:6219434a0cb5 54 m.rtr = NOT_A_REQUEST;
sam_grove 0:6219434a0cb5 55 m.len = 2;
sam_grove 0:6219434a0cb5 56 m.data[0] = cs;
sam_grove 0:6219434a0cb5 57 m.data[1] = Node_ID;
sam_grove 0:6219434a0cb5 58
sam_grove 0:6219434a0cb5 59 return canSend(d->canHandle,&m);
sam_grove 0:6219434a0cb5 60 }
sam_grove 0:6219434a0cb5 61
sam_grove 0:6219434a0cb5 62
sam_grove 0:6219434a0cb5 63 /*!
sam_grove 0:6219434a0cb5 64 **
sam_grove 0:6219434a0cb5 65 **
sam_grove 0:6219434a0cb5 66 ** @param d
sam_grove 0:6219434a0cb5 67 ** @param nodeId
sam_grove 0:6219434a0cb5 68 **
sam_grove 0:6219434a0cb5 69 ** @return
sam_grove 0:6219434a0cb5 70 **/
sam_grove 0:6219434a0cb5 71 UNS8 masterSendNMTnodeguard(CO_Data* d, UNS8 nodeId)
sam_grove 0:6219434a0cb5 72 {
sam_grove 0:6219434a0cb5 73 Message m;
sam_grove 0:6219434a0cb5 74
sam_grove 0:6219434a0cb5 75 /* message configuration */
sam_grove 0:6219434a0cb5 76 UNS16 tmp = nodeId | (NODE_GUARD << 7);
sam_grove 0:6219434a0cb5 77 m.cob_id = UNS16_LE(tmp);
sam_grove 0:6219434a0cb5 78 m.rtr = REQUEST;
sam_grove 0:6219434a0cb5 79 m.len = 0;
sam_grove 0:6219434a0cb5 80
sam_grove 0:6219434a0cb5 81 MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId);
sam_grove 0:6219434a0cb5 82
sam_grove 0:6219434a0cb5 83 return canSend(d->canHandle,&m);
sam_grove 0:6219434a0cb5 84 }
sam_grove 0:6219434a0cb5 85
sam_grove 0:6219434a0cb5 86 /*!
sam_grove 0:6219434a0cb5 87 **
sam_grove 0:6219434a0cb5 88 **
sam_grove 0:6219434a0cb5 89 ** @param d
sam_grove 0:6219434a0cb5 90 ** @param nodeId
sam_grove 0:6219434a0cb5 91 **
sam_grove 0:6219434a0cb5 92 ** @return
sam_grove 0:6219434a0cb5 93 **/
sam_grove 0:6219434a0cb5 94 UNS8 masterRequestNodeState(CO_Data* d, UNS8 nodeId)
sam_grove 0:6219434a0cb5 95 {
sam_grove 0:6219434a0cb5 96 /* FIXME: should warn for bad toggle bit. */
sam_grove 0:6219434a0cb5 97
sam_grove 0:6219434a0cb5 98 /* NMTable configuration to indicate that the master is waiting
sam_grove 0:6219434a0cb5 99 for a Node_Guard frame from the slave whose node_id is ID
sam_grove 0:6219434a0cb5 100 */
sam_grove 0:6219434a0cb5 101 d->NMTable[nodeId] = Unknown_state; /* A state that does not exist
sam_grove 0:6219434a0cb5 102 */
sam_grove 0:6219434a0cb5 103
sam_grove 0:6219434a0cb5 104 if (nodeId == 0) { /* NMT broadcast */
sam_grove 0:6219434a0cb5 105 UNS8 i = 0;
sam_grove 0:6219434a0cb5 106 for (i = 0 ; i < NMT_MAX_NODE_ID ; i++) {
sam_grove 0:6219434a0cb5 107 d->NMTable[i] = Unknown_state;
sam_grove 0:6219434a0cb5 108 }
sam_grove 0:6219434a0cb5 109 }
sam_grove 0:6219434a0cb5 110 return masterSendNMTnodeguard(d,nodeId);
sam_grove 0:6219434a0cb5 111 }
sam_grove 0:6219434a0cb5 112