Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | /*
* 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_WATCHDOG_H_
#define ZEPHYR_INCLUDE_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
/**
* WDT clock cycles for timeout type.
*/
enum wdt_clock_timeout_cycles {
WDT_2_16_CYCLES,
WDT_2_17_CYCLES,
WDT_2_18_CYCLES,
WDT_2_19_CYCLES,
WDT_2_20_CYCLES,
WDT_2_21_CYCLES,
WDT_2_22_CYCLES,
WDT_2_23_CYCLES,
WDT_2_24_CYCLES,
WDT_2_25_CYCLES,
WDT_2_26_CYCLES,
WDT_2_27_CYCLES,
WDT_2_28_CYCLES,
WDT_2_29_CYCLES,
WDT_2_30_CYCLES,
WDT_2_31_CYCLES
};
/**
* WDT configuration struct.
*/
struct wdt_config {
u32_t timeout;
void (*interrupt_fn)(struct device *dev);
};
/**
* @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.
*/
__syscall int wdt_setup(struct device *dev, u8_t options);
static inline int z_impl_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.
*/
__syscall int wdt_disable(struct device *dev);
static inline int z_impl_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.
*/
__syscall int wdt_feed(struct device *dev, int channel_id);
static inline int z_impl_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
/**
* @}
*/
#include <syscalls/watchdog.h>
#endif /* _ZEPHYR_WATCHDOG_H__ */
|