中文 | English
This is a simple eventloop library for embedded c projects. It is designed to be simple and easy to use.
- Simple and easy to use
- No dynamic memory allocation
- No dependencies
- No operating system required
- Port easily to any platform. Without asm code.
- Low memory usage
- Implement by pure C
void async_task(void *arg) {
// do something
}
// async_task will be called after 1000ms
el_setTimeout(async_task,NULL,1000);
// async_task will be called every 1000ms
el_setInterval(async_task,NULL,1000);
el_enterLoop();
You can see more examples in examples directory.
Open el_port.h and define el_tick_t to the type of your system tick. For example, if your system tick is 32bit, you can define el_tick_t as uint32_t.
typedef uint32_t el_tick_t;
Define el_portTickGet to get system tick. System tick is the millisecond since system startup. For example, in linux, we can use gettimeofday to get system tick.
el_tick_t el_portTickGet() {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
Luckly, many platforms such as STM32 has a system tick counter. You can get system tick by reading the counter.
Run task after timeout.
void el_setTimeout(el_task_t task, void *arg, uint32_t timeout);
Run task every interval.
void el_setInterval(el_task_t task, void *arg, uint32_t interval);
Cancel timeout task.
void el_clearTimeout(el_task_t task);
Cancel interval task.
void el_clearInterval(el_task_t task);
Run eventloop.
void el_enterLoop();
MIT License
Author: Evan Xiao