kopia lustrzana https://github.com/micropython/micropython
samd/mbedtls: Add time and date functions for mbedtls.
Signed-off-by: robert-hh <robert@hammelrath.com>pull/12464/head
rodzic
d5e5edef62
commit
0096fa2378
|
@ -26,6 +26,10 @@
|
|||
#ifndef MICROPY_INCLUDED_MBEDTLS_CONFIG_H
|
||||
#define MICROPY_INCLUDED_MBEDTLS_CONFIG_H
|
||||
|
||||
// Time hook.
|
||||
#include <time.h>
|
||||
extern time_t samd_rtctime_seconds(time_t *timer);
|
||||
#define MBEDTLS_PLATFORM_TIME_MACRO samd_rtctime_seconds
|
||||
// Set MicroPython-specific options.
|
||||
#define MICROPY_MBEDTLS_CONFIG_BARE_METAL (1)
|
||||
|
||||
|
|
|
@ -28,7 +28,13 @@
|
|||
|
||||
#include "mbedtls_config.h"
|
||||
#include <stdint.h>
|
||||
uint32_t trng_random_u32();
|
||||
uint32_t trng_random_u32(void);
|
||||
#if defined(MBEDTLS_HAVE_TIME) || defined(MBEDTLS_HAVE_TIME_DATE)
|
||||
#include <stdbool.h>
|
||||
#include "py/runtime.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
extern void rtc_gettime(timeutils_struct_time_t *tm);
|
||||
#endif
|
||||
|
||||
int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen) {
|
||||
|
||||
|
@ -40,3 +46,31 @@ int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
time_t samd_rtctime_seconds(time_t *timer) {
|
||||
timeutils_struct_time_t tm;
|
||||
rtc_gettime(&tm);
|
||||
return timeutils_seconds_since_epoch(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME_DATE)
|
||||
struct tm *gmtime(const time_t *timep) {
|
||||
static struct tm tm;
|
||||
timeutils_struct_time_t tm_buf = {0};
|
||||
timeutils_seconds_since_epoch_to_struct_time(*timep, &tm_buf);
|
||||
|
||||
tm.tm_sec = tm_buf.tm_sec;
|
||||
tm.tm_min = tm_buf.tm_min;
|
||||
tm.tm_hour = tm_buf.tm_hour;
|
||||
tm.tm_mday = tm_buf.tm_mday;
|
||||
tm.tm_mon = tm_buf.tm_mon - 1;
|
||||
tm.tm_year = tm_buf.tm_year - 1900;
|
||||
tm.tm_wday = tm_buf.tm_wday;
|
||||
tm.tm_yday = tm_buf.tm_yday;
|
||||
tm.tm_isdst = -1;
|
||||
|
||||
return &tm;
|
||||
}
|
||||
#endif
|
||||
|
|
Ładowanie…
Reference in New Issue