From e2addab7f0328ef144219f665555445579b21f2d Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 27 Aug 2020 23:11:19 +0200 Subject: [PATCH] cpu/kinetis: RTC use rtc_mktime() Use RTC helper functions instead of libc functions. This gives us y2038 safety by the extended epoch and saves a good chunk of memory: mktime(): text data bss dec hex filename 24756 232 2736 27724 6c4c testssperiph_rtc/bin/openlabs-kw41z-mini/tests_periph_rtc.elf rtc_mktime(): text data bss dec hex filename 16348 132 2696 19176 4ae8 tests/periph_rtc/bin/openlabs-kw41z-mini/tests_periph_rtc.elf --- cpu/kinetis/periph/rtc.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/cpu/kinetis/periph/rtc.c b/cpu/kinetis/periph/rtc.c index cf89681a5b..6e022b8809 100644 --- a/cpu/kinetis/periph/rtc.c +++ b/cpu/kinetis/periph/rtc.c @@ -20,8 +20,6 @@ * @} */ -#include -#include #include "cpu.h" #include "periph/rtc.h" #include "periph/rtt.h" @@ -41,7 +39,7 @@ static rtc_state_t rtc_callback; * * @param[inout] arg argument passed from the RTT interrupt */ -static void rtc_cb(void* arg); +static void rtc_cb(void *arg); void rtc_init(void) { @@ -50,38 +48,38 @@ void rtc_init(void) int rtc_set_time(struct tm *time) { - time_t t = mktime(time); + uint32_t t = rtc_mktime(time); - rtt_set_counter((uint32_t)t); + rtt_set_counter(t); return 0; } int rtc_get_time(struct tm *time) { - time_t t = (time_t)rtt_get_counter(); + uint32_t t = rtt_get_counter(); - gmtime_r(&t, time); + rtc_localtime(t, time); return 0; } int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg) { - time_t t = mktime(time); + uint32_t t = rtc_mktime(time); rtc_callback.cb = cb; - rtt_set_alarm((uint32_t)t, rtc_cb, arg); + rtt_set_alarm(t, rtc_cb, arg); return 0; } int rtc_get_alarm(struct tm *time) { - time_t t = (time_t)rtt_get_alarm(); + uint32_t t = rtt_get_alarm(); - gmtime_r(&t, time); + rtc_localtime(t, time); return 0; } @@ -102,7 +100,7 @@ void rtc_poweroff(void) rtt_poweroff(); } -static void rtc_cb(void* arg) +static void rtc_cb(void *arg) { if (rtc_callback.cb != NULL) { rtc_callback.cb(arg);