wes3 commented on a change in pull request #1299: [RFC] [NRF52] Remove uint64_t
div in watchdog init
URL: https://github.com/apache/mynewt-core/pull/1299#discussion_r205834969
##########
File path: hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c
##########
@@ -44,13 +44,20 @@ nrf52_wdt_irq_handler(void)
int
hal_watchdog_init(uint32_t expire_msecs)
{
- uint64_t expiration;
-
NRF_WDT->CONFIG = WDT_CONFIG_SLEEP_Msk;
- /* Convert msec timeout to counts of a 32768 crystal */
- expiration = ((uint64_t)expire_msecs * 32768) / 1000;
- NRF_WDT->CRV = (uint32_t)expiration;
+ if (expire_msecs >= 1048576) {
+ /* watchdog with more than 17 minutes? */
+ assert(0);
+ } else {
+ uint32_t e = expire_msecs, rtc = 32768, d = 1000;
+ while (e >= 131072) {
+ e /= 2;
+ rtc /= 2;
+ d /= 2;
Review comment:
I think you could do this in the following manner and get much more range. I
probably should have done this from the start but did not worry about the
65-bit divide. We are trying to do the following: (x * 32768) / 1000. This is
the same as doing this: x * 32.768. Since we do not want to use floating point
you can do this: (x * 32) + ((x * 768) / 1000) which is also this: (x * 32) +
((x * 96) / 125). You can then get much more range.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services