ESP8266_RTOS example tweaks

PUBLISHED_FROM=11096f272afc0716e0677c68d58ebf4d4e001a47
This commit is contained in:
Deomid Ryabkov authored and rojer committed 2016-03-21 22:45:54 +00:00
1 parent 4f9627c612
commit f1cc8379e7
6 files changed
+27 -40

No files matched your search

+14 -4
View File
@@ -16,7 +16,6 @@
#include "esp_common.h"
/* Makes fprintf(stdout) and stderr work. */
/*
_ssize_t _write_r(struct _reent *r, int fd, void *buf, size_t len) {
if (fd == 1 || fd == 2) {
size_t i;
@@ -27,7 +26,6 @@ _ssize_t _write_r(struct _reent *r, int fd, void *buf, size_t len) {
}
return -1;
}
*/
/*
* You'll need to implement _open_r and friends if you want file operations. See
@@ -47,9 +45,21 @@ void _exit(int status) {
abort();
}
/*
* This will prevent counter wrap if time is read regularly.
* At least Mongoose poll queries time, so we're covered.
*/
int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tzp) {
static uint32_t prev_time = 0;
static uint32_t num_overflows = 0;
uint32_t time = system_get_time();
tp->tv_sec = time / 1000000;
tp->tv_usec = time % 1000000;
uint64_t time64 = time;
if (prev_time > 0 && time < prev_time) num_overflows++;
time64 += (((uint64_t) num_overflows) * (1ULL << 32));
tp->tv_sec = time64 / 1000000ULL;
tp->tv_usec = time64 % 1000000ULL;
prev_time = time;
return 0;
(void) r;
(void) tzp;
}