author | greg |
Sat, 08 Dec 2007 15:01:14 +0100 | |
changeset 329 | 7717252e3ed9 |
parent 291 | 6165554cbfe9 |
child 365 | 9b76e0881beb |
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" |
|
42 |
||
43 |
/* Prototypes for internals functions */ |
|
44 |
||
45 |
/*! |
|
46 |
** |
|
47 |
** |
|
48 |
** @param d |
|
49 |
** @param id |
|
50 |
**/ |
|
51 |
void SyncAlarm(CO_Data* d, UNS32 id); |
|
52 |
UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, |
|
53 |
UNS8 unsused_bSubindex); |
|
54 |
||
55 |
/*! |
|
56 |
** |
|
57 |
** |
|
58 |
** @param d |
|
59 |
** @param id |
|
60 |
**/ |
|
61 |
void SyncAlarm(CO_Data* d, UNS32 id) |
|
62 |
{ |
|
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
|
63 |
sendSYNC(d) ; |
252 | 64 |
} |
65 |
||
66 |
/*! |
|
67 |
** This is called when Index 0x1005 is updated. |
|
68 |
** |
|
69 |
** @param d |
|
70 |
** @param unsused_indextable |
|
71 |
** @param unsused_bSubindex |
|
72 |
** |
|
73 |
** @return |
|
74 |
**/ |
|
75 |
UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex) |
|
76 |
{ |
|
77 |
startSYNC(d); |
|
78 |
return 0; |
|
79 |
} |
|
80 |
||
81 |
/*! |
|
82 |
** |
|
83 |
** |
|
84 |
** @param d |
|
85 |
**/ |
|
86 |
void startSYNC(CO_Data* d) |
|
87 |
{ |
|
88 |
RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate); |
|
89 |
RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate); |
|
90 |
||
91 |
if(d->syncTimer != TIMER_NONE){ |
|
92 |
stopSYNC(d); |
|
93 |
} |
|
94 |
||
95 |
if(*d->COB_ID_Sync & 0x40000000 && *d->Sync_Cycle_Period) |
|
96 |
{ |
|
97 |
d->syncTimer = SetAlarm( |
|
98 |
d, |
|
99 |
0 /*No id needed*/, |
|
100 |
&SyncAlarm, |
|
101 |
US_TO_TIMEVAL(*d->Sync_Cycle_Period), |
|
102 |
US_TO_TIMEVAL(*d->Sync_Cycle_Period)); |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
/*! |
|
107 |
** |
|
108 |
** |
|
109 |
** @param d |
|
110 |
**/ |
|
111 |
void stopSYNC(CO_Data* d) |
|
112 |
{ |
|
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
|
113 |
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
|
114 |
RegisterSetODentryCallBack(d, 0x1006, 0, NULL); |
252 | 115 |
d->syncTimer = DelAlarm(d->syncTimer); |
116 |
} |
|
117 |
||
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
|
118 |
|
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 |
** @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
|
123 |
** @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
|
124 |
** |
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 |
** @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
|
126 |
**/ |
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
|
127 |
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
|
128 |
{ |
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 |
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
|
130 |
|
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 |
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
|
132 |
|
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
|
133 |
m.cob_id.w = *d->COB_ID_Sync & 0x1FFFFFFF; |
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
|
134 |
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
|
135 |
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
|
136 |
|
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 |
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
|
138 |
} |
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 |
|
252 | 141 |
/*! |
142 |
** |
|
143 |
** |
|
144 |
** @param d |
|
145 |
** @param cob_id |
|
146 |
** |
|
147 |
** @return |
|
148 |
**/ |
|
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
|
149 |
UNS8 sendSYNC(CO_Data* d) |
252 | 150 |
{ |
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
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
return res ; |
252 | 155 |
} |
156 |
||
157 |
/*! |
|
158 |
** |
|
159 |
** |
|
160 |
** @param d |
|
161 |
** @param m |
|
162 |
** |
|
163 |
** @return |
|
164 |
**/ |
|
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
|
165 |
UNS8 proceedSYNC(CO_Data* d) |
252 | 166 |
{ |
167 |
||
168 |
UNS8 res; |
|
169 |
||
170 |
MSG_WAR(0x3002, "SYNC received. Proceed. ", 0); |
|
171 |
||
172 |
(*d->post_sync)(); |
|
173 |
||
174 |
/* only operational state allows PDO transmission */ |
|
175 |
if(! d->CurrentCommunicationState.csPDO) |
|
176 |
return 0; |
|
177 |
||
178 |
res = _sendPDOevent(d, 1 /*isSyncEvent*/ ); |
|
179 |
||
180 |
/*Call user app callback*/ |
|
181 |
(*d->post_TPDO)(); |
|
182 |
||
183 |
return res; |
|
184 |
||
185 |
} |
|
186 |
||
187 |
||
188 |
void _post_sync(){} |
|
189 |
void _post_TPDO(){} |