1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #14766 from benpicco/cpu/native-rtc_set_alarm

cpu/native: RTC: implement rtc_set_alarm()
This commit is contained in:
benpicco 2020-08-28 17:39:47 +02:00 committed by GitHub
commit 029ae8c7d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 14 deletions

View File

@ -16,6 +16,9 @@ endif
ifeq (,$(filter stdio_%,$(USEMODULE)))
USEMODULE += stdio_native
endif
ifeq (,$(filter periph_rtc,$(USEMODULE)))
USEMODULE += xtimer
endif
USEMODULE += periph

View File

@ -29,6 +29,7 @@
#include "periph/rtc.h"
#include "cpu.h"
#include "xtimer.h"
#include "native_internal.h"
@ -41,6 +42,8 @@ static struct tm _native_rtc_alarm;
static rtc_alarm_cb_t _native_rtc_alarm_callback;
static void *_native_rtc_alarm_argument;
static xtimer_t _timer;
void rtc_init(void)
{
DEBUG("rtc_init\n");
@ -126,7 +129,6 @@ int rtc_get_time(struct tm *ttime)
return 0;
}
/* TODO: implement alarm scheduling */
int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
{
(void) time;
@ -142,11 +144,16 @@ int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
return -1;
}
struct tm now;
rtc_get_time(&now);
_native_rtc_alarm = *time;
warnx("rtc_set_alarm: not implemented");
_timer.callback = cb;
_timer.arg = arg;
xtimer_set64(&_timer, (mktime(time) - mktime(&now)) * US_PER_SEC);
return -1;
return 0;
}
int rtc_get_alarm(struct tm *time)
@ -167,8 +174,6 @@ int rtc_get_alarm(struct tm *time)
return 0;
}
/* TODO: implement alarm unscheduling once rtc_set_alarm is
* implemented */
void rtc_clear_alarm(void)
{
DEBUG("rtc_clear_alarm()\n");
@ -180,5 +185,6 @@ void rtc_clear_alarm(void)
warnx("rtc_clear_alarm: not powered on");
}
xtimer_remove(&_timer);
memset(&_native_rtc_alarm, 0, sizeof(_native_rtc_alarm));
}

View File

@ -32,18 +32,12 @@ def testfunc(child):
child.expect(r' Setting alarm to ({})'.format(DATE_PATTERN))
alarm_set = child.match.group(1)
if BOARD == 'native':
child.expect(r'.*rtc_set_alarm: not implemented')
child.expect(r' Alarm is set to ({})'.format(DATE_PATTERN))
alarm_value = child.match.group(1)
if BOARD != 'native':
# Set alarm is not implemented for native board so no need to compare
# alarm values
assert alarm_set == alarm_value
assert alarm_set == alarm_value
if BOARD != 'native':
for _ in range(alarm_count):
child.expect_exact('Alarm!')
for _ in range(alarm_count):
child.expect_exact('Alarm!')
if __name__ == "__main__":