• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Talkweb Co., Ltd.
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 
16 #include <stdio.h>
17 #include <hdf_log.h>
18 #include <uart_if.h>
19 #include "los_task.h"
20 #include "los_compiler.h"
21 #include "cmsis_os2.h"
22 #include "samgr_lite.h"
23 #include "ohos_run.h"
24 #define USE_FULL_LL_DRIVER
25 
26 #define HDF_WATCHDOG_STACK_SIZE 0x1000
27 #define HDF_WATCHDOG_TASK_NAME "hdf_watchdog_test_task"
28 #define HDF_WATCHDOG_TASK_PRIORITY 25
29 
30 #define HDF_WATCHDOG_TIMEOUT_TEST 1200
31 
HdfWatchdogTestEntry(void * arg)32 static void* HdfWatchdogTestEntry(void* arg)
33 {
34     int32_t ret;
35     DevHandle handle = NULL;
36     int32_t status;
37     uint32_t timeOut = 0;
38 
39     HDF_LOGE("HdfWatchdogTestEntry ----------\n");
40 
41     ret = WatchdogOpen(0, &handle);
42     if (HDF_SUCCESS != ret || handle == NULL) {
43         HDF_LOGE("WatchdogOpen: failed, ret %d\n", ret);
44         return NULL;
45     }
46 
47     ret = WatchdogGetStatus(handle, &status);
48     if (ret != 0) {
49         HDF_LOGE("WatchdogGetStatus: failed, ret %d\n", ret);
50         return NULL;
51     } else
52         HDF_LOGE("WatchdogGetStatus: %d\n", status);
53 
54     ret = WatchdogGetTimeout(handle, &timeOut);
55     if (ret != 0) {
56         HDF_LOGE("WatchdogGetTimeout: failed, ret %d\n", ret);
57         return NULL;
58     } else
59         HDF_LOGE("WatchdogGetTimeout: %d\n", timeOut);
60 
61     ret = WatchdogSetTimeout(handle, HDF_WATCHDOG_TIMEOUT_TEST);
62     if (ret != 0) {
63         HDF_LOGE("WatchdogSetTimeout: failed, ret %d\n", ret);
64         return NULL;
65     } else
66         HDF_LOGE("WatchdogSetTimeout: 1200\n");
67 
68     ret = WatchdogGetTimeout(handle, &timeOut);
69     if (ret != 0) {
70         HDF_LOGE("WatchdogGetTimeout: failed, ret %d\n", ret);
71         return NULL;
72     } else
73         HDF_LOGE("WatchdogGetTimeout: %d\n", timeOut);
74 
75     ret = WatchdogStart(handle);
76     if (ret != 0) {
77         HDF_LOGE("WatchdogStart: failed, ret %d\n", ret);
78         return NULL;
79     } else
80         HDF_LOGE("---> WatchdogStart.\n");
81 
82     ret = WatchdogGetStatus(handle, &status);
83     if (ret != 0) {
84         HDF_LOGE("WatchdogGetStatus: failed, ret %d\n", ret);
85         return NULL;
86     } else
87         HDF_LOGE("WatchdogGetStatus: %d\n", status);
88 
89     while (1) {
90         ret = WatchdogFeed(handle);
91         if (ret != 0) {
92             HDF_LOGE("WatchdogFeed: failed, ret %d\n", ret);
93             return NULL;
94         } else
95             HDF_LOGE("--> WatchdogFeed success!");
96         osDelay(timeOut);
97     }
98 }
99 
StartHdfWatchdogTest(void)100 void StartHdfWatchdogTest(void)
101 {
102     UINT32 uwRet;
103     UINT32 taskID;
104     TSK_INIT_PARAM_S stTask = {0};
105 
106     stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)HdfWatchdogTestEntry;
107     stTask.uwStackSize = HDF_WATCHDOG_STACK_SIZE;
108     stTask.pcName = HDF_WATCHDOG_TASK_NAME;
109     stTask.usTaskPrio = HDF_WATCHDOG_TASK_PRIORITY;
110     uwRet = LOS_TaskCreate(&taskID, &stTask);
111     if (uwRet != LOS_OK) {
112         printf("Task1 create failed\n");
113     }
114 }
115 
116 OHOS_APP_RUN(StartHdfWatchdogTest);
117 
118