Software timer manager for embedded systems.
C99 | Zero dependencies | Zero allocations | Oneshot + Periodic | Portable
Embedded main loops often contain repeated timing checks:
if (now - last_blink > 500) { toggle_led(); last_blink = now; }
if (now - last_send > 5000) { send_telemetry(); last_send = now; }
if (now - last_check > 1000) { check_sensors(); last_check = now; }microtimer replaces this with registered timers and a single tick path:
mtimer_create(&tm, "blink", 500, MTIMER_PERIODIC, on_blink, NULL);
mtimer_create(&tm, "send", 5000, MTIMER_PERIODIC, on_send, NULL);
mtimer_create(&tm, "timeout", 3000, MTIMER_ONESHOT, on_timeout, NULL);
while (1) {
mtimer_tick(&tm);
}- Oneshot timers that auto-stop after firing.
- Periodic timers with drift correction.
- Pause/resume with remaining-time preservation.
- Dynamic interval changes at runtime.
- Slot reuse through destroy/create.
- Named timer lookup for diagnostics and shell commands.
- Per-timer and global fire counters.
Requirements:
- C99 compiler (
gccorclang) make
Run tests:
# clone microtest next to this repository root
# expected path: ../microtest/include
make -C testsKey functions:
mtimer_initmtimer_create,mtimer_destroymtimer_start,mtimer_stop,mtimer_pause,mtimer_resumemtimer_set_intervalmtimer_tickmtimer_count,mtimer_find,mtimer_remaining
See include/mtimer.h for full API details.
include/mtimer.h- public APIsrc/mtimer.c- implementationtests/test_all.c- unit testsdocs/DESIGN.md- design rationale
MTIMER_MAX_TIMERS(default:8)
See CONTRIBUTING.md.
See CHANGELOG.md.
MIT - see LICENSE.