From e1c74b41a0bc6e76fe863b97599c3c5195bc16a7 Mon Sep 17 00:00:00 2001 From: Nehemiah Negussie Date: Sat, 22 Jan 2022 23:07:55 +0000 Subject: [PATCH 1/2] Completed Firmware 102 homework, request for code review --- projects/timer_hw/README.md | 16 ++++++++++ projects/timer_hw/rules.mk | 9 ++++++ projects/timer_hw/src/main.c | 61 ++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 projects/timer_hw/README.md create mode 100644 projects/timer_hw/rules.mk create mode 100644 projects/timer_hw/src/main.c 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..45a12ad49 --- /dev/null +++ b/projects/timer_hw/src/main.c @@ -0,0 +1,61 @@ +#include "interrupt.h" +#include "soft_timer.h" +#include "log.h" +#include "wait.h" + +#include +#include + +#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; +} From b1a2c2aa539049adf7684d0b2b2cb829366f2535 Mon Sep 17 00:00:00 2001 From: Nehemiah Negussie Date: Sun, 23 Jan 2022 23:36:54 +0000 Subject: [PATCH 2/2] Updated formatting for 102 hw --- projects/timer_hw/src/main.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/projects/timer_hw/src/main.c b/projects/timer_hw/src/main.c index 45a12ad49..ac69553c3 100644 --- a/projects/timer_hw/src/main.c +++ b/projects/timer_hw/src/main.c @@ -1,11 +1,11 @@ +#include +#include + #include "interrupt.h" -#include "soft_timer.h" #include "log.h" +#include "soft_timer.h" #include "wait.h" -#include -#include - #define COUNTER_PERIOD_MS 500 typedef struct Counters { @@ -18,13 +18,10 @@ 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); + + soft_timer_start_millis(COUNTER_PERIOD_MS, prv_timer_callback_2, storage, NULL); } void prv_timer_callback_2(SoftTimerId timer_id, void *context) { @@ -35,27 +32,20 @@ void prv_timer_callback_2(SoftTimerId timer_id, void *context) { 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); + 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); - + + soft_timer_start_millis(COUNTER_PERIOD_MS, prv_timer_callback, &storage, NULL); + while (true) { wait(); } - + return 0; }