Skip to content

Commit

Permalink
kernel/os: Fix issue that causes WDOG reset reason to be lost
Browse files Browse the repository at this point in the history
In the default irq handler, hal_watchdog_tickle() was called before doing a core dump
but on Dialog da1469x this causes the reset reason to be lost, and reboot log was
recording the reset reason as HAL_RESET_SOFT instead of HAL_RESET_WDOG.

The issue is fixed by calling hal_watchdog_disable() instead of hal_watchdog_tickle()
before doing a core dump.

This PR also adds hal_watchdog_disable() to the HAL API for all MCUs (for now it
is implemented only for Dialog da1469x and CMAC).
  • Loading branch information
benmccrea committed Oct 13, 2023
1 parent c9a3c6b commit 3a768ba
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 1 deletion.
5 changes: 5 additions & 0 deletions hw/hal/include/hal/hal_watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ int hal_watchdog_init(uint32_t expire_msecs);
*/
void hal_watchdog_enable(void);

/**
* Stops the watchdog.
*/
void hal_watchdog_disable(void);

/**
* Tickles the watchdog. This needs to be done periodically, before
* the value configured in :c:func:`hal_watchdog_init()` expires.
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/ambiq/apollo2/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ hal_watchdog_enable(void)
/* XXX: Unimplemented. */
}

void
hal_watchdog_disable(void)
{
/* XXX: Unimplemented. */
}

void
hal_watchdog_tickle(void)
{
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/ambiq/apollo3/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ hal_watchdog_enable(void)
/* XXX: Unimplemented. */
}

void
hal_watchdog_disable(void)
{
/* XXX: Unimplemented. */
}

void
hal_watchdog_tickle(void)
{
Expand Down
5 changes: 5 additions & 0 deletions hw/mcu/arc/snps/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ hal_watchdog_enable(void)
{
}

void
hal_watchdog_disable(void)
{
}

void
hal_watchdog_tickle(void)
{
Expand Down
7 changes: 7 additions & 0 deletions hw/mcu/dialog/cmac/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ hal_watchdog_enable(void)
hal_watchdog_tickle();
}

void
hal_watchdog_disable(void)
{
GPREG->SET_FREEZE_REG |= GPREG_SET_FREEZE_REG_FRZ_CMAC_WDOG_Msk;
return;
}

void
hal_watchdog_tickle(void)
{
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/dialog/da1469x/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ hal_watchdog_enable(void)
GPREG->RESET_FREEZE_REG |= GPREG_RESET_FREEZE_REG_FRZ_SYS_WDOG_Msk;
}

void
hal_watchdog_disable(void)
{
GPREG->SET_FREEZE_REG |= GPREG_SET_FREEZE_REG_FRZ_SYS_WDOG_Msk;
}

void
hal_watchdog_tickle(void)
{
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/microchip/pic32mx470f512h/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ hal_watchdog_enable(void)
WDTCONSET = _WDTCON_ON_MASK;
}

void
hal_watchdog_disable(void)
{
return;
}

void
hal_watchdog_tickle(void)
{
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/microchip/pic32mz/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ hal_watchdog_enable(void)
WDTCONSET = _WDTCON_ON_MASK;
}

void
hal_watchdog_disable(void)
{
return;
}

void
hal_watchdog_tickle(void)
{
Expand Down
5 changes: 5 additions & 0 deletions hw/mcu/mips/danube/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ hal_watchdog_enable(void)
{
}

void
hal_watchdog_disable(void)
{
}

void
hal_watchdog_tickle(void)
{
Expand Down
5 changes: 5 additions & 0 deletions hw/mcu/native/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ hal_watchdog_enable(void)
{
}

void
hal_watchdog_disable(void)
{
}

void
hal_watchdog_tickle(void)
{
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ hal_watchdog_enable(void)
NRF_WDT->TASKS_START = 1;
}

void
hal_watchdog_disable(void)
{
return;
}

void
hal_watchdog_tickle(void)
{
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ hal_watchdog_enable(void)
NRF_WDT->TASKS_START = 1;
}

void
hal_watchdog_disable(void)
{
return;
}

void
hal_watchdog_tickle(void)
{
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/nordic/nrf5340/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ hal_watchdog_enable(void)
NRF_WDT0->TASKS_START = 1;
}

void
hal_watchdog_disable(void)
{
return;
}

void
hal_watchdog_tickle(void)
{
Expand Down
5 changes: 5 additions & 0 deletions hw/mcu/nordic/nrf5340_net/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ hal_watchdog_enable(void)
NRF_WDT_NS->TASKS_START = 1;
}

void
hal_watchdog_disable(void)
{
}

void
hal_watchdog_tickle(void)
{
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/nordic/nrf91xx/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ hal_watchdog_enable(void)
NRF_WDT->TASKS_START = 1;
}

void
hal_watchdog_disable(void)
{
return;
}

void
hal_watchdog_tickle(void)
{
Expand Down
5 changes: 5 additions & 0 deletions hw/mcu/nxp/kinetis/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ void hal_watchdog_enable(void)
#endif
}

void hal_watchdog_disable(void)
{
return;
}

void hal_watchdog_tickle(void)
{
#ifndef WATCHDOG_STUB
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/nxp/mkw41z/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ hal_watchdog_enable(void)
return;
}

void
hal_watchdog_disable(void)
{
return;
}

void
hal_watchdog_tickle(void)
{
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/sifive/fe310/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ hal_watchdog_enable(void)
#endif
}

void
hal_watchdog_disable(void)
{
return;
}

void
hal_watchdog_tickle(void)
{
Expand Down
6 changes: 6 additions & 0 deletions hw/mcu/stm/stm32_common/src/hal_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ hal_watchdog_enable(void)
HAL_IWDG_Init(&g_wdt_cfg);
}

void
hal_watchdog_disable(void)
{
return;
}

void
hal_watchdog_tickle(void)
{
Expand Down
2 changes: 1 addition & 1 deletion kernel/os/src/arch/cortex_m33/os_fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ os_default_irq(struct trap_frame *tf)
#endif

#if MYNEWT_VAL(OS_COREDUMP)
hal_watchdog_tickle();
hal_watchdog_disable();
#if MYNEWT_VAL(OS_COREDUMP_CB)
os_coredump_cb(tf);
#else
Expand Down

0 comments on commit 3a768ba

Please sign in to comment.