author | Laurent Bessard |
Thu, 02 May 2013 09:42:37 +0200 | |
changeset 782 | c0869429c72a |
parent 743 | 17715d2ecf10 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
208 | 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 |
|
0 | 23 |
*/ |
24 |
#include "pdo.h" |
|
25 |
#include "objacces.h" |
|
149 | 26 |
#include "canfestival.h" |
370
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
27 |
#include "sysdep.h" |
0 | 28 |
|
208 | 29 |
/*! |
30 |
** @file pdo.c |
|
31 |
** @author Edouard TISSERANT and Francis DUPIN |
|
32 |
** @date Tue Jun 5 09:32:32 2007 |
|
33 |
** |
|
34 |
** @brief |
|
35 |
** |
|
36 |
** |
|
37 |
*/ |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
38 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
39 |
/*! |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
40 |
** |
208 | 41 |
** |
42 |
** @param d |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
43 |
** @param TPDO_com TPDO communication parameters OD entry |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
44 |
** @param TPDO_map TPDO mapping parameters OD entry |
208 | 45 |
** |
46 |
** @return |
|
47 |
**/ |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
48 |
|
524 | 49 |
UNS8 buildPDO (CO_Data * d, UNS8 numPdo, Message * pdo) |
425 | 50 |
{ |
51 |
const indextable *TPDO_com = d->objdict + d->firstIndex->PDO_TRS + numPdo; |
|
524 | 52 |
const indextable *TPDO_map = d->objdict + d->firstIndex->PDO_TRS_MAP + numPdo; |
425 | 53 |
|
54 |
UNS8 prp_j = 0x00; |
|
587 | 55 |
UNS32 offset = 0x00000000; |
425 | 56 |
const UNS8 *pMappingCount = (UNS8 *) TPDO_map->pSubindex[0].pObject; |
57 |
||
649
3beb784bacee
CHANGED: - function sendOnePDOevent (CO_Data* d, UNS32 pdoNum) into sendOnePDOevent (CO_Data* d, UNS8 pdoNum)
Christian Taedcke
parents:
630
diff
changeset
|
58 |
pdo->cob_id = (UNS16) UNS16_LE(*(UNS32*)TPDO_com->pSubindex[1].pObject & 0x7FF); |
425 | 59 |
pdo->rtr = NOT_A_REQUEST; |
60 |
||
61 |
MSG_WAR (0x3009, " PDO CobId is : ", |
|
62 |
*(UNS32 *) TPDO_com->pSubindex[1].pObject); |
|
63 |
MSG_WAR (0x300D, " Number of objects mapped : ", *pMappingCount); |
|
64 |
||
65 |
do |
|
66 |
{ |
|
67 |
UNS8 dataType; /* Unused */ |
|
68 |
UNS8 tmp[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; /* temporary space to hold bits */ |
|
69 |
||
70 |
/* pointer fo the var which holds the mapping parameter of an mapping entry */ |
|
71 |
UNS32 *pMappingParameter = |
|
72 |
(UNS32 *) TPDO_map->pSubindex[prp_j + 1].pObject; |
|
73 |
UNS16 index = (UNS16) ((*pMappingParameter) >> 16); |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
524
diff
changeset
|
74 |
UNS32 Size = (UNS32) (*pMappingParameter & (UNS32) 0x000000FF); /* Size in bits */ |
425 | 75 |
|
76 |
/* get variable only if Size != 0 and Size is lower than remaining bits in the PDO */ |
|
77 |
if (Size && ((offset + Size) <= 64)) |
|
78 |
{ |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
524
diff
changeset
|
79 |
UNS32 ByteSize = 1 + ((Size - 1) >> 3); /*1->8 => 1 ; 9->16 => 2, ... */ |
425 | 80 |
UNS8 subIndex = |
81 |
(UNS8) (((*pMappingParameter) >> (UNS8) 8) & (UNS32) 0x000000FF); |
|
82 |
||
83 |
MSG_WAR (0x300F, " got mapping parameter : ", *pMappingParameter); |
|
84 |
MSG_WAR (0x3050, " at index : ", TPDO_map->index); |
|
85 |
MSG_WAR (0x3051, " sub-index : ", prp_j + 1); |
|
86 |
||
87 |
if (getODentry (d, index, subIndex, tmp, &ByteSize, &dataType, 0) != |
|
88 |
OD_SUCCESSFUL) |
|
89 |
{ |
|
90 |
MSG_ERR (0x1013, |
|
91 |
" Couldn't find mapped variable at index-subindex-size : ", |
|
711 | 92 |
(UNS32) (*pMappingParameter)); |
425 | 93 |
return 0xFF; |
94 |
} |
|
95 |
/* copy bit per bit in little endian */ |
|
587 | 96 |
CopyBits ((UNS8) Size, ((UNS8 *) tmp), 0, 0, |
97 |
(UNS8 *) & pdo->data[offset >> 3], (UNS8)(offset % 8), 0); |
|
425 | 98 |
|
99 |
offset += Size; |
|
100 |
} |
|
101 |
prp_j++; |
|
102 |
} |
|
103 |
while (prp_j < *pMappingCount); |
|
104 |
||
587 | 105 |
pdo->len = (UNS8)(1 + ((offset - 1) >> 3)); |
425 | 106 |
|
107 |
MSG_WAR (0x3015, " End scan mapped variable", 0); |
|
108 |
||
109 |
return 0; |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
110 |
} |
208 | 111 |
|
112 |
/*! |
|
113 |
** |
|
114 |
** |
|
115 |
** @param d |
|
116 |
** @param cobId |
|
117 |
** |
|
118 |
** @return |
|
119 |
**/ |
|
425 | 120 |
UNS8 |
121 |
sendPDOrequest (CO_Data * d, UNS16 RPDOIndex) |
|
122 |
{ |
|
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
123 |
UNS16 *pwCobId; |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
124 |
UNS16 offset = d->firstIndex->PDO_RCV; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
125 |
UNS16 lastIndex = d->lastIndex->PDO_RCV; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
126 |
|
611 | 127 |
if (!d->CurrentCommunicationState.csPDO) |
128 |
{ |
|
129 |
return 0; |
|
130 |
} |
|
131 |
||
215 | 132 |
/* Sending the request only if the cobid have been found on the PDO |
208 | 133 |
receive */ |
215 | 134 |
/* part dictionary */ |
425 | 135 |
|
136 |
MSG_WAR (0x3930, "sendPDOrequest RPDO Index : ", RPDOIndex); |
|
137 |
||
138 |
if (offset && RPDOIndex >= 0x1400) |
|
139 |
{ |
|
140 |
offset += RPDOIndex - 0x1400; |
|
141 |
if (offset <= lastIndex) |
|
142 |
{ |
|
143 |
/* get the CobId */ |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
428
diff
changeset
|
144 |
pwCobId = d->objdict[offset].pSubindex[1].pObject; |
425 | 145 |
|
146 |
MSG_WAR (0x3930, "sendPDOrequest cobId is : ", *pwCobId); |
|
147 |
{ |
|
148 |
Message pdo; |
|
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
149 |
pdo.cob_id = UNS16_LE(*pwCobId); |
425 | 150 |
pdo.rtr = REQUEST; |
151 |
pdo.len = 0; |
|
152 |
return canSend (d->canHandle, &pdo); |
|
153 |
} |
|
154 |
} |
|
208 | 155 |
} |
425 | 156 |
MSG_ERR (0x1931, "sendPDOrequest : RPDO Index not found : ", RPDOIndex); |
0 | 157 |
return 0xFF; |
158 |
} |
|
159 |
||
160 |
||
208 | 161 |
/*! |
162 |
** |
|
163 |
** |
|
164 |
** @param d |
|
165 |
** @param m |
|
166 |
** |
|
167 |
** @return |
|
168 |
**/ |
|
425 | 169 |
UNS8 |
170 |
proceedPDO (CO_Data * d, Message * m) |
|
171 |
{ |
|
172 |
UNS8 numPdo; |
|
173 |
UNS8 numMap; /* Number of the mapped varable */ |
|
174 |
UNS8 *pMappingCount = NULL; /* count of mapped objects... */ |
|
215 | 175 |
/* pointer to the var which is mapped to a pdo... */ |
176 |
/* void * pMappedAppObject = NULL; */ |
|
177 |
/* pointer fo the var which holds the mapping parameter of an |
|
208 | 178 |
mapping entry */ |
425 | 179 |
UNS32 *pMappingParameter = NULL; |
180 |
UNS8 *pTransmissionType = NULL; /* pointer to the transmission |
|
181 |
type */ |
|
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
182 |
UNS16 *pwCobId = NULL; |
425 | 183 |
UNS8 Size; |
184 |
UNS8 offset; |
|
185 |
UNS8 status; |
|
186 |
UNS32 objDict; |
|
187 |
UNS16 offsetObjdict; |
|
188 |
UNS16 lastIndex; |
|
189 |
||
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
190 |
status = state2; |
208 | 191 |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
428
diff
changeset
|
192 |
MSG_WAR (0x3935, "proceedPDO, cobID : ", (UNS16_LE(m->cob_id) & 0x7ff)); |
0 | 193 |
offset = 0x00; |
194 |
numPdo = 0; |
|
195 |
numMap = 0; |
|
425 | 196 |
if ((*m).rtr == NOT_A_REQUEST) |
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
197 |
{ |
425 | 198 |
offsetObjdict = d->firstIndex->PDO_RCV; |
199 |
lastIndex = d->lastIndex->PDO_RCV; |
|
200 |
||
201 |
if (offsetObjdict) |
|
202 |
while (offsetObjdict <= lastIndex) |
|
203 |
{ |
|
204 |
switch (status) |
|
205 |
{ |
|
206 |
||
207 |
case state2: |
|
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
208 |
pwCobId = d->objdict[offsetObjdict].pSubindex[1].pObject; |
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
428
diff
changeset
|
209 |
if (*pwCobId == UNS16_LE(m->cob_id)) |
425 | 210 |
{ |
211 |
/* The cobId is recognized */ |
|
212 |
status = state4; |
|
213 |
MSG_WAR (0x3936, "cobId found at index ", |
|
214 |
0x1400 + numPdo); |
|
215 |
break; |
|
216 |
} |
|
217 |
else |
|
218 |
{ |
|
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
219 |
/* received cobId does not match */ |
425 | 220 |
numPdo++; |
221 |
offsetObjdict++; |
|
222 |
status = state2; |
|
223 |
break; |
|
224 |
} |
|
225 |
||
226 |
case state4: /* Get Mapped Objects Number */ |
|
227 |
/* The cobId of the message received has been found in the |
|
228 |
dictionnary. */ |
|
229 |
offsetObjdict = d->firstIndex->PDO_RCV_MAP; |
|
230 |
lastIndex = d->lastIndex->PDO_RCV_MAP; |
|
231 |
pMappingCount = |
|
232 |
(UNS8 *) (d->objdict + offsetObjdict + |
|
233 |
numPdo)->pSubindex[0].pObject; |
|
234 |
numMap = 0; |
|
235 |
while (numMap < *pMappingCount) |
|
236 |
{ |
|
237 |
UNS8 tmp[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
524
diff
changeset
|
238 |
UNS32 ByteSize; |
425 | 239 |
pMappingParameter = |
240 |
(UNS32 *) (d->objdict + offsetObjdict + |
|
241 |
numPdo)->pSubindex[numMap + 1].pObject; |
|
242 |
if (pMappingParameter == NULL) |
|
243 |
{ |
|
244 |
MSG_ERR (0x1937, "Couldn't get mapping parameter : ", |
|
245 |
numMap + 1); |
|
246 |
return 0xFF; |
|
247 |
} |
|
248 |
/* Get the addresse of the mapped variable. */ |
|
249 |
/* detail of *pMappingParameter : */ |
|
250 |
/* The 16 hight bits contains the index, the medium 8 bits |
|
251 |
contains the subindex, */ |
|
252 |
/* and the lower 8 bits contains the size of the mapped |
|
253 |
variable. */ |
|
254 |
||
255 |
Size = (UNS8) (*pMappingParameter & (UNS32) 0x000000FF); |
|
256 |
||
497 | 257 |
/* set variable only if Size != 0 and |
258 |
* Size is lower than remaining bits in the PDO */ |
|
425 | 259 |
if (Size && ((offset + Size) <= (m->len << 3))) |
260 |
{ |
|
261 |
/* copy bit per bit in little endian */ |
|
262 |
CopyBits (Size, (UNS8 *) & m->data[offset >> 3], |
|
263 |
offset % 8, 0, ((UNS8 *) tmp), 0, 0); |
|
497 | 264 |
/*1->8 => 1 ; 9->16 =>2, ... */ |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
524
diff
changeset
|
265 |
ByteSize = (UNS32)(1 + ((Size - 1) >> 3)); |
425 | 266 |
|
267 |
objDict = |
|
268 |
setODentry (d, (UNS16) ((*pMappingParameter) >> 16), |
|
269 |
(UNS8) (((*pMappingParameter) >> 8) & |
|
270 |
0xFF), tmp, &ByteSize, 0); |
|
271 |
||
272 |
if (objDict != OD_SUCCESSFUL) |
|
273 |
{ |
|
274 |
MSG_ERR (0x1938, |
|
275 |
"error accessing to the mapped var : ", |
|
276 |
numMap + 1); |
|
277 |
MSG_WAR (0x2939, " Mapped at index : ", |
|
278 |
(*pMappingParameter) >> 16); |
|
279 |
MSG_WAR (0x2940, " subindex : ", |
|
280 |
((*pMappingParameter) >> 8) & 0xFF); |
|
281 |
return 0xFF; |
|
282 |
} |
|
283 |
||
284 |
MSG_WAR (0x3942, |
|
497 | 285 |
"Variable updated by PDO cobid : ", |
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
428
diff
changeset
|
286 |
UNS16_LE(m->cob_id)); |
425 | 287 |
MSG_WAR (0x3943, " Mapped at index : ", |
288 |
(*pMappingParameter) >> 16); |
|
289 |
MSG_WAR (0x3944, " subindex : ", |
|
290 |
((*pMappingParameter) >> 8) & 0xFF); |
|
291 |
offset += Size; |
|
292 |
} |
|
293 |
numMap++; |
|
294 |
} /* end loop while on mapped variables */ |
|
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
295 |
if (d->RxPDO_EventTimers) |
670
e37511baf56b
New feature : event timers allowed for RxPDOs (subidx 5 in RxPDO com paramaters)
Mongo
parents:
661
diff
changeset
|
296 |
{ |
742
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
297 |
TIMEVAL EventTimerDuration = *(UNS16 *)d->objdict[offsetObjdict].pSubindex[5].pObject; |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
298 |
if(EventTimerDuration){ |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
299 |
DelAlarm (d->RxPDO_EventTimers[numPdo]); |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
300 |
d->RxPDO_EventTimers[numPdo] = SetAlarm (d, numPdo, d->RxPDO_EventTimers_Handler, |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
301 |
MS_TO_TIMEVAL (EventTimerDuration), 0); |
10e165c6743c
pdo.c : missalignment problem on some cpu when comparing cobids, various typo fixes
Edouard Tisserant
parents:
712
diff
changeset
|
302 |
} |
670
e37511baf56b
New feature : event timers allowed for RxPDOs (subidx 5 in RxPDO com paramaters)
Mongo
parents:
661
diff
changeset
|
303 |
} |
425 | 304 |
return 0; |
305 |
||
306 |
} /* end switch status */ |
|
307 |
} /* end while */ |
|
308 |
} /* end if Donnees */ |
|
309 |
else if ((*m).rtr == REQUEST) |
|
310 |
{ |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
428
diff
changeset
|
311 |
MSG_WAR (0x3946, "Receive a PDO request cobId : ", UNS16_LE(m->cob_id)); |
425 | 312 |
status = state1; |
313 |
offsetObjdict = d->firstIndex->PDO_TRS; |
|
314 |
lastIndex = d->lastIndex->PDO_TRS; |
|
315 |
if (offsetObjdict) |
|
316 |
while (offsetObjdict <= lastIndex) |
|
317 |
{ |
|
318 |
/* study of all PDO stored in the objects dictionary */ |
|
319 |
||
320 |
switch (status) |
|
321 |
{ |
|
322 |
||
323 |
case state1: /* check the CobId */ |
|
324 |
/* get CobId of the dictionary which match to the received PDO |
|
325 |
*/ |
|
326 |
pwCobId = |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
428
diff
changeset
|
327 |
(d->objdict + |
425 | 328 |
offsetObjdict)->pSubindex[1].pObject; |
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
428
diff
changeset
|
329 |
if (*pwCobId == UNS16_LE(m->cob_id)) |
425 | 330 |
{ |
331 |
status = state4; |
|
332 |
break; |
|
333 |
} |
|
334 |
else |
|
335 |
{ |
|
336 |
numPdo++; |
|
337 |
offsetObjdict++; |
|
338 |
} |
|
339 |
status = state1; |
|
340 |
break; |
|
341 |
||
342 |
||
343 |
case state4: /* check transmission type */ |
|
344 |
pTransmissionType = |
|
345 |
(UNS8 *) d->objdict[offsetObjdict].pSubindex[2].pObject; |
|
346 |
/* If PDO is to be sampled and send on RTR, do it */ |
|
347 |
if ((*pTransmissionType == TRANS_RTR)) |
|
348 |
{ |
|
349 |
status = state5; |
|
350 |
break; |
|
351 |
} |
|
497 | 352 |
/* RTR_SYNC means data prepared at SYNC, transmitted on RTR */ |
425 | 353 |
else if ((*pTransmissionType == TRANS_RTR_SYNC)) |
354 |
{ |
|
355 |
if (d->PDO_status[numPdo]. |
|
356 |
transmit_type_parameter & PDO_RTR_SYNC_READY) |
|
357 |
{ |
|
358 |
/*Data ready, just send */ |
|
359 |
canSend (d->canHandle, |
|
360 |
&d->PDO_status[numPdo].last_message); |
|
361 |
return 0; |
|
362 |
} |
|
363 |
else |
|
364 |
{ |
|
497 | 365 |
/* if SYNC did never occur, transmit current data */ |
425 | 366 |
/* DS301 do not tell what to do in such a case... */ |
367 |
MSG_ERR (0x1947, |
|
368 |
"Not ready RTR_SYNC TPDO send current data : ", |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
428
diff
changeset
|
369 |
UNS16_LE(m->cob_id)); |
425 | 370 |
status = state5; |
371 |
} |
|
372 |
break; |
|
373 |
} |
|
374 |
else if ((*pTransmissionType == TRANS_EVENT_PROFILE) || |
|
375 |
(*pTransmissionType == TRANS_EVENT_SPECIFIC)) |
|
376 |
{ |
|
377 |
/* Zap all timers and inhibit flag */ |
|
378 |
d->PDO_status[numPdo].event_timer = |
|
379 |
DelAlarm (d->PDO_status[numPdo].event_timer); |
|
380 |
d->PDO_status[numPdo].inhibit_timer = |
|
381 |
DelAlarm (d->PDO_status[numPdo].inhibit_timer); |
|
382 |
d->PDO_status[numPdo].transmit_type_parameter &= |
|
383 |
~PDO_INHIBITED; |
|
497 | 384 |
/* Call PDOEventTimerAlarm for this TPDO, |
385 |
* this will trigger emission et reset timers */ |
|
425 | 386 |
PDOEventTimerAlarm (d, numPdo); |
387 |
return 0; |
|
388 |
} |
|
389 |
else |
|
390 |
{ |
|
391 |
/* The requested PDO is not to send on request. So, does |
|
392 |
nothing. */ |
|
393 |
MSG_WAR (0x2947, "PDO is not to send on request : ", |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
428
diff
changeset
|
394 |
UNS16_LE(m->cob_id)); |
425 | 395 |
return 0xFF; |
396 |
} |
|
397 |
||
398 |
case state5: /* build and send requested PDO */ |
|
399 |
{ |
|
400 |
Message pdo; |
|
401 |
if (buildPDO (d, numPdo, &pdo)) |
|
402 |
{ |
|
688 | 403 |
MSG_ERR (0x1948, " Couldn't build TPDO number : ", numPdo); |
425 | 404 |
return 0xFF; |
405 |
} |
|
406 |
canSend (d->canHandle, &pdo); |
|
407 |
return 0; |
|
408 |
} |
|
409 |
} /* end switch status */ |
|
410 |
} /* end while */ |
|
411 |
} /* end if Requete */ |
|
208 | 412 |
|
0 | 413 |
return 0; |
414 |
} |
|
415 |
||
208 | 416 |
/*! |
417 |
** |
|
418 |
** |
|
419 |
** @param NbBits |
|
420 |
** @param SrcByteIndex |
|
421 |
** @param SrcBitIndex |
|
422 |
** @param SrcBigEndian |
|
423 |
** @param DestByteIndex |
|
424 |
** @param DestBitIndex |
|
425 |
** @param DestBigEndian |
|
426 |
**/ |
|
425 | 427 |
void |
428 |
CopyBits (UNS8 NbBits, UNS8 * SrcByteIndex, UNS8 SrcBitIndex, |
|
429 |
UNS8 SrcBigEndian, UNS8 * DestByteIndex, UNS8 DestBitIndex, |
|
430 |
UNS8 DestBigEndian) |
|
431 |
{ |
|
432 |
/* This loop copy as many bits that it can each time, crossing */ |
|
433 |
/* successively bytes */ |
|
208 | 434 |
// boundaries from LSB to MSB. |
425 | 435 |
while (NbBits > 0) |
208 | 436 |
{ |
425 | 437 |
/* Bit missalignement between src and dest */ |
208 | 438 |
INTEGER8 Vect = DestBitIndex - SrcBitIndex; |
439 |
||
425 | 440 |
/* We can now get src and align it to dest */ |
441 |
UNS8 Aligned = |
|
442 |
Vect > 0 ? *SrcByteIndex << Vect : *SrcByteIndex >> -Vect; |
|
443 |
||
444 |
/* Compute the nb of bit we will be able to copy */ |
|
445 |
UNS8 BoudaryLimit = (Vect > 0 ? 8 - DestBitIndex : 8 - SrcBitIndex); |
|
208 | 446 |
UNS8 BitsToCopy = BoudaryLimit > NbBits ? NbBits : BoudaryLimit; |
447 |
||
425 | 448 |
/* Create a mask that will serve in: */ |
449 |
UNS8 Mask = |
|
450 |
((0xff << (DestBitIndex + BitsToCopy)) | |
|
451 |
(0xff >> (8 - DestBitIndex))); |
|
452 |
||
453 |
/* - Filtering src */ |
|
208 | 454 |
UNS8 Filtered = Aligned & ~Mask; |
455 |
||
425 | 456 |
/* - and erase bits where we write, preserve where we don't */ |
208 | 457 |
*DestByteIndex &= Mask; |
458 |
||
425 | 459 |
/* Then write. */ |
460 |
*DestByteIndex |= Filtered; |
|
461 |
||
462 |
/*Compute next time cursors for src */ |
|
463 |
if ((SrcBitIndex += BitsToCopy) > 7) /* cross boundary ? */ |
|
208 | 464 |
{ |
425 | 465 |
SrcBitIndex = 0; /* First bit */ |
466 |
SrcByteIndex += (SrcBigEndian ? -1 : 1); /* Next byte */ |
|
215 | 467 |
} |
468 |
||
469 |
||
425 | 470 |
/*Compute next time cursors for dest */ |
471 |
if ((DestBitIndex += BitsToCopy) > 7) |
|
208 | 472 |
{ |
425 | 473 |
DestBitIndex = 0; /* First bit */ |
474 |
DestByteIndex += (DestBigEndian ? -1 : 1); /* Next byte */ |
|
215 | 475 |
} |
476 |
||
425 | 477 |
/*And decrement counter. */ |
208 | 478 |
NbBits -= BitsToCopy; |
479 |
} |
|
201 | 480 |
|
481 |
} |
|
425 | 482 |
|
611 | 483 |
static void sendPdo(CO_Data * d, UNS32 pdoNum, Message * pdo) |
484 |
{ |
|
485 |
/*store_as_last_message */ |
|
486 |
d->PDO_status[pdoNum].last_message = *pdo; |
|
660
cff8e50333e8
Fixed incorrect struct access in sendPDO() and inserted a missing variable in sendOnePDOEvent(). These errors occured at compile-time when configuring the project with './configure --debug=PDO' or './configure --debug=WAR'.
skratochwil
parents:
649
diff
changeset
|
487 |
MSG_WAR (0x396D, "sendPDO cobId :", UNS16_LE(pdo->cob_id)); |
cff8e50333e8
Fixed incorrect struct access in sendPDO() and inserted a missing variable in sendOnePDOEvent(). These errors occured at compile-time when configuring the project with './configure --debug=PDO' or './configure --debug=WAR'.
skratochwil
parents:
649
diff
changeset
|
488 |
MSG_WAR (0x396E, " Nb octets : ", pdo->len); |
611 | 489 |
|
490 |
canSend (d->canHandle, pdo); |
|
491 |
} |
|
492 |
||
493 |
||
208 | 494 |
/*! |
495 |
** |
|
496 |
** |
|
497 |
** @param d |
|
498 |
** |
|
499 |
** @return |
|
500 |
**/ |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
501 |
|
425 | 502 |
UNS8 |
503 |
sendPDOevent (CO_Data * d) |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
504 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
505 |
/* Calls _sendPDOevent specifying it is not a sync event */ |
425 | 506 |
return _sendPDOevent (d, 0); |
507 |
} |
|
508 |
||
611 | 509 |
UNS8 |
649
3beb784bacee
CHANGED: - function sendOnePDOevent (CO_Data* d, UNS32 pdoNum) into sendOnePDOevent (CO_Data* d, UNS8 pdoNum)
Christian Taedcke
parents:
630
diff
changeset
|
510 |
sendOnePDOevent (CO_Data * d, UNS8 pdoNum) |
611 | 511 |
{ |
629 | 512 |
UNS16 offsetObjdict; |
513 |
Message pdo; |
|
611 | 514 |
if (!d->CurrentCommunicationState.csPDO || |
630
96919642e99c
Moced CosateQ's doc at the right place, and fix PDO INHIBIT bit check error again.
edouard
parents:
629
diff
changeset
|
515 |
(d->PDO_status[pdoNum].transmit_type_parameter & PDO_INHIBITED)) |
611 | 516 |
{ |
517 |
return 0; |
|
518 |
} |
|
519 |
||
649
3beb784bacee
CHANGED: - function sendOnePDOevent (CO_Data* d, UNS32 pdoNum) into sendOnePDOevent (CO_Data* d, UNS8 pdoNum)
Christian Taedcke
parents:
630
diff
changeset
|
520 |
offsetObjdict = (UNS16) (d->firstIndex->PDO_TRS + pdoNum); |
660
cff8e50333e8
Fixed incorrect struct access in sendPDO() and inserted a missing variable in sendOnePDOEvent(). These errors occured at compile-time when configuring the project with './configure --debug=PDO' or './configure --debug=WAR'.
skratochwil
parents:
649
diff
changeset
|
521 |
|
611 | 522 |
MSG_WAR (0x3968, " PDO is on EVENT. Trans type : ", |
661
06494ae5b2b6
Removed unneccessary overhead introduced with the last fix.
Stefan@Sheldon
parents:
660
diff
changeset
|
523 |
*((UNS8 *) d->objdict[offsetObjdict].pSubindex[2].pObject)); |
629 | 524 |
|
611 | 525 |
memset(&pdo, 0, sizeof(pdo)); |
526 |
if (buildPDO (d, pdoNum, &pdo)) |
|
527 |
{ |
|
528 |
MSG_ERR (0x3907, " Couldn't build TPDO number : ", |
|
529 |
pdoNum); |
|
619
96f84395154f
Enhancements for 'None' target : produce pre-linked object, remove some windows CRLF problems, fixed pedantic compiler warnings
edouard
parents:
611
diff
changeset
|
530 |
return 0; |
611 | 531 |
} |
532 |
||
533 |
/*Compare new and old PDO */ |
|
534 |
if (d->PDO_status[pdoNum].last_message.cob_id == pdo.cob_id |
|
535 |
&& d->PDO_status[pdoNum].last_message.len == pdo.len |
|
536 |
&& memcmp(d->PDO_status[pdoNum].last_message.data, |
|
537 |
pdo.data, 8) == 0 |
|
538 |
) |
|
539 |
{ |
|
540 |
/* No changes -> go to next pdo */ |
|
619
96f84395154f
Enhancements for 'None' target : produce pre-linked object, remove some windows CRLF problems, fixed pedantic compiler warnings
edouard
parents:
611
diff
changeset
|
541 |
return 0; |
611 | 542 |
} |
543 |
else |
|
544 |
{ |
|
545 |
||
546 |
TIMEVAL EventTimerDuration; |
|
547 |
TIMEVAL InhibitTimerDuration; |
|
548 |
||
549 |
MSG_WAR (0x306A, "Changes TPDO number : ", pdoNum); |
|
550 |
/* Changes detected -> transmit message */ |
|
551 |
EventTimerDuration = |
|
552 |
*(UNS16 *) d->objdict[offsetObjdict].pSubindex[5]. |
|
553 |
pObject; |
|
554 |
InhibitTimerDuration = |
|
555 |
*(UNS16 *) d->objdict[offsetObjdict].pSubindex[3]. |
|
556 |
pObject; |
|
557 |
||
558 |
/* Start both event_timer and inhibit_timer */ |
|
559 |
if (EventTimerDuration) |
|
560 |
{ |
|
561 |
DelAlarm (d->PDO_status[pdoNum].event_timer); |
|
562 |
d->PDO_status[pdoNum].event_timer = |
|
563 |
SetAlarm (d, pdoNum, &PDOEventTimerAlarm, |
|
564 |
MS_TO_TIMEVAL (EventTimerDuration), 0); |
|
565 |
} |
|
566 |
||
567 |
if (InhibitTimerDuration) |
|
568 |
{ |
|
569 |
DelAlarm (d->PDO_status[pdoNum].inhibit_timer); |
|
570 |
d->PDO_status[pdoNum].inhibit_timer = |
|
571 |
SetAlarm (d, pdoNum, &PDOInhibitTimerAlarm, |
|
572 |
US_TO_TIMEVAL (InhibitTimerDuration * |
|
573 |
100), 0); |
|
574 |
/* and inhibit TPDO */ |
|
575 |
d->PDO_status[pdoNum].transmit_type_parameter |= |
|
576 |
PDO_INHIBITED; |
|
577 |
} |
|
578 |
||
579 |
sendPdo(d, pdoNum, &pdo); |
|
580 |
} |
|
619
96f84395154f
Enhancements for 'None' target : produce pre-linked object, remove some windows CRLF problems, fixed pedantic compiler warnings
edouard
parents:
611
diff
changeset
|
581 |
return 1; |
611 | 582 |
} |
425 | 583 |
|
584 |
void |
|
585 |
PDOEventTimerAlarm (CO_Data * d, UNS32 pdoNum) |
|
586 |
{ |
|
587 |
/* This is needed to avoid deletion of re-attribuated timer */ |
|
588 |
d->PDO_status[pdoNum].event_timer = TIMER_NONE; |
|
589 |
/* force emission of PDO by artificially changing last emitted */ |
|
590 |
d->PDO_status[pdoNum].last_message.cob_id = 0; |
|
649
3beb784bacee
CHANGED: - function sendOnePDOevent (CO_Data* d, UNS32 pdoNum) into sendOnePDOevent (CO_Data* d, UNS8 pdoNum)
Christian Taedcke
parents:
630
diff
changeset
|
591 |
sendOnePDOevent (d, (UNS8) pdoNum); |
425 | 592 |
} |
593 |
||
594 |
void |
|
595 |
PDOInhibitTimerAlarm (CO_Data * d, UNS32 pdoNum) |
|
596 |
{ |
|
597 |
/* This is needed to avoid deletion of re-attribuated timer */ |
|
598 |
d->PDO_status[pdoNum].inhibit_timer = TIMER_NONE; |
|
599 |
/* Remove inhibit flag */ |
|
600 |
d->PDO_status[pdoNum].transmit_type_parameter &= ~PDO_INHIBITED; |
|
649
3beb784bacee
CHANGED: - function sendOnePDOevent (CO_Data* d, UNS32 pdoNum) into sendOnePDOevent (CO_Data* d, UNS8 pdoNum)
Christian Taedcke
parents:
630
diff
changeset
|
601 |
sendOnePDOevent (d, (UNS8) pdoNum); |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
602 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
603 |
|
670
e37511baf56b
New feature : event timers allowed for RxPDOs (subidx 5 in RxPDO com paramaters)
Mongo
parents:
661
diff
changeset
|
604 |
void |
e37511baf56b
New feature : event timers allowed for RxPDOs (subidx 5 in RxPDO com paramaters)
Mongo
parents:
661
diff
changeset
|
605 |
_RxPDO_EventTimers_Handler(CO_Data *d, UNS32 pdoNum) |
e37511baf56b
New feature : event timers allowed for RxPDOs (subidx 5 in RxPDO com paramaters)
Mongo
parents:
661
diff
changeset
|
606 |
{ |
e37511baf56b
New feature : event timers allowed for RxPDOs (subidx 5 in RxPDO com paramaters)
Mongo
parents:
661
diff
changeset
|
607 |
} |
e37511baf56b
New feature : event timers allowed for RxPDOs (subidx 5 in RxPDO com paramaters)
Mongo
parents:
661
diff
changeset
|
608 |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
609 |
/*! |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
610 |
** |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
611 |
** |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
612 |
** @param d |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
613 |
** @param isSyncEvent |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
614 |
** |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
615 |
** @return |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
616 |
**/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
617 |
|
425 | 618 |
UNS8 |
619 |
_sendPDOevent (CO_Data * d, UNS8 isSyncEvent) |
|
620 |
{ |
|
621 |
UNS8 pdoNum = 0x00; /* number of the actual processed pdo-nr. */ |
|
622 |
UNS8 *pTransmissionType = NULL; |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
623 |
UNS8 status = state3; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
624 |
UNS16 offsetObjdict = d->firstIndex->PDO_TRS; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
625 |
UNS16 offsetObjdictMap = d->firstIndex->PDO_TRS_MAP; |
425 | 626 |
UNS16 lastIndex = d->lastIndex->PDO_TRS; |
627 |
||
611 | 628 |
if (!d->CurrentCommunicationState.csPDO) |
629 |
{ |
|
630 |
return 0; |
|
631 |
} |
|
632 |
||
633 |
||
425 | 634 |
/* study all PDO stored in the objects dictionary */ |
635 |
if (offsetObjdict) |
|
636 |
{ |
|
497 | 637 |
Message pdo;/* = Message_Initializer;*/ |
638 |
memset(&pdo, 0, sizeof(pdo)); |
|
425 | 639 |
while (offsetObjdict <= lastIndex) |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
640 |
{ |
425 | 641 |
switch (status) |
642 |
{ |
|
643 |
case state3: |
|
497 | 644 |
if ( /* bSubCount always 5 with objdictedit -> check disabled */ |
645 |
/*d->objdict[offsetObjdict].bSubCount < 5 ||*/ |
|
425 | 646 |
/* check if TPDO is not valid */ |
647 |
*(UNS32 *) d->objdict[offsetObjdict].pSubindex[1]. |
|
648 |
pObject & 0x80000000) |
|
649 |
{ |
|
650 |
MSG_WAR (0x3960, "Not a valid PDO ", 0x1800 + pdoNum); |
|
651 |
/*Go next TPDO */ |
|
652 |
status = state11; |
|
653 |
break; |
|
654 |
} |
|
655 |
/* get the PDO transmission type */ |
|
656 |
pTransmissionType = |
|
657 |
(UNS8 *) d->objdict[offsetObjdict].pSubindex[2].pObject; |
|
658 |
MSG_WAR (0x3962, "Reading PDO at index : ", 0x1800 + pdoNum); |
|
659 |
||
660 |
/* check if transmission type is SYNCRONOUS */ |
|
497 | 661 |
/* message transmited every n SYNC with n=TransmissionType */ |
425 | 662 |
if (isSyncEvent && |
663 |
(*pTransmissionType >= TRANS_SYNC_MIN) && |
|
664 |
(*pTransmissionType <= TRANS_SYNC_MAX) && |
|
665 |
(++d->PDO_status[pdoNum].transmit_type_parameter == |
|
666 |
*pTransmissionType)) |
|
667 |
{ |
|
668 |
/*Reset count of SYNC */ |
|
669 |
d->PDO_status[pdoNum].transmit_type_parameter = 0; |
|
670 |
MSG_WAR (0x3964, " PDO is on SYNCHRO. Trans type : ", |
|
671 |
*pTransmissionType); |
|
497 | 672 |
memset(&pdo, 0, sizeof(pdo)); |
673 |
/*{ |
|
425 | 674 |
Message msg_init = Message_Initializer; |
675 |
pdo = msg_init; |
|
497 | 676 |
}*/ |
425 | 677 |
if (buildPDO (d, pdoNum, &pdo)) |
678 |
{ |
|
679 |
MSG_ERR (0x1906, " Couldn't build TPDO number : ", |
|
680 |
pdoNum); |
|
681 |
status = state11; |
|
682 |
break; |
|
683 |
} |
|
684 |
status = state5; |
|
685 |
/* If transmission RTR, with data sampled on SYNC */ |
|
686 |
} |
|
687 |
else if (isSyncEvent && (*pTransmissionType == TRANS_RTR_SYNC)) |
|
688 |
{ |
|
689 |
if (buildPDO |
|
690 |
(d, pdoNum, &d->PDO_status[pdoNum].last_message)) |
|
691 |
{ |
|
692 |
MSG_ERR (0x1966, " Couldn't build TPDO number : ", |
|
693 |
pdoNum); |
|
694 |
d->PDO_status[pdoNum].transmit_type_parameter &= |
|
695 |
~PDO_RTR_SYNC_READY; |
|
696 |
} |
|
697 |
else |
|
698 |
{ |
|
699 |
d->PDO_status[pdoNum].transmit_type_parameter |= |
|
700 |
PDO_RTR_SYNC_READY; |
|
701 |
} |
|
702 |
status = state11; |
|
703 |
break; |
|
704 |
/* If transmission on Event and not inhibited, check for changes */ |
|
705 |
} |
|
426
8011552b1319
Preliminary support for TRANS_SYNC_ACYCLIC (0) transmit type.
etisserant
parents:
425
diff
changeset
|
706 |
else |
611 | 707 |
if ( (isSyncEvent && (*pTransmissionType == TRANS_SYNC_ACYCLIC)) |
708 |
|| |
|
709 |
(!isSyncEvent && (*pTransmissionType == TRANS_EVENT_PROFILE || *pTransmissionType == TRANS_EVENT_SPECIFIC) |
|
710 |
&& !(d->PDO_status[pdoNum].transmit_type_parameter & PDO_INHIBITED))) |
|
425 | 711 |
{ |
611 | 712 |
sendOnePDOevent(d, pdoNum); |
713 |
status = state11; |
|
425 | 714 |
} |
715 |
else |
|
716 |
{ |
|
717 |
MSG_WAR (0x306C, |
|
718 |
" PDO is not on EVENT or synchro or not at this SYNC. Trans type : ", |
|
719 |
*pTransmissionType); |
|
720 |
status = state11; |
|
721 |
} |
|
722 |
break; |
|
723 |
case state5: /*Send the pdo */ |
|
611 | 724 |
sendPdo(d, pdoNum, &pdo); |
425 | 725 |
status = state11; |
726 |
break; |
|
727 |
case state11: /*Go to next TPDO */ |
|
728 |
pdoNum++; |
|
729 |
offsetObjdict++; |
|
730 |
offsetObjdictMap++; |
|
731 |
MSG_WAR (0x3970, "next pdo index : ", pdoNum); |
|
732 |
status = state3; |
|
733 |
break; |
|
734 |
||
735 |
default: |
|
688 | 736 |
MSG_ERR (0x1972, "Unknown state has been reached :", status); |
425 | 737 |
return 0xFF; |
738 |
} /* end switch case */ |
|
739 |
||
740 |
} /* end while */ |
|
741 |
} |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
742 |
return 0; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
743 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
744 |
|
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
745 |
/*! |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
746 |
** |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
747 |
** |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
748 |
** @param d |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
749 |
** @param OD_entry |
524 | 750 |
** @param bSubindex |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
751 |
** @return always 0 |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
752 |
**/ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
753 |
|
425 | 754 |
UNS32 |
755 |
TPDO_Communication_Parameter_Callback (CO_Data * d, |
|
756 |
const indextable * OD_entry, |
|
757 |
UNS8 bSubindex) |
|
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
758 |
{ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
759 |
/* If PDO are actives */ |
425 | 760 |
if (d->CurrentCommunicationState.csPDO) |
761 |
switch (bSubindex) |
|
762 |
{ |
|
763 |
case 2: /* Changed transmition type */ |
|
764 |
case 3: /* Changed inhibit time */ |
|
765 |
case 5: /* Changed event time */ |
|
766 |
{ |
|
767 |
const indextable *TPDO_com = d->objdict + d->firstIndex->PDO_TRS; |
|
649
3beb784bacee
CHANGED: - function sendOnePDOevent (CO_Data* d, UNS32 pdoNum) into sendOnePDOevent (CO_Data* d, UNS8 pdoNum)
Christian Taedcke
parents:
630
diff
changeset
|
768 |
UNS8 numPdo = (UNS8) (OD_entry - TPDO_com); /* number of the actual processed pdo-nr. */ |
425 | 769 |
|
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
770 |
/* Zap all timers and inhibit flag */ |
425 | 771 |
d->PDO_status[numPdo].event_timer = |
772 |
DelAlarm (d->PDO_status[numPdo].event_timer); |
|
773 |
d->PDO_status[numPdo].inhibit_timer = |
|
774 |
DelAlarm (d->PDO_status[numPdo].inhibit_timer); |
|
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
775 |
d->PDO_status[numPdo].transmit_type_parameter = 0; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
776 |
/* Call PDOEventTimerAlarm for this TPDO, this will trigger emission et reset timers */ |
425 | 777 |
PDOEventTimerAlarm (d, numPdo); |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
778 |
return 0; |
425 | 779 |
} |
780 |
||
781 |
default: /* other subindex are ignored */ |
|
782 |
break; |
|
783 |
} |
|
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
784 |
return 0; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
785 |
} |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
786 |
|
425 | 787 |
void |
788 |
PDOInit (CO_Data * d) |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
789 |
{ |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
790 |
/* For each TPDO mapping parameters */ |
425 | 791 |
UNS16 pdoIndex = 0x1800; /* OD index of TDPO */ |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
792 |
|
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
793 |
UNS16 offsetObjdict = d->firstIndex->PDO_TRS; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
794 |
UNS16 lastIndex = d->lastIndex->PDO_TRS; |
425 | 795 |
if (offsetObjdict) |
796 |
while (offsetObjdict <= lastIndex) |
|
797 |
{ |
|
798 |
/* Assign callbacks to sensible TPDO mapping subindexes */ |
|
799 |
UNS32 errorCode; |
|
800 |
ODCallback_t *CallbackList; |
|
801 |
/* Find callback list */ |
|
802 |
scanIndexOD (d, pdoIndex, &errorCode, &CallbackList); |
|
803 |
if (errorCode == OD_SUCCESSFUL && CallbackList) |
|
804 |
{ |
|
805 |
/*Assign callbacks to corresponding subindex */ |
|
806 |
/* Transmission type */ |
|
807 |
CallbackList[2] = &TPDO_Communication_Parameter_Callback; |
|
808 |
/* Inhibit time */ |
|
809 |
CallbackList[3] = &TPDO_Communication_Parameter_Callback; |
|
810 |
/* Event timer */ |
|
811 |
CallbackList[5] = &TPDO_Communication_Parameter_Callback; |
|
812 |
} |
|
813 |
pdoIndex++; |
|
814 |
offsetObjdict++; |
|
815 |
} |
|
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
816 |
|
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
817 |
/* Trigger a non-sync event */ |
425 | 818 |
_sendPDOevent (d, 0); |
819 |
} |
|
820 |
||
821 |
void |
|
822 |
PDOStop (CO_Data * d) |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
823 |
{ |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
824 |
/* For each TPDO mapping parameters */ |
425 | 825 |
UNS8 pdoNum = 0x00; /* number of the actual processed pdo-nr. */ |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
826 |
UNS16 offsetObjdict = d->firstIndex->PDO_TRS; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
827 |
UNS16 lastIndex = d->lastIndex->PDO_TRS; |
425 | 828 |
if (offsetObjdict) |
829 |
while (offsetObjdict <= lastIndex) |
|
830 |
{ |
|
831 |
/* Delete TPDO timers */ |
|
832 |
d->PDO_status[pdoNum].event_timer = |
|
833 |
DelAlarm (d->PDO_status[pdoNum].event_timer); |
|
834 |
d->PDO_status[pdoNum].inhibit_timer = |
|
835 |
DelAlarm (d->PDO_status[pdoNum].inhibit_timer); |
|
836 |
/* Reset transmit type parameter */ |
|
837 |
d->PDO_status[pdoNum].transmit_type_parameter = 0; |
|
838 |
d->PDO_status[pdoNum].last_message.cob_id = 0; |
|
839 |
pdoNum++; |
|
840 |
offsetObjdict++; |
|
841 |
} |
|
842 |
} |