From 79ac908472766400f8c6ee6fbc441a8ecd9eb5a5 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Fri, 17 Aug 2018 15:22:49 +0100 Subject: [PATCH] add ESP32 impl --- timed.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/timed.cpp b/timed.cpp index 92a98ed..9bdd7ba 100644 --- a/timed.cpp +++ b/timed.cpp @@ -1,17 +1,18 @@ -#ifdef notdef +#include -#include -#include +#if defined(__LM4F120H5QR__) #include #include #include #include +#endif #include "timed.h" static Timed *t; // FIXME: disable timer when tick() returns false +#if defined(__LM4F120H5QR__) static void timer0isr(void) { ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); t->tick(); @@ -27,4 +28,16 @@ void timer_create(unsigned freq, Timed *client) { ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet() / freq); } +#elif defined(ESP_PLATFORM) + +void IRAM_ATTR onTimer() { + t->tick(); +} + +void timer_create(unsigned freq, Timed *client) { + hw_timer_t *timer = timerBegin(3, 80, true); // prescaler of 80 + timerAttachInterrupt(timer, &onTimer, true); + timerAlarmWrite(timer, 1000000 / freq, true); + timerAlarmEnable(timer); +} #endif