Skip to content

Commit

Permalink
[Watchdog] Fix code based on sigprof's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna committed Feb 17, 2025
1 parent fe0f6d6 commit c9fc0d7
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions users/drashna/features/watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@
# include <math.h>
# include <stddef.h>

# if defined(MCU_STM32)
// STM32-specific watchdog config calculations
// timeout = tick * PR * (RL + 1)
// tick = 1000000 / (lsi) clock
# if !defined(WATCHDOG_CLOCK)
# if defined(MCU_STM32)
# if !defined(WATCHDOG_CLOCK)
# define WATCHDOG_CLOCK STM32_LSICLK
# elif defined(MCU_RP)
# define WATCHDOG_CLOCK RP_XOSCCLK
# endif
# endif // !defined(WATCHDOG_CLOCK)

# define _IWDG_LSI(us) ((us) * WATCHDOG_CLOCK / 1000000)
# define _IWDG_PR_US(us) (uint8_t)(log(_IWDG_LSI(us)) / log(2) - 11) // 3
# define _IWDG_PR_S(s) _IWDG_PR_US(s * 1000000.0)
# define _IWDG_SCALAR(us) (2 << ((uint8_t)_IWDG_PR_US(us) + 1))
# define _IWDG_RL_US(us) (uint64_t)(_IWDG_LSI(us)) / _IWDG_SCALAR(us)
# define _IWDG_RL_S(s) _IWDG_RL_US(s * 1000000.0)
# endif // !defined(WATCHDOG_CLOCK)

# define _IWDG_LSI(us) ((us) * WATCHDOG_CLOCK / 1000000)
# define _IWDG_PR_US(us) (uint8_t)(log(_IWDG_LSI(us)) / log(2) - 11) // 3
# define _IWDG_PR_S(s) _IWDG_PR_US(s * 1000000.0)
# define _IWDG_SCALAR(us) (2 << ((uint8_t)_IWDG_PR_US(us) + 1))
# define _IWDG_RL_US(us) (uint64_t)(_IWDG_LSI(us)) / _IWDG_SCALAR(us)
# define _IWDG_RL_S(s) _IWDG_RL_US(s * 1000000.0)
# elif defined(MCU_RP)
// investigate the actual timing this uses
# define _IWDG_RL_S(s) (uint32_t)(s * 1000)
# else
# error "Current MCU not supported yet"
# endif

# if !defined(WATCHDOG_TIMEOUT)
# define WATCHDOG_TIMEOUT 5.0f
Expand Down

0 comments on commit c9fc0d7

Please sign in to comment.