diff options
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/timertest/Makefile.inc | 3 | ||||
-rw-r--r-- | src/app/timertest/main.cc | 43 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/app/timertest/Makefile.inc b/src/app/timertest/Makefile.inc new file mode 100644 index 0000000..9d375f1 --- /dev/null +++ b/src/app/timertest/Makefile.inc @@ -0,0 +1,3 @@ +loop ?= 1 +timer_s ?= 1 +arch_drivers += ,timer diff --git a/src/app/timertest/main.cc b/src/app/timertest/main.cc new file mode 100644 index 0000000..23f0b60 --- /dev/null +++ b/src/app/timertest/main.cc @@ -0,0 +1,43 @@ +#include "arch.h" +#include "driver/gpio.h" +#include "driver/stdout.h" +#include "driver/timer.h" +#include "driver/uptime.h" + +#ifndef F_TIMER +#define F_TIMER 100000 +#endif + +volatile unsigned long int timer_val = 0; + +void loop(void) +{ + gpio.led_toggle(1); + kout << "Actual frequency: approx. " << timer_val << " Hz" << endl; + timer_val = 0; +} + +int main(void) +{ + arch.setup(); + gpio.setup(); + kout.setup(); +#if F_TIMER > 999 + timer.setup_khz(F_TIMER / 1000); +#else + timer.setup_hz(F_TIMER); +#endif + timer.start(1); + + gpio.led_on(0); + kout << "Timer running at " << dec << F_TIMER << " Hz" << endl; + + arch.idle_loop(); + + return 0; +} + +ON_TIMER_INTERRUPT_head + gpio.led_toggle(0); + timer_val++; +ON_TIMER_INTERRUPT_tail |