mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Implement delay()
This commit is contained in:
parent
15b434f5e2
commit
c55b5a89eb
@ -26,30 +26,46 @@
|
|||||||
#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()
|
||||||
{
|
{
|
||||||
unsigned long m = system_get_time() / 1000;
|
unsigned long m = system_get_time() / 1000;
|
||||||
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()
|
||||||
{
|
{
|
||||||
unsigned long m = system_get_time();
|
unsigned long m = system_get_time();
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void delayMicroseconds(unsigned int us)
|
void delayMicroseconds(unsigned int us)
|
||||||
{
|
{
|
||||||
os_delay_us(us);
|
os_delay_us(us);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
system_timer_reinit();
|
// system_timer_reinit();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user