26
26
27
27
#include "rng.h"
28
28
#include "mbedtls_config.h"
29
+ #if defined(MBEDTLS_HAVE_TIME ) || defined(MBEDTLS_HAVE_TIME_DATE )
30
+ #include "rtc.h"
31
+ #include "shared/timeutils/timeutils.h"
32
+ #endif
29
33
30
34
int mbedtls_hardware_poll (void * data , unsigned char * output , size_t len , size_t * olen ) {
31
35
uint32_t val = 0 ;
@@ -42,3 +46,34 @@ int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t
42
46
}
43
47
return 0 ;
44
48
}
49
+
50
+ #if defined(MBEDTLS_HAVE_TIME )
51
+ time_t stm32_rtctime_seconds (time_t * timer ) {
52
+ rtc_init_finalise ();
53
+ RTC_DateTypeDef date ;
54
+ RTC_TimeTypeDef time ;
55
+ HAL_RTC_GetTime (& RTCHandle , & time , RTC_FORMAT_BIN );
56
+ HAL_RTC_GetDate (& RTCHandle , & date , RTC_FORMAT_BIN );
57
+ return timeutils_seconds_since_epoch (2000 + date .Year , date .Month , date .Date , time .Hours , time .Minutes , time .Seconds );
58
+ }
59
+ #endif
60
+
61
+ #if defined(MBEDTLS_HAVE_TIME_DATE )
62
+ struct tm * gmtime (const time_t * timep ) {
63
+ static struct tm tm ;
64
+ timeutils_struct_time_t tm_buf = {0 };
65
+ timeutils_seconds_since_epoch_to_struct_time (* timep , & tm_buf );
66
+
67
+ tm .tm_sec = tm_buf .tm_sec ;
68
+ tm .tm_min = tm_buf .tm_min ;
69
+ tm .tm_hour = tm_buf .tm_hour ;
70
+ tm .tm_mday = tm_buf .tm_mday ;
71
+ tm .tm_mon = tm_buf .tm_mon - 1 ;
72
+ tm .tm_year = tm_buf .tm_year - 1900 ;
73
+ tm .tm_wday = tm_buf .tm_wday ;
74
+ tm .tm_yday = tm_buf .tm_yday ;
75
+ tm .tm_isdst = -1 ;
76
+
77
+ return & tm ;
78
+ }
79
+ #endif
0 commit comments