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