2 * $Id: htimerNtp.c,v 0.0.0.1 2003/08/21
4 * DEBUG: section 2 HTimer for NtpTime
5 * AUTHOR: Petr Smolik petr.smolik@wo.cz
7 * ORTE - OCERA Real-Time Ethernet http://www.ocera.org/
8 * --------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
24 GAVL_FLES_INT_DEC(ul_htim_queue, ul_htim_queue_t, ul_htim_node_t, ul_htim_time_t,
25 timers, node, expires, ul_htimer_cmp_fnc)
28 GAVL_FLES_INT_IMP(ul_htim_queue, ul_htim_queue_t, ul_htim_node_t, ul_htim_time_t,
29 timers, node, expires, ul_htimer_cmp_fnc, GAVL_FAFTER,
30 root->first_changed=1,/**/,root->first_changed=1)
32 /*****************************************************************************/
33 UL_HTIMER_IMP(htimerRoot, \
39 htimerRoot_run_expired(ORTEDomain *d,
40 ul_htim_time_t *pact_time) {
41 HTimFncRootNode *timer;
43 while((timer=htimerRoot_cut_expired(&d->objectEntry, pact_time))){
44 timer->func(d,timer->objectEntryAID,pact_time);
48 /*****************************************************************************/
49 UL_HTIMER_IMP(htimerUnicastCommon, \
56 htimerUnicastCommon_update_root_timer(ObjectEntry *objectEntry,
57 ObjectEntryAID *objectEntryAID) {
60 //if first item is changed -> update root timer queue
61 if (htimerUnicastCommon_first_changed(objectEntryAID)) {
62 //deatach old timer from this queue (if any)
63 htimerRoot_detach(objectEntry,
64 &objectEntryAID->htimUnicast.commonNode);
65 if (htimerUnicastCommon_next_expire(objectEntryAID,&nextExpire)!=0) {
67 objectEntryAID->htimUnicast.commonNode.func=
68 htimerUnicastCommon_run_expired;
69 objectEntryAID->htimUnicast.commonNode.objectEntryAID=
71 htimerRoot_set_expire(
72 &objectEntryAID->htimUnicast.commonNode,
74 //insert new timer to root htimer node
75 htimerRoot_add(objectEntry,
76 &objectEntryAID->htimUnicast.commonNode);
77 debug(2,10) ("htimerUnicastCommon: root updated, wakeup\n");
78 //wake-up sending thread to process event
79 ORTEDomainWakeUpSendingThread(objectEntry);
85 htimerUnicastCommon_run_expired(ORTEDomain *d,
86 ObjectEntryAID *objectEntryAID,
87 ul_htim_time_t *pact_time) {
88 HTimFncUserNode *timer;
90 pthread_rwlock_t *lock;
92 while((timer=htimerUnicastCommon_cut_expired(objectEntryAID, pact_time))){
93 if ((lock=timer->lock)) //after proc. timer->func can be timer freed
94 pthread_rwlock_wrlock(timer->lock);
95 debug(2,10) ("htimerUnicastCommon: %s\n",
97 retValue=timer->func(d,timer->arg1);
99 pthread_rwlock_unlock(timer->lock);
100 if (retValue==2) //object deleted
103 htimerUnicastCommon_update_root_timer(&d->objectEntry,objectEntryAID);
106 /*****************************************************************************/
107 UL_HTIMER_IMP(htimerUnicastSendMetatraffic, \
110 htimUnicast.sendMetatraffic, \
114 htimerUnicastSendMetatraffic_update_root_timer(ObjectEntry *objectEntry,
115 ObjectEntryAID *objectEntryAID) {
118 //if first item is changed -> update root timer queue
119 if (htimerUnicastSendMetatraffic_first_changed(objectEntryAID)) {
120 //deatach old timer from this queue (if any)
121 htimerRoot_detach(objectEntry,
122 &objectEntryAID->htimUnicast.sendMetatrafficNode);
123 if (htimerUnicastSendMetatraffic_next_expire(objectEntryAID,&nextExpire)!=0) {
125 objectEntryAID->htimUnicast.sendMetatrafficNode.func=
126 htimerUnicastSendMetatraffic_run_expired;
127 objectEntryAID->htimUnicast.sendMetatrafficNode.objectEntryAID=
129 htimerRoot_set_expire(
130 &objectEntryAID->htimUnicast.sendMetatrafficNode,
132 //insert new timer to root htimer node
133 htimerRoot_add(objectEntry,
134 &objectEntryAID->htimUnicast.sendMetatrafficNode);
135 debug(2,10) ("htimerUnicastMetatraffic: root updated, wakeup\n");
136 //wake-up sending thread to process event
137 ORTEDomainWakeUpSendingThread(objectEntry);
143 htimerUnicastSendMetatraffic_run_expired(ORTEDomain *d,
144 ObjectEntryAID *objectEntryAID,
145 ul_htim_time_t *pact_time) {
146 HTimFncUserNode *timer;
149 while((timer=htimerUnicastSendMetatraffic_cut_expired(objectEntryAID, pact_time))){
151 pthread_rwlock_wrlock(timer->lock);
152 debug(2,10) ("htimerUnicastMetatraffic: %s\n",
154 retValue=timer->func(d,timer->arg1);
155 while (d->mbSend.needSend) {
156 ORTESendData(d,objectEntryAID,ORTE_TRUE);
157 timer->func(d,timer->arg1);
160 pthread_rwlock_unlock(timer->lock);
162 htimerUnicastSendMetatraffic_update_root_timer(&d->objectEntry,objectEntryAID);
163 if (d->mbSend.cdrStream.length>RTPS_HEADER_LENGTH) {
164 ORTESendData(d,objectEntryAID,ORTE_TRUE);
168 /*****************************************************************************/
169 UL_HTIMER_IMP(htimerUnicastSendUserData, \
172 htimUnicast.sendUserData, \
176 htimerUnicastSendUserData_update_root_timer(ObjectEntry *objectEntry,
177 ObjectEntryAID *objectEntryAID) {
180 //if first item is changed -> update root timer queue
181 if (htimerUnicastSendUserData_first_changed(objectEntryAID)) {
182 //deatach old timer from this queue (if any)
183 htimerRoot_detach(objectEntry,
184 &objectEntryAID->htimUnicast.sendUserDataNode);
185 if (htimerUnicastSendUserData_next_expire(objectEntryAID,&nextExpire)!=0) {
187 objectEntryAID->htimUnicast.sendUserDataNode.func=
188 htimerUnicastSendUserData_run_expired;
189 objectEntryAID->htimUnicast.sendUserDataNode.objectEntryAID=
191 htimerRoot_set_expire(
192 &objectEntryAID->htimUnicast.sendUserDataNode,
194 //insert new timer to root htimer node
195 htimerRoot_add(objectEntry,
196 &objectEntryAID->htimUnicast.sendUserDataNode);
197 debug(2,10) ("htimerUnicastUserdata: root updated, wakeup\n");
198 //wake-up sending thread to process event
199 ORTEDomainWakeUpSendingThread(objectEntry);
205 htimerUnicastSendUserData_run_expired(ORTEDomain *d,
206 ObjectEntryAID *objectEntryAID,
207 ul_htim_time_t *pact_time) {
208 HTimFncUserNode *timer;
211 while((timer=htimerUnicastSendUserData_cut_expired(objectEntryAID, pact_time))){
213 pthread_rwlock_wrlock(timer->lock);
214 retValue=timer->func(d,timer->arg1);
215 while (d->mbSend.needSend) {
216 ORTESendData(d,objectEntryAID,ORTE_FALSE);
217 timer->func(d,timer->arg1);
220 pthread_rwlock_unlock(timer->lock);
222 htimerUnicastSendUserData_update_root_timer(&d->objectEntry,objectEntryAID);
223 if (d->mbSend.cdrStream.length>RTPS_HEADER_LENGTH) {
224 ORTESendData(d,objectEntryAID,ORTE_FALSE);
228 /*********************************************************************/
230 getActualNtpTime(void) {
232 #ifndef CONFIG_ORTE_RT
235 gettimeofday(&time,NULL);
236 NtpTimeAssembFromUs(result,time.tv_sec,time.tv_usec);
237 NtpTimeAssembFromUs(result,time.tv_sec,time.tv_usec);
239 struct timespec time;
241 clock_gettime(CLOCK_REALTIME, &time);
242 time.tv_nsec/=1000; //conver to us
243 NtpTimeAssembFromUs(result,time.tv_sec,time.tv_nsec);