Skip to content
Permalink
Browse files

cleanup: include/: move watchdog.h to drivers/watchdog.h

move watchdog.h to drivers/watchdog.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
  • Loading branch information...
nashif committed Jun 25, 2019
1 parent 4be2e9e commit d4d20677acbee9e81e204282c608ca992cb1fec7
@@ -10,7 +10,7 @@

#include <errno.h>
#include <soc.h>
#include <watchdog.h>
#include <drivers/watchdog.h>
#include <misc/printk.h>
#include <misc/reboot.h>

@@ -10,7 +10,7 @@

#include <soc.h>
#include <string.h>
#include <watchdog.h>
#include <drivers/watchdog.h>
#include <device.h>

enum wdt_mode {
@@ -6,7 +6,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <watchdog.h>
#include <drivers/watchdog.h>
#include <soc.h>
#include <errno.h>
#include <assert.h>
@@ -5,7 +5,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <watchdog.h>
#include <drivers/watchdog.h>
#include <clock_control.h>
#include <fsl_wdog.h>

@@ -5,7 +5,7 @@
*/

#include <nrfx_wdt.h>
#include <watchdog.h>
#include <drivers/watchdog.h>

#define LOG_LEVEL CONFIG_WDT_LOG_LEVEL
#include <logging/log.h>
@@ -7,15 +7,15 @@
#include <init.h>
#include <device.h>
#include <kernel.h>
#include <watchdog.h>
#include <drivers/watchdog.h>
#include <drivers/interrupt_controller/ioapic.h>
#include <power/power.h>
#include <soc.h>

#include "clk.h"
#include "qm_isr.h"
#include "qm_wdt.h"
#include <watchdog.h>
#include <drivers/watchdog.h>

struct wdt_data {
#ifdef CONFIG_WDT_QMSI_API_REENTRANCY
@@ -17,7 +17,7 @@
* CONFIG_WDT_DISABLE_AT_BOOT must be unset in the app's config file
*/

#include <watchdog.h>
#include <drivers/watchdog.h>
#include <soc.h>

#define LOG_LEVEL CONFIG_WDT_LOG_LEVEL
@@ -6,7 +6,7 @@
*/

#include <soc.h>
#include <watchdog.h>
#include <drivers/watchdog.h>

#define LOG_LEVEL CONFIG_WDT_LOG_LEVEL
#include <logging/log.h>
@@ -36,6 +36,6 @@
*
******************************************************************************/

#include "watchdog.h"
#include <drivers/watchdog.h>

// See watchdog.h for implementation
@@ -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 <zephyr/types.h>
#include <misc/util.h>
#include <device.h>

#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__ */

0 comments on commit d4d2067

Please sign in to comment.
You can’t perform that action at this time.