author | greg |
Wed, 15 Jul 2009 09:36:36 +0200 | |
changeset 556 | 8296acd119a9 |
parent 447 | c9d01296d6d9 |
child 587 | c175351a6994 |
permissions | -rw-r--r-- |
252 | 1 |
/* |
2 |
This file is part of CanFestival, a library implementing CanOpen Stack. |
|
3 |
||
4 |
||
5 |
Copyright (C): Edouard TISSERANT and Francis DUPIN |
|
6 |
||
7 |
||
8 |
See COPYING file for copyrights details. |
|
9 |
||
10 |
||
11 |
This library is free software; you can redistribute it and/or |
|
12 |
modify it under the terms of the GNU Lesser General Public |
|
13 |
License as published by the Free Software Foundation; either |
|
14 |
version 2.1 of the License, or (at your option) any later version. |
|
15 |
||
16 |
||
17 |
This library is distributed in the hope that it will be useful, |
|
18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
20 |
Lesser General Public License for more details. |
|
21 |
||
22 |
||
23 |
You should have received a copy of the GNU Lesser General Public |
|
24 |
License along with this library; if not, write to the Free Software |
|
25 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
26 |
*/ |
|
27 |
||
28 |
||
29 |
/*! |
|
30 |
** @file sync.c |
|
31 |
** @author Edouard TISSERANT and Francis DUPIN |
|
32 |
** @date Tue Jun 5 09:32:32 2007 |
|
33 |
** |
|
34 |
** @brief |
|
35 |
** |
|
36 |
** |
|
37 |
*/ |
|
38 |
||
39 |
#include "data.h" |
|
40 |
#include "sync.h" |
|
41 |
#include "canfestival.h" |
|
370
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
42 |
#include "sysdep.h" |
252 | 43 |
|
44 |
/* Prototypes for internals functions */ |
|
45 |
||
46 |
/*! |
|
47 |
** |
|
48 |
** |
|
49 |
** @param d |
|
50 |
** @param id |
|
51 |
**/ |
|
52 |
void SyncAlarm(CO_Data* d, UNS32 id); |
|
53 |
UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, |
|
54 |
UNS8 unsused_bSubindex); |
|
55 |
||
56 |
/*! |
|
57 |
** |
|
58 |
** |
|
59 |
** @param d |
|
60 |
** @param id |
|
61 |
**/ |
|
62 |
void SyncAlarm(CO_Data* d, UNS32 id) |
|
63 |
{ |
|
291
6165554cbfe9
Some tricks in communication services status struct (states.c) and in sync.c to fit with Beremiz generated node code.
etisserant
parents:
263
diff
changeset
|
64 |
sendSYNC(d) ; |
252 | 65 |
} |
66 |
||
67 |
/*! |
|
68 |
** This is called when Index 0x1005 is updated. |
|
69 |
** |
|
70 |
** @param d |
|
71 |
** @param unsused_indextable |
|
72 |
** @param unsused_bSubindex |
|
73 |
** |
|
74 |
** @return |
|
75 |
**/ |
|
76 |
UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex) |
|
77 |
{ |
|
78 |
startSYNC(d); |
|
79 |
return 0; |
|
80 |
} |
|
81 |
||
82 |
/*! |
|
83 |
** |
|
84 |
** |
|
85 |
** @param d |
|
86 |
**/ |
|
87 |
void startSYNC(CO_Data* d) |
|
88 |
{ |
|
443
994c99afb344
sync.c : fixed some endianize problem, and calback de-registering when re-starting service.
etisserant
parents:
378
diff
changeset
|
89 |
if(d->syncTimer != TIMER_NONE){ |
994c99afb344
sync.c : fixed some endianize problem, and calback de-registering when re-starting service.
etisserant
parents:
378
diff
changeset
|
90 |
stopSYNC(d); |
994c99afb344
sync.c : fixed some endianize problem, and calback de-registering when re-starting service.
etisserant
parents:
378
diff
changeset
|
91 |
} |
994c99afb344
sync.c : fixed some endianize problem, and calback de-registering when re-starting service.
etisserant
parents:
378
diff
changeset
|
92 |
|
252 | 93 |
RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate); |
94 |
RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate); |
|
95 |
||
443
994c99afb344
sync.c : fixed some endianize problem, and calback de-registering when re-starting service.
etisserant
parents:
378
diff
changeset
|
96 |
if(*d->COB_ID_Sync & 0x40000000ul && *d->Sync_Cycle_Period) |
252 | 97 |
{ |
98 |
d->syncTimer = SetAlarm( |
|
99 |
d, |
|
100 |
0 /*No id needed*/, |
|
101 |
&SyncAlarm, |
|
102 |
US_TO_TIMEVAL(*d->Sync_Cycle_Period), |
|
103 |
US_TO_TIMEVAL(*d->Sync_Cycle_Period)); |
|
104 |
} |
|
105 |
} |
|
106 |
||
107 |
/*! |
|
108 |
** |
|
109 |
** |
|
110 |
** @param d |
|
111 |
**/ |
|
112 |
void stopSYNC(CO_Data* d) |
|
113 |
{ |
|
263
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
114 |
RegisterSetODentryCallBack(d, 0x1005, 0, NULL); |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
115 |
RegisterSetODentryCallBack(d, 0x1006, 0, NULL); |
252 | 116 |
d->syncTimer = DelAlarm(d->syncTimer); |
117 |
} |
|
118 |
||
263
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
119 |
|
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
120 |
/*! |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
121 |
** |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
122 |
** |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
123 |
** @param d |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
124 |
** @param cob_id |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
125 |
** |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
126 |
** @return |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
127 |
**/ |
291
6165554cbfe9
Some tricks in communication services status struct (states.c) and in sync.c to fit with Beremiz generated node code.
etisserant
parents:
263
diff
changeset
|
128 |
UNS8 sendSYNCMessage(CO_Data* d) |
263
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
129 |
{ |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
130 |
Message m; |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
131 |
|
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
132 |
MSG_WAR(0x3001, "sendSYNC ", 0); |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
133 |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
446
diff
changeset
|
134 |
m.cob_id = UNS16_LE(*d->COB_ID_Sync); |
263
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
135 |
m.rtr = NOT_A_REQUEST; |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
136 |
m.len = 0; |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
137 |
|
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
138 |
return canSend(d->canHandle,&m); |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
139 |
} |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
140 |
|
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
141 |
|
252 | 142 |
/*! |
143 |
** |
|
144 |
** |
|
145 |
** @param d |
|
146 |
** @param cob_id |
|
147 |
** |
|
148 |
** @return |
|
149 |
**/ |
|
291
6165554cbfe9
Some tricks in communication services status struct (states.c) and in sync.c to fit with Beremiz generated node code.
etisserant
parents:
263
diff
changeset
|
150 |
UNS8 sendSYNC(CO_Data* d) |
252 | 151 |
{ |
263
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
152 |
UNS8 res; |
291
6165554cbfe9
Some tricks in communication services status struct (states.c) and in sync.c to fit with Beremiz generated node code.
etisserant
parents:
263
diff
changeset
|
153 |
res = sendSYNCMessage(d); |
263
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
154 |
proceedSYNC(d) ; |
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
155 |
return res ; |
252 | 156 |
} |
157 |
||
158 |
/*! |
|
159 |
** |
|
160 |
** |
|
161 |
** @param d |
|
162 |
** @param m |
|
163 |
** |
|
164 |
** @return |
|
165 |
**/ |
|
263
d221d387ad2f
Minor changes in SYNC. Splitted SendSync in SendSync and SendSyncMessage to allow manual SYNC message transmission and separate SYNC proceeding (synced TPDOs)
etisserant
parents:
252
diff
changeset
|
166 |
UNS8 proceedSYNC(CO_Data* d) |
252 | 167 |
{ |
168 |
||
169 |
UNS8 res; |
|
170 |
||
171 |
MSG_WAR(0x3002, "SYNC received. Proceed. ", 0); |
|
172 |
||
378
d2abf6c8c27b
As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents:
370
diff
changeset
|
173 |
(*d->post_sync)(d); |
252 | 174 |
|
175 |
/* only operational state allows PDO transmission */ |
|
176 |
if(! d->CurrentCommunicationState.csPDO) |
|
177 |
return 0; |
|
178 |
||
179 |
res = _sendPDOevent(d, 1 /*isSyncEvent*/ ); |
|
180 |
||
181 |
/*Call user app callback*/ |
|
378
d2abf6c8c27b
As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents:
370
diff
changeset
|
182 |
(*d->post_TPDO)(d); |
252 | 183 |
|
184 |
return res; |
|
185 |
||
186 |
} |
|
187 |
||
188 |
||
378
d2abf6c8c27b
As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents:
370
diff
changeset
|
189 |
void _post_sync(CO_Data* d){} |
d2abf6c8c27b
As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents:
370
diff
changeset
|
190 |
void _post_TPDO(CO_Data* d){} |