nico@207: nico@207: nico@215: CanFestival: src/sync.c Source File nico@207: nico@207: nico@207: nico@207: nico@207:
nico@207:
nico@207:
nico@207:
nico@215: nico@215:

sync.c

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

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