1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * 15 * Description: Provides Watchdog driver \n 16 * 17 * History: \n 18 * 2022-07-26, Create file. \n 19 */ 20 #ifndef WATCHDOG_H 21 #define WATCHDOG_H 22 23 #include <stdint.h> 24 #include "errcode.h" 25 26 #ifdef __cplusplus 27 #if __cplusplus 28 extern "C" { 29 #endif /* __cplusplus */ 30 #endif /* __cplusplus */ 31 32 /** 33 * @defgroup drivers_driver_watchdog Watchdog 34 * @ingroup drivers_driver 35 * @{ 36 */ 37 38 /** 39 * @if Eng 40 * @brief Watchdog trigger mode. 41 * @else 42 * @brief 看门狗触发模式。 43 * @endif 44 */ 45 typedef enum { 46 WDT_MODE_RESET = 0, /** @if Eng Will reset core direcotry, when Watchdog trigger. 47 * @else 当看门狗触发时,将重启系统。 48 * @endif */ 49 WDT_MODE_INTERRUPT, /** @if Eng Will enter interrupt, when WDT trigger. If WDT not kick in interrupt, \n 50 * core will reset. 51 * @else 当看门狗触发时,将进入中断。如果在中断中没有喂狗,系统将重启。 52 * @endif */ 53 WDT_MODE_MAX 54 } wdt_mode_t; 55 56 /** 57 * @if Eng 58 * @brief Init Watchdog. 59 * @param [in] timeout The timeout of Watchdog. 60 * @retval ERRCODE_SUCC Success. 61 * @retval Other Failure. For details, see @ref errcode_t. 62 * @else 63 * @brief 初始化Watchdog。 64 * @param [in] timeout 看门狗超时时间。 65 * @retval ERRCODE_SUCC 成功。 66 * @retval Other 失败,参考 @ref errcode_t 。 67 * @endif 68 */ 69 errcode_t uapi_watchdog_init(uint32_t timeout); 70 71 /** 72 * @if Eng 73 * @brief Deinit Watchdog. 74 * @retval ERRCODE_SUCC Success. 75 * @retval Other Failure. For details, see @ref errcode_t. 76 * @else 77 * @brief 去初始化Watchdog。 78 * @retval ERRCODE_SUCC 成功。 79 * @retval Other 失败,参考 @ref errcode_t 。 80 * @endif 81 */ 82 errcode_t uapi_watchdog_deinit(void); 83 84 /** 85 * @if Eng 86 * @brief Enable Watchdog. 87 * @param [in] mode The mode of watchdog, see @ref wdt_mode_t. 88 * @retval ERRCODE_SUCC Success. 89 * @retval Other Failure. For details, see @ref errcode_t. 90 * @else 91 * @brief 使能Watchdog。 92 * @param [in] mode 看门狗模式,参考 @ref wdt_mode_t 。 93 * @retval ERRCODE_SUCC 成功。 94 * @retval Other 失败,参考 @ref errcode_t 。 95 * @endif 96 */ 97 errcode_t uapi_watchdog_enable(wdt_mode_t mode); 98 99 /** 100 * @if Eng 101 * @brief Disable Watchdog. 102 * @retval ERRCODE_SUCC Success. 103 * @retval Other Failure. For details, see @ref errcode_t. 104 * @else 105 * @brief 去使能Watchdog。 106 * @retval ERRCODE_SUCC 成功。 107 * @retval Other 失败,参考 @ref errcode_t 。 108 * @endif 109 */ 110 errcode_t uapi_watchdog_disable(void); 111 112 /** 113 * @if Eng 114 * @brief Kick Watchdog. 115 * @retval ERRCODE_SUCC Success. 116 * @retval Other Failure. For details, see @ref errcode_t 117 * @else 118 * @brief 喂狗。 119 * @retval ERRCODE_SUCC 成功。 120 * @retval Other 失败,参考 @ref errcode_t 。 121 * @endif 122 */ 123 errcode_t uapi_watchdog_kick(void); 124 125 /** 126 * @if Eng 127 * @brief Set timeout of Watchdog. 128 * @param [in] timeout The timeout of Watchdog, unit s. 129 * @retval ERRCODE_SUCC Success. 130 * @retval Other Failure. For details, see @ref errcode_t 131 * @else 132 * @brief 设置Watchdog超时时间。 133 * @param [in] timeout 看门狗超时时间,单位秒。 134 * @retval ERRCODE_SUCC 成功。 135 * @retval Other 失败,参考 @ref errcode_t 。 136 * @endif 137 */ 138 errcode_t uapi_watchdog_set_time(uint32_t timeout); 139 140 /** 141 * @if Eng 142 * @brief Get the time left of Watchdog counter. 143 * @param [in] timeout The time left. 144 * @retval ERRCODE_SUCC Success. 145 * @retval Other Failure. For details, see @ref errcode_t 146 * @else 147 * @brief 获取看门狗计数器的剩余值。 148 * @param [in] timeout 时间剩余值。 149 * @retval ERRCODE_SUCC 成功。 150 * @retval Other 失败,参考 @ref errcode_t 。 151 * @endif 152 */ 153 errcode_t uapi_watchdog_get_left_time(uint32_t *timeout); 154 155 /** 156 * @if Eng 157 * @brief Watchdog timeout callback. 158 * @param [in] param Parameters of the callback function. 159 * @retval ERRCODE_SUCC Success. 160 * @retval Other Failure. For details, see @ref errcode_t 161 * @else 162 * @brief Watchdog超时回调。 163 * @param [in] param 回调函数的参数。 164 * @retval ERRCODE_SUCC 成功。 165 * @retval Other 失败,参考 @ref errcode_t 。 166 * @endif 167 */ 168 typedef errcode_t (*watchdog_callback_t)(uintptr_t param); 169 170 /** 171 * @if Eng 172 * @brief Register Watchdog callback. 173 * @param [in] callback If Watchdog timeout, the callback is called to handle the exception. 174 * @retval ERRCODE_SUCC Success. 175 * @retval Other Failure. For details, see @ref errcode_t. 176 * @else 177 * @brief 注册看门狗回调。 178 * @param [in] callback 如果看门狗超时,则调用回调来处理异常。 179 * @retval ERRCODE_SUCC 成功。 180 * @retval Other 失败,参考 @ref errcode_t 。 181 * @endif 182 */ 183 errcode_t uapi_register_watchdog_callback(watchdog_callback_t callback); 184 185 #ifdef CONFIG_WATCHDOG_SUPPORT_LPM 186 /** 187 * @if Eng 188 * @brief resume Watchdog. 189 * @param [in] arg Argument for resume. 190 * @retval ERRCODE_SUCC Success. 191 * @retval Other Failure. For details, see @ref errcode_t 192 * @else 193 * @brief 恢复看门狗模块。 194 * @retval ERRCODE_SUCC 成功。 195 * @retval Other 失败,参考 @ref errcode_t 。 196 * @endif 197 */ 198 errcode_t uapi_watchdog_resume(uintptr_t arg); 199 200 /** 201 * @if Eng 202 * @brief suspend Watchdog. 203 * @param [in] arg Argument for suspend. 204 * @retval ERRCODE_SUCC Success. 205 * @retval Other Failure. For details, see @ref errcode_t 206 * @else 207 * @brief 挂起看门狗模块。 208 * @retval ERRCODE_SUCC 成功。 209 * @retval Other 失败,参考 @ref errcode_t 。 210 * @endif 211 */ 212 errcode_t uapi_watchdog_suspend(uintptr_t arg); 213 #endif 214 /** 215 * @} 216 */ 217 218 #ifdef __cplusplus 219 #if __cplusplus 220 } 221 #endif /* __cplusplus */ 222 #endif /* __cplusplus */ 223 224 #endif