1 /*
2 * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
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 #ifndef __WATCHDOG_H__
16 #define __WATCHDOG_H__
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 #ifdef RTOS
23 # ifdef __WATCHER_DOG_RESET__
24 # define APP_WATCHDOG
25 # endif
26 #endif
27
28 #ifdef APP_WATCHDOG
29 int app_wdt_open(int seconds);
30
31 int app_wdt_reopen(int seconds);
32
33 int app_wdt_close(void);
34
35 int app_wdt_set_ping_time(int seconds);
36
37 /*
38 * when enable, the watchdog ping timer will also check the ilde task's heath,
39 * and if the idle task was not schedule for a period time, there maybe
40 * something wrong with system, and assert will happen.
41 */
42 int app_wdt_hung_task_check_enable(int enable);
43
44 #else
45 static inline int app_wdt_open(int seconds) {return 0;}
46
47 static inline int app_wdt_reopen(int seconds) {return 0;}
48
49 static inline int app_wdt_close(void) {return 0;}
50
51 static inline int app_wdt_set_ping_time(int seconds) {return 0;}
52
53 static inline int app_wdt_hung_task_check_enable(int enable) {return 0;}
54
55 #endif
56
57
58 #ifdef __WATCHER_DOG_RESET__
59
60 #define system_shutdown_wdt_config(seconds) \
61 do{ \
62 hal_wdt_stop(HAL_WDT_ID_0); \
63 hal_wdt_set_irq_callback(HAL_WDT_ID_0, NULL); \
64 hal_wdt_set_timeout(HAL_WDT_ID_0, seconds); \
65 hal_wdt_start(HAL_WDT_ID_0); \
66 hal_sleep_set_sleep_hook(HAL_SLEEP_HOOK_USER_OTA, NULL); \
67 }while(0)
68
69 int watchdog_hw_stop(void);
70
71 int watchdog_hw_start(int seconds);
72
73 void watchdog_ping(void);
74 #else
75
76 #define system_shutdown_wdt_config(seconds)
77
watchdog_hw_stop(void)78 static inline int watchdog_hw_stop(void) {return 0;}
79
watchdog_hw_start(int seconds)80 static inline int watchdog_hw_start(int seconds) {return 0;}
81
watchdog_ping(void)82 static inline void watchdog_ping(void) {}
83
84 #endif
85
86 #ifdef __cplusplus
87 }
88 #endif
89
90 #endif /*_ __WATCHDOG_H__*/
91