-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SOFT-999] Completed Firmware 102 homework, request for code review #488
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!-- | ||
General guidelines | ||
These are just guidelines, not strict rules - document however seems best. | ||
A README for a firmware-only project (e.g. Babydriver, MU, bootloader, CAN explorer) should answer the following questions: | ||
- What is it? | ||
- What problem does it solve? | ||
- How do I use it? (with usage examples / example commands, etc) | ||
- How does it work? (architectural overview) | ||
A README for a board project (powering a hardware board, e.g. power distribution, centre console, charger, BMS carrier) should answer the following questions: | ||
- What is the purpose of the board? | ||
- What are all the things that the firmware needs to do? | ||
- How does it fit into the overall system? | ||
- How does it work? (architectural overview, e.g. what each module's purpose is or how data flows through the firmware) | ||
--> | ||
# timer_hw | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
#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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can (and should) do all the soft-timer functionality in one timer callback function instead of 2, see if you can figure it out, but if not feel free to ask for help 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, all private functions in a file should be declared as static, ie |
||
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry about forward declaring your functions, just declare them where you write the function bodies.
This line can go