sync.c

Go to the documentation of this file.
00001 /*
00002 This file is part of CanFestival, a library implementing CanOpen Stack. 
00003 
00004 Copyright (C): Edouard TISSERANT and Francis DUPIN
00005 
00006 See COPYING file for copyrights details.
00007 
00008 This library is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU Lesser General Public
00010 License as published by the Free Software Foundation; either
00011 version 2.1 of the License, or (at your option) any later version.
00012 
00013 This library is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 Lesser General Public License for more details.
00017 
00018 You should have received a copy of the GNU Lesser General Public
00019 License along with this library; if not, write to the Free Software
00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00033 #include "data.h"
00034 #include "sync.h"
00035 #include "canfestival.h"
00036 
00037 /* Prototypes for internals functions */
00038 
00045 void SyncAlarm(CO_Data* d, UNS32 id);
00046 UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, 
00047         UNS8 unsused_bSubindex);
00048 
00055 void SyncAlarm(CO_Data* d, UNS32 id)
00056 {
00057         sendSYNC(d, *d->COB_ID_Sync & 0x1FFFFFFF) ;
00058 }
00059 
00069 UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
00070 {
00071         startSYNC(d);
00072         return 0;
00073 }
00074 
00080 void startSYNC(CO_Data* d)
00081 {
00082         RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate);
00083         RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate);
00084 
00085         if(d->syncTimer != TIMER_NONE){
00086                 stopSYNC(d);
00087         }
00088         
00089         if(*d->COB_ID_Sync & 0x40000000 && *d->Sync_Cycle_Period)
00090         {
00091                 d->syncTimer = SetAlarm(
00092                                 d,
00093                                 0 /*No id needed*/,
00094                                 &SyncAlarm,
00095                                 US_TO_TIMEVAL(*d->Sync_Cycle_Period), 
00096                                 US_TO_TIMEVAL(*d->Sync_Cycle_Period));
00097         }
00098 }
00099 
00105 void stopSYNC(CO_Data* d)
00106 {
00107         d->syncTimer = DelAlarm(d->syncTimer);
00108 }
00109 
00118 UNS8 sendSYNC(CO_Data* d, UNS32 cob_id)
00119 {
00120   Message m;
00121   UNS8 resultat ;
00122   
00123   MSG_WAR(0x3001, "sendSYNC ", 0);
00124   
00125   m.cob_id.w = cob_id ;
00126   m.rtr = NOT_A_REQUEST;
00127   m.len = 0;
00128   resultat = canSend(d->canHandle,&m) ;
00129   proceedSYNC(d, &m) ; 
00130   return resultat ;
00131 }
00132 
00141 UNS8 proceedSYNC(CO_Data* d, Message *m)
00142 {
00143 
00144   UNS8 res;
00145   
00146   MSG_WAR(0x3002, "SYNC received. Proceed. ", 0);
00147   
00148   (*d->post_sync)();
00149 
00150   /* only operational state allows PDO transmission */
00151   if(! d->CurrentCommunicationState.csPDO) 
00152     return 0;
00153 
00154   res = _sendPDOevent(d, 1 /*isSyncEvent*/ );
00155   
00156   /*Call user app callback*/
00157   (*d->post_TPDO)();
00158   
00159   return res;
00160   
00161 }
00162 
00163 
00164 void _post_sync(){}
00165 void _post_TPDO(){}

Generated on Mon Jul 2 19:10:16 2007 for CanFestival by  doxygen 1.5.1