2 This file is part of CanFestival, a library implementing CanOpen Stack.
\r
4 Copyright (C): Edouard TISSERANT and Francis DUPIN
\r
6 See COPYING file for copyrights details.
\r
8 This library is free software; you can redistribute it and/or
\r
9 modify it under the terms of the GNU Lesser General Public
\r
10 License as published by the Free Software Foundation; either
\r
11 version 2.1 of the License, or (at your option) any later version.
\r
13 This library is distributed in the hope that it will be useful,
\r
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
16 Lesser General Public License for more details.
\r
18 You should have received a copy of the GNU Lesser General Public
\r
19 License along with this library; if not, write to the Free Software
\r
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
25 ** @author Edouard TISSERANT and Francis DUPIN
\r
26 ** @date Tue Jun 5 09:32:32 2007
\r
35 #include "canfestival.h"
\r
37 /* Prototypes for internals functions */
\r
45 void SyncAlarm(CO_Data* d, UNS32 id);
\r
46 UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable,
\r
47 UNS8 unsused_bSubindex);
\r
55 void SyncAlarm(CO_Data* d, UNS32 id)
\r
57 sendSYNC(d, *d->COB_ID_Sync & 0x1FFFFFFF) ;
\r
61 ** This is called when Index 0x1005 is updated.
\r
64 ** @param unsused_indextable
\r
65 ** @param unsused_bSubindex
\r
69 UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
\r
80 void startSYNC(CO_Data* d)
\r
82 RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate);
\r
83 RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate);
\r
85 if(d->syncTimer != TIMER_NONE){
\r
89 if(*d->COB_ID_Sync & 0x40000000 && *d->Sync_Cycle_Period)
\r
91 d->syncTimer = SetAlarm(
\r
95 US_TO_TIMEVAL(*d->Sync_Cycle_Period),
\r
96 US_TO_TIMEVAL(*d->Sync_Cycle_Period));
\r
105 void stopSYNC(CO_Data* d)
\r
107 d->syncTimer = DelAlarm(d->syncTimer);
\r
118 UNS8 sendSYNC(CO_Data* d, UNS32 cob_id)
\r
123 MSG_WAR(0x3001, "sendSYNC ", 0);
\r
125 m.cob_id.w = cob_id ;
\r
126 m.rtr = NOT_A_REQUEST;
\r
128 resultat = canSend(d->canHandle,&m) ;
\r
129 proceedSYNC(d, &m) ;
\r
141 UNS8 proceedSYNC(CO_Data* d, Message *m)
\r
144 UNS8 pdoNum, /* number of the actual processed pdo-nr. */
\r
147 const UNS8 * pMappingCount = NULL; /* count of mapped objects...*/
\r
148 /** pointer to the var which is mapped to a pdo */
\r
149 /* void * pMappedAppObject = NULL; */
\r
150 /** pointer fo the var which holds the mapping parameter of an mapping entry */
\r
151 UNS32 * pMappingParameter = NULL;
\r
152 /** pointer to the transmissiontype...*/
\r
153 UNS8 * pTransmissionType = NULL;
\r
154 UNS32 * pwCobId = NULL;
\r
163 UNS16 offsetObjdict;
\r
164 UNS16 offsetObjdictMap;
\r
172 MSG_WAR(0x3002, "SYNC received. Proceed. ", 0);
\r
176 /** only operational state allows PDO transmission */
\r
177 if( d->nodeState != Operational )
\r
180 /** So, the node is in operational state */
\r
181 /** study all PDO stored in the objects dictionary */
\r
183 offsetObjdict = d->firstIndex->PDO_TRS;
\r
184 lastIndex = d->lastIndex->PDO_TRS;
\r
185 offsetObjdictMap = d->firstIndex->PDO_TRS_MAP;
\r
187 if(offsetObjdict) while( offsetObjdict <= lastIndex) {
\r
190 case state3: /** get the PDO transmission type */
\r
191 if (d->objdict[offsetObjdict].bSubCount <= 2) {
\r
192 MSG_ERR(0x1004, "Subindex 2 not found at index ", 0x1800 + pdoNum);
\r
195 pTransmissionType = d->objdict[offsetObjdict].pSubindex[2].pObject;
\r
196 MSG_WAR(0x3005, "Reading PDO at index : ", 0x1800 + pdoNum);
\r
199 case state4: /** check if transmission type is after (this) SYNC */
\r
200 /** The message may not be transmited every SYNC but every n SYNC */
\r
201 if( (*pTransmissionType >= TRANS_SYNC_MIN) && (*pTransmissionType <= TRANS_SYNC_MAX) &&
\r
202 (++d->count_sync[pdoNum] == *pTransmissionType) ) {
\r
203 d->count_sync[pdoNum] = 0;
\r
204 MSG_WAR(0x3007, " PDO is on SYNCHRO. Trans type : ", *pTransmissionType);
\r
209 MSG_WAR(0x3008, " Not on synchro or not at this SYNC. Trans type : ",
\r
210 *pTransmissionType);
\r
213 offsetObjdictMap++;
\r
217 case state5: /** get PDO CobId */
\r
218 pwCobId = d->objdict[offsetObjdict].pSubindex[1].pObject;
\r
219 MSG_WAR(0x3009, " PDO CobId is : ", *pwCobId);
\r
222 case state7: /** get mapped objects number to transmit with this PDO */
\r
223 pMappingCount = d->objdict[offsetObjdictMap].pSubindex[0].pObject;
\r
224 MSG_WAR(0x300D, " Number of objects mapped : ",*pMappingCount );
\r
226 case state8: /** get mapping parameters */
\r
227 pMappingParameter = d->objdict[offsetObjdictMap].pSubindex[prp_j + 1].pObject;
\r
228 MSG_WAR(0x300F, " got mapping parameter : ", *pMappingParameter);
\r
229 MSG_WAR(0x3050, " at index : ", 0x1A00 + pdoNum);
\r
230 MSG_WAR(0x3051, " sub-index : ", prp_j + 1);
\r
233 case state9: /** get data to transmit */
\r
236 UNS8 tmp[]= {0,0,0,0,0,0,0,0};
\r
237 index = (UNS16)((*pMappingParameter) >> 16);
\r
238 subIndex = (UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF);
\r
239 Size = (UNS8)(*pMappingParameter); /* Size in bits */
\r
240 ByteSize = 1 + ((Size - 1) >> 3); /*1->8 => 1 ; 9->16 => 2, ... */
\r
241 objDict = getODentry(d, index, subIndex, tmp, &ByteSize, &dataType, 0 );
\r
242 /** copy bit per bit in little endian*/
\r
243 CopyBits(Size, ((UNS8*)tmp), 0 , 0, (UNS8*)&d->process_var.data[offset>>3], offset%8, 0);
\r
245 if( objDict != OD_SUCCESSFUL ){
\r
246 MSG_ERR(0x1013, " Couldn't find mapped variable at index-subindex-size : ", (UNS16)(*pMappingParameter));
\r
251 d->process_var.count = 1 + ((offset - 1) >> 3);
\r
256 case state10: /** loop to get all the data to transmit */
\r
257 if( prp_j < *pMappingCount ){
\r
258 MSG_WAR(0x3014, " next variable mapped : ", prp_j);
\r
263 MSG_WAR(0x3015, " End scan mapped variable", 0);
\r
264 PDOmGR( d, *pwCobId );
\r
265 MSG_WAR(0x3016, " End of this pdo. Should have been sent", 0);
\r
268 offsetObjdictMap++;
\r
276 MSG_WAR(0x3017, "next pdo index : ", pdoNum);
\r
281 MSG_ERR(0x1019,"Unknown state has been reached : %d",status);
\r
283 }/* end switch case */
\r
285 }/* end while( prp_i<dict_cstes.max_count_of_PDO_transmit ) */
\r
293 void _post_sync(){}
\r
294 void _post_TPDO(){}
\r