From 168156d210897bacb4e703a822bc444784c04da5 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 16 Nov 2014 16:09:55 +0300 Subject: [PATCH] Wiring time functions --- cores/esp8266/wiring.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/cores/esp8266/wiring.c b/cores/esp8266/wiring.c index 6afe05cb9..36e078dad 100644 --- a/cores/esp8266/wiring.c +++ b/cores/esp8266/wiring.c @@ -23,46 +23,33 @@ */ #include "wiring_private.h" - -// the prescaler is set so that timer0 ticks every 64 clock cycles, and the -// the overflow handler is called every 256 ticks. -#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256)) - -// the whole number of milliseconds per timer0 overflow -#define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000) - -// the fractional number of milliseconds per timer0 overflow. we shift right -// by three to fit these numbers into a byte. (for the clock speeds we care -// about - 8 and 16 MHz - this doesn't lose precision.) -#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) -#define FRACT_MAX (1000 >> 3) - -volatile unsigned long timer0_overflow_count = 0; -volatile unsigned long timer0_millis = 0; -static unsigned char timer0_fract = 0; - +#include "ets_sys.h" +#include "osapi.h" +#include "user_interface.h" unsigned long millis() { - unsigned long m = 0; - - return m; -} - -unsigned long micros() { - unsigned long m = 0; - + unsigned long m = system_get_time() / 1000; return m; } void delay(unsigned long ms) { + os_delay_us(1000*ms); +} + +unsigned long micros() +{ + unsigned long m = system_get_time(); + return m; } void delayMicroseconds(unsigned int us) { + os_delay_us(us); } void init() { + system_timer_reinit(); }