diff --git a/drivers/rtt64/rtt64_rtc.c b/drivers/rtt64/rtt64_rtc.c new file mode 100644 index 0000000000000..410cb935eb704 --- /dev/null +++ b/drivers/rtt64/rtt64_rtc.c @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2022 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup drivers_rtt64 + * @{ + * + * @file + * @brief Basic RTC implementation based on RTT64 + * + * @note Unlike a real RTC, this emulated version is not guaranteed to keep + * time across reboots or deep sleep. + * If your hardware provides the means to implement a real RTC, always + * prefer that over this emulated version! + * + * @author Benjamin Valentin + * + * @} + */ + +#include + +#include "irq.h" +#include "periph/rtc.h" +#include "rtt64.h" +#include "time_units.h" + +#define ENABLE_DEBUG 0 +#include "debug.h" + +void rtc_init(void) +{ + rtt64_init(); +} + +int rtc_set_time(struct tm *time) +{ + rtt64_set_time(mktime(time), 0); + return 0; +} + +int rtc_get_time_ms(struct tm *time, uint16_t *ms) +{ + uint64_t secs; + uint32_t us; + + rtt64_get_time(&secs, &us); + + if (ms) { + *ms = us / US_PER_MS; + } + localtime_r((time_t *)&secs, time); + + return 0; +} + +int rtc_get_time(struct tm *time) +{ + return rtc_get_time_ms(time, NULL); +} + +int rtc_get_alarm(struct tm *time) +{ + uint64_t secs; + uint32_t us; + + rtt64_get_alarm_time(&secs, &us); + localtime_r((time_t *)&secs, time); + + return 0; +} + +int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg) +{ + rtt64_set_alarm_time(mktime(time), 0, cb, arg); + + return 0; +} + +void rtc_clear_alarm(void) +{ + rtt64_clear_alarm(); +} + +void rtc_poweron(void) +{ + rtt_poweron(); +} + +void rtc_poweroff(void) +{ + rtt_poweroff(); +} diff --git a/pkg/fatfs/Makefile.dep b/pkg/fatfs/Makefile.dep index c1443f3ac3df2..ec686af20915d 100644 --- a/pkg/fatfs/Makefile.dep +++ b/pkg/fatfs/Makefile.dep @@ -6,6 +6,6 @@ ifneq (,$(filter vfs_auto_format,$(USEMODULE))) endif # Use RTC for timestamps if available -ifeq (,$(filter rtt_rtc,$(USEMODULE))) +ifeq (,$(filter rtt_rtc rtt64,$(USEMODULE))) FEATURES_OPTIONAL += periph_rtc endif diff --git a/pkg/fatfs/Makefile.include b/pkg/fatfs/Makefile.include index 43d2785d5163b..f40e4642f0d24 100644 --- a/pkg/fatfs/Makefile.include +++ b/pkg/fatfs/Makefile.include @@ -6,12 +6,12 @@ NATIVEINCLUDES += -I$(RIOTPKG)/fatfs/vendor/include DIRS += $(RIOTBASE)/pkg/fatfs/fatfs_diskio/mtd -ifneq (,$(filter fatfs_vfs,$(USEMODULE))) +ifneq (,$(filter fatfs_vfs rtt64,$(USEMODULE))) DIRS += $(RIOTBASE)/pkg/fatfs/fatfs_vfs endif #if periph_rtc is available use it. Otherwise use static timestamps -ifeq (,$(filter rtt_rtc periph_rtc,$(USEMODULE))) +ifeq (,$(filter rtt_rtc periph_rtc rtt64,$(USEMODULE))) CFLAGS += -DFATFS_FFCONF_OPT_FS_NORTC=1 else CFLAGS += -DFATFS_FFCONF_OPT_FS_NORTC=0 diff --git a/sys/shell/commands/Makefile b/sys/shell/commands/Makefile index 12300217ce332..17529deaefc57 100644 --- a/sys/shell/commands/Makefile +++ b/sys/shell/commands/Makefile @@ -106,7 +106,7 @@ ifneq (,$(filter lwip_netif,$(USEMODULE))) SRC += sc_lwip_netif.c endif -ifneq (,$(filter rtt_rtc periph_rtc,$(USEMODULE))) +ifneq (,$(filter rtt_rtc periph_rtc rtt64,$(USEMODULE))) SRC += sc_rtc.c endif diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index 7598355e93d9e..9dbb0e52d78cf 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -64,7 +64,7 @@ extern int _at30tse75x_handler(int argc, char **argv); extern int _saul(int argc, char **argv); #endif -#if defined(MODULE_PERIPH_RTC) || defined(MODULE_RTT_RTC) +#if defined(MODULE_PERIPH_RTC) || defined(MODULE_RTT_RTC) || defined(MODULE_RTT64) extern int _rtc_handler(int argc, char **argv); #endif @@ -278,7 +278,7 @@ const shell_command_t _shell_command_list[] = { { "random_init", "initializes the PRNG", _random_init }, { "random_get", "returns 32 bit of pseudo randomness", _random_get }, #endif -#if defined(MODULE_PERIPH_RTC) || defined(MODULE_RTT_RTC) +#if defined(MODULE_PERIPH_RTC) || defined(MODULE_RTT_RTC) || defined(MODULE_RTT64) {"rtc", "control RTC peripheral interface", _rtc_handler}, #endif #ifdef MODULE_RTT_CMD