24
24
* THE SOFTWARE.
25
25
*/
26
26
27
+ #include "py/runtime.h"
28
+
27
29
#ifdef MICROPY_SSL_MBEDTLS
28
30
29
31
#include "mbedtls_config.h"
32
+ #if defined(MBEDTLS_HAVE_TIME ) || defined(MBEDTLS_HAVE_TIME_DATE )
33
+ #include "fsl_snvs_lp.h"
34
+ #include "shared/timeutils/timeutils.h"
35
+ #endif
36
+
30
37
void trng_random_data (unsigned char * output , size_t len );
31
38
32
39
int mbedtls_hardware_poll (void * data , unsigned char * output , size_t len , size_t * olen ) {
@@ -38,4 +45,33 @@ int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t
38
45
return 0 ;
39
46
}
40
47
48
+ #if defined(MBEDTLS_HAVE_TIME )
49
+ time_t mimxrt_rtctime_seconds (time_t * timer ) {
50
+ // Get date and date in CPython order.
51
+ snvs_lp_srtc_datetime_t date ;
52
+ SNVS_LP_SRTC_GetDatetime (SNVS , & date );
53
+ return timeutils_seconds_since_epoch (date .year , date .month , date .day , date .hour , date .minute , date .second );
54
+ }
55
+ #endif
56
+
57
+ #if defined(MBEDTLS_HAVE_TIME_DATE )
58
+ struct tm * gmtime (const time_t * timep ) {
59
+ static struct tm tm ;
60
+ timeutils_struct_time_t tm_buf = {0 };
61
+ timeutils_seconds_since_epoch_to_struct_time (* timep , & tm_buf );
62
+
63
+ tm .tm_sec = tm_buf .tm_sec ;
64
+ tm .tm_min = tm_buf .tm_min ;
65
+ tm .tm_hour = tm_buf .tm_hour ;
66
+ tm .tm_mday = tm_buf .tm_mday ;
67
+ tm .tm_mon = tm_buf .tm_mon - 1 ;
68
+ tm .tm_year = tm_buf .tm_year - 1900 ;
69
+ tm .tm_wday = tm_buf .tm_wday ;
70
+ tm .tm_yday = tm_buf .tm_yday ;
71
+ tm .tm_isdst = -1 ;
72
+
73
+ return & tm ;
74
+ }
75
+ #endif
76
+
41
77
#endif
0 commit comments