Added quick and dirty _gettimeofday_r() test implementation.

This commit is contained in:
doragasu 2016-03-11 13:11:15 +01:00
parent 16c831fffa
commit 0482aebf7d
2 changed files with 22 additions and 0 deletions

View file

@ -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);

View file

@ -4,6 +4,10 @@
* Jesus Alonso (doragasu)
*/
#include <sys/reent.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <stdio.h>
#include <espressif/esp_common.h>
#include <esp/timer.h>
@ -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