author | etisserant |
Sun, 24 Feb 2008 02:03:19 +0100 | |
changeset 407 | 384c3cd7afa2 |
parent 380 | fe47568b8281 |
child 425 | 4bc4706528ae |
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 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
49 |
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
|
50 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
51 |
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
|
52 |
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
|
53 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
54 |
UNS8 prp_j = 0x00; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
55 |
UNS8 offset = 0x00; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
56 |
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
|
57 |
|
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
|
58 |
pdo->cob_id = *(UNS16*)TPDO_com->pSubindex[1].pObject & UNS16_LE(0x7FF); |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
59 |
pdo->rtr = NOT_A_REQUEST; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
60 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
61 |
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
|
62 |
MSG_WAR(0x300D, " Number of objects mapped : ",*pMappingCount ); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
63 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
64 |
do{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
65 |
UNS8 dataType; /* Unused */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
66 |
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
|
67 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
68 |
/* 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
|
69 |
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
|
70 |
UNS16 index = (UNS16)((*pMappingParameter) >> 16); |
380 | 71 |
UNS8 Size = (UNS8)(*pMappingParameter & (UNS32)0x000000FF); /* Size in bits */ |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
72 |
|
350
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
73 |
/* get variable only if Size != 0 and Size is lower than remaining bits in the PDO */ |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
74 |
if(Size && ((offset + Size) <= 64)) { |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
75 |
UNS8 ByteSize = 1 + ((Size - 1) >> 3); /*1->8 => 1 ; 9->16 => 2, ... */ |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
76 |
UNS8 subIndex = (UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
77 |
|
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
78 |
MSG_WAR(0x300F, " got mapping parameter : ", *pMappingParameter); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
79 |
MSG_WAR(0x3050, " at index : ", TPDO_map->index); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
80 |
MSG_WAR(0x3051, " sub-index : ", prp_j + 1); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
81 |
|
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
82 |
if( getODentry(d, index, subIndex, tmp, &ByteSize, &dataType, 0 ) != OD_SUCCESSFUL ){ |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
83 |
MSG_ERR(0x1013, " Couldn't find mapped variable at index-subindex-size : ", (UNS16)(*pMappingParameter)); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
84 |
return 0xFF; |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
85 |
} |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
86 |
/* copy bit per bit in little endian*/ |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
87 |
CopyBits(Size, ((UNS8*)tmp), 0 , 0, (UNS8*)&pdo->data[offset>>3], offset%8, 0); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
88 |
|
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
89 |
offset += Size ; |
235
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 |
prp_j++; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
92 |
}while( prp_j < *pMappingCount ); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
93 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
94 |
pdo->len = 1 + ((offset - 1) >> 3); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
95 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
96 |
MSG_WAR(0x3015, " End scan mapped variable", 0); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
97 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
98 |
return 0; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
99 |
} |
208 | 100 |
|
101 |
/*! |
|
102 |
** |
|
103 |
** |
|
104 |
** @param d |
|
105 |
** @param cobId |
|
106 |
** |
|
107 |
** @return |
|
108 |
**/ |
|
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
109 |
UNS8 sendPDOrequest( CO_Data* d, UNS16 RPDOIndex ) |
208 | 110 |
{ |
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
|
111 |
UNS16 * pwCobId; |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
112 |
UNS16 offset = d->firstIndex->PDO_RCV; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
113 |
UNS16 lastIndex = d->lastIndex->PDO_RCV; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
114 |
|
215 | 115 |
/* Sending the request only if the cobid have been found on the PDO |
208 | 116 |
receive */ |
215 | 117 |
/* part dictionary */ |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
118 |
|
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
119 |
MSG_WAR(0x3930, "sendPDOrequest RPDO Index : ",RPDOIndex); |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
120 |
|
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
121 |
if (offset && RPDOIndex >= 0x1400){ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
122 |
offset += RPDOIndex - 0x1400; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
123 |
if (offset <= lastIndex) { |
215 | 124 |
/* get the CobId*/ |
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
|
125 |
pwCobId = (UNS16*) d->objdict[offset].pSubindex[1].pObject; |
208 | 126 |
|
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
127 |
MSG_WAR(0x3930, "sendPDOrequest cobId is : ",*pwCobId); |
252 | 128 |
{ |
285
dbf7695290ae
Removed struct initializer with non-constant pointer, making TI compiler fail
etisserant
parents:
252
diff
changeset
|
129 |
Message pdo; |
365 | 130 |
pdo.cob_id = *pwCobId; |
285
dbf7695290ae
Removed struct initializer with non-constant pointer, making TI compiler fail
etisserant
parents:
252
diff
changeset
|
131 |
pdo.rtr = REQUEST; |
dbf7695290ae
Removed struct initializer with non-constant pointer, making TI compiler fail
etisserant
parents:
252
diff
changeset
|
132 |
pdo.len = 0; |
dbf7695290ae
Removed struct initializer with non-constant pointer, making TI compiler fail
etisserant
parents:
252
diff
changeset
|
133 |
return canSend(d->canHandle,&pdo); |
252 | 134 |
} |
208 | 135 |
} |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
136 |
} |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
137 |
MSG_ERR(0x1931, "sendPDOrequest : RPDO Index not found : ", RPDOIndex); |
0 | 138 |
return 0xFF; |
139 |
} |
|
140 |
||
141 |
||
208 | 142 |
/*! |
143 |
** |
|
144 |
** |
|
145 |
** @param d |
|
146 |
** @param m |
|
147 |
** |
|
148 |
** @return |
|
149 |
**/ |
|
0 | 150 |
UNS8 proceedPDO(CO_Data* d, Message *m) |
208 | 151 |
{ |
0 | 152 |
UNS8 numPdo; |
215 | 153 |
UNS8 numMap; /* Number of the mapped varable */ |
154 |
UNS8 * pMappingCount = NULL; /* count of mapped objects... */ |
|
155 |
/* pointer to the var which is mapped to a pdo... */ |
|
156 |
/* void * pMappedAppObject = NULL; */ |
|
157 |
/* pointer fo the var which holds the mapping parameter of an |
|
208 | 158 |
mapping entry */ |
159 |
UNS32 * pMappingParameter = NULL; |
|
215 | 160 |
UNS8 * pTransmissionType = NULL; /* pointer to the transmission |
208 | 161 |
type */ |
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
|
162 |
UNS16 * pwCobId = NULL; |
0 | 163 |
UNS8 Size; |
164 |
UNS8 offset; |
|
165 |
UNS8 status; |
|
166 |
UNS32 objDict; |
|
167 |
UNS16 offsetObjdict; |
|
168 |
UNS16 lastIndex; |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
169 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
170 |
status = state2; |
208 | 171 |
|
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
|
172 |
MSG_WAR(0x3935, "proceedPDO, cobID : ", ((*m).cob_id & UNS16_LE(0x7ff))); |
0 | 173 |
offset = 0x00; |
174 |
numPdo = 0; |
|
175 |
numMap = 0; |
|
215 | 176 |
if((*m).rtr == NOT_A_REQUEST ) { /* The PDO received is not a |
208 | 177 |
request. */ |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
178 |
|
0 | 179 |
offsetObjdict = d->firstIndex->PDO_RCV; |
180 |
lastIndex = d->lastIndex->PDO_RCV; |
|
208 | 181 |
|
215 | 182 |
/* study of all the PDO stored in the dictionary */ |
0 | 183 |
if(offsetObjdict) |
208 | 184 |
while (offsetObjdict <= lastIndex) { |
185 |
||
186 |
switch( status ) { |
|
187 |
||
188 |
case state2: |
|
215 | 189 |
/* get CobId of the dictionary correspondant to the received |
208 | 190 |
PDO */ |
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
|
191 |
pwCobId = (UNS16*) d->objdict[offsetObjdict].pSubindex[1].pObject; |
215 | 192 |
/* check the CobId coherance */ |
193 |
/*pwCobId is the cobId read in the dictionary at the state 3 |
|
208 | 194 |
*/ |
365 | 195 |
if ( *pwCobId == (*m).cob_id ){ |
215 | 196 |
/* The cobId is recognized */ |
208 | 197 |
status = state4; |
198 |
MSG_WAR(0x3936, "cobId found at index ", 0x1400 + numPdo); |
|
199 |
break; |
|
200 |
} |
|
201 |
else { |
|
215 | 202 |
/* cobId received does not match with those write in the |
208 | 203 |
dictionnary */ |
204 |
numPdo++; |
|
205 |
offsetObjdict++; |
|
206 |
status = state2; |
|
207 |
break; |
|
208 |
} |
|
209 |
||
215 | 210 |
case state4:/* Get Mapped Objects Number */ |
211 |
/* The cobId of the message received has been found in the |
|
208 | 212 |
dictionnary. */ |
213 |
offsetObjdict = d->firstIndex->PDO_RCV_MAP; |
|
214 |
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
|
215 |
pMappingCount = (UNS8*) (d->objdict + offsetObjdict + numPdo)->pSubindex[0].pObject; |
208 | 216 |
numMap = 0; |
217 |
while (numMap < *pMappingCount) { |
|
218 |
UNS8 tmp[]= {0,0,0,0,0,0,0,0}; |
|
219 |
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
|
220 |
pMappingParameter = (UNS32*) (d->objdict + offsetObjdict + numPdo)->pSubindex[numMap + 1].pObject; |
208 | 221 |
if (pMappingParameter == NULL) { |
222 |
MSG_ERR(0x1937, "Couldn't get mapping parameter : ", numMap + 1); |
|
223 |
return 0xFF; |
|
224 |
} |
|
215 | 225 |
/* Get the addresse of the mapped variable. */ |
226 |
/* detail of *pMappingParameter : */ |
|
227 |
/* The 16 hight bits contains the index, the medium 8 bits |
|
208 | 228 |
contains the subindex, */ |
215 | 229 |
/* and the lower 8 bits contains the size of the mapped |
208 | 230 |
variable. */ |
231 |
||
380 | 232 |
Size = (UNS8)(*pMappingParameter & (UNS32)0x000000FF); |
350
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
233 |
|
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
234 |
/* set variable only if Size != 0 and Size is lower than remaining bits in the PDO */ |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
235 |
if(Size && ((offset + Size) <= (m->len << 3))) { |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
236 |
/* copy bit per bit in little endian */ |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
237 |
CopyBits(Size, (UNS8*)&m->data[offset>>3], offset%8, 0, ((UNS8*)tmp), 0, 0); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
238 |
|
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
239 |
ByteSize = 1 + ((Size - 1) >> 3); /*1->8 => 1 ; 9->16 => |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
240 |
2, ... */ |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
241 |
|
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
242 |
objDict = setODentry(d, (UNS16)((*pMappingParameter) >> 16), |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
243 |
(UNS8)(((*pMappingParameter) >> 8 ) & 0xFF), |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
244 |
tmp, &ByteSize, 0 ); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
245 |
|
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
246 |
if(objDict != OD_SUCCESSFUL) { |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
247 |
MSG_ERR(0x1938, "error accessing to the mapped var : ", numMap + 1); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
248 |
MSG_WAR(0x2939, " Mapped at index : ", (*pMappingParameter) >> 16); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
249 |
MSG_WAR(0x2940, " subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
250 |
return 0xFF; |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
251 |
} |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
252 |
|
365 | 253 |
MSG_WAR(0x3942, "Variable updated with value received by PDO cobid : ", m->cob_id); |
350
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
254 |
MSG_WAR(0x3943, " Mapped at index : ", (*pMappingParameter) >> 16); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
255 |
MSG_WAR(0x3944, " subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF); |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
256 |
/* MSG_WAR(0x3945, " data : ",*((UNS32*)pMappedAppObject)); */ |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
257 |
offset += Size; |
e90113f7030b
Size verification of the mapped variables in PDOs (both reception and transmission)
luis
parents:
320
diff
changeset
|
258 |
} |
208 | 259 |
numMap++; |
215 | 260 |
} /* end loop while on mapped variables */ |
208 | 261 |
|
262 |
offset=0x00; |
|
263 |
numMap = 0; |
|
264 |
return 0; |
|
265 |
||
215 | 266 |
}/* end switch status*/ |
267 |
}/* end while*/ |
|
268 |
}/* end if Donnees */ |
|
208 | 269 |
else if ((*m).rtr == REQUEST ){ |
365 | 270 |
MSG_WAR(0x3946, "Receive a PDO request cobId : ", m->cob_id); |
208 | 271 |
status = state1; |
272 |
offsetObjdict = d->firstIndex->PDO_TRS; |
|
273 |
lastIndex = d->lastIndex->PDO_TRS; |
|
274 |
if(offsetObjdict) while( offsetObjdict <= lastIndex ){ |
|
215 | 275 |
/* study of all PDO stored in the objects dictionary */ |
208 | 276 |
|
277 |
switch( status ){ |
|
278 |
||
215 | 279 |
case state1:/* check the CobId */ |
280 |
/* get CobId of the dictionary which match to the received PDO |
|
208 | 281 |
*/ |
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
|
282 |
pwCobId = (UNS16*) (d->objdict + offsetObjdict)->pSubindex[1].pObject; |
365 | 283 |
if ( *pwCobId == (*m).cob_id ) { |
208 | 284 |
status = state4; |
285 |
break; |
|
286 |
} |
|
287 |
else { |
|
288 |
numPdo++; |
|
289 |
offsetObjdict++; |
|
290 |
} |
|
291 |
status = state1; |
|
292 |
break; |
|
293 |
||
294 |
||
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
295 |
case state4:/* check transmission type */ |
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
|
296 |
pTransmissionType = (UNS8*) d->objdict[offsetObjdict].pSubindex[2].pObject; |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
297 |
/* If PDO is to be sampled and send on RTR, do it*/ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
298 |
if ( (*pTransmissionType == TRANS_RTR)) { |
208 | 299 |
status = state5; |
300 |
break; |
|
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
301 |
/* RTR_SYNC mean data is prepared at SYNC, and transmitted on RTR */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
302 |
}else if ((*pTransmissionType == TRANS_RTR_SYNC )) { |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
303 |
if(d->PDO_status[numPdo].transmit_type_parameter & PDO_RTR_SYNC_READY){ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
304 |
/*Data ready, just send*/ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
305 |
canSend(d->canHandle,&d->PDO_status[numPdo].last_message); |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
306 |
return 0; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
307 |
}else{ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
308 |
/* if SYNC did never occur, force emission with current data */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
309 |
/* DS301 do not tell what to do in such a case...*/ |
365 | 310 |
MSG_ERR(0x1947, "Not ready RTR_SYNC TPDO send current data : ", m->cob_id); |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
311 |
status = state5; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
312 |
} |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
313 |
break; |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
314 |
}else if( |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
315 |
(*pTransmissionType == TRANS_EVENT_PROFILE) || |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
316 |
(*pTransmissionType == TRANS_EVENT_SPECIFIC) ) { |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
317 |
/* Zap all timers and inhibit flag */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
/* 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
|
322 |
PDOEventTimerAlarm(d, numPdo); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
323 |
return 0; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
324 |
}else { |
215 | 325 |
/* The requested PDO is not to send on request. So, does |
208 | 326 |
nothing. */ |
365 | 327 |
MSG_WAR(0x2947, "PDO is not to send on request : ", m->cob_id); |
208 | 328 |
return 0xFF; |
329 |
} |
|
330 |
||
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
331 |
case state5:/* build and send requested PDO */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
332 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
333 |
Message pdo; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
334 |
if( buildPDO(d, numPdo, &pdo)) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
335 |
{ |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
336 |
MSG_ERR(0x1948, " Couldn't build TPDO n°", numPdo); |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
337 |
return 0xFF; |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
338 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
339 |
canSend(d->canHandle,&pdo); |
208 | 340 |
return 0; |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
341 |
} |
215 | 342 |
}/* end switch status */ |
343 |
}/* end while */ |
|
344 |
}/* end if Requete */ |
|
208 | 345 |
|
0 | 346 |
return 0; |
347 |
} |
|
348 |
||
208 | 349 |
/*! |
350 |
** |
|
351 |
** |
|
352 |
** @param NbBits |
|
353 |
** @param SrcByteIndex |
|
354 |
** @param SrcBitIndex |
|
355 |
** @param SrcBigEndian |
|
356 |
** @param DestByteIndex |
|
357 |
** @param DestBitIndex |
|
358 |
** @param DestBigEndian |
|
359 |
**/ |
|
201 | 360 |
void CopyBits(UNS8 NbBits, UNS8* SrcByteIndex, UNS8 SrcBitIndex, UNS8 SrcBigEndian, UNS8* DestByteIndex, UNS8 DestBitIndex, UNS8 DestBigEndian) |
361 |
{ |
|
215 | 362 |
/* This loop copy as many bits that it can each time, crossing*/ |
363 |
/* successively bytes*/ |
|
208 | 364 |
// boundaries from LSB to MSB. |
365 |
while(NbBits > 0) |
|
366 |
{ |
|
215 | 367 |
/* Bit missalignement between src and dest*/ |
208 | 368 |
INTEGER8 Vect = DestBitIndex - SrcBitIndex; |
369 |
||
215 | 370 |
/* We can now get src and align it to dest*/ |
208 | 371 |
UNS8 Aligned = Vect>0 ? *SrcByteIndex << Vect : *SrcByteIndex >> -Vect; |
372 |
||
215 | 373 |
/* Compute the nb of bit we will be able to copy*/ |
208 | 374 |
UNS8 BoudaryLimit = (Vect>0 ? 8 - DestBitIndex : 8 - SrcBitIndex ); |
375 |
UNS8 BitsToCopy = BoudaryLimit > NbBits ? NbBits : BoudaryLimit; |
|
376 |
||
215 | 377 |
/* Create a mask that will serve in:*/ |
208 | 378 |
UNS8 Mask = ((0xff << (DestBitIndex + BitsToCopy)) | (0xff >> (8 - DestBitIndex))); |
379 |
||
215 | 380 |
/* - Filtering src*/ |
208 | 381 |
UNS8 Filtered = Aligned & ~Mask; |
382 |
||
215 | 383 |
/* - and erase bits where we write, preserve where we don't*/ |
208 | 384 |
*DestByteIndex &= Mask; |
385 |
||
215 | 386 |
/* Then write.*/ |
208 | 387 |
*DestByteIndex |= Filtered ; |
388 |
||
215 | 389 |
/*Compute next time cursors for src*/ |
390 |
if((SrcBitIndex += BitsToCopy)>7)/* cross boundary ?*/ |
|
208 | 391 |
{ |
215 | 392 |
SrcBitIndex = 0;/* First bit*/ |
393 |
SrcByteIndex += (SrcBigEndian ? -1 : 1);/* Next byte*/ |
|
394 |
} |
|
395 |
||
396 |
||
397 |
/*Compute next time cursors for dest*/ |
|
208 | 398 |
if((DestBitIndex += BitsToCopy)>7) |
399 |
{ |
|
215 | 400 |
DestBitIndex = 0;/* First bit*/ |
401 |
DestByteIndex += (DestBigEndian ? -1 : 1);/* Next byte*/ |
|
402 |
} |
|
403 |
||
404 |
/*And decrement counter.*/ |
|
208 | 405 |
NbBits -= BitsToCopy; |
406 |
} |
|
201 | 407 |
|
408 |
} |
|
208 | 409 |
/*! |
410 |
** |
|
411 |
** |
|
412 |
** @param d |
|
413 |
** |
|
414 |
** @return |
|
415 |
**/ |
|
235
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 |
UNS8 sendPDOevent( CO_Data* d) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
418 |
{ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
419 |
/* 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
|
420 |
return _sendPDOevent(d, 0); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
421 |
} |
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 |
void PDOEventTimerAlarm(CO_Data* d, UNS32 pdoNum) |
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 |
/* 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
|
427 |
d->PDO_status[pdoNum].event_timer = TIMER_NONE; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
428 |
/* force emission of PDO by artificially changing last emitted*/ |
365 | 429 |
d->PDO_status[pdoNum].last_message.cob_id = 0; |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
430 |
_sendPDOevent( d, 0 ); /* not a Sync Event*/ |
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 |
void PDOInhibitTimerAlarm(CO_Data* d, UNS32 pdoNum) |
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 |
/* 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
|
436 |
d->PDO_status[pdoNum].inhibit_timer = TIMER_NONE; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
437 |
/* Remove inhibit flag */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
438 |
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
|
439 |
_sendPDOevent( d, 0 ); /* not a Sync Event*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
440 |
} |
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 |
/*! |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
443 |
** |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
444 |
** |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
445 |
** @param d |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
446 |
** @param isSyncEvent |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
447 |
** |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
448 |
** @return |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
449 |
**/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
450 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
451 |
UNS8 _sendPDOevent( CO_Data* d, UNS8 isSyncEvent ) |
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 |
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
|
454 |
UNS8* pTransmissionType = NULL; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
455 |
UNS8 status = state3; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
456 |
UNS16 offsetObjdict = d->firstIndex->PDO_TRS; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
457 |
UNS16 offsetObjdictMap = d->firstIndex->PDO_TRS_MAP; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
458 |
UNS16 lastIndex = d->lastIndex->PDO_TRS; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
459 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
460 |
/* study all PDO stored in the objects dictionary */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
461 |
if(offsetObjdict){ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
462 |
Message pdo = Message_Initializer; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
463 |
while( offsetObjdict <= lastIndex) { |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
464 |
switch( status ) { |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
465 |
case state3: |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
466 |
if (/*d->objdict[offsetObjdict].bSubCount < 5 || not necessary with objdictedit (always 5)*/ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
467 |
/* check if TPDO is not valid */ |
298 | 468 |
*(UNS32*)d->objdict[offsetObjdict].pSubindex[1].pObject & 0x80000000) { |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
469 |
MSG_WAR(0x3960, "Not a valid PDO ", 0x1800 + pdoNum); |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
470 |
/*Go next TPDO*/ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
471 |
status = state11; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
472 |
break; |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
473 |
} |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
474 |
/* get the PDO transmission type */ |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
475 |
pTransmissionType = (UNS8*) d->objdict[offsetObjdict].pSubindex[2].pObject; |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
476 |
MSG_WAR(0x3962, "Reading PDO at index : ", 0x1800 + pdoNum); |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
477 |
|
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
478 |
/* check if transmission type is SYNCRONOUS */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
479 |
/* The message is transmited every n SYNC with n=TransmissionType */ |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
480 |
if( isSyncEvent && |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
481 |
(*pTransmissionType >= TRANS_SYNC_MIN) && |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
482 |
(*pTransmissionType <= TRANS_SYNC_MAX) && |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
483 |
(++d->PDO_status[pdoNum].transmit_type_parameter == *pTransmissionType) ) { |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
484 |
/*Reset count of SYNC*/ |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
485 |
d->PDO_status[pdoNum].transmit_type_parameter = 0; |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
486 |
MSG_WAR(0x3964, " PDO is on SYNCHRO. Trans type : ", *pTransmissionType); |
252 | 487 |
{ |
488 |
Message msg_init = Message_Initializer; |
|
489 |
pdo = msg_init; |
|
490 |
} |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
491 |
if(buildPDO(d, pdoNum, &pdo)) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
492 |
{ |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
493 |
MSG_ERR(0x1906, " Couldn't build TPDO number : ", pdoNum); |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
494 |
status = state11; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
495 |
break; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
496 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
497 |
status = state5; |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
498 |
/* If transmission RTR, with data sampled on SYNC */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
499 |
}else if( isSyncEvent && |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
500 |
(*pTransmissionType == TRANS_RTR_SYNC)) { |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
501 |
if(buildPDO(d, pdoNum, &d->PDO_status[pdoNum].last_message)) |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
502 |
{ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
503 |
MSG_ERR(0x1966, " Couldn't build TPDO number : ", pdoNum); |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
504 |
d->PDO_status[pdoNum].transmit_type_parameter &= ~PDO_RTR_SYNC_READY; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
505 |
}else{ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
506 |
d->PDO_status[pdoNum].transmit_type_parameter |= PDO_RTR_SYNC_READY; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
507 |
} |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
508 |
status = state11; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
509 |
break; |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
510 |
/* If transmission on Event and not inhibited, check for changes */ |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
511 |
}else if((*pTransmissionType == TRANS_EVENT_PROFILE || |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
512 |
*pTransmissionType == TRANS_EVENT_SPECIFIC )&& |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
513 |
!(d->PDO_status[pdoNum].transmit_type_parameter & PDO_INHIBITED)) { |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
514 |
MSG_WAR(0x3968, " PDO is on EVENT. Trans type : ", *pTransmissionType); |
252 | 515 |
{ |
516 |
Message msg_init = Message_Initializer; |
|
517 |
pdo = msg_init; |
|
518 |
} |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
519 |
if(buildPDO(d, pdoNum, &pdo)) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
520 |
{ |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
521 |
MSG_ERR(0x3907, " Couldn't build TPDO number : ", pdoNum); |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
522 |
status = state11; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
523 |
break; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
524 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
525 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
526 |
/*Compare new and old PDO*/ |
365 | 527 |
if(d->PDO_status[pdoNum].last_message.cob_id == pdo.cob_id && |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
528 |
d->PDO_status[pdoNum].last_message.len == pdo.len && |
315
1d3bf87b8658
Workaround for unsupported UNS64 on some compiler.
etisserant
parents:
298
diff
changeset
|
529 |
#ifdef UNS64 |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
530 |
*(UNS64*)(&d->PDO_status[pdoNum].last_message.data[0]) == *(UNS64*)(&pdo.data[0])){ |
315
1d3bf87b8658
Workaround for unsupported UNS64 on some compiler.
etisserant
parents:
298
diff
changeset
|
531 |
#else /* don't ALLOW_64BIT_OPS*/ |
1d3bf87b8658
Workaround for unsupported UNS64 on some compiler.
etisserant
parents:
298
diff
changeset
|
532 |
*(UNS32*)(&d->PDO_status[pdoNum].last_message.data[0]) == *(UNS32*)(&pdo.data[0]) && |
1d3bf87b8658
Workaround for unsupported UNS64 on some compiler.
etisserant
parents:
298
diff
changeset
|
533 |
*(UNS32*)(&d->PDO_status[pdoNum].last_message.data[4]) == *(UNS32*)(&pdo.data[4])){ |
1d3bf87b8658
Workaround for unsupported UNS64 on some compiler.
etisserant
parents:
298
diff
changeset
|
534 |
#endif |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
535 |
/* No changes -> go to next pdo*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
536 |
status = state11; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
537 |
}else{ |
298 | 538 |
|
539 |
UNS16 EventTimerDuration; |
|
540 |
UNS16 InhibitTimerDuration; |
|
541 |
||
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
542 |
MSG_WAR(0x306A, "Changes TPDO number : ", pdoNum); |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
543 |
/* Changes detected -> transmit message */ |
298 | 544 |
EventTimerDuration = *(UNS16*)d->objdict[offsetObjdict].pSubindex[5].pObject; |
545 |
InhibitTimerDuration = *(UNS16*)d->objdict[offsetObjdict].pSubindex[3].pObject; |
|
297
639e5ec5a120
Fixed some transmit type issues (for 254 255) with null event and/or inhibit time
etisserant
parents:
285
diff
changeset
|
546 |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
547 |
status = state5; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
548 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
549 |
/* Start both event_timer and inhibit_timer*/ |
297
639e5ec5a120
Fixed some transmit type issues (for 254 255) with null event and/or inhibit time
etisserant
parents:
285
diff
changeset
|
550 |
if(EventTimerDuration){ |
639e5ec5a120
Fixed some transmit type issues (for 254 255) with null event and/or inhibit time
etisserant
parents:
285
diff
changeset
|
551 |
DelAlarm(d->PDO_status[pdoNum].event_timer); |
639e5ec5a120
Fixed some transmit type issues (for 254 255) with null event and/or inhibit time
etisserant
parents:
285
diff
changeset
|
552 |
d->PDO_status[pdoNum].event_timer = SetAlarm(d, pdoNum, &PDOEventTimerAlarm, MS_TO_TIMEVAL(EventTimerDuration), 0); |
639e5ec5a120
Fixed some transmit type issues (for 254 255) with null event and/or inhibit time
etisserant
parents:
285
diff
changeset
|
553 |
} |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
554 |
|
297
639e5ec5a120
Fixed some transmit type issues (for 254 255) with null event and/or inhibit time
etisserant
parents:
285
diff
changeset
|
555 |
if(InhibitTimerDuration){ |
639e5ec5a120
Fixed some transmit type issues (for 254 255) with null event and/or inhibit time
etisserant
parents:
285
diff
changeset
|
556 |
DelAlarm(d->PDO_status[pdoNum].inhibit_timer); |
639e5ec5a120
Fixed some transmit type issues (for 254 255) with null event and/or inhibit time
etisserant
parents:
285
diff
changeset
|
557 |
d->PDO_status[pdoNum].inhibit_timer = SetAlarm(d, pdoNum, &PDOInhibitTimerAlarm, US_TO_TIMEVAL(InhibitTimerDuration * 100), 0); |
639e5ec5a120
Fixed some transmit type issues (for 254 255) with null event and/or inhibit time
etisserant
parents:
285
diff
changeset
|
558 |
/* and inhibit TPDO */ |
639e5ec5a120
Fixed some transmit type issues (for 254 255) with null event and/or inhibit time
etisserant
parents:
285
diff
changeset
|
559 |
d->PDO_status[pdoNum].transmit_type_parameter |= PDO_INHIBITED; |
639e5ec5a120
Fixed some transmit type issues (for 254 255) with null event and/or inhibit time
etisserant
parents:
285
diff
changeset
|
560 |
} |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
561 |
|
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 |
}else{ |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
564 |
MSG_WAR(0x306C, " PDO is not on EVENT or synchro or not at this SYNC. Trans type : ", *pTransmissionType); |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
565 |
status = state11; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
566 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
567 |
break; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
568 |
case state5: /*Send the pdo*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
569 |
/*store_as_last_message*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
570 |
d->PDO_status[pdoNum].last_message = pdo; |
365 | 571 |
MSG_WAR(0x396D, "sendPDO cobId :", pdo.cob_id); |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
572 |
MSG_WAR(0x396E, " Nb octets : ", pdo.len); |
235
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 |
canSend(d->canHandle,&pdo); |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
575 |
status = state11; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
576 |
break; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
577 |
case state11: /*Go to next TPDO*/ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
578 |
pdoNum++; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
579 |
offsetObjdict++; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
580 |
offsetObjdictMap++; |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
581 |
MSG_WAR(0x3970, "next pdo index : ", pdoNum); |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
582 |
status = state3; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
583 |
break; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
584 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
585 |
default: |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
586 |
MSG_ERR(0x1972,"Unknown state has been reached : %d",status); |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
587 |
return 0xFF; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
588 |
}/* end switch case */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
589 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
590 |
}/* end while */ |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
591 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
592 |
return 0; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
593 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
594 |
|
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
595 |
/*! |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
596 |
** |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
597 |
** |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
598 |
** @param d |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
599 |
** @param OD_entry |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
600 |
** @param bSubindex |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
601 |
** @return always 0 |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
602 |
**/ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
603 |
|
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
604 |
UNS32 TPDO_Communication_Parameter_Callback(CO_Data* d, const indextable * OD_entry, UNS8 bSubindex) |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
605 |
{ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
606 |
/* If PDO are actives */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
607 |
if(d->CurrentCommunicationState.csPDO) switch(bSubindex) |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
608 |
{ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
609 |
case 2: /* Changed transmition type */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
610 |
case 3: /* Changed inhibit time */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
611 |
case 5: /* Changed event time */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
612 |
{ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
613 |
const indextable* TPDO_com = d->objdict + d->firstIndex->PDO_TRS; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
614 |
UNS8 numPdo = OD_entry - TPDO_com; /* number of the actual processed pdo-nr. */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
615 |
|
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
616 |
/* Zap all timers and inhibit flag */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
617 |
d->PDO_status[numPdo].event_timer = DelAlarm(d->PDO_status[numPdo].event_timer); |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
618 |
d->PDO_status[numPdo].inhibit_timer = DelAlarm(d->PDO_status[numPdo].inhibit_timer); |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
619 |
d->PDO_status[numPdo].transmit_type_parameter = 0; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
620 |
/* Call PDOEventTimerAlarm for this TPDO, this will trigger emission et reset timers */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
621 |
PDOEventTimerAlarm(d, numPdo); |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
622 |
return 0; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
623 |
} |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
624 |
|
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
625 |
default: /* other subindex are ignored*/ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
626 |
break; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
627 |
} |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
628 |
return 0; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
629 |
} |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
630 |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
631 |
void PDOInit(CO_Data* d) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
632 |
{ |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
633 |
/* For each TPDO mapping parameters */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
634 |
UNS16 pdoIndex = 0x1800; /* OD index of TDPO */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
635 |
|
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
636 |
UNS16 offsetObjdict = d->firstIndex->PDO_TRS; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
637 |
UNS16 lastIndex = d->lastIndex->PDO_TRS; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
638 |
if(offsetObjdict) while( offsetObjdict <= lastIndex) { |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
639 |
/* Assign callbacks to sensible TPDO mapping subindexes */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
640 |
UNS32 errorCode; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
641 |
ODCallback_t *CallbackList; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
642 |
/* Find callback list */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
643 |
scanIndexOD (d, pdoIndex, &errorCode, &CallbackList); |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
644 |
if(errorCode == OD_SUCCESSFUL && CallbackList) |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
645 |
{ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
646 |
/*Assign callbacks to corresponding subindex*/ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
647 |
/* Transmission type */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
648 |
CallbackList[2] = &TPDO_Communication_Parameter_Callback; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
649 |
/* Inhibit time */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
650 |
CallbackList[3] = &TPDO_Communication_Parameter_Callback; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
651 |
/* Event timer */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
652 |
CallbackList[5] = &TPDO_Communication_Parameter_Callback; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
653 |
} |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
654 |
pdoIndex++; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
655 |
offsetObjdict++; |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
656 |
} |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
657 |
|
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
658 |
/* Trigger a non-sync event */ |
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
659 |
_sendPDOevent( d, 0 ); |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
660 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
661 |
|
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
662 |
void PDOStop(CO_Data* d) |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
663 |
{ |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
664 |
/* For each TPDO mapping parameters */ |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
665 |
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
|
666 |
UNS16 offsetObjdict = d->firstIndex->PDO_TRS; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
667 |
UNS16 lastIndex = d->lastIndex->PDO_TRS; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
668 |
if(offsetObjdict) while( offsetObjdict <= lastIndex) { |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
669 |
/* Delete TPDO timers */ |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
670 |
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
|
671 |
d->PDO_status[pdoNum].inhibit_timer = DelAlarm(d->PDO_status[pdoNum].inhibit_timer); |
236
905677ed00f3
Full preliminary implementation of TPDO transmit type:
etisserant
parents:
235
diff
changeset
|
672 |
/* Reset transmit type parameter */ |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
673 |
d->PDO_status[pdoNum].transmit_type_parameter = 0; |
365 | 674 |
d->PDO_status[pdoNum].last_message.cob_id = 0; |
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
675 |
pdoNum++; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
676 |
offsetObjdict++; |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
677 |
} |
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
217
diff
changeset
|
678 |
} |