This repository was archived by the owner on Oct 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
[SOFT-999] Completed Firmware 102 homework, request for code review #488
Open
nehemiah-negussie
wants to merge
2
commits into
master
Choose a base branch
from
soft_999_nehemiah_negussie_fw_102
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
|
Contributor
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 🙂
Contributor
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; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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