nico@207: nico@207:
nico@207:00001 /* nico@210: 00002 This file is part of CanFestival, a library implementing CanOpen nico@210: 00003 Stack. nico@210: 00004 nico@210: 00005 Copyright (C): Edouard TISSERANT and Francis DUPIN nico@210: 00006 nico@210: 00007 See COPYING file for copyrights details. nico@210: 00008 nico@210: 00009 This library is free software; you can redistribute it and/or nico@210: 00010 modify it under the terms of the GNU Lesser General Public nico@210: 00011 License as published by the Free Software Foundation; either nico@210: 00012 version 2.1 of the License, or (at your option) any later version. nico@210: 00013 nico@210: 00014 This library is distributed in the hope that it will be useful, nico@210: 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of nico@210: 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU nico@210: 00017 Lesser General Public License for more details. nico@210: 00018 nico@210: 00019 You should have received a copy of the GNU Lesser General Public nico@210: 00020 License along with this library; if not, write to the Free Software nico@210: 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 nico@210: 00022 USA nico@210: 00023 */ nico@210: 00024 nico@210: 00035 #include <data.h> nico@210: 00036 #include "lifegrd.h" nico@210: 00037 #include "canfestival.h" nico@207: 00038 nico@210: 00039 nico@210: 00040 void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id); nico@210: 00041 nico@210: 00042 nico@210: 00043 void ProducerHearbeatAlarm(CO_Data* d, UNS32 id); nico@210: 00044 nico@210: 00045 UNS32 OnHearbeatProducerUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex); nico@210: 00046 nico@210: 00055 e_nodeState getNodeState (CO_Data* d, UNS8 nodeId) nico@210: 00056 { nico@210: 00057 e_nodeState networkNodeState = d->NMTable[nodeId]; nico@210: 00058 return networkNodeState; nico@210: 00059 } nico@210: 00060 nico@210: 00067 void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id) nico@210: 00068 { nico@210: 00069 /*MSG_WAR(0x00, "ConsumerHearbeatAlarm", 0x00);*/ nico@210: 00070 nico@210: 00072 (*d->heartbeatError)((UNS8)( ((d->ConsumerHeartbeatEntries[id]) & (UNS32)0x00FF0000) >> (UNS8)16 )); nico@210: 00073 } nico@210: 00074 nico@210: 00081 void proceedNODE_GUARD(CO_Data* d, Message* m ) nico@210: 00082 { nico@210: 00083 UNS8 nodeId = (UNS8) GET_NODE_ID((*m)); nico@210: 00084 nico@210: 00085 if((m->rtr == 1) ) nico@210: 00090 { nico@210: 00097 if (nodeId == *d->bDeviceNodeId ) nico@210: 00098 { nico@210: 00099 Message msg; nico@210: 00100 msg.cob_id.w = *d->bDeviceNodeId + 0x700; nico@210: 00101 msg.len = (UNS8)0x01; nico@210: 00102 msg.rtr = 0; nico@210: 00103 msg.data[0] = d->nodeState; nico@210: 00104 if (d->toggle) nico@210: 00105 { nico@210: 00106 msg.data[0] |= 0x80 ; nico@210: 00107 d->toggle = 0 ; nico@210: 00108 } nico@210: 00109 else nico@210: 00110 d->toggle = 1 ; nico@210: 00112 MSG_WAR(0x3130, "Sending NMT Nodeguard to master, state: ", d->nodeState); nico@210: 00113 canSend(d->canHandle,&msg ); nico@210: 00114 } nico@210: 00115 nico@210: 00116 }else{ nico@210: 00118 MSG_WAR(0x3110, "Received NMT nodeId : ", nodeId); nico@210: 00121 d->NMTable[nodeId] = (e_nodeState) ((*m).data[0] & 0x7F) ; nico@210: 00122 nico@210: 00124 if ( d->NMTable[nodeId] == Initialisation) nico@210: 00125 { nico@210: 00135 MSG_WAR(0x3100, "The NMT is a bootup from node : ", nodeId); nico@210: 00136 } nico@210: 00137 nico@210: 00138 if( d->NMTable[nodeId] != Unknown_state ) { nico@210: 00139 UNS8 index, ConsummerHeartBeat_nodeId ; nico@210: 00140 for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ ) nico@210: 00141 { nico@210: 00142 ConsummerHeartBeat_nodeId = (UNS8)( ((d->ConsumerHeartbeatEntries[index]) & (UNS32)0x00FF0000) >> (UNS8)16 ); nico@210: 00143 if ( nodeId == ConsummerHeartBeat_nodeId ) nico@210: 00144 { nico@210: 00145 TIMEVAL time = ( (d->ConsumerHeartbeatEntries[index]) & (UNS32)0x0000FFFF ) ; nico@210: 00146 /* Renew alarm for next heartbeat. */ nico@210: 00147 DelAlarm(d->ConsumerHeartBeatTimers[index]); nico@210: 00148 d->ConsumerHeartBeatTimers[index] = SetAlarm(d, index, &ConsumerHearbeatAlarm, MS_TO_TIMEVAL(time), 0); nico@210: 00149 } nico@210: 00150 } nico@210: 00151 } nico@210: 00152 } nico@210: 00153 } nico@210: 00154 nico@210: 00161 void ProducerHearbeatAlarm(CO_Data* d, UNS32 id) nico@210: 00162 { nico@210: 00163 if(*d->ProducerHeartBeatTime) nico@210: 00164 { nico@210: 00165 Message msg; nico@210: 00172 msg.cob_id.w = *d->bDeviceNodeId + 0x700; nico@210: 00173 msg.len = (UNS8)0x01; nico@210: 00174 msg.rtr = 0; nico@210: 00175 msg.data[0] = d->nodeState; nico@210: 00177 MSG_WAR(0x3130, "Producing heartbeat: ", d->nodeState); nico@210: 00178 canSend(d->canHandle,&msg ); nico@210: 00179 nico@210: 00180 }else{ nico@210: 00181 d->ProducerHeartBeatTimer = DelAlarm(d->ProducerHeartBeatTimer); nico@210: 00182 } nico@210: 00183 } nico@210: 00184 nico@210: 00194 UNS32 OnHeartbeatProducerUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex) nico@210: 00195 { nico@210: 00196 heartbeatStop(d); nico@210: 00197 heartbeatInit(d); nico@210: 00198 return 0; nico@210: 00199 } nico@210: 00200 nico@210: 00206 void heartbeatInit(CO_Data* d) nico@210: 00207 { nico@210: 00208 nico@210: 00209 UNS8 index; nico@210: 00210 RegisterSetODentryCallBack(d, 0x1017, 0x00, &OnHeartbeatProducerUpdate); nico@210: 00211 nico@210: 00212 d->toggle = 0; nico@210: 00213 nico@210: 00214 for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ ) nico@210: 00215 { nico@210: 00216 TIMEVAL time = (UNS16) ( (d->ConsumerHeartbeatEntries[index]) & (UNS32)0x0000FFFF ) ; nico@210: 00218 if ( time ) nico@210: 00219 { nico@210: 00220 d->ConsumerHeartBeatTimers[index] = SetAlarm(d, index, &ConsumerHearbeatAlarm, MS_TO_TIMEVAL(time), 0); nico@210: 00221 } nico@210: 00222 } nico@210: 00223 nico@210: 00224 if ( *d->ProducerHeartBeatTime ) nico@210: 00225 { nico@210: 00226 TIMEVAL time = *d->ProducerHeartBeatTime; nico@210: 00227 d->ProducerHeartBeatTimer = SetAlarm(d, 0, &ProducerHearbeatAlarm, MS_TO_TIMEVAL(time), MS_TO_TIMEVAL(time)); nico@210: 00228 } nico@210: 00229 } nico@210: 00230 nico@210: 00236 void heartbeatStop(CO_Data* d) nico@210: 00237 { nico@210: 00238 UNS8 index; nico@210: 00239 for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ ) nico@210: 00240 { nico@210: 00241 d->ConsumerHeartBeatTimers[index + 1] = DelAlarm(d->ConsumerHeartBeatTimers[index + 1]);; nico@210: 00242 } nico@210: 00243 nico@210: 00244 d->ProducerHeartBeatTimer = DelAlarm(d->ProducerHeartBeatTimer);; nico@210: 00245 } nico@210: 00246 nico@210: 00252 void _heartbeatError(UNS8 heartbeatID){} nico@210: