0
|
1 |
/*
|
|
2 |
This file is part of CanFestival, a library implementing CanOpen Stack.
|
|
3 |
|
|
4 |
Copyright (C): Edouard TISSERANT and Francis DUPIN
|
|
5 |
|
|
6 |
See COPYING file for copyrights details.
|
|
7 |
|
|
8 |
This library is free software; you can redistribute it and/or
|
|
9 |
modify it under the terms of the GNU Lesser General Public
|
|
10 |
License as published by the Free Software Foundation; either
|
|
11 |
version 2.1 of the License, or (at your option) any later version.
|
|
12 |
|
|
13 |
This library is distributed in the hope that it will be useful,
|
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16 |
Lesser General Public License for more details.
|
|
17 |
|
|
18 |
You should have received a copy of the GNU Lesser General Public
|
|
19 |
License along with this library; if not, write to the Free Software
|
|
20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 |
*/
|
|
22 |
|
|
23 |
#include "data.h"
|
|
24 |
#include "sync.h"
|
|
25 |
|
53
|
26 |
// Prototypes for internals functions
|
|
27 |
void SyncAlarm(CO_Data* d, UNS32 id);
|
|
28 |
UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable,
|
|
29 |
UNS8 unsused_bSubindex);
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
/*****************************************************************************/
|
0
|
34 |
void SyncAlarm(CO_Data* d, UNS32 id)
|
|
35 |
{
|
|
36 |
sendSYNC(d, *d->COB_ID_Sync & 0x1FFFFFFF) ;
|
|
37 |
}
|
|
38 |
|
53
|
39 |
/*****************************************************************************/
|
0
|
40 |
// This is called when Index 0x1005 is updated.
|
|
41 |
UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
|
|
42 |
{
|
|
43 |
startSYNC(d);
|
31
|
44 |
return 0;
|
0
|
45 |
}
|
|
46 |
|
53
|
47 |
/*****************************************************************************/
|
0
|
48 |
void startSYNC(CO_Data* d)
|
|
49 |
{
|
|
50 |
RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate);
|
|
51 |
RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate);
|
|
52 |
|
|
53 |
if(d->syncTimer != TIMER_NONE){
|
|
54 |
stopSYNC(d);
|
|
55 |
}
|
|
56 |
|
|
57 |
if(*d->COB_ID_Sync & 0x40000000 && *d->Sync_Cycle_Period)
|
|
58 |
{
|
|
59 |
d->syncTimer = SetAlarm(
|
|
60 |
d,
|
|
61 |
0/*No id needed*/,
|
|
62 |
&SyncAlarm,
|
|
63 |
US_TO_TIMEVAL(*d->Sync_Cycle_Period),
|
|
64 |
US_TO_TIMEVAL(*d->Sync_Cycle_Period));
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
53
|
68 |
/*****************************************************************************/
|
0
|
69 |
void stopSYNC(CO_Data* d)
|
|
70 |
{
|
|
71 |
d->syncTimer = DelAlarm(d->syncTimer);
|
|
72 |
}
|
|
73 |
|
|
74 |
/*********************************************************************/
|
|
75 |
UNS8 sendSYNC(CO_Data* d, UNS32 cob_id)
|
|
76 |
{
|
|
77 |
Message m;
|
|
78 |
UNS8 resultat ;
|
|
79 |
|
|
80 |
MSG_WAR(0x3001, "sendSYNC ", 0);
|
|
81 |
|
|
82 |
m.cob_id.w = cob_id ;
|
|
83 |
m.rtr = NOT_A_REQUEST;
|
|
84 |
m.len = 0;
|
|
85 |
resultat = (*d->canSend)(&m) ;
|
|
86 |
proceedSYNC(d, &m) ;
|
|
87 |
return resultat ;
|
|
88 |
}
|
|
89 |
|
|
90 |
/*****************************************************************************/
|
|
91 |
UNS8 proceedSYNC(CO_Data* d, Message *m)
|
|
92 |
{
|
|
93 |
|
|
94 |
MSG_WAR(0x3002, "SYNC received. Proceed. ", 0);
|
|
95 |
|
|
96 |
UNS8 pdoNum, // number of the actual processed pdo-nr.
|
|
97 |
prp_j;
|
|
98 |
|
|
99 |
const UNS8 * pMappingCount = NULL; // count of mapped objects...
|
|
100 |
// pointer to the var which is mapped to a pdo
|
|
101 |
// void * pMappedAppObject = NULL;
|
|
102 |
// pointer fo the var which holds the mapping parameter of an mapping entry
|
|
103 |
UNS32 * pMappingParameter = NULL;
|
|
104 |
// pointer to the transmissiontype...
|
|
105 |
UNS8 * pTransmissionType = NULL;
|
|
106 |
UNS32 * pwCobId = NULL;
|
|
107 |
|
|
108 |
UNS8 * pSize;
|
|
109 |
UNS8 size;
|
|
110 |
UNS8 dataType;
|
|
111 |
UNS16 index;
|
|
112 |
UNS8 subIndex;
|
|
113 |
UNS8 offset;
|
|
114 |
UNS8 status;
|
|
115 |
UNS8 sizeData;
|
|
116 |
pSize = &size;
|
|
117 |
UNS32 objDict;
|
|
118 |
status = state3;
|
|
119 |
pdoNum=0x00;
|
|
120 |
prp_j=0x00;
|
|
121 |
offset = 0x00;
|
|
122 |
UNS16 offsetObjdict;
|
|
123 |
UNS16 offsetObjdictMap;
|
|
124 |
UNS16 lastIndex;
|
|
125 |
|
|
126 |
/* only operational state allows PDO transmission */
|
|
127 |
if( d->nodeState != Operational )
|
|
128 |
return 0;
|
|
129 |
|
|
130 |
(*d->post_sync)();
|
|
131 |
|
|
132 |
/* So, the node is in operational state */
|
|
133 |
/* study all PDO stored in the objects dictionary */
|
|
134 |
|
|
135 |
offsetObjdict = d->firstIndex->PDO_TRS;
|
|
136 |
lastIndex = d->lastIndex->PDO_TRS;
|
|
137 |
offsetObjdictMap = d->firstIndex->PDO_TRS_MAP;
|
|
138 |
|
|
139 |
if(offsetObjdict) while( offsetObjdict <= lastIndex) {
|
|
140 |
switch( status ) {
|
|
141 |
|
|
142 |
case state3: /* get the PDO transmission type */
|
|
143 |
if (d->objdict[offsetObjdict].bSubCount <= 2) {
|
|
144 |
MSG_ERR(0x1004, "Subindex 2 not found at index ", 0x1800 + pdoNum);
|
|
145 |
return 0xFF;
|
|
146 |
}
|
|
147 |
pTransmissionType = d->objdict[offsetObjdict].pSubindex[2].pObject;
|
|
148 |
MSG_WAR(0x3005, "Reading PDO at index : ", 0x1800 + pdoNum);
|
|
149 |
status = state4;
|
|
150 |
break;
|
|
151 |
case state4: /* check if transmission type is after (this) SYNC */
|
|
152 |
/* The message may not be transmited every SYNC but every n SYNC */
|
|
153 |
if( (*pTransmissionType >= TRANS_SYNC_MIN) && (*pTransmissionType <= TRANS_SYNC_MAX) &&
|
|
154 |
(++d->count_sync[pdoNum] == *pTransmissionType) ) {
|
|
155 |
d->count_sync[pdoNum] = 0;
|
|
156 |
MSG_WAR(0x3007, " PDO is on SYNCHRO. Trans type : ", *pTransmissionType);
|
|
157 |
status = state5;
|
|
158 |
break;
|
|
159 |
}
|
|
160 |
else {
|
|
161 |
MSG_WAR(0x3008, " Not on synchro or not at this SYNC. Trans type : ",
|
|
162 |
*pTransmissionType);
|
|
163 |
pdoNum++;
|
|
164 |
offsetObjdict++;
|
|
165 |
offsetObjdictMap++;
|
|
166 |
status = state11;
|
|
167 |
break;
|
|
168 |
}
|
|
169 |
case state5: /* get PDO CobId */
|
|
170 |
pwCobId = d->objdict[offsetObjdict].pSubindex[1].pObject;
|
|
171 |
MSG_WAR(0x3009, " PDO CobId is : ", *pwCobId);
|
|
172 |
status = state7;
|
|
173 |
break;
|
|
174 |
case state7: /* get mapped objects number to transmit with this PDO */
|
|
175 |
pMappingCount = d->objdict[offsetObjdictMap].pSubindex[0].pObject;
|
|
176 |
MSG_WAR(0x300D, " Number of objects mapped : ",*pMappingCount );
|
|
177 |
status = state8;
|
|
178 |
case state8: /* get mapping parameters */
|
|
179 |
pMappingParameter = d->objdict[offsetObjdictMap].pSubindex[prp_j + 1].pObject;
|
|
180 |
MSG_WAR(0x300F, " got mapping parameter : ", *pMappingParameter);
|
|
181 |
MSG_WAR(0x3050, " at index : ", 0x1A00 + pdoNum);
|
|
182 |
MSG_WAR(0x3051, " sub-index : ", prp_j + 1);
|
|
183 |
status = state9;
|
|
184 |
|
|
185 |
case state9: /* get data to transmit */
|
|
186 |
index = (UNS16)((*pMappingParameter) >> 16);
|
|
187 |
subIndex = (UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF);
|
|
188 |
// <<3 because in *pMappingParameter the size is in bits
|
|
189 |
sizeData = (UNS8) ((*pMappingParameter & (UNS32)0x000000FF) >> 3) ;
|
|
190 |
|
|
191 |
objDict = getODentry(d, index, subIndex, (void *)&d->process_var.data[offset], &sizeData, &dataType, 0 );
|
|
192 |
|
|
193 |
if( objDict != OD_SUCCESSFUL ){
|
|
194 |
MSG_ERR(0x1013, " Couldn't find mapped variable at index-subindex-size : ", (UNS16)(*pMappingParameter));
|
|
195 |
return 0xFF;
|
|
196 |
}
|
|
197 |
|
|
198 |
offset += sizeData ;
|
|
199 |
d->process_var.count = offset;
|
|
200 |
prp_j++;
|
|
201 |
status = state10;
|
|
202 |
break;
|
|
203 |
|
|
204 |
case state10: /* loop to get all the data to transmit */
|
|
205 |
if( prp_j < *pMappingCount ){
|
|
206 |
MSG_WAR(0x3014, " next variable mapped : ", prp_j);
|
|
207 |
status = state8;
|
|
208 |
break;
|
|
209 |
}
|
|
210 |
else {
|
|
211 |
MSG_WAR(0x3015, " End scan mapped variable", 0);
|
|
212 |
PDOmGR( d, *pwCobId );
|
|
213 |
MSG_WAR(0x3016, " End of this pdo. Should have been sent", 0);
|
|
214 |
pdoNum++;
|
|
215 |
offsetObjdict++;
|
|
216 |
offsetObjdictMap++;
|
|
217 |
offset = 0x00;
|
|
218 |
prp_j = 0x00;
|
|
219 |
status = state11;
|
|
220 |
break;
|
|
221 |
}
|
|
222 |
|
|
223 |
case state11:
|
|
224 |
MSG_WAR(0x3017, "next pdo index : ", pdoNum);
|
|
225 |
status = state3;
|
|
226 |
break;
|
|
227 |
|
|
228 |
default:
|
|
229 |
MSG_ERR(0x1019,"Unknown state has been reached : %d",status);
|
|
230 |
return 0xFF;
|
|
231 |
}// end switch case
|
|
232 |
|
|
233 |
}// end while( prp_i<dict_cstes.max_count_of_PDO_transmit )
|
|
234 |
|
|
235 |
(*d->post_TPDO)();
|
|
236 |
|
|
237 |
return 0;
|
|
238 |
}
|
|
239 |
|
|
240 |
|