diff --git a/r65emu.h b/r65emu.h index fd8b5f8..ed8eb9c 100644 --- a/r65emu.h +++ b/r65emu.h @@ -11,6 +11,7 @@ #include "utftdisplay.h" #include "keyboard.h" #include "sdtape.h" +#include "timed.h" #include "hardware.h" #endif diff --git a/timed.cpp b/timed.cpp new file mode 100644 index 0000000..7ef3bb9 --- /dev/null +++ b/timed.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include +#include + +#include "timed.h" + +static Timed *t; + +// FIXME: disable timer when tick() returns false +static void timer0isr(void) { + ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); + t->tick(); +} + +void timer_create(unsigned freq, Timed *client) { + t = client; + ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); + ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); + TimerIntRegister(TIMER0_BASE, TIMER_A, timer0isr); + ROM_TimerEnable(TIMER0_BASE, TIMER_A); + ROM_IntEnable(INT_TIMER0A); + ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); + ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet() / freq); +} diff --git a/timed.h b/timed.h new file mode 100644 index 0000000..2644af5 --- /dev/null +++ b/timed.h @@ -0,0 +1,11 @@ +#ifndef __TIMED_H__ +#define __TIMED_H__ + +class Timed { +public: + virtual bool tick() = 0; +}; + +void timer_create(unsigned freq, Timed *client); + +#endif