diff --git a/projects/timer_hw/README.md b/projects/timer_hw/README.md new file mode 100644 index 000000000..6b8c4f179 --- /dev/null +++ b/projects/timer_hw/README.md @@ -0,0 +1,16 @@ + +# timer_hw + diff --git a/projects/timer_hw/rules.mk b/projects/timer_hw/rules.mk new file mode 100644 index 000000000..f1806d7cd --- /dev/null +++ b/projects/timer_hw/rules.mk @@ -0,0 +1,9 @@ +# Defines $(T)_SRC, $(T)_INC, $(T)_DEPS, and $(T)_CFLAGS for the build makefile. +# Tests can be excluded by defining $(T)_EXCLUDE_TESTS. +# Pre-defined: +# $(T)_SRC_ROOT: $(T)_DIR/src +# $(T)_INC_DIRS: $(T)_DIR/inc{/$(PLATFORM)} +# $(T)_SRC: $(T)_DIR/src{/$(PLATFORM)}/*.{c,s} + +# Specify the libraries you want to include +$(T)_DEPS := ms-common diff --git a/projects/timer_hw/src/main.c b/projects/timer_hw/src/main.c new file mode 100644 index 000000000..ac69553c3 --- /dev/null +++ b/projects/timer_hw/src/main.c @@ -0,0 +1,51 @@ +#include +#include + +#include "interrupt.h" +#include "log.h" +#include "soft_timer.h" +#include "wait.h" + +#define COUNTER_PERIOD_MS 500 + +typedef struct Counters { + uint8_t counter_a; + uint8_t counter_b; +} Counters; + +void prv_timer_callback_2(SoftTimerId timer_id, void *context); + +void prv_timer_callback(SoftTimerId timer_id, void *context) { + Counters *storage = context; + storage->counter_a++; + + LOG_DEBUG("Counter A: %i\n", storage->counter_a); + + soft_timer_start_millis(COUNTER_PERIOD_MS, prv_timer_callback_2, storage, NULL); +} + +void prv_timer_callback_2(SoftTimerId timer_id, void *context) { + Counters *storage = context; + storage->counter_a++; + storage->counter_b++; + + LOG_DEBUG("Counter A: %i\n", storage->counter_a); + LOG_DEBUG("Counter B: %i\n", storage->counter_b); + + soft_timer_start_millis(COUNTER_PERIOD_MS, prv_timer_callback, storage, NULL); +} + +int main() { + interrupt_init(); + soft_timer_init(); + + Counters storage = { 0 }; + + soft_timer_start_millis(COUNTER_PERIOD_MS, prv_timer_callback, &storage, NULL); + + while (true) { + wait(); + } + + return 0; +}