esp_platform_time.c 565 B

12345678910111213141516171819202122232425
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "mbedtls/build_info.h"
  7. #include "mbedtls/platform_time.h"
  8. #ifdef MBEDTLS_PLATFORM_MS_TIME_ALT
  9. mbedtls_ms_time_t mbedtls_ms_time()
  10. {
  11. int ret;
  12. struct timespec tv = {};
  13. mbedtls_ms_time_t current_ms;
  14. ret = clock_gettime(CLOCK_MONOTONIC, &tv);
  15. if (ret) {
  16. return time(NULL) * 1000L;
  17. }
  18. current_ms = tv.tv_sec;
  19. return current_ms * 1000L + tv.tv_nsec / 1000000L;
  20. }
  21. #endif // MBEDTLS_PLATFORM_MS_TIME_ALT