| 231 | } |
| 232 | |
| 233 | static 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(×tamp); |
| 248 | #ifdef RT_ALARM_USING_LOCAL_TIME |
| 249 | localtime_r(×tamp, &now); |
| 250 | #else |
| 251 | gmtime_r(×tamp, &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(×tamp); |
| 263 | #ifdef RT_ALARM_USING_LOCAL_TIME |
| 264 | localtime_r(×tamp, &now); |
| 265 | #else |
| 266 | gmtime_r(×tamp, &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) |
no test coverage detected