Can_open_slavenode

Dependencies:   mbed

Committer:
sam_grove
Date:
Mon May 30 07:14:41 2011 +0000
Revision:
0:6219434a0cb5
Initial public release of slave node framework port

Who changed what in which revision?

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