author | etisserant |
Fri, 29 Jun 2007 19:51:39 +0200 | |
changeset 235 | f812bf6b7237 |
parent 217 | 94c3f89bc3cc |
child 236 | 905677ed00f3 |
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" |
0 | 27 |
|
208 | 28 |
/*! |
29 |
** @file pdo.c |
|
30 |
** @author Edouard TISSERANT and Francis DUPIN |
|
31 |
** @date Tue Jun 5 09:32:32 2007 |
|
32 |
** |
|
33 |
** @brief |
|
34 |
** |
|
35 |
** |
|
36 |
*/ |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
37 |
|
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 |
** |
208 | 40 |
** |
41 |
** @param d |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
42 |
** @param TPDO_com TPDO communication parameters OD entry |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
43 |
** @param TPDO_map TPDO mapping parameters OD entry |
208 | 44 |
** |
45 |
** @return |
|
46 |
**/ |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
47 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
48 |
UNS8 buildPDO(CO_Data* d, UNS8 numPdo, Message *pdo) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
49 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
50 |
const indextable* TPDO_com = d->objdict + d->firstIndex->PDO_TRS + numPdo; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
51 |
const indextable* TPDO_map = d->objdict + d->firstIndex->PDO_TRS_MAP + numPdo; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
52 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
53 |
UNS8 prp_j = 0x00; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
54 |
UNS8 offset = 0x00; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
55 |
const UNS8* pMappingCount = (UNS8*) TPDO_map->pSubindex[0].pObject; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
56 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
57 |
pdo->cob_id.w = *(UNS32*)TPDO_com->pSubindex[1].pObject; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
58 |
pdo->rtr = NOT_A_REQUEST; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
59 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
60 |
MSG_WAR(0x3009, " PDO CobId is : ", *(UNS32*)TPDO_com->pSubindex[1].pObject); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
61 |
MSG_WAR(0x300D, " Number of objects mapped : ",*pMappingCount ); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
62 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
63 |
do{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
64 |
UNS8 dataType; /* Unused */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
65 |
UNS8 tmp[]= {0,0,0,0,0,0,0,0}; /* temporary space to hold bits */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
66 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
67 |
/* pointer fo the var which holds the mapping parameter of an mapping entry */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
68 |
UNS32* pMappingParameter = (UNS32*) TPDO_map->pSubindex[prp_j + 1].pObject; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
69 |
UNS16 index = (UNS16)((*pMappingParameter) >> 16); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
70 |
UNS8 Size = (UNS8)(*pMappingParameter); /* Size in bits */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
71 |
UNS8 ByteSize = 1 + ((Size - 1) >> 3); /*1->8 => 1 ; 9->16 => 2, ... */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
72 |
UNS8 subIndex = (UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
73 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
74 |
MSG_WAR(0x300F, " got mapping parameter : ", *pMappingParameter); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
75 |
MSG_WAR(0x3050, " at index : ", TPDO_map->index); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
76 |
MSG_WAR(0x3051, " sub-index : ", prp_j + 1); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
77 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
78 |
if( getODentry(d, index, subIndex, tmp, &ByteSize, &dataType, 0 ) != OD_SUCCESSFUL ){ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
79 |
MSG_ERR(0x1013, " Couldn't find mapped variable at index-subindex-size : ", (UNS16)(*pMappingParameter)); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
80 |
return 0xFF; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
81 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
82 |
/* copy bit per bit in little endian*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
83 |
CopyBits(Size, ((UNS8*)tmp), 0 , 0, (UNS8*)&pdo->data[offset>>3], offset%8, 0); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
84 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
85 |
offset += Size ; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
86 |
prp_j++; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
87 |
}while( prp_j < *pMappingCount ); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
88 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
89 |
pdo->len = 1 + ((offset - 1) >> 3); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
90 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
91 |
MSG_WAR(0x3015, " End scan mapped variable", 0); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
92 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
93 |
return 0; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
94 |
} |
208 | 95 |
|
96 |
/*! |
|
97 |
** |
|
98 |
** |
|
99 |
** @param d |
|
100 |
** @param cobId |
|
101 |
** |
|
102 |
** @return |
|
103 |
**/ |
|
0 | 104 |
UNS8 sendPDOrequest( CO_Data* d, UNS32 cobId ) |
208 | 105 |
{ |
106 |
UNS32 * pwCobId; |
|
0 | 107 |
UNS16 offset; |
108 |
UNS16 lastIndex; |
|
109 |
UNS8 err; |
|
110 |
||
208 | 111 |
MSG_WAR(0x3930, "sendPDOrequest ",0); |
215 | 112 |
/* Sending the request only if the cobid have been found on the PDO |
208 | 113 |
receive */ |
215 | 114 |
/* part dictionary */ |
0 | 115 |
offset = d->firstIndex->PDO_RCV; |
116 |
lastIndex = d->lastIndex->PDO_RCV; |
|
117 |
if (offset) |
|
208 | 118 |
while (offset <= lastIndex) { |
215 | 119 |
/* get the CobId*/ |
217
94c3f89bc3cc
Fixed compile error because of missed type casting in certain compiler (http://www.iar.se/). Thanks to Raphael Studer
etisserant
parents:
215
diff
changeset
|
120 |
pwCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject; |
208 | 121 |
|
122 |
if ( *pwCobId == cobId ) { |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
123 |
Message pdo = {*pwCobId, REQUEST, 0}; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
124 |
return canSend(d->canHandle,&pdo); |
208 | 125 |
} |
126 |
offset++; |
|
127 |
} |
|
128 |
MSG_WAR(0x1931, "sendPDOrequest : COBID not found : ", cobId); |
|
0 | 129 |
return 0xFF; |
130 |
} |
|
131 |
||
132 |
||
208 | 133 |
/*! |
134 |
** |
|
135 |
** |
|
136 |
** @param d |
|
137 |
** @param m |
|
138 |
** |
|
139 |
** @return |
|
140 |
**/ |
|
0 | 141 |
UNS8 proceedPDO(CO_Data* d, Message *m) |
208 | 142 |
{ |
0 | 143 |
UNS8 numPdo; |
215 | 144 |
UNS8 numMap; /* Number of the mapped varable */ |
0 | 145 |
UNS8 i; |
215 | 146 |
UNS8 * pMappingCount = NULL; /* count of mapped objects... */ |
147 |
/* pointer to the var which is mapped to a pdo... */ |
|
148 |
/* void * pMappedAppObject = NULL; */ |
|
149 |
/* pointer fo the var which holds the mapping parameter of an |
|
208 | 150 |
mapping entry */ |
151 |
UNS32 * pMappingParameter = NULL; |
|
215 | 152 |
UNS8 * pTransmissionType = NULL; /* pointer to the transmission |
208 | 153 |
type */ |
0 | 154 |
UNS32 * pwCobId = NULL; |
155 |
UNS8 Size; |
|
156 |
UNS8 dataType; |
|
157 |
UNS8 offset; |
|
158 |
UNS8 status; |
|
159 |
UNS32 objDict; |
|
160 |
UNS16 offsetObjdict; |
|
161 |
UNS16 lastIndex; |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
162 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
163 |
status = state2; |
208 | 164 |
|
165 |
MSG_WAR(0x3935, "proceedPDO, cobID : ", ((*m).cob_id.w & 0x7ff)); |
|
0 | 166 |
offset = 0x00; |
167 |
numPdo = 0; |
|
168 |
numMap = 0; |
|
215 | 169 |
if((*m).rtr == NOT_A_REQUEST ) { /* The PDO received is not a |
208 | 170 |
request. */ |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
171 |
|
0 | 172 |
offsetObjdict = d->firstIndex->PDO_RCV; |
173 |
lastIndex = d->lastIndex->PDO_RCV; |
|
208 | 174 |
|
215 | 175 |
/* study of all the PDO stored in the dictionary */ |
0 | 176 |
if(offsetObjdict) |
208 | 177 |
while (offsetObjdict <= lastIndex) { |
178 |
||
179 |
switch( status ) { |
|
180 |
||
181 |
case state2: |
|
215 | 182 |
/* get CobId of the dictionary correspondant to the received |
208 | 183 |
PDO */ |
217
94c3f89bc3cc
Fixed compile error because of missed type casting in certain compiler (http://www.iar.se/). Thanks to Raphael Studer
etisserant
parents:
215
diff
changeset
|
184 |
pwCobId = (UNS32*) d->objdict[offsetObjdict].pSubindex[1].pObject; |
215 | 185 |
/* check the CobId coherance */ |
186 |
/*pwCobId is the cobId read in the dictionary at the state 3 |
|
208 | 187 |
*/ |
188 |
if ( *pwCobId == (*m).cob_id.w ){ |
|
215 | 189 |
/* The cobId is recognized */ |
208 | 190 |
status = state4; |
191 |
MSG_WAR(0x3936, "cobId found at index ", 0x1400 + numPdo); |
|
192 |
break; |
|
193 |
} |
|
194 |
else { |
|
215 | 195 |
/* cobId received does not match with those write in the |
208 | 196 |
dictionnary */ |
197 |
numPdo++; |
|
198 |
offsetObjdict++; |
|
199 |
status = state2; |
|
200 |
break; |
|
201 |
} |
|
202 |
||
215 | 203 |
case state4:/* Get Mapped Objects Number */ |
204 |
/* The cobId of the message received has been found in the |
|
208 | 205 |
dictionnary. */ |
206 |
offsetObjdict = d->firstIndex->PDO_RCV_MAP; |
|
207 |
lastIndex = d->lastIndex->PDO_RCV_MAP; |
|
217
94c3f89bc3cc
Fixed compile error because of missed type casting in certain compiler (http://www.iar.se/). Thanks to Raphael Studer
etisserant
parents:
215
diff
changeset
|
208 |
pMappingCount = (UNS8*) (d->objdict + offsetObjdict + numPdo)->pSubindex[0].pObject; |
208 | 209 |
numMap = 0; |
210 |
while (numMap < *pMappingCount) { |
|
211 |
UNS8 tmp[]= {0,0,0,0,0,0,0,0}; |
|
212 |
UNS8 ByteSize; |
|
217
94c3f89bc3cc
Fixed compile error because of missed type casting in certain compiler (http://www.iar.se/). Thanks to Raphael Studer
etisserant
parents:
215
diff
changeset
|
213 |
pMappingParameter = (UNS32*) (d->objdict + offsetObjdict + numPdo)->pSubindex[numMap + 1].pObject; |
208 | 214 |
if (pMappingParameter == NULL) { |
215 |
MSG_ERR(0x1937, "Couldn't get mapping parameter : ", numMap + 1); |
|
216 |
return 0xFF; |
|
217 |
} |
|
215 | 218 |
/* Get the addresse of the mapped variable. */ |
219 |
/* detail of *pMappingParameter : */ |
|
220 |
/* The 16 hight bits contains the index, the medium 8 bits |
|
208 | 221 |
contains the subindex, */ |
215 | 222 |
/* and the lower 8 bits contains the size of the mapped |
208 | 223 |
variable. */ |
224 |
||
225 |
Size = (UNS8)(*pMappingParameter); |
|
226 |
||
215 | 227 |
/* copy bit per bit in little endian */ |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
228 |
CopyBits(Size, (UNS8*)&m->data[offset>>3], offset%8, 0, ((UNS8*)tmp), 0, 0); |
208 | 229 |
|
230 |
ByteSize = 1 + ((Size - 1) >> 3); /*1->8 => 1 ; 9->16 => |
|
231 |
2, ... */ |
|
232 |
||
233 |
objDict = setODentry(d, (UNS16)((*pMappingParameter) >> 16), |
|
234 |
(UNS8)(((*pMappingParameter) >> 8 ) & 0xFF), |
|
235 |
tmp, &ByteSize, 0 ); |
|
236 |
||
237 |
if(objDict != OD_SUCCESSFUL) { |
|
238 |
MSG_ERR(0x1938, "error accessing to the mapped var : ", numMap + 1); |
|
239 |
MSG_WAR(0x2939, " Mapped at index : ", (*pMappingParameter) >> 16); |
|
240 |
MSG_WAR(0x2940, " subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF); |
|
241 |
return 0xFF; |
|
242 |
} |
|
243 |
||
244 |
MSG_WAR(0x3942, "Variable updated with value received by PDO cobid : ", m->cob_id.w); |
|
245 |
MSG_WAR(0x3943, " Mapped at index : ", (*pMappingParameter) >> 16); |
|
246 |
MSG_WAR(0x3944, " subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF); |
|
215 | 247 |
/* MSG_WAR(0x3945, " data : ",*((UNS32*)pMappedAppObject)); */ |
208 | 248 |
offset += Size; |
249 |
numMap++; |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
250 |
/*TODO : check that offset is not not greater that message size (in bit) */ |
215 | 251 |
} /* end loop while on mapped variables */ |
208 | 252 |
|
253 |
offset=0x00; |
|
254 |
numMap = 0; |
|
255 |
return 0; |
|
256 |
||
215 | 257 |
}/* end switch status*/ |
258 |
}/* end while*/ |
|
259 |
}/* end if Donnees */ |
|
208 | 260 |
else if ((*m).rtr == REQUEST ){ |
261 |
MSG_WAR(0x3946, "Receive a PDO request cobId : ", m->cob_id.w); |
|
262 |
status = state1; |
|
263 |
offsetObjdict = d->firstIndex->PDO_TRS; |
|
264 |
lastIndex = d->lastIndex->PDO_TRS; |
|
265 |
if(offsetObjdict) while( offsetObjdict <= lastIndex ){ |
|
215 | 266 |
/* study of all PDO stored in the objects dictionary */ |
208 | 267 |
|
268 |
switch( status ){ |
|
269 |
||
215 | 270 |
case state1:/* check the CobId */ |
271 |
/* get CobId of the dictionary which match to the received PDO |
|
208 | 272 |
*/ |
217
94c3f89bc3cc
Fixed compile error because of missed type casting in certain compiler (http://www.iar.se/). Thanks to Raphael Studer
etisserant
parents:
215
diff
changeset
|
273 |
pwCobId = (UNS32*) (d->objdict + offsetObjdict)->pSubindex[1].pObject; |
208 | 274 |
if ( *pwCobId == (*m).cob_id.w ) { |
275 |
status = state4; |
|
276 |
break; |
|
277 |
} |
|
278 |
else { |
|
279 |
numPdo++; |
|
280 |
offsetObjdict++; |
|
281 |
} |
|
282 |
status = state1; |
|
283 |
break; |
|
284 |
||
285 |
||
215 | 286 |
case state4:/* check transmission type (after request?) */ |
217
94c3f89bc3cc
Fixed compile error because of missed type casting in certain compiler (http://www.iar.se/). Thanks to Raphael Studer
etisserant
parents:
215
diff
changeset
|
287 |
pTransmissionType = (UNS8*) d->objdict[offsetObjdict].pSubindex[2].pObject; |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
288 |
if ( (*pTransmissionType == TRANS_RTR) || |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
289 |
(*pTransmissionType == TRANS_RTR_SYNC )) { |
208 | 290 |
status = state5; |
291 |
break; |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
292 |
}else if( |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
293 |
(*pTransmissionType == TRANS_EVENT_PROFILE) || |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
294 |
(*pTransmissionType == TRANS_EVENT_SPECIFIC) ) { |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
295 |
/* Zap all timers and inhibit flag */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
296 |
d->PDO_status[numPdo].event_timer = DelAlarm(d->PDO_status[numPdo].event_timer); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
297 |
d->PDO_status[numPdo].inhibit_timer = DelAlarm(d->PDO_status[numPdo].inhibit_timer); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
298 |
d->PDO_status[numPdo].transmit_type_parameter &= ~PDO_INHIBITED; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
299 |
/* Call PDOEventTimerAlarm for this TPDO, this will trigger emission et reset timers */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
300 |
PDOEventTimerAlarm(d, numPdo); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
301 |
return 0; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
302 |
}else { |
215 | 303 |
/* The requested PDO is not to send on request. So, does |
208 | 304 |
nothing. */ |
305 |
MSG_WAR(0x2947, "PDO is not to send on request : ", m->cob_id.w); |
|
306 |
return 0xFF; |
|
307 |
} |
|
308 |
||
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
309 |
case state5:/* build and send requested PDO */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
310 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
311 |
Message pdo; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
312 |
if( buildPDO(d, numPdo, &pdo)) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
313 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
314 |
MSG_ERR(0x1013, " Couldn't find mapped variable at index-subindex-size : ", (UNS16)(*pMappingParameter)); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
315 |
//return 0xFF; /*No real reason to stop...*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
316 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
317 |
canSend(d->canHandle,&pdo); |
208 | 318 |
return 0; |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
319 |
} |
215 | 320 |
}/* end switch status */ |
321 |
}/* end while */ |
|
322 |
}/* end if Requete */ |
|
208 | 323 |
|
0 | 324 |
return 0; |
325 |
} |
|
326 |
||
208 | 327 |
/*! |
328 |
** |
|
329 |
** |
|
330 |
** @param NbBits |
|
331 |
** @param SrcByteIndex |
|
332 |
** @param SrcBitIndex |
|
333 |
** @param SrcBigEndian |
|
334 |
** @param DestByteIndex |
|
335 |
** @param DestBitIndex |
|
336 |
** @param DestBigEndian |
|
337 |
**/ |
|
201 | 338 |
void CopyBits(UNS8 NbBits, UNS8* SrcByteIndex, UNS8 SrcBitIndex, UNS8 SrcBigEndian, UNS8* DestByteIndex, UNS8 DestBitIndex, UNS8 DestBigEndian) |
339 |
{ |
|
215 | 340 |
/* This loop copy as many bits that it can each time, crossing*/ |
341 |
/* successively bytes*/ |
|
208 | 342 |
// boundaries from LSB to MSB. |
343 |
while(NbBits > 0) |
|
344 |
{ |
|
215 | 345 |
/* Bit missalignement between src and dest*/ |
208 | 346 |
INTEGER8 Vect = DestBitIndex - SrcBitIndex; |
347 |
||
215 | 348 |
/* We can now get src and align it to dest*/ |
208 | 349 |
UNS8 Aligned = Vect>0 ? *SrcByteIndex << Vect : *SrcByteIndex >> -Vect; |
350 |
||
215 | 351 |
/* Compute the nb of bit we will be able to copy*/ |
208 | 352 |
UNS8 BoudaryLimit = (Vect>0 ? 8 - DestBitIndex : 8 - SrcBitIndex ); |
353 |
UNS8 BitsToCopy = BoudaryLimit > NbBits ? NbBits : BoudaryLimit; |
|
354 |
||
215 | 355 |
/* Create a mask that will serve in:*/ |
208 | 356 |
UNS8 Mask = ((0xff << (DestBitIndex + BitsToCopy)) | (0xff >> (8 - DestBitIndex))); |
357 |
||
215 | 358 |
/* - Filtering src*/ |
208 | 359 |
UNS8 Filtered = Aligned & ~Mask; |
360 |
||
215 | 361 |
/* - and erase bits where we write, preserve where we don't*/ |
208 | 362 |
*DestByteIndex &= Mask; |
363 |
||
215 | 364 |
/* Then write.*/ |
208 | 365 |
*DestByteIndex |= Filtered ; |
366 |
||
215 | 367 |
/*Compute next time cursors for src*/ |
368 |
if((SrcBitIndex += BitsToCopy)>7)/* cross boundary ?*/ |
|
208 | 369 |
{ |
215 | 370 |
SrcBitIndex = 0;/* First bit*/ |
371 |
SrcByteIndex += (SrcBigEndian ? -1 : 1);/* Next byte*/ |
|
372 |
} |
|
373 |
||
374 |
||
375 |
/*Compute next time cursors for dest*/ |
|
208 | 376 |
if((DestBitIndex += BitsToCopy)>7) |
377 |
{ |
|
215 | 378 |
DestBitIndex = 0;/* First bit*/ |
379 |
DestByteIndex += (DestBigEndian ? -1 : 1);/* Next byte*/ |
|
380 |
} |
|
381 |
||
382 |
/*And decrement counter.*/ |
|
208 | 383 |
NbBits -= BitsToCopy; |
384 |
} |
|
201 | 385 |
|
386 |
} |
|
208 | 387 |
/*! |
388 |
** |
|
389 |
** |
|
390 |
** @param d |
|
391 |
** |
|
392 |
** @return |
|
393 |
**/ |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
394 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
395 |
UNS8 sendPDOevent( CO_Data* d) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
396 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
397 |
/* Calls _sendPDOevent specifying it is not a sync event */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
398 |
return _sendPDOevent(d, 0); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
399 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
400 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
401 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
402 |
void PDOEventTimerAlarm(CO_Data* d, UNS32 pdoNum) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
403 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
404 |
printf("EV PDOEventTimerAlarm : %d\n", pdoNum); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
405 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
406 |
/* This is needed to avoid deletion of re-attribuated timer */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
407 |
d->PDO_status[pdoNum].event_timer = TIMER_NONE; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
408 |
/* force emission of PDO by artificially changing last emitted*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
409 |
d->PDO_status[pdoNum].last_message.cob_id.w = 0; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
410 |
_sendPDOevent( d, 0 ); /* not a Sync Event*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
411 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
412 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
413 |
void PDOInhibitTimerAlarm(CO_Data* d, UNS32 pdoNum) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
414 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
415 |
printf("EV PDOInhibitTimerAlarm : %d\n", pdoNum); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
416 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
417 |
/* This is needed to avoid deletion of re-attribuated timer */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
418 |
d->PDO_status[pdoNum].inhibit_timer = TIMER_NONE; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
419 |
/* Remove inhibit flag */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
420 |
d->PDO_status[pdoNum].transmit_type_parameter &= ~PDO_INHIBITED; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
421 |
_sendPDOevent( d, 0 ); /* not a Sync Event*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
422 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
423 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
424 |
/*! |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
425 |
** |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
426 |
** |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
427 |
** @param d |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
428 |
** @param isSyncEvent |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
429 |
** |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
430 |
** @return |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
431 |
**/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
432 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
433 |
UNS8 _sendPDOevent( CO_Data* d, UNS8 isSyncEvent ) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
434 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
435 |
UNS8 pdoNum = 0x00; /* number of the actual processed pdo-nr. */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
436 |
UNS8* pTransmissionType = NULL; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
437 |
UNS8 status = state3; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
438 |
UNS16 offsetObjdict = d->firstIndex->PDO_TRS; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
439 |
UNS16 offsetObjdictMap = d->firstIndex->PDO_TRS_MAP; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
440 |
UNS16 lastIndex = d->lastIndex->PDO_TRS; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
441 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
442 |
/* study all PDO stored in the objects dictionary */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
443 |
if(offsetObjdict){ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
444 |
Message clean = Message_Initializer; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
445 |
Message pdo = Message_Initializer; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
446 |
while( offsetObjdict <= lastIndex) { |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
447 |
switch( status ) { |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
448 |
case state3: /* get the PDO transmission type */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
449 |
if (d->objdict[offsetObjdict].bSubCount <= 2) { |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
450 |
MSG_ERR(0x1004, "Subindex 2 not found at index ", 0x1800 + pdoNum); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
451 |
return 0xFF; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
452 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
453 |
pTransmissionType = (UNS8*) d->objdict[offsetObjdict].pSubindex[2].pObject; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
454 |
MSG_WAR(0x3005, "Reading PDO at index : ", 0x1800 + pdoNum); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
455 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
456 |
/* check if transmission type is after (this) SYNC */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
457 |
/* The message may not be transmited every SYNC but every n SYNC */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
458 |
if( isSyncEvent && |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
459 |
(*pTransmissionType >= TRANS_SYNC_MIN) && |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
460 |
(*pTransmissionType <= TRANS_SYNC_MAX) && |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
461 |
(++d->PDO_status[pdoNum].transmit_type_parameter == *pTransmissionType) ) { |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
462 |
d->PDO_status[pdoNum].transmit_type_parameter = 0; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
463 |
MSG_WAR(0x3007, " PDO is on SYNCHRO. Trans type : ", *pTransmissionType); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
464 |
pdo = clean; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
465 |
if(buildPDO(d, pdoNum, &pdo)) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
466 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
467 |
MSG_ERR(0x3006, " Couldn't build TPDO number : ", pdoNum); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
468 |
status = state11; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
469 |
break; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
470 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
471 |
status = state5; |
208 | 472 |
} |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
473 |
/* If transmission on Event and not inhibited, check for changes */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
474 |
else if((*pTransmissionType == TRANS_EVENT_PROFILE || |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
475 |
*pTransmissionType == TRANS_EVENT_SPECIFIC )&& |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
476 |
!(d->PDO_status[pdoNum].transmit_type_parameter & PDO_INHIBITED)) { |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
477 |
MSG_WAR(0x3008, " PDO is on EVENT. Trans type : ", *pTransmissionType); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
478 |
pdo = pdo = clean; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
479 |
if(buildPDO(d, pdoNum, &pdo)) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
480 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
481 |
MSG_ERR(0x3007, " Couldn't build TPDO number : ", pdoNum); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
482 |
status = state11; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
483 |
break; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
484 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
485 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
486 |
/*Compare new and old PDO*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
487 |
if(d->PDO_status[pdoNum].last_message.cob_id.w == pdo.cob_id.w && |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
488 |
d->PDO_status[pdoNum].last_message.len == pdo.len && |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
489 |
*(UNS64*)(&d->PDO_status[pdoNum].last_message.data[0]) == *(UNS64*)(&pdo.data[0])){ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
490 |
/* No changes -> go to next pdo*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
491 |
status = state11; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
492 |
}else{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
493 |
MSG_WAR(0x3008, "Changes TPDO number : ", pdoNum); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
494 |
printf("EV Changes TPDO number : %d\n", pdoNum); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
495 |
/* Changes detected -> transmit message */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
496 |
status = state5; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
497 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
498 |
/* Start both event_timer and inhibit_timer*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
499 |
DelAlarm(d->PDO_status[pdoNum].event_timer); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
500 |
d->PDO_status[pdoNum].event_timer = SetAlarm(d, pdoNum, &PDOEventTimerAlarm, MS_TO_TIMEVAL(*(UNS16*)d->objdict[offsetObjdict].pSubindex[5].pObject), 0); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
501 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
502 |
DelAlarm(d->PDO_status[pdoNum].inhibit_timer); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
503 |
d->PDO_status[pdoNum].inhibit_timer = SetAlarm(d, pdoNum, &PDOInhibitTimerAlarm, US_TO_TIMEVAL(*(UNS16*)d->objdict[offsetObjdict].pSubindex[3].pObject * 100), 0); |
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 |
/* and inhibit TPDO */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
506 |
d->PDO_status[pdoNum].transmit_type_parameter |= PDO_INHIBITED; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
507 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
508 |
}else{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
509 |
MSG_WAR(0x3009, " PDO is not on EVENT or synchro or not at this SYNC. Trans type : ", *pTransmissionType); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
510 |
status = state11; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
511 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
512 |
break; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
513 |
case state5: /*Send the pdo*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
514 |
/*store_as_last_message*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
515 |
d->PDO_status[pdoNum].last_message = pdo; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
516 |
MSG_WAR(0x3901, "sendPDO cobId :", pdo.cob_id.w); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
517 |
MSG_WAR(0x3902, " Nb octets : ", pdo.len); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
518 |
{int i; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
519 |
for (i = 0 ; i < pdo.len ; i++) { |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
520 |
MSG_WAR(0x3903," data : ", pdo.data[i]); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
521 |
}} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
522 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
523 |
canSend(d->canHandle,&pdo); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
524 |
status = state11; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
525 |
break; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
526 |
case state11: /*Go to next TPDO*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
527 |
pdoNum++; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
528 |
offsetObjdict++; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
529 |
offsetObjdictMap++; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
530 |
MSG_WAR(0x3017, "next pdo index : ", pdoNum); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
531 |
status = state3; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
532 |
break; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
533 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
534 |
default: |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
535 |
MSG_ERR(0x1019,"Unknown state has been reached : %d",status); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
536 |
return 0xFF; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
537 |
}/* end switch case */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
538 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
539 |
}/* end while */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
540 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
541 |
return 0; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
542 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
543 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
544 |
void PDOInit(CO_Data* d) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
545 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
546 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
547 |
/* TODO: implement callbacks on 140xh |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
548 |
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
549 |
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
550 |
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
551 |
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
552 |
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
553 |
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
554 |
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
555 |
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
556 |
*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
557 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
558 |
_sendPDOevent(d, 0 ); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
559 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
560 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
561 |
void PDOStop(CO_Data* d) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
562 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
563 |
UNS8 pdoNum = 0x00; /* number of the actual processed pdo-nr. */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
564 |
UNS16 offsetObjdict = d->firstIndex->PDO_TRS; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
565 |
UNS16 lastIndex = d->lastIndex->PDO_TRS; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
566 |
if(offsetObjdict) while( offsetObjdict <= lastIndex) { |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
567 |
d->PDO_status[pdoNum].event_timer = DelAlarm(d->PDO_status[pdoNum].event_timer); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
568 |
d->PDO_status[pdoNum].inhibit_timer = DelAlarm(d->PDO_status[pdoNum].inhibit_timer); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
569 |
d->PDO_status[pdoNum].transmit_type_parameter = 0; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
570 |
d->PDO_status[pdoNum].last_message.cob_id.w = 0; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
571 |
pdoNum++; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
572 |
offsetObjdict++; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
573 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
574 |
} |