![](/media/cache/profiles/IMG_2753.JPG.50x50_q85.jpg)
Can_open_masternode
framework/src/sync.c@7:537bae5a6fc6, 2012-09-26 (annotated)
- Committer:
- sam_grove
- Date:
- Wed Sep 26 05:48:14 2012 +0000
- Revision:
- 7:537bae5a6fc6
- Parent:
- 0:9dd7c6129683
Pushing the project into the new repo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove |
0:9dd7c6129683 | 1 | /* |
sam_grove |
0:9dd7c6129683 | 2 | This file is part of CanFestival, a library implementing CanOpen Stack. |
sam_grove |
0:9dd7c6129683 | 3 | |
sam_grove |
0:9dd7c6129683 | 4 | |
sam_grove |
0:9dd7c6129683 | 5 | Copyright (C): Edouard TISSERANT and Francis DUPIN |
sam_grove |
0:9dd7c6129683 | 6 | |
sam_grove |
0:9dd7c6129683 | 7 | |
sam_grove |
0:9dd7c6129683 | 8 | See COPYING file for copyrights details. |
sam_grove |
0:9dd7c6129683 | 9 | |
sam_grove |
0:9dd7c6129683 | 10 | |
sam_grove |
0:9dd7c6129683 | 11 | This library is free software; you can redistribute it and/or |
sam_grove |
0:9dd7c6129683 | 12 | modify it under the terms of the GNU Lesser General Public |
sam_grove |
0:9dd7c6129683 | 13 | License as published by the Free Software Foundation; either |
sam_grove |
0:9dd7c6129683 | 14 | version 2.1 of the License, or (at your option) any later version. |
sam_grove |
0:9dd7c6129683 | 15 | |
sam_grove |
0:9dd7c6129683 | 16 | |
sam_grove |
0:9dd7c6129683 | 17 | This library is distributed in the hope that it will be useful, |
sam_grove |
0:9dd7c6129683 | 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
sam_grove |
0:9dd7c6129683 | 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
sam_grove |
0:9dd7c6129683 | 20 | Lesser General Public License for more details. |
sam_grove |
0:9dd7c6129683 | 21 | |
sam_grove |
0:9dd7c6129683 | 22 | |
sam_grove |
0:9dd7c6129683 | 23 | You should have received a copy of the GNU Lesser General Public |
sam_grove |
0:9dd7c6129683 | 24 | License along with this library; if not, write to the Free Software |
sam_grove |
0:9dd7c6129683 | 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
sam_grove |
0:9dd7c6129683 | 26 | */ |
sam_grove |
0:9dd7c6129683 | 27 | |
sam_grove |
0:9dd7c6129683 | 28 | |
sam_grove |
0:9dd7c6129683 | 29 | /*! |
sam_grove |
0:9dd7c6129683 | 30 | ** @file sync.c |
sam_grove |
0:9dd7c6129683 | 31 | ** @author Edouard TISSERANT and Francis DUPIN |
sam_grove |
0:9dd7c6129683 | 32 | ** @date Tue Jun 5 09:32:32 2007 |
sam_grove |
0:9dd7c6129683 | 33 | ** |
sam_grove |
0:9dd7c6129683 | 34 | ** @brief |
sam_grove |
0:9dd7c6129683 | 35 | ** |
sam_grove |
0:9dd7c6129683 | 36 | ** |
sam_grove |
0:9dd7c6129683 | 37 | */ |
sam_grove |
0:9dd7c6129683 | 38 | |
sam_grove |
0:9dd7c6129683 | 39 | #include "data.h" |
sam_grove |
0:9dd7c6129683 | 40 | #include "sync.h" |
sam_grove |
0:9dd7c6129683 | 41 | #include "canfestival.h" |
sam_grove |
0:9dd7c6129683 | 42 | #include "sysdep.h" |
sam_grove |
0:9dd7c6129683 | 43 | |
sam_grove |
0:9dd7c6129683 | 44 | /* Prototypes for internals functions */ |
sam_grove |
0:9dd7c6129683 | 45 | |
sam_grove |
0:9dd7c6129683 | 46 | /*! |
sam_grove |
0:9dd7c6129683 | 47 | ** |
sam_grove |
0:9dd7c6129683 | 48 | ** |
sam_grove |
0:9dd7c6129683 | 49 | ** @param d |
sam_grove |
0:9dd7c6129683 | 50 | ** @param id |
sam_grove |
0:9dd7c6129683 | 51 | **/ |
sam_grove |
0:9dd7c6129683 | 52 | void SyncAlarm(CO_Data* d, UNS32 id); |
sam_grove |
0:9dd7c6129683 | 53 | UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, |
sam_grove |
0:9dd7c6129683 | 54 | UNS8 unsused_bSubindex); |
sam_grove |
0:9dd7c6129683 | 55 | |
sam_grove |
0:9dd7c6129683 | 56 | /*! |
sam_grove |
0:9dd7c6129683 | 57 | ** |
sam_grove |
0:9dd7c6129683 | 58 | ** |
sam_grove |
0:9dd7c6129683 | 59 | ** @param d |
sam_grove |
0:9dd7c6129683 | 60 | ** @param id |
sam_grove |
0:9dd7c6129683 | 61 | **/ |
sam_grove |
0:9dd7c6129683 | 62 | void SyncAlarm(CO_Data* d, UNS32 id) |
sam_grove |
0:9dd7c6129683 | 63 | { |
sam_grove |
0:9dd7c6129683 | 64 | sendSYNC(d) ; |
sam_grove |
0:9dd7c6129683 | 65 | } |
sam_grove |
0:9dd7c6129683 | 66 | |
sam_grove |
0:9dd7c6129683 | 67 | /*! |
sam_grove |
0:9dd7c6129683 | 68 | ** This is called when Index 0x1005 is updated. |
sam_grove |
0:9dd7c6129683 | 69 | ** |
sam_grove |
0:9dd7c6129683 | 70 | ** @param d |
sam_grove |
0:9dd7c6129683 | 71 | ** @param unsused_indextable |
sam_grove |
0:9dd7c6129683 | 72 | ** @param unsused_bSubindex |
sam_grove |
0:9dd7c6129683 | 73 | ** |
sam_grove |
0:9dd7c6129683 | 74 | ** @return |
sam_grove |
0:9dd7c6129683 | 75 | **/ |
sam_grove |
0:9dd7c6129683 | 76 | UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex) |
sam_grove |
0:9dd7c6129683 | 77 | { |
sam_grove |
0:9dd7c6129683 | 78 | startSYNC(d); |
sam_grove |
0:9dd7c6129683 | 79 | return 0; |
sam_grove |
0:9dd7c6129683 | 80 | } |
sam_grove |
0:9dd7c6129683 | 81 | |
sam_grove |
0:9dd7c6129683 | 82 | /*! |
sam_grove |
0:9dd7c6129683 | 83 | ** |
sam_grove |
0:9dd7c6129683 | 84 | ** |
sam_grove |
0:9dd7c6129683 | 85 | ** @param d |
sam_grove |
0:9dd7c6129683 | 86 | **/ |
sam_grove |
0:9dd7c6129683 | 87 | void startSYNC(CO_Data* d) |
sam_grove |
0:9dd7c6129683 | 88 | { |
sam_grove |
0:9dd7c6129683 | 89 | if(d->syncTimer != TIMER_NONE){ |
sam_grove |
0:9dd7c6129683 | 90 | stopSYNC(d); |
sam_grove |
0:9dd7c6129683 | 91 | } |
sam_grove |
0:9dd7c6129683 | 92 | |
sam_grove |
0:9dd7c6129683 | 93 | RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate); |
sam_grove |
0:9dd7c6129683 | 94 | RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate); |
sam_grove |
0:9dd7c6129683 | 95 | |
sam_grove |
0:9dd7c6129683 | 96 | if(*d->COB_ID_Sync & 0x40000000ul && *d->Sync_Cycle_Period) |
sam_grove |
0:9dd7c6129683 | 97 | { |
sam_grove |
0:9dd7c6129683 | 98 | d->syncTimer = SetAlarm( |
sam_grove |
0:9dd7c6129683 | 99 | d, |
sam_grove |
0:9dd7c6129683 | 100 | 0 /*No id needed*/, |
sam_grove |
0:9dd7c6129683 | 101 | &SyncAlarm, |
sam_grove |
0:9dd7c6129683 | 102 | US_TO_TIMEVAL(*d->Sync_Cycle_Period), |
sam_grove |
0:9dd7c6129683 | 103 | US_TO_TIMEVAL(*d->Sync_Cycle_Period)); |
sam_grove |
0:9dd7c6129683 | 104 | } |
sam_grove |
0:9dd7c6129683 | 105 | } |
sam_grove |
0:9dd7c6129683 | 106 | |
sam_grove |
0:9dd7c6129683 | 107 | /*! |
sam_grove |
0:9dd7c6129683 | 108 | ** |
sam_grove |
0:9dd7c6129683 | 109 | ** |
sam_grove |
0:9dd7c6129683 | 110 | ** @param d |
sam_grove |
0:9dd7c6129683 | 111 | **/ |
sam_grove |
0:9dd7c6129683 | 112 | void stopSYNC(CO_Data* d) |
sam_grove |
0:9dd7c6129683 | 113 | { |
sam_grove |
0:9dd7c6129683 | 114 | RegisterSetODentryCallBack(d, 0x1005, 0, NULL); |
sam_grove |
0:9dd7c6129683 | 115 | RegisterSetODentryCallBack(d, 0x1006, 0, NULL); |
sam_grove |
0:9dd7c6129683 | 116 | d->syncTimer = DelAlarm(d->syncTimer); |
sam_grove |
0:9dd7c6129683 | 117 | } |
sam_grove |
0:9dd7c6129683 | 118 | |
sam_grove |
0:9dd7c6129683 | 119 | |
sam_grove |
0:9dd7c6129683 | 120 | /*! |
sam_grove |
0:9dd7c6129683 | 121 | ** |
sam_grove |
0:9dd7c6129683 | 122 | ** |
sam_grove |
0:9dd7c6129683 | 123 | ** @param d |
sam_grove |
0:9dd7c6129683 | 124 | ** @param cob_id |
sam_grove |
0:9dd7c6129683 | 125 | ** |
sam_grove |
0:9dd7c6129683 | 126 | ** @return |
sam_grove |
0:9dd7c6129683 | 127 | **/ |
sam_grove |
0:9dd7c6129683 | 128 | UNS8 sendSYNCMessage(CO_Data* d) |
sam_grove |
0:9dd7c6129683 | 129 | { |
sam_grove |
0:9dd7c6129683 | 130 | Message m; |
sam_grove |
0:9dd7c6129683 | 131 | |
sam_grove |
0:9dd7c6129683 | 132 | MSG_WAR(0x3001, "sendSYNC ", 0); |
sam_grove |
0:9dd7c6129683 | 133 | |
sam_grove |
0:9dd7c6129683 | 134 | m.cob_id = (UNS16)UNS16_LE(*d->COB_ID_Sync); |
sam_grove |
0:9dd7c6129683 | 135 | m.rtr = NOT_A_REQUEST; |
sam_grove |
0:9dd7c6129683 | 136 | m.len = 0; |
sam_grove |
0:9dd7c6129683 | 137 | |
sam_grove |
0:9dd7c6129683 | 138 | return canSend(d->canHandle,&m); |
sam_grove |
0:9dd7c6129683 | 139 | } |
sam_grove |
0:9dd7c6129683 | 140 | |
sam_grove |
0:9dd7c6129683 | 141 | |
sam_grove |
0:9dd7c6129683 | 142 | /*! |
sam_grove |
0:9dd7c6129683 | 143 | ** |
sam_grove |
0:9dd7c6129683 | 144 | ** |
sam_grove |
0:9dd7c6129683 | 145 | ** @param d |
sam_grove |
0:9dd7c6129683 | 146 | ** @param cob_id |
sam_grove |
0:9dd7c6129683 | 147 | ** |
sam_grove |
0:9dd7c6129683 | 148 | ** @return |
sam_grove |
0:9dd7c6129683 | 149 | **/ |
sam_grove |
0:9dd7c6129683 | 150 | UNS8 sendSYNC(CO_Data* d) |
sam_grove |
0:9dd7c6129683 | 151 | { |
sam_grove |
0:9dd7c6129683 | 152 | UNS8 res; |
sam_grove |
0:9dd7c6129683 | 153 | res = sendSYNCMessage(d); |
sam_grove |
0:9dd7c6129683 | 154 | proceedSYNC(d) ; |
sam_grove |
0:9dd7c6129683 | 155 | return res ; |
sam_grove |
0:9dd7c6129683 | 156 | } |
sam_grove |
0:9dd7c6129683 | 157 | |
sam_grove |
0:9dd7c6129683 | 158 | /*! |
sam_grove |
0:9dd7c6129683 | 159 | ** |
sam_grove |
0:9dd7c6129683 | 160 | ** |
sam_grove |
0:9dd7c6129683 | 161 | ** @param d |
sam_grove |
0:9dd7c6129683 | 162 | ** @param m |
sam_grove |
0:9dd7c6129683 | 163 | ** |
sam_grove |
0:9dd7c6129683 | 164 | ** @return |
sam_grove |
0:9dd7c6129683 | 165 | **/ |
sam_grove |
0:9dd7c6129683 | 166 | UNS8 proceedSYNC(CO_Data* d) |
sam_grove |
0:9dd7c6129683 | 167 | { |
sam_grove |
0:9dd7c6129683 | 168 | |
sam_grove |
0:9dd7c6129683 | 169 | UNS8 res; |
sam_grove |
0:9dd7c6129683 | 170 | |
sam_grove |
0:9dd7c6129683 | 171 | MSG_WAR(0x3002, "SYNC received. Proceed. ", 0); |
sam_grove |
0:9dd7c6129683 | 172 | |
sam_grove |
0:9dd7c6129683 | 173 | (*d->post_sync)(d); |
sam_grove |
0:9dd7c6129683 | 174 | |
sam_grove |
0:9dd7c6129683 | 175 | /* only operational state allows PDO transmission */ |
sam_grove |
0:9dd7c6129683 | 176 | if(! d->CurrentCommunicationState.csPDO) |
sam_grove |
0:9dd7c6129683 | 177 | return 0; |
sam_grove |
0:9dd7c6129683 | 178 | |
sam_grove |
0:9dd7c6129683 | 179 | res = _sendPDOevent(d, 1 /*isSyncEvent*/ ); |
sam_grove |
0:9dd7c6129683 | 180 | |
sam_grove |
0:9dd7c6129683 | 181 | /*Call user app callback*/ |
sam_grove |
0:9dd7c6129683 | 182 | (*d->post_TPDO)(d); |
sam_grove |
0:9dd7c6129683 | 183 | |
sam_grove |
0:9dd7c6129683 | 184 | return res; |
sam_grove |
0:9dd7c6129683 | 185 | |
sam_grove |
0:9dd7c6129683 | 186 | } |
sam_grove |
0:9dd7c6129683 | 187 | |
sam_grove |
0:9dd7c6129683 | 188 | |
sam_grove |
0:9dd7c6129683 | 189 | void _post_sync(CO_Data* d){} |
sam_grove |
0:9dd7c6129683 | 190 | void _post_TPDO(CO_Data* d){} |