mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Fix millis rollover
This commit is contained in:
parent
b924b59c86
commit
c17e86842e
@ -30,14 +30,12 @@ extern void esp_schedule();
|
|||||||
extern void esp_yield();
|
extern void esp_yield();
|
||||||
|
|
||||||
static os_timer_t delay_timer;
|
static os_timer_t delay_timer;
|
||||||
|
static os_timer_t micros_overflow_timer;
|
||||||
|
static uint32_t micros_at_last_overflow_tick = 0;
|
||||||
|
static uint32_t micros_overflow_count = 0;
|
||||||
#define ONCE 0
|
#define ONCE 0
|
||||||
#define REPEAT 1
|
#define REPEAT 1
|
||||||
|
|
||||||
unsigned long millis()
|
|
||||||
{
|
|
||||||
unsigned long m = system_get_time() / 1000;
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
void delay_end(void* arg)
|
void delay_end(void* arg)
|
||||||
{
|
{
|
||||||
@ -62,10 +60,24 @@ void delay(unsigned long ms)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void micros_overflow_tick(void* arg)
|
||||||
|
{
|
||||||
|
uint32_t m = system_get_time();
|
||||||
|
if (m < micros_at_last_overflow_tick)
|
||||||
|
++micros_overflow_count;
|
||||||
|
micros_at_last_overflow_tick = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long millis()
|
||||||
|
{
|
||||||
|
uint32_t m = system_get_time();
|
||||||
|
uint32_t c = micros_overflow_count + ((m < micros_at_last_overflow_tick) ? 1 : 0);
|
||||||
|
return c * 4294967 + m / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long micros()
|
unsigned long micros()
|
||||||
{
|
{
|
||||||
unsigned long m = system_get_time();
|
return system_get_time();
|
||||||
return m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void delayMicroseconds(unsigned int us)
|
void delayMicroseconds(unsigned int us)
|
||||||
@ -76,4 +88,6 @@ void delayMicroseconds(unsigned int us)
|
|||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
initPins();
|
initPins();
|
||||||
|
os_timer_setfn(µs_overflow_timer, (os_timer_func_t*) µs_overflow_tick, 0);
|
||||||
|
os_timer_arm(µs_overflow_timer, 60000, REPEAT);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user