diff --git a/drivers/watchdog/wdt_cmsdk_apb.c b/drivers/watchdog/wdt_cmsdk_apb.c index 4e40f3738be..69b60264de8 100644 --- a/drivers/watchdog/wdt_cmsdk_apb.c +++ b/drivers/watchdog/wdt_cmsdk_apb.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include diff --git a/drivers/watchdog/wdt_esp32.c b/drivers/watchdog/wdt_esp32.c index ff07b5adbb0..73b07cb7da8 100644 --- a/drivers/watchdog/wdt_esp32.c +++ b/drivers/watchdog/wdt_esp32.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include enum wdt_mode { diff --git a/drivers/watchdog/wdt_iwdg_stm32.c b/drivers/watchdog/wdt_iwdg_stm32.c index dbf9ca09fa4..c04c5575315 100644 --- a/drivers/watchdog/wdt_iwdg_stm32.c +++ b/drivers/watchdog/wdt_iwdg_stm32.c @@ -6,7 +6,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/drivers/watchdog/wdt_mcux_wdog.c b/drivers/watchdog/wdt_mcux_wdog.c index ab5ef28a0e4..71a49132786 100644 --- a/drivers/watchdog/wdt_mcux_wdog.c +++ b/drivers/watchdog/wdt_mcux_wdog.c @@ -5,7 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include diff --git a/drivers/watchdog/wdt_nrfx.c b/drivers/watchdog/wdt_nrfx.c index 4ee75f1972d..4709801c507 100644 --- a/drivers/watchdog/wdt_nrfx.c +++ b/drivers/watchdog/wdt_nrfx.c @@ -5,7 +5,7 @@ */ #include -#include +#include #define LOG_LEVEL CONFIG_WDT_LOG_LEVEL #include diff --git a/drivers/watchdog/wdt_qmsi.c b/drivers/watchdog/wdt_qmsi.c index e0b8c239fe4..af5e3de586d 100644 --- a/drivers/watchdog/wdt_qmsi.c +++ b/drivers/watchdog/wdt_qmsi.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -15,7 +15,7 @@ #include "clk.h" #include "qm_isr.h" #include "qm_wdt.h" -#include +#include struct wdt_data { #ifdef CONFIG_WDT_QMSI_API_REENTRANCY diff --git a/drivers/watchdog/wdt_sam.c b/drivers/watchdog/wdt_sam.c index 7ee3d3c7916..70153da243f 100644 --- a/drivers/watchdog/wdt_sam.c +++ b/drivers/watchdog/wdt_sam.c @@ -17,7 +17,7 @@ * CONFIG_WDT_DISABLE_AT_BOOT must be unset in the app's config file */ -#include +#include #include #define LOG_LEVEL CONFIG_WDT_LOG_LEVEL diff --git a/drivers/watchdog/wdt_sam0.c b/drivers/watchdog/wdt_sam0.c index b9d3f69b2eb..fe08af179aa 100644 --- a/drivers/watchdog/wdt_sam0.c +++ b/drivers/watchdog/wdt_sam0.c @@ -6,7 +6,7 @@ */ #include -#include +#include #define LOG_LEVEL CONFIG_WDT_LOG_LEVEL #include diff --git a/ext/hal/ti/simplelink/source/ti/devices/cc13x2_cc26x2/driverlib/watchdog.c b/ext/hal/ti/simplelink/source/ti/devices/cc13x2_cc26x2/driverlib/watchdog.c index 3527cff0857..2cac28c38e9 100644 --- a/ext/hal/ti/simplelink/source/ti/devices/cc13x2_cc26x2/driverlib/watchdog.c +++ b/ext/hal/ti/simplelink/source/ti/devices/cc13x2_cc26x2/driverlib/watchdog.c @@ -36,6 +36,6 @@ * ******************************************************************************/ -#include "watchdog.h" +#include // See watchdog.h for implementation diff --git a/include/drivers/watchdog.h b/include/drivers/watchdog.h new file mode 100644 index 00000000000..8e9aa58126c --- /dev/null +++ b/include/drivers/watchdog.h @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2017 Nordic Semiconductor ASA + * Copyright (c) 2015 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Public API for watchdog drivers. + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_WATCHDOG_H_ +#define ZEPHYR_INCLUDE_DRIVERS_WATCHDOG_H_ + +/** + * @brief Watchdog Interface + * @defgroup watchdog_interface Watchdog Interface + * @ingroup io_interfaces + * @{ + */ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Pause watchdog timer when CPU is in sleep state. + */ +#define WDT_OPT_PAUSE_IN_SLEEP BIT(0) + +/** + * @brief Pause watchdog timer when CPU is halted by the debugger. + */ +#define WDT_OPT_PAUSE_HALTED_BY_DBG BIT(1) + +/** + * @brief Watchdog reset flag bit field mask shift. + */ +#define WDT_FLAG_RESET_SHIFT (0) +/** + * @brief Watchdog reset flag bit field mask. + */ +#define WDT_FLAG_RESET_MASK (0x3 << WDT_FLAG_RESET_SHIFT) + +/** + * @name Watchdog Reset Behavior. + * Reset behavior after timeout. + * @{ + */ +/** No reset */ +#define WDT_FLAG_RESET_NONE (0 << WDT_FLAG_RESET_SHIFT) +/** CPU core reset */ +#define WDT_FLAG_RESET_CPU_CORE (1 << WDT_FLAG_RESET_SHIFT) +/** Global SoC reset */ +#define WDT_FLAG_RESET_SOC (2 << WDT_FLAG_RESET_SHIFT) +/** + * @} + */ + +/** + * @brief Watchdog timeout window. + * + * Each installed timeout needs feeding within the specified time window, + * otherwise the watchdog will trigger. If the watchdog instance does not + * support window timeouts then min value must be equal to 0. + * + * @param min Lower limit of watchdog feed timeout in milliseconds. + * @param max Upper limit of watchdog feed timeout in milliseconds. + * + * @note If specified values can not be precisely set they are always + * rounded up. + */ +struct wdt_window { + u32_t min; + u32_t max; +}; + +/** Watchdog callback. */ +typedef void (*wdt_callback_t)(struct device *dev, int channel_id); + +/** + * @brief Watchdog timeout configuration struct. + * + * @param window Timing parameters of watchdog timeout. + * @param callback Timeout callback. Passing NULL means that no callback + * will be run. + * @param next Pointer to the next timeout configuration. This pointer is used + * for watchdogs with staged timeouts functionality. Value must be + * NULL for single stage timeout. + * @param flags Bit field with following parts: + * + * reset [ 0 : 1 ] - perform specified reset after timeout/callback + */ +struct wdt_timeout_cfg { + struct wdt_window window; + wdt_callback_t callback; +#ifdef CONFIG_WDT_MULTISTAGE + struct wdt_timeout_cfg *next; +#endif + u8_t flags; +}; + +/** + * @typedef wdt_api_setup + * @brief Callback API for setting up watchdog instance. + * See wdt_setup() for argument descriptions + */ +typedef int (*wdt_api_setup)(struct device *dev, u8_t options); + +/** + * @typedef wdt_api_disable + * @brief Callback API for disabling watchdog instance. + * See wdt_disable() for argument descriptions + */ +typedef int (*wdt_api_disable)(struct device *dev); + +/** + * @typedef wdt_api_install_timeout + * @brief Callback API for installing new timeout. + * See wdt_install_timeout() for argument descriptions + */ +typedef int (*wdt_api_install_timeout)(struct device *dev, + const struct wdt_timeout_cfg *cfg); + +/** + * @typedef wdt_api_feed + * @brief Callback API for feeding specified watchdog timeout. + * See (wdt_feed) for argument descriptions + */ +typedef int (*wdt_api_feed)(struct device *dev, int channel_id); + +/** @cond INTERNAL_HIDDEN */ +struct wdt_driver_api { + wdt_api_setup setup; + wdt_api_disable disable; + wdt_api_install_timeout install_timeout; + wdt_api_feed feed; +}; +/** + * @endcond + */ + +/** + * @brief Set up watchdog instance. + * + * This function is used for configuring global watchdog settings that + * affect all timeouts. It should be called after installing timeouts. + * After successful return, all installed timeouts are valid and must be + * serviced periodically by calling wdt_feed(). + * + * @param dev Pointer to the device structure for the driver instance. + * @param options Configuration options as defined by the WDT_OPT_* constants + * + * @retval 0 If successful. + * @retval -ENOTSUP If any of the set options is not supported. + * @retval -EBUSY If watchdog instance has been already setup. + */ +static inline int wdt_setup(struct device *dev, u8_t options) +{ + const struct wdt_driver_api *api = + (const struct wdt_driver_api *)dev->driver_api; + + return api->setup(dev, options); +} + +/** + * @brief Disable watchdog instance. + * + * This function disables the watchdog instance and automatically uninstalls all + * timeouts. To set up a new watchdog, install timeouts and call wdt_setup() + * again. Not all watchdogs can be restarted after they are disabled. + * + * @param dev Pointer to the device structure for the driver instance. + * + * @retval 0 If successful. + * @retval -EFAULT If watchdog instance is not enabled. + * @retval -EPERM If watchdog can not be disabled directly by application code. + */ +static inline int wdt_disable(struct device *dev) +{ + const struct wdt_driver_api *api = + (const struct wdt_driver_api *)dev->driver_api; + + return api->disable(dev); +} + +/** + * @brief Install new timeout. + * + * This function must be used before wdt_setup(). Changes applied here + * have no effects until wdt_setup() is called. + * + * @param dev Pointer to the device structure for the driver instance. + * @param cfg Pointer to timeout configuration structure. + * + * @retval channel_id If successful, a non-negative value indicating the index + * of the channel to which the timeout was assigned. This + * value is supposed to be used as the parameter in calls to + * wdt_feed(). + * @retval -EBUSY If timeout can not be installed while watchdog has already + * been setup. + * @retval -ENOMEM If no more timeouts can be installed. + * @retval -ENOTSUP If any of the set flags is not supported. + * @retval -EINVAL If any of the window timeout value is out of possible range. + * This value is also returned if watchdog supports only one + * timeout value for all timeouts and the supplied timeout + * window differs from windows for alarms installed so far. + */ +static inline int wdt_install_timeout(struct device *dev, + const struct wdt_timeout_cfg *cfg) +{ + const struct wdt_driver_api *api = + (const struct wdt_driver_api *) dev->driver_api; + + return api->install_timeout(dev, cfg); +} + +/** + * @brief Feed specified watchdog timeout. + * + * @param dev Pointer to the device structure for the driver instance. + * @param channel_id Index of the fed channel. + * + * @retval 0 If successful. + * @retval -EINVAL If there is no installed timeout for supplied channel. + */ +static inline int wdt_feed(struct device *dev, int channel_id) +{ + const struct wdt_driver_api *api = + (const struct wdt_driver_api *)dev->driver_api; + + return api->feed(dev, channel_id); +} + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif /* _ZEPHYR_WATCHDOG_H__ */ diff --git a/include/watchdog.h b/include/watchdog.h index 09bdddc77ce..15e4749a1c4 100644 --- a/include/watchdog.h +++ b/include/watchdog.h @@ -1,248 +1,15 @@ /* - * Copyright (c) 2017 Nordic Semiconductor ASA - * Copyright (c) 2015 Intel Corporation + * Copyright (c) 2019 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ - -/** - * @file - * @brief Public API for watchdog drivers. - */ - #ifndef ZEPHYR_INCLUDE_WATCHDOG_H_ #define ZEPHYR_INCLUDE_WATCHDOG_H_ -/** - * @brief Watchdog Interface - * @defgroup watchdog_interface Watchdog Interface - * @ingroup io_interfaces - * @{ - */ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { +#ifndef CONFIG_COMPAT_INCLUDES +#warning "This header file has moved, include instead." #endif -/** - * @brief Pause watchdog timer when CPU is in sleep state. - */ -#define WDT_OPT_PAUSE_IN_SLEEP BIT(0) +#include -/** - * @brief Pause watchdog timer when CPU is halted by the debugger. - */ -#define WDT_OPT_PAUSE_HALTED_BY_DBG BIT(1) - -/** - * @brief Watchdog reset flag bit field mask shift. - */ -#define WDT_FLAG_RESET_SHIFT (0) -/** - * @brief Watchdog reset flag bit field mask. - */ -#define WDT_FLAG_RESET_MASK (0x3 << WDT_FLAG_RESET_SHIFT) - -/** - * @name Watchdog Reset Behavior. - * Reset behavior after timeout. - * @{ - */ -/** No reset */ -#define WDT_FLAG_RESET_NONE (0 << WDT_FLAG_RESET_SHIFT) -/** CPU core reset */ -#define WDT_FLAG_RESET_CPU_CORE (1 << WDT_FLAG_RESET_SHIFT) -/** Global SoC reset */ -#define WDT_FLAG_RESET_SOC (2 << WDT_FLAG_RESET_SHIFT) -/** - * @} - */ - -/** - * @brief Watchdog timeout window. - * - * Each installed timeout needs feeding within the specified time window, - * otherwise the watchdog will trigger. If the watchdog instance does not - * support window timeouts then min value must be equal to 0. - * - * @param min Lower limit of watchdog feed timeout in milliseconds. - * @param max Upper limit of watchdog feed timeout in milliseconds. - * - * @note If specified values can not be precisely set they are always - * rounded up. - */ -struct wdt_window { - u32_t min; - u32_t max; -}; - -/** Watchdog callback. */ -typedef void (*wdt_callback_t)(struct device *dev, int channel_id); - -/** - * @brief Watchdog timeout configuration struct. - * - * @param window Timing parameters of watchdog timeout. - * @param callback Timeout callback. Passing NULL means that no callback - * will be run. - * @param next Pointer to the next timeout configuration. This pointer is used - * for watchdogs with staged timeouts functionality. Value must be - * NULL for single stage timeout. - * @param flags Bit field with following parts: - * - * reset [ 0 : 1 ] - perform specified reset after timeout/callback - */ -struct wdt_timeout_cfg { - struct wdt_window window; - wdt_callback_t callback; -#ifdef CONFIG_WDT_MULTISTAGE - struct wdt_timeout_cfg *next; -#endif - u8_t flags; -}; - -/** - * @typedef wdt_api_setup - * @brief Callback API for setting up watchdog instance. - * See wdt_setup() for argument descriptions - */ -typedef int (*wdt_api_setup)(struct device *dev, u8_t options); - -/** - * @typedef wdt_api_disable - * @brief Callback API for disabling watchdog instance. - * See wdt_disable() for argument descriptions - */ -typedef int (*wdt_api_disable)(struct device *dev); - -/** - * @typedef wdt_api_install_timeout - * @brief Callback API for installing new timeout. - * See wdt_install_timeout() for argument descriptions - */ -typedef int (*wdt_api_install_timeout)(struct device *dev, - const struct wdt_timeout_cfg *cfg); - -/** - * @typedef wdt_api_feed - * @brief Callback API for feeding specified watchdog timeout. - * See (wdt_feed) for argument descriptions - */ -typedef int (*wdt_api_feed)(struct device *dev, int channel_id); - -/** @cond INTERNAL_HIDDEN */ -struct wdt_driver_api { - wdt_api_setup setup; - wdt_api_disable disable; - wdt_api_install_timeout install_timeout; - wdt_api_feed feed; -}; -/** - * @endcond - */ - -/** - * @brief Set up watchdog instance. - * - * This function is used for configuring global watchdog settings that - * affect all timeouts. It should be called after installing timeouts. - * After successful return, all installed timeouts are valid and must be - * serviced periodically by calling wdt_feed(). - * - * @param dev Pointer to the device structure for the driver instance. - * @param options Configuration options as defined by the WDT_OPT_* constants - * - * @retval 0 If successful. - * @retval -ENOTSUP If any of the set options is not supported. - * @retval -EBUSY If watchdog instance has been already setup. - */ -static inline int wdt_setup(struct device *dev, u8_t options) -{ - const struct wdt_driver_api *api = - (const struct wdt_driver_api *)dev->driver_api; - - return api->setup(dev, options); -} - -/** - * @brief Disable watchdog instance. - * - * This function disables the watchdog instance and automatically uninstalls all - * timeouts. To set up a new watchdog, install timeouts and call wdt_setup() - * again. Not all watchdogs can be restarted after they are disabled. - * - * @param dev Pointer to the device structure for the driver instance. - * - * @retval 0 If successful. - * @retval -EFAULT If watchdog instance is not enabled. - * @retval -EPERM If watchdog can not be disabled directly by application code. - */ -static inline int wdt_disable(struct device *dev) -{ - const struct wdt_driver_api *api = - (const struct wdt_driver_api *)dev->driver_api; - - return api->disable(dev); -} - -/** - * @brief Install new timeout. - * - * This function must be used before wdt_setup(). Changes applied here - * have no effects until wdt_setup() is called. - * - * @param dev Pointer to the device structure for the driver instance. - * @param cfg Pointer to timeout configuration structure. - * - * @retval channel_id If successful, a non-negative value indicating the index - * of the channel to which the timeout was assigned. This - * value is supposed to be used as the parameter in calls to - * wdt_feed(). - * @retval -EBUSY If timeout can not be installed while watchdog has already - * been setup. - * @retval -ENOMEM If no more timeouts can be installed. - * @retval -ENOTSUP If any of the set flags is not supported. - * @retval -EINVAL If any of the window timeout value is out of possible range. - * This value is also returned if watchdog supports only one - * timeout value for all timeouts and the supplied timeout - * window differs from windows for alarms installed so far. - */ -static inline int wdt_install_timeout(struct device *dev, - const struct wdt_timeout_cfg *cfg) -{ - const struct wdt_driver_api *api = - (const struct wdt_driver_api *) dev->driver_api; - - return api->install_timeout(dev, cfg); -} - -/** - * @brief Feed specified watchdog timeout. - * - * @param dev Pointer to the device structure for the driver instance. - * @param channel_id Index of the fed channel. - * - * @retval 0 If successful. - * @retval -EINVAL If there is no installed timeout for supplied channel. - */ -static inline int wdt_feed(struct device *dev, int channel_id) -{ - const struct wdt_driver_api *api = - (const struct wdt_driver_api *)dev->driver_api; - - return api->feed(dev, channel_id); -} - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ - -#endif /* _ZEPHYR_WATCHDOG_H__ */ +#endif /* ZEPHYR_INCLUDE_WATCHDOG_H_ */ diff --git a/samples/drivers/watchdog/src/main.c b/samples/drivers/watchdog/src/main.c index 9226cc43ea5..605fdd0819b 100644 --- a/samples/drivers/watchdog/src/main.c +++ b/samples/drivers/watchdog/src/main.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #define WDT_FEED_TRIES 5 diff --git a/tests/application_development/cpp/src/main.cpp b/tests/application_development/cpp/src/main.cpp index fa8e2efb8a2..9631c9cdf6d 100644 --- a/tests/application_development/cpp/src/main.cpp +++ b/tests/application_development/cpp/src/main.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include diff --git a/tests/drivers/watchdog/wdt_basic_api/src/test_wdt.c b/tests/drivers/watchdog/wdt_basic_api/src/test_wdt.c index 2299fb4d15b..b572019c222 100644 --- a/tests/drivers/watchdog/wdt_basic_api/src/test_wdt.c +++ b/tests/drivers/watchdog/wdt_basic_api/src/test_wdt.c @@ -57,7 +57,7 @@ * @} */ -#include +#include #include #include #include "test_wdt.h"