diff --git a/examples/sntp/sntp_example.c b/examples/sntp/sntp_example.c index 6083f96..8702718 100644 --- a/examples/sntp/sntp_example.c +++ b/examples/sntp/sntp_example.c @@ -50,6 +50,14 @@ void SntpTsk(void *pvParameters) sntp_initialize(1, 0); sntp_set_servers(servers, sizeof(servers) / sizeof(char*)); printf("DONE!\n"); + + struct timespec ts; + clock_getres(CLOCK_REALTIME, &ts); + printf("Time resolution: %d secs, %d nanosecs\n", t.tv_sec, t.tv_nsec); + + clock_gettime(CLOCK_REALTIME, &t); + printf("Time: %d secs, %d nanosecs\n", t.tv_sec, t.tv_nsec); + while(1) { vTaskDelayMs(5000); time_t ts = sntp_get_rtc_time(NULL); diff --git a/extras/sntp/sntp_fun.c b/extras/sntp/sntp_fun.c index 83f5e6b..f4c02ae 100644 --- a/extras/sntp/sntp_fun.c +++ b/extras/sntp/sntp_fun.c @@ -4,6 +4,10 @@ * Jesus Alonso (doragasu) */ +#include +#include +#include +#include #include #include #include @@ -84,6 +88,16 @@ time_t sntp_get_rtc_time(int32_t *us) { return secs; } +int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tzp) { + (void)r; + (void)tzp; + + printf("DEB; gettimeofday called"); + tp->tv_sec = sntp_get_rtc_time((int32_t*)&tp->tv_usec); + return 0; +} + + /// Update RTC timer. Called by SNTP module each time it receives an update. void sntp_update_rtc(time_t t, uint32_t us) { // Apply daylight and timezone correction