28
28
29
29
#include "mbedtls_config.h"
30
30
#include <stdint.h>
31
- uint32_t trng_random_u32 ();
31
+ uint32_t trng_random_u32 (void );
32
+ #if defined(MBEDTLS_HAVE_TIME ) || defined(MBEDTLS_HAVE_TIME_DATE )
33
+ #include <stdbool.h>
34
+ #include "py/runtime.h"
35
+ #include "shared/timeutils/timeutils.h"
36
+ extern void rtc_gettime (timeutils_struct_time_t * tm );
37
+ #endif
32
38
33
39
int mbedtls_hardware_poll (void * data , unsigned char * output , size_t len , size_t * olen ) {
34
40
@@ -40,3 +46,31 @@ int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t
40
46
}
41
47
42
48
#endif
49
+
50
+ #if defined(MBEDTLS_HAVE_TIME )
51
+ time_t samd_rtctime_seconds (time_t * timer ) {
52
+ timeutils_struct_time_t tm ;
53
+ rtc_gettime (& tm );
54
+ return timeutils_seconds_since_epoch (tm .tm_year , tm .tm_mon , tm .tm_mday , tm .tm_hour , tm .tm_min , tm .tm_sec );
55
+ }
56
+ #endif
57
+
58
+ #if defined(MBEDTLS_HAVE_TIME_DATE )
59
+ struct tm * gmtime (const time_t * timep ) {
60
+ static struct tm tm ;
61
+ timeutils_struct_time_t tm_buf = {0 };
62
+ timeutils_seconds_since_epoch_to_struct_time (* timep , & tm_buf );
63
+
64
+ tm .tm_sec = tm_buf .tm_sec ;
65
+ tm .tm_min = tm_buf .tm_min ;
66
+ tm .tm_hour = tm_buf .tm_hour ;
67
+ tm .tm_mday = tm_buf .tm_mday ;
68
+ tm .tm_mon = tm_buf .tm_mon - 1 ;
69
+ tm .tm_year = tm_buf .tm_year - 1900 ;
70
+ tm .tm_wday = tm_buf .tm_wday ;
71
+ tm .tm_yday = tm_buf .tm_yday ;
72
+ tm .tm_isdst = -1 ;
73
+
74
+ return & tm ;
75
+ }
76
+ #endif
0 commit comments