1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Implement delay()

This commit is contained in:
Ivan Grokhotkov 2014-11-21 12:16:12 +03:00
parent 15b434f5e2
commit c55b5a89eb

View File

@ -26,6 +26,14 @@
#include "ets_sys.h" #include "ets_sys.h"
#include "osapi.h" #include "osapi.h"
#include "user_interface.h" #include "user_interface.h"
#include "cont.h"
extern cont_t g_cont;
extern void loop_schedule();
static os_timer_t delay_timer;
#define ONCE 0
#define REPEAT 1
unsigned long millis() unsigned long millis()
{ {
@ -33,9 +41,17 @@ unsigned long millis()
return m; return m;
} }
void delay_end(void* arg)
{
loop_schedule();
}
void delay(unsigned long ms) void delay(unsigned long ms)
{ {
os_delay_us(1000*ms); os_timer_setfn(&delay_timer, (os_timer_func_t*) &delay_end, 0);
os_timer_arm(&delay_timer, ms, ONCE);
cont_yield(&g_cont);
os_timer_disarm(&delay_timer);
} }
unsigned long micros() unsigned long micros()
@ -51,5 +67,5 @@ void delayMicroseconds(unsigned int us)
void init() void init()
{ {
system_timer_reinit(); // system_timer_reinit();
} }