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

Function alarm_setup

components/drivers/rtc/dev_alarm.c:366–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364}
365
366static rt_err_t alarm_setup(rt_alarm_t alarm, struct tm *wktime)
367{
368 rt_err_t ret = -RT_ERROR;
369 time_t timestamp = (time_t)0;
370 struct tm *setup, now;
371
372 setup = &alarm->wktime;
373 *setup = *wktime;
374 /* get time of now */
375 get_timestamp(&timestamp);
376#ifdef RT_ALARM_USING_LOCAL_TIME
377 localtime_r(&timestamp, &now);
378#else
379 gmtime_r(&timestamp, &now);
380#endif
381
382 /* if these are a "don't care" value,we set them to now*/
383 if ((setup->tm_sec > 59) || (setup->tm_sec < 0))
384 setup->tm_sec = now.tm_sec;
385 if ((setup->tm_min > 59) || (setup->tm_min < 0))
386 setup->tm_min = now.tm_min;
387 if ((setup->tm_hour > 23) || (setup->tm_hour < 0))
388 setup->tm_hour = now.tm_hour;
389
390 switch (alarm->flag & 0xFF00)
391 {
392 case RT_ALARM_SECOND:
393 {
394 alarm->wktime.tm_hour = now.tm_hour;
395 alarm->wktime.tm_min = now.tm_min;
396 alarm->wktime.tm_sec = now.tm_sec + 1;
397 if (alarm->wktime.tm_sec > 59)
398 {
399 alarm->wktime.tm_sec = 0;
400 alarm->wktime.tm_min = alarm->wktime.tm_min + 1;
401 if (alarm->wktime.tm_min > 59)
402 {
403 alarm->wktime.tm_min = 0;
404 alarm->wktime.tm_hour = alarm->wktime.tm_hour + 1;
405 if (alarm->wktime.tm_hour > 23)
406 {
407 alarm->wktime.tm_hour = 0;
408 }
409 }
410 }
411 }
412 break;
413 case RT_ALARM_MINUTE:
414 {
415 alarm->wktime.tm_hour = now.tm_hour;
416 alarm->wktime.tm_min = now.tm_min + 1;
417 if (alarm->wktime.tm_min > 59)
418 {
419 alarm->wktime.tm_min = 0;
420 alarm->wktime.tm_hour = alarm->wktime.tm_hour + 1;
421 if (alarm->wktime.tm_hour > 23)
422 {
423 alarm->wktime.tm_hour = 0;

Callers 2

rt_alarm_controlFunction · 0.85
rt_alarm_startFunction · 0.85

Calls 4

localtime_rFunction · 0.85
is_valid_dateFunction · 0.85
get_timestampFunction · 0.70
gmtime_rFunction · 0.50

Tested by

no test coverage detected