• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: WDT Sample Source. \n
16  *
17  * History: \n
18  * 2023-06-29, Create file. \n
19  */
20 #include "pinctrl.h"
21 #include "watchdog.h"
22 #include "soc_osal.h"
23 #include "app_init.h"
24 
25 #define TIME_OUT                  2
26 #define WDT_MODE                  1
27 #define TEST_PARAM_KICK_TIME      10
28 #define WDT_TASK_DURATION_MS      500
29 
30 #define WDT_TASK_PRIO             24
31 #define WDT_TASK_STACK_SIZE       0x1000
32 
watchdog_callback(uintptr_t param)33 static errcode_t watchdog_callback(uintptr_t param)
34 {
35     UNUSED(param);
36     osal_printk("watchdog kick timeout!\r\n");
37     return ERRCODE_SUCC;
38 }
39 
watchdog_task(const char * arg)40 static void *watchdog_task(const char *arg)
41 {
42     UNUSED(arg);
43 
44     errcode_t ret = uapi_watchdog_init(TIME_OUT);
45     if (ret == ERRCODE_INVALID_PARAM) {
46         osal_printk("param is error, timeout is %d.\r\n", TIME_OUT);
47         return NULL;
48     }
49     (void)uapi_watchdog_enable((wdt_mode_t)WDT_MODE);
50     (void)uapi_register_watchdog_callback(watchdog_callback);
51     osal_printk("init watchdog\r\n");
52 #if defined(CONFIG_WDT_TIMEOUT_SAMPLE)
53     while (1) {};
54 #endif
55 
56 #if defined(CONFIG_WDT_KICK_SAMPLE)
57     while (1) {
58         osal_msleep(WDT_TASK_DURATION_MS);
59         (void)uapi_watchdog_kick();
60         osal_printk("kick success\r\n");
61     }
62 #endif
63     (void)uapi_watchdog_deinit();
64     return NULL;
65 }
66 
watchdog_entry(void)67 static void watchdog_entry(void)
68 {
69     osal_task *task_handle = NULL;
70     osal_kthread_lock();
71     task_handle = osal_kthread_create((osal_kthread_handler)watchdog_task, 0, "WatchdogTask", WDT_TASK_STACK_SIZE);
72     if (task_handle != NULL) {
73         osal_kthread_set_priority(task_handle, WDT_TASK_PRIO);
74         osal_kfree(task_handle);
75     }
76     osal_kthread_unlock();
77 }
78 
79 /* Run the watchdog_entry. */
80 app_run(watchdog_entry);