Refactor, document and fix the Watchdog driver#1710
Conversation
Fix the configuration of the behaviours configuration that was not properly implemented (but it didn't cause any side effect since the correct value was eventually set in NRF_WDT->CONFIG). Fix the wrong interpretation of the reset reasons caused by implicit conversions of int to bool.
|
Build size and comparison to main:
|
FintasticMan
left a comment
There was a problem hiding this comment.
I personally prefer this solution to #1705.
Riksu9000
left a comment
There was a problem hiding this comment.
I like this. There are a lot of comments, but in low level code some are necessary.
There are a few potential improvements I can see, which nonetheless shouldn't be blocking. The timeout could be set using std::chrono durations, and the reset reason enum class could contain the values that the reset reason register itself may contain, so it can also be used in GetResetReason() and the value in the register doesn't need to be converted to another format.
Rename enum ResetReasons, SleepBehaviours and HaltBehaviours to ResetReason, SleepBehaviour and HaltBehaviour. Rename the function ResetReason() to GetResetReason() to avoid name conflict. Use named constants (WDT_CONFIG_HALT_Pos & WDT_CONFIG_SLEEP_Pos) from the NRF MDK instead of the numerical ones. Fix typo in the comments.
Thanks! Some comments might be a bit overkill, but they explain how the datasheet was translated into code :)
I also had this idea, but that would make the implementation of
We cannot simply cast the value of the register to the value of the enum because the register might have multiple bits that are set (especially if the register was not cleared between 2 resets). |
Refactor and document the Watchdog driver to make it more readable.
Fix the configuration of the behaviours configuration that was not properly implemented (but it didn't cause any side effect since the correct value was eventually set in NRF_WDT->CONFIG).
Fix the wrong interpretation of the reset reasons caused by implicit conversions of int to bool.
Watchdog is now probably one of the most documented class of the project. What do you think of this format? It's quite helpful in IDEs that support Doxygen like CLion:

This PR is an alternative solution to #1705.