Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
sync.c
00001 /* 00002 This file is part of CanFestival, a library implementing CanOpen Stack. 00003 00004 00005 Copyright (C): Edouard TISSERANT and Francis DUPIN 00006 00007 00008 See COPYING file for copyrights details. 00009 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Lesser General Public 00013 License as published by the Free Software Foundation; either 00014 version 2.1 of the License, or (at your option) any later version. 00015 00016 00017 This library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 Lesser General Public License for more details. 00021 00022 00023 You should have received a copy of the GNU Lesser General Public 00024 License along with this library; if not, write to the Free Software 00025 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00026 */ 00027 00028 00029 /*! 00030 ** @file sync.c 00031 ** @author Edouard TISSERANT and Francis DUPIN 00032 ** @date Tue Jun 5 09:32:32 2007 00033 ** 00034 ** @brief 00035 ** 00036 ** 00037 */ 00038 00039 #include "data.h" 00040 #include "sync.h" 00041 #include "canfestival.h" 00042 #include "sysdep.h" 00043 00044 /* Prototypes for internals functions */ 00045 00046 /*! 00047 ** 00048 ** 00049 ** @param d 00050 ** @param id 00051 **/ 00052 void SyncAlarm (CO_Data* d, UNS32 id); 00053 UNS32 OnCOB_ID_SyncUpdate (CO_Data* d, const indextable * unsused_indextable, 00054 UNS8 unsused_bSubindex); 00055 00056 /*! 00057 ** 00058 ** 00059 ** @param d 00060 ** @param id 00061 **/ 00062 void SyncAlarm (CO_Data* d, UNS32 id) 00063 { 00064 sendSYNC(d) ; 00065 } 00066 00067 /*! 00068 ** This is called when Index 0x1005 is updated. 00069 ** 00070 ** @param d 00071 ** @param unsused_indextable 00072 ** @param unsused_bSubindex 00073 ** 00074 ** @return 00075 **/ 00076 UNS32 OnCOB_ID_SyncUpdate (CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex) 00077 { 00078 startSYNC (d); 00079 return 0; 00080 } 00081 00082 /*! 00083 ** 00084 ** 00085 ** @param d 00086 **/ 00087 void startSYNC (CO_Data* d) 00088 { 00089 if(d->syncTimer != TIMER_NONE){ 00090 stopSYNC (d); 00091 } 00092 00093 RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate ); 00094 RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate ); 00095 00096 if(*d->COB_ID_Sync & 0x40000000ul && *d->Sync_Cycle_Period) 00097 { 00098 d->syncTimer = SetAlarm( 00099 d, 00100 0 /*No id needed*/, 00101 &SyncAlarm , 00102 US_TO_TIMEVAL(*d->Sync_Cycle_Period), 00103 US_TO_TIMEVAL(*d->Sync_Cycle_Period)); 00104 } 00105 } 00106 00107 /*! 00108 ** 00109 ** 00110 ** @param d 00111 **/ 00112 void stopSYNC (CO_Data* d) 00113 { 00114 RegisterSetODentryCallBack(d, 0x1005, 0, NULL); 00115 RegisterSetODentryCallBack(d, 0x1006, 0, NULL); 00116 d->syncTimer = DelAlarm(d->syncTimer); 00117 } 00118 00119 00120 /*! 00121 ** 00122 ** 00123 ** @param d 00124 ** @param cob_id 00125 ** 00126 ** @return 00127 **/ 00128 UNS8 sendSYNCMessage(CO_Data* d) 00129 { 00130 Message m; 00131 00132 MSG_WAR(0x3001, "sendSYNC ", 0); 00133 00134 m.cob_id = (UNS16)UNS16_LE(*d->COB_ID_Sync); 00135 m.rtr = NOT_A_REQUEST; 00136 m.len = 0; 00137 00138 return canSend(d->canHandle,&m); 00139 } 00140 00141 00142 /*! 00143 ** 00144 ** 00145 ** @param d 00146 ** @param cob_id 00147 ** 00148 ** @return 00149 **/ 00150 UNS8 sendSYNC(CO_Data* d) 00151 { 00152 UNS8 res; 00153 res = sendSYNCMessage(d); 00154 proceedSYNC(d) ; 00155 return res ; 00156 } 00157 00158 /*! 00159 ** 00160 ** 00161 ** @param d 00162 ** @param m 00163 ** 00164 ** @return 00165 **/ 00166 UNS8 proceedSYNC(CO_Data* d) 00167 { 00168 00169 UNS8 res; 00170 00171 MSG_WAR(0x3002, "SYNC received. Proceed. ", 0); 00172 00173 (*d->post_sync)(d); 00174 00175 /* only operational state allows PDO transmission */ 00176 if(! d->CurrentCommunicationState.csPDO) 00177 return 0; 00178 00179 res = _sendPDOevent(d, 1 /*isSyncEvent*/ ); 00180 00181 /*Call user app callback*/ 00182 (*d->post_TPDO)(d); 00183 00184 return res; 00185 00186 } 00187 00188 00189 void _post_sync(CO_Data* d){} 00190 void _post_TPDO(CO_Data* d){}
Generated on Tue Jul 12 2022 17:11:51 by
1.7.2