1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
19340: cpu/native: implement periph_rtc_ms r=benpicco a=benpicco



19352: pkg/tinydtls: don't require ztimer64 r=benpicco a=benpicco



Co-authored-by: Benjamin Valentin <benpicco@beuth-hochschule.de>
This commit is contained in:
bors[bot] 2023-03-06 17:34:53 +00:00 committed by GitHub
commit 777857ae4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 6 deletions

View File

@ -15,6 +15,7 @@ config BOARD_NATIVE
# Put defined MCU peripherals here (in alphabetical order) # Put defined MCU peripherals here (in alphabetical order)
select HAS_PERIPH_RTC select HAS_PERIPH_RTC
select HAS_PERIPH_RTC_MS
select HAS_PERIPH_TIMER select HAS_PERIPH_TIMER
select HAS_PERIPH_UART select HAS_PERIPH_UART
select HAS_PERIPH_GPIO select HAS_PERIPH_GPIO

View File

@ -2,6 +2,7 @@ CPU = native
# Put defined MCU peripherals here (in alphabetical order) # Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_rtc FEATURES_PROVIDED += periph_rtc
FEATURES_PROVIDED += periph_rtc_ms
FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_gpio

View File

@ -37,6 +37,13 @@
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
/**
* @brief Time source of the native RTC
*/
#ifndef NATIVE_RTC_SOURCE
#define NATIVE_RTC_SOURCE CLOCK_REALTIME
#endif
static int _native_rtc_initialized = 0; static int _native_rtc_initialized = 0;
static int _native_rtc_powered = 0; static int _native_rtc_powered = 0;
@ -141,10 +148,15 @@ int rtc_set_time(struct tm *ttime)
warnx("rtc_set_time: out of time_t range"); warnx("rtc_set_time: out of time_t range");
return -1; return -1;
} }
struct timespec tv;
_native_syscall_enter(); _native_syscall_enter();
_native_rtc_offset = tnew - time(NULL); clock_gettime(NATIVE_RTC_SOURCE, &tv);
_native_syscall_leave(); _native_syscall_leave();
_native_rtc_offset = tnew - tv.tv_sec;
if (_native_rtc_alarm_callback) { if (_native_rtc_alarm_callback) {
rtc_set_alarm(&_native_rtc_alarm, _native_rtc_alarm_callback, rtc_set_alarm(&_native_rtc_alarm, _native_rtc_alarm_callback,
_native_rtc_timer.arg); _native_rtc_timer.arg);
@ -153,9 +165,9 @@ int rtc_set_time(struct tm *ttime)
return 0; return 0;
} }
int rtc_get_time(struct tm *ttime) int rtc_get_time_ms(struct tm *ttime, uint16_t *ms)
{ {
time_t t; struct timespec tv;
if (!_native_rtc_initialized) { if (!_native_rtc_initialized) {
warnx("rtc_get_time: not initialized"); warnx("rtc_get_time: not initialized");
@ -167,9 +179,14 @@ int rtc_get_time(struct tm *ttime)
} }
_native_syscall_enter(); _native_syscall_enter();
t = time(NULL) + _native_rtc_offset; clock_gettime(NATIVE_RTC_SOURCE, &tv);
tv.tv_sec += _native_rtc_offset;
if (localtime_r(&t, ttime) == NULL) { if (ms) {
*ms = tv.tv_nsec / NS_PER_MS;
}
if (localtime_r(&tv.tv_sec, ttime) == NULL) {
err(EXIT_FAILURE, "rtc_get_time: localtime_r"); err(EXIT_FAILURE, "rtc_get_time: localtime_r");
} }
_native_syscall_leave(); _native_syscall_leave();
@ -180,6 +197,11 @@ int rtc_get_time(struct tm *ttime)
return 0; return 0;
} }
int rtc_get_time(struct tm *ttime)
{
return rtc_get_time_ms(ttime, NULL);
}
int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg) int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
{ {
if (!_native_rtc_initialized) { if (!_native_rtc_initialized) {

View File

@ -5,7 +5,7 @@ USEMODULE += hashes
USEMODULE += random USEMODULE += random
USEMODULE += tinydtls_aes USEMODULE += tinydtls_aes
USEMODULE += tinydtls_ecc USEMODULE += tinydtls_ecc
USEMODULE += ztimer64_msec USEMODULE += ztimer_msec
# TinyDTLS only has support for 32-bit architectures ATM # TinyDTLS only has support for 32-bit architectures ATM
FEATURES_REQUIRED += arch_32bit FEATURES_REQUIRED += arch_32bit