Skip to content

drivers: watchdog: Watchdog API redesign [RFC] #1260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ The Zephyr APIs are used the same way on all SoCs and boards.
bluetooth.rst
networking.rst
io_interfaces.rst
timer_counter_interfaces.rst
power_management_api
file_system
15 changes: 15 additions & 0 deletions doc/api/timer_counter_interfaces.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.. _timer_counter_interfaces:

Timer / Counter Driver APIs
###########################

.. contents::
:depth: 1
:local:
:backlinks: top

Watchdog Interface
******************

.. doxygengroup:: watchdog_interface
:project: Zephyr
37 changes: 32 additions & 5 deletions drivers/watchdog/Kconfig
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
# Kconfig - Watchdog configuration options
#
#
# Copyright (c) 2015 Intel Corporation
# Copyright (c) 2017 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
#

#
# Watchdog options
#
menuconfig WATCHDOG
bool
prompt "Watchdog Support"
default n
help
Include support for watchdogs.

if WATCHDOG

config WDT_DISABLE_AT_BOOT
bool
prompt "Disable at boot"
help
Disable watchdog at Zephyr system startup.

config SYS_LOG_WDT_LEVEL
int
prompt "Watchdog Driver Log level"
depends on SYS_LOG
default 0
range 0 4
help
Sets log level for Watchdog drivers.
Levels are:
0 OFF, do not write
1 ERROR, only write SYS_LOG_ERR
2 WARNING, write SYS_LOG_WRN in addition to previous level
3 INFO, write SYS_LOG_INF in addition to previous levels
4 DEBUG, write SYS_LOG_DBG in addition to previous levels

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to add WDT_DISABLE_AT_BOOT option to Kconfig to allow disabling watchdog at boot. Useful at the initial stage of the project development as well as for many sample applications where we don't explicitly handle watchdogs.

Copy link
Collaborator Author

@m-kru m-kru Sep 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mnkp Should it depend on WATCHDOG? It would be funny if you enable WATCHDOG to disable it :).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but actually it should depend on WATCHDOG. If the watchdog subsystem is not enabled we can't disable it.

Copy link
Collaborator Author

@m-kru m-kru Sep 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mnkp You think it should be default y or default n?
By the way which one is correct: at boot or on boot?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be default n. The board defconfig file can still choose to set it to default y if deemed required.

Later we should only ensure that all the applications in samples/ directory that don't explicitly handle watchdog have WDT_DISABLE_AT_BOOT option enabled.

config HAVE_WDT_MULTISTAGE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i there any SoC which has it already?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESP32 supports 4 watchdog stages.

bool

config WDT_MULTISTAGE
bool
prompt "Enable multistage timeouts"
depends on HAVE_WDT_MULTISTAGE
help
Enable multistage operation of watchdog timeouts.

source "drivers/watchdog/Kconfig.qmsi"

source "drivers/watchdog/Kconfig.stm32"
Expand Down
4 changes: 3 additions & 1 deletion drivers/watchdog/iwdg_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ static void iwdg_stm32_enable(struct device *dev)
iwdg->kr.bit.key = STM32_IWDG_KR_START;
}

static void iwdg_stm32_disable(struct device *dev)
static int iwdg_stm32_disable(struct device *dev)
{
/* watchdog cannot be stopped once started */
ARG_UNUSED(dev);

return 0;
}

static int iwdg_stm32_set_config(struct device *dev,
Expand Down
4 changes: 3 additions & 1 deletion drivers/watchdog/wdog_cmsdk_apb.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ static void wdog_cmsdk_apb_enable(struct device *dev)
wdog->ctrl = (CMSDK_APB_WDOG_CTRL_RESEN | CMSDK_APB_WDOG_CTRL_INTEN);
}

static void wdog_cmsdk_apb_disable(struct device *dev)
static int wdog_cmsdk_apb_disable(struct device *dev)
{
volatile struct wdog_cmsdk_apb *wdog = WDOG_STRUCT;

ARG_UNUSED(dev);

/* Stop the watchdog counter with INTEN bit */
wdog->ctrl = ~(CMSDK_APB_WDOG_CTRL_RESEN | CMSDK_APB_WDOG_CTRL_INTEN);

return 0;
}

static int wdog_cmsdk_apb_set_config(struct device *dev,
Expand Down
4 changes: 3 additions & 1 deletion drivers/watchdog/wdt_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void wdt_esp32_enable(struct device *dev)
wdt_esp32_seal();
}

static void wdt_esp32_disable(struct device *dev)
static int wdt_esp32_disable(struct device *dev)
{
volatile u32_t *reg = (u32_t *)TIMG_WDTCONFIG0_REG(1);

Expand All @@ -57,6 +57,8 @@ static void wdt_esp32_disable(struct device *dev)
wdt_esp32_unseal();
*reg &= ~BIT(TIMG_WDT_EN_S);
wdt_esp32_seal();

return 0;
}

static void adjust_timeout(u32_t timeout)
Expand Down
4 changes: 3 additions & 1 deletion drivers/watchdog/wdt_qmsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ static void enable(struct device *dev)
clk_periph_enable(CLK_PERIPH_WDT_REGISTER | CLK_PERIPH_CLK);
}

static void disable(struct device *dev)
static int disable(struct device *dev)
{
clk_periph_disable(CLK_PERIPH_WDT_REGISTER);

return 0;
}

static const struct wdt_driver_api api = {
Expand Down
4 changes: 3 additions & 1 deletion drivers/watchdog/wdt_sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ static void wdt_sam_enable(struct device *dev)
SYS_LOG_ERR("Function not implemented!");
}

static void wdt_sam_disable(struct device *dev)
static int wdt_sam_disable(struct device *dev)
{
Wdt *const wdt = DEV_CFG(dev)->regs;

wdt->WDT_MR |= WDT_MR_WDDIS;

return 0;
}

static int wdt_sam_set_config(struct device *dev, struct wdt_config *config)
Expand Down
Loading