author | etisserant |
Tue, 15 Jan 2008 09:29:29 +0100 | |
changeset 355 | 12adbd08e10c |
parent 352 | 3347581c3140 |
child 357 | 838e5397ae67 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
207 | 2 |
This file is part of CanFestival, a library implementing CanOpen |
3 |
Stack. |
|
4 |
||
5 |
Copyright (C): Edouard TISSERANT and Francis DUPIN |
|
6 |
||
7 |
See COPYING file for copyrights details. |
|
8 |
||
9 |
This library is free software; you can redistribute it and/or |
|
10 |
modify it under the terms of the GNU Lesser General Public |
|
11 |
License as published by the Free Software Foundation; either |
|
12 |
version 2.1 of the License, or (at your option) any later version. |
|
13 |
||
14 |
This library is distributed in the hope that it will be useful, |
|
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 |
Lesser General Public License for more details. |
|
18 |
||
19 |
You should have received a copy of the GNU Lesser General Public |
|
20 |
License along with this library; if not, write to the Free Software |
|
21 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
22 |
USA |
|
23 |
*/ |
|
24 |
||
25 |
/*! |
|
208 | 26 |
** @file lifegrd.c |
207 | 27 |
** @author Edouard TISSERANT |
28 |
** @date Mon Jun 4 17:19:24 2007 |
|
29 |
** |
|
30 |
** @brief |
|
31 |
** |
|
32 |
** |
|
0 | 33 |
*/ |
34 |
||
35 |
#include <data.h> |
|
36 |
#include "lifegrd.h" |
|
149 | 37 |
#include "canfestival.h" |
0 | 38 |
|
208 | 39 |
|
53 | 40 |
void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id); |
207 | 41 |
|
208 | 42 |
|
53 | 43 |
void ProducerHearbeatAlarm(CO_Data* d, UNS32 id); |
207 | 44 |
|
185 | 45 |
UNS32 OnHearbeatProducerUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex); |
53 | 46 |
|
207 | 47 |
/*! |
48 |
** |
|
49 |
** |
|
50 |
** @param d |
|
51 |
** @param nodeId |
|
52 |
** |
|
53 |
** @return |
|
54 |
**/ |
|
0 | 55 |
e_nodeState getNodeState (CO_Data* d, UNS8 nodeId) |
56 |
{ |
|
207 | 57 |
e_nodeState networkNodeState = d->NMTable[nodeId]; |
58 |
return networkNodeState; |
|
59 |
} |
|
60 |
||
208 | 61 |
/*! |
62 |
** The Consumer Timer Callback |
|
207 | 63 |
** |
64 |
** @param d |
|
65 |
** @param id |
|
66 |
**/ |
|
0 | 67 |
void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id) |
68 |
{ |
|
207 | 69 |
/*MSG_WAR(0x00, "ConsumerHearbeatAlarm", 0x00);*/ |
70 |
||
352
3347581c3140
Fixed timer problem on late Heartbeat. Thanks to Jorge.
etisserant
parents:
349
diff
changeset
|
71 |
/* timer have been notified and is now free (non periodic)*/ |
3347581c3140
Fixed timer problem on late Heartbeat. Thanks to Jorge.
etisserant
parents:
349
diff
changeset
|
72 |
/* -> avoid deleting re-assigned timer if message is received too late*/ |
3347581c3140
Fixed timer problem on late Heartbeat. Thanks to Jorge.
etisserant
parents:
349
diff
changeset
|
73 |
d->ConsumerHeartBeatTimers[id]=TIMER_NONE; |
207 | 74 |
/*! call heartbeat error with NodeId */ |
75 |
(*d->heartbeatError)((UNS8)( ((d->ConsumerHeartbeatEntries[id]) & (UNS32)0x00FF0000) >> (UNS8)16 )); |
|
76 |
} |
|
77 |
||
78 |
/*! |
|
79 |
** |
|
80 |
** |
|
81 |
** @param d |
|
82 |
** @param m |
|
83 |
**/ |
|
0 | 84 |
void proceedNODE_GUARD(CO_Data* d, Message* m ) |
85 |
{ |
|
86 |
UNS8 nodeId = (UNS8) GET_NODE_ID((*m)); |
|
207 | 87 |
|
88 |
if((m->rtr == 1) ) |
|
89 |
/*! |
|
90 |
** Notice that only the master can have sent this |
|
91 |
** node guarding request |
|
92 |
*/ |
|
93 |
{ |
|
94 |
/*! |
|
95 |
** Receiving a NMT NodeGuarding (request of the state by the |
|
96 |
** master) |
|
97 |
** Only answer to the NMT NodeGuarding request, the master is |
|
98 |
** not checked (not implemented) |
|
99 |
*/ |
|
100 |
if (nodeId == *d->bDeviceNodeId ) |
|
101 |
{ |
|
102 |
Message msg; |
|
103 |
msg.cob_id.w = *d->bDeviceNodeId + 0x700; |
|
104 |
msg.len = (UNS8)0x01; |
|
105 |
msg.rtr = 0; |
|
106 |
msg.data[0] = d->nodeState; |
|
107 |
if (d->toggle) |
|
108 |
{ |
|
109 |
msg.data[0] |= 0x80 ; |
|
110 |
d->toggle = 0 ; |
|
111 |
} |
|
112 |
else |
|
113 |
d->toggle = 1 ; |
|
215 | 114 |
/* send the nodeguard response. */ |
207 | 115 |
MSG_WAR(0x3130, "Sending NMT Nodeguard to master, state: ", d->nodeState); |
116 |
canSend(d->canHandle,&msg ); |
|
117 |
} |
|
118 |
||
215 | 119 |
}else{ /* Not a request CAN */ |
207 | 120 |
|
121 |
MSG_WAR(0x3110, "Received NMT nodeId : ", nodeId); |
|
215 | 122 |
/* the slave's state receievd is stored in the NMTable */ |
123 |
/* The state is stored on 7 bit */ |
|
207 | 124 |
d->NMTable[nodeId] = (e_nodeState) ((*m).data[0] & 0x7F) ; |
125 |
||
215 | 126 |
/* Boot-Up frame reception */ |
207 | 127 |
if ( d->NMTable[nodeId] == Initialisation) |
128 |
{ |
|
215 | 129 |
/* |
207 | 130 |
** The device send the boot-up message (Initialisation) |
131 |
** to indicate the master that it is entered in |
|
132 |
** pre_operational mode |
|
133 |
** Because the device enter automaticaly in pre_operational |
|
134 |
** mode, |
|
135 |
** the pre_operational mode is stored |
|
136 |
** NMTable[bus_id][nodeId] = Pre_operational |
|
137 |
*/ |
|
138 |
MSG_WAR(0x3100, "The NMT is a bootup from node : ", nodeId); |
|
343 | 139 |
|
349 | 140 |
if(!send_consise_dcf(d,nodeId)){ |
343 | 141 |
/* call post SlaveBootup with NodeId */ |
349 | 142 |
(*d->post_SlaveBootup)(nodeId); |
143 |
} |
|
207 | 144 |
} |
145 |
||
146 |
if( d->NMTable[nodeId] != Unknown_state ) { |
|
147 |
UNS8 index, ConsummerHeartBeat_nodeId ; |
|
148 |
for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ ) |
|
149 |
{ |
|
150 |
ConsummerHeartBeat_nodeId = (UNS8)( ((d->ConsumerHeartbeatEntries[index]) & (UNS32)0x00FF0000) >> (UNS8)16 ); |
|
151 |
if ( nodeId == ConsummerHeartBeat_nodeId ) |
|
152 |
{ |
|
153 |
TIMEVAL time = ( (d->ConsumerHeartbeatEntries[index]) & (UNS32)0x0000FFFF ) ; |
|
154 |
/* Renew alarm for next heartbeat. */ |
|
155 |
DelAlarm(d->ConsumerHeartBeatTimers[index]); |
|
156 |
d->ConsumerHeartBeatTimers[index] = SetAlarm(d, index, &ConsumerHearbeatAlarm, MS_TO_TIMEVAL(time), 0); |
|
157 |
} |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
/*! The Consumer Timer Callback |
|
164 |
** |
|
165 |
** |
|
166 |
** @param d |
|
167 |
** @param id |
|
168 |
**/ |
|
169 |
void ProducerHearbeatAlarm(CO_Data* d, UNS32 id) |
|
170 |
{ |
|
171 |
if(*d->ProducerHeartBeatTime) |
|
0 | 172 |
{ |
173 |
Message msg; |
|
215 | 174 |
/* Time expired, the heartbeat must be sent immediately |
207 | 175 |
** generate the correct node-id: this is done by the offset 1792 |
176 |
** (decimal) and additionaly |
|
177 |
** the node-id of this device. |
|
178 |
*/ |
|
179 |
||
0 | 180 |
msg.cob_id.w = *d->bDeviceNodeId + 0x700; |
181 |
msg.len = (UNS8)0x01; |
|
182 |
msg.rtr = 0; |
|
215 | 183 |
msg.data[0] = d->nodeState; /* No toggle for heartbeat !*/ |
184 |
/* send the heartbeat */ |
|
207 | 185 |
MSG_WAR(0x3130, "Producing heartbeat: ", d->nodeState); |
149 | 186 |
canSend(d->canHandle,&msg ); |
207 | 187 |
|
188 |
}else{ |
|
189 |
d->ProducerHeartBeatTimer = DelAlarm(d->ProducerHeartBeatTimer); |
|
190 |
} |
|
191 |
} |
|
192 |
||
193 |
/*! This is called when Index 0x1017 is updated. |
|
194 |
** |
|
195 |
** |
|
196 |
** @param d |
|
197 |
** @param unsused_indextable |
|
198 |
** @param unsused_bSubindex |
|
199 |
** |
|
200 |
** @return |
|
201 |
**/ |
|
202 |
UNS32 OnHeartbeatProducerUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex) |
|
203 |
{ |
|
204 |
heartbeatStop(d); |
|
205 |
heartbeatInit(d); |
|
206 |
return 0; |
|
207 |
} |
|
208 |
||
209 |
/*! |
|
210 |
** |
|
211 |
** |
|
212 |
** @param d |
|
213 |
**/ |
|
214 |
void heartbeatInit(CO_Data* d) |
|
215 |
{ |
|
216 |
||
215 | 217 |
UNS8 index; /* Index to scan the table of heartbeat consumers */ |
207 | 218 |
RegisterSetODentryCallBack(d, 0x1017, 0x00, &OnHeartbeatProducerUpdate); |
219 |
||
220 |
d->toggle = 0; |
|
221 |
||
222 |
for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ ) |
|
223 |
{ |
|
224 |
TIMEVAL time = (UNS16) ( (d->ConsumerHeartbeatEntries[index]) & (UNS32)0x0000FFFF ) ; |
|
215 | 225 |
/* MSG_WAR(0x3121, "should_time : ", should_time ) ; */ |
207 | 226 |
if ( time ) |
0 | 227 |
{ |
207 | 228 |
d->ConsumerHeartBeatTimers[index] = SetAlarm(d, index, &ConsumerHearbeatAlarm, MS_TO_TIMEVAL(time), 0); |
0 | 229 |
} |
230 |
} |
|
207 | 231 |
|
232 |
if ( *d->ProducerHeartBeatTime ) |
|
233 |
{ |
|
234 |
TIMEVAL time = *d->ProducerHeartBeatTime; |
|
235 |
d->ProducerHeartBeatTimer = SetAlarm(d, 0, &ProducerHearbeatAlarm, MS_TO_TIMEVAL(time), MS_TO_TIMEVAL(time)); |
|
236 |
} |
|
237 |
} |
|
238 |
||
239 |
/*! |
|
240 |
** |
|
241 |
** |
|
242 |
** @param d |
|
243 |
**/ |
|
0 | 244 |
void heartbeatStop(CO_Data* d) |
245 |
{ |
|
207 | 246 |
UNS8 index; |
247 |
for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ ) |
|
248 |
{ |
|
249 |
d->ConsumerHeartBeatTimers[index + 1] = DelAlarm(d->ConsumerHeartBeatTimers[index + 1]);; |
|
250 |
} |
|
251 |
||
252 |
d->ProducerHeartBeatTimer = DelAlarm(d->ProducerHeartBeatTimer);; |
|
253 |
} |
|
254 |
||
255 |
/*! |
|
256 |
** |
|
257 |
** |
|
258 |
** @param heartbeatID |
|
259 |
**/ |
|
149 | 260 |
void _heartbeatError(UNS8 heartbeatID){} |
343 | 261 |
void _post_SlaveBootup(UNS8 SlaveID){} |