2 This file is part of CanFestival, a library implementing CanOpen Stack.
5 Copyright (C): Edouard TISSERANT and Francis DUPIN
8 See COPYING file for copyrights details.
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 ** @author Edouard TISSERANT and Francis DUPIN
32 ** @date Tue Jun 5 09:32:32 2007
41 #include "canfestival.h"
44 /* Prototypes for internals functions */
52 void SyncAlarm(CO_Data* d, UNS32 id);
53 UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable,
54 UNS8 unsused_bSubindex);
62 void SyncAlarm(CO_Data* d, UNS32 id)
68 ** This is called when Index 0x1005 is updated.
71 ** @param unsused_indextable
72 ** @param unsused_bSubindex
76 UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
87 void startSYNC(CO_Data* d)
89 if(d->syncTimer != TIMER_NONE){
93 RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate);
94 RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate);
96 if(*d->COB_ID_Sync & 0x40000000ul && *d->Sync_Cycle_Period)
98 d->syncTimer = SetAlarm(
102 US_TO_TIMEVAL(*d->Sync_Cycle_Period),
103 US_TO_TIMEVAL(*d->Sync_Cycle_Period));
112 void stopSYNC(CO_Data* d)
114 RegisterSetODentryCallBack(d, 0x1005, 0, NULL);
115 RegisterSetODentryCallBack(d, 0x1006, 0, NULL);
116 d->syncTimer = DelAlarm(d->syncTimer);
128 UNS8 sendSYNCMessage(CO_Data* d)
132 MSG_WAR(0x3001, "sendSYNC ", 0);
134 m.cob_id = UNS16_LE(*d->COB_ID_Sync);
135 m.rtr = NOT_A_REQUEST;
138 return canSend(d->canHandle,&m);
150 UNS8 sendSYNC(CO_Data* d)
153 res = sendSYNCMessage(d);
166 UNS8 proceedSYNC(CO_Data* d)
171 MSG_WAR(0x3002, "SYNC received. Proceed. ", 0);
175 /* only operational state allows PDO transmission */
176 if(! d->CurrentCommunicationState.csPDO)
179 res = _sendPDOevent(d, 1 /*isSyncEvent*/ );
181 /*Call user app callback*/
189 void _post_sync(CO_Data* d){}
190 void _post_TPDO(CO_Data* d){}