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"
43 /* Prototypes for internals functions */
51 void SyncAlarm(CO_Data* d, UNS32 id);
52 UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable,
53 UNS8 unsused_bSubindex);
61 void SyncAlarm(CO_Data* d, UNS32 id)
67 ** This is called when Index 0x1005 is updated.
70 ** @param unsused_indextable
71 ** @param unsused_bSubindex
75 UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
86 void startSYNC(CO_Data* d)
88 RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate);
89 RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate);
91 if(d->syncTimer != TIMER_NONE){
95 if(*d->COB_ID_Sync & 0x40000000 && *d->Sync_Cycle_Period)
97 d->syncTimer = SetAlarm(
101 US_TO_TIMEVAL(*d->Sync_Cycle_Period),
102 US_TO_TIMEVAL(*d->Sync_Cycle_Period));
111 void stopSYNC(CO_Data* d)
113 RegisterSetODentryCallBack(d, 0x1005, 0, NULL);
114 RegisterSetODentryCallBack(d, 0x1006, 0, NULL);
115 d->syncTimer = DelAlarm(d->syncTimer);
127 UNS8 sendSYNCMessage(CO_Data* d)
131 MSG_WAR(0x3001, "sendSYNC ", 0);
133 m.cob_id.w = *d->COB_ID_Sync & 0x1FFFFFFF;
134 m.rtr = NOT_A_REQUEST;
137 return canSend(d->canHandle,&m);
149 UNS8 sendSYNC(CO_Data* d)
152 res = sendSYNCMessage(d);
165 UNS8 proceedSYNC(CO_Data* d)
170 MSG_WAR(0x3002, "SYNC received. Proceed. ", 0);
174 /* only operational state allows PDO transmission */
175 if(! d->CurrentCommunicationState.csPDO)
178 res = _sendPDOevent(d, 1 /*isSyncEvent*/ );
180 /*Call user app callback*/