MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / alarm_update

Function alarm_update

components/drivers/rtc/dev_alarm.c:233–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233static void alarm_update(rt_uint32_t event)
234{
235 struct rt_alarm *alm_prev = RT_NULL, *alm_next = RT_NULL;
236 struct rt_alarm *alarm;
237 rt_int32_t sec_now, sec_alarm, sec_tmp;
238 rt_int32_t sec_next = 24 * 3600, sec_prev = 0;
239 time_t timestamp = (time_t)0;
240 struct tm now;
241 rt_list_t *next;
242
243 rt_mutex_take(&_container.mutex, RT_WAITING_FOREVER);
244 if (!rt_list_isempty(&_container.head))
245 {
246 /* get time of now */
247 get_timestamp(&timestamp);
248#ifdef RT_ALARM_USING_LOCAL_TIME
249 localtime_r(&timestamp, &now);
250#else
251 gmtime_r(&timestamp, &now);
252#endif
253
254 for (next = _container.head.next; next != &_container.head; next = next->next)
255 {
256 alarm = rt_list_entry(next, struct rt_alarm, list);
257 /* check the overtime alarm */
258 alarm_wakeup(alarm, &now);
259 }
260
261 /* get time of now */
262 get_timestamp(&timestamp);
263#ifdef RT_ALARM_USING_LOCAL_TIME
264 localtime_r(&timestamp, &now);
265#else
266 gmtime_r(&timestamp, &now);
267#endif
268 sec_now = alarm_mkdaysec(&now);
269
270 for (next = _container.head.next; next != &_container.head; next = next->next)
271 {
272 alarm = rt_list_entry(next, struct rt_alarm, list);
273 /* calculate seconds from 00:00:00 */
274 sec_alarm = alarm_mkdaysec(&alarm->wktime);
275 if (alarm->flag & RT_ALARM_STATE_START)
276 {
277 sec_tmp = sec_alarm - sec_now;
278 if (sec_tmp > 0)
279 {
280 /* find alarm after now(now to 23:59:59) and the most recent */
281 if (sec_tmp < sec_next)
282 {
283 sec_next = sec_tmp;
284 alm_next = alarm;
285 }
286 }
287 else
288 {
289 /* find alarm before now(00:00:00 to now) and furthest from now */
290 if (sec_tmp < sec_prev)

Callers 3

rt_alarm_stopFunction · 0.85
rt_alarm_deleteFunction · 0.85
rt_alarmsvc_thread_initFunction · 0.85

Calls 9

rt_mutex_takeFunction · 0.85
rt_list_isemptyFunction · 0.85
localtime_rFunction · 0.85
alarm_wakeupFunction · 0.85
alarm_mkdaysecFunction · 0.85
alarm_setFunction · 0.85
rt_mutex_releaseFunction · 0.85
get_timestampFunction · 0.70
gmtime_rFunction · 0.50

Tested by

no test coverage detected