1e41f4b71Sopenharmony_ci# Watchdog 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## Overview 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci### Function 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciA watchdog, also called a watchdog timer, is a hardware timing device used to facilitate automatic correction of temporary hardware faults or recover from system malfunctions. Generally, it has an input to feed the watchdog and an output to the reset pin of the system. If an error occurs in the main program of the system and the watchdog timer is not cleared in time, the watchdog timer sends a reset signal to restore the system to the normal state. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ciThe watchdog module provides APIs for watchdog operations, including: 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci- Opening or closing a watchdog 12e41f4b71Sopenharmony_ci- Starting or stopping a watchdog 13e41f4b71Sopenharmony_ci- Setting or obtaining the watchdog timeout period 14e41f4b71Sopenharmony_ci- Obtaining the watchdog status 15e41f4b71Sopenharmony_ci- Feeding a watchdog 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci### Basic Concepts 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciWhen the system works properly, a signal is output to the watchdog to prevent it from timing out. This operation is called watchdog feeding. If the watchdog is not fed within the specified time, the watchdog times out and a reset signal is sent to the system to reset the system. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci### Working Principles 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciIn the Hardware Driver Foundation (HDF), the PWM uses the independent service mode (see Figure 1) for API adaptation. In this mode, each device independently publishes a service to process external access requests. When receiving an access request, the HDF DeviceManager extracts parameters from the request to call the internal APIs of the target device. In the independent service mode, the HDF DeviceManager provides service management capabilities. However, you need to configure a node for each device, which increases memory usage. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ciIn the independent service mode, the core layer does not publish a service for the upper layer. Therefore, a service must be published for each controller. To achieve this purpose: 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci- You need to implement the **Bind()** function in **HdfDriverEntry** to bind services. 28e41f4b71Sopenharmony_ci- The **policy** field of **deviceNode** in the **device_info.hcs** file can be **1** or **2**, but not **0**. 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ciThe watchdog module is divided into the following layers: 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci- Interface layer: provides APIs for opening or closing a watchdog, starting or stopping a watchdog, setting or obtaining the watchdog timeout period, and feeding a watchdog 33e41f4b71Sopenharmony_ci- Core layer: provides the capabilities of adding or removing a watchdog controller and managing watchdog devices. The core layer interacts with the adaptation layer through hook functions. 34e41f4b71Sopenharmony_ci- Adaptation layer: instantiates the hook functions to implement specific features. 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci**Figure 1** Independent service mode 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci## Usage Guidelines 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci### When to Use 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ciWatchdogs are used to automatically detect the software exceptions that cannot be directly observed and reset the system when an exception is detected. 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci### Available APIs 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ciThe following table describes the APIs provided by the watchdog module. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci**Table 1** Watchdog APIs 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci| API| Description| 53e41f4b71Sopenharmony_ci| -------- | -------- | 54e41f4b71Sopenharmony_ci| int32_t WatchdogOpen(int16_t wdtId, DevHandle *handle) | Opens a watchdog.| 55e41f4b71Sopenharmony_ci| void WatchdogClose(DevHandle handle) | Closes a watchdog.| 56e41f4b71Sopenharmony_ci| int32_t WatchdogStart(DevHandle handle) | Starts a watchdog.| 57e41f4b71Sopenharmony_ci| int32_t WatchdogStop(DevHandle handle) | Stops a watchdog.| 58e41f4b71Sopenharmony_ci| int32_t WatchdogSetTimeout(DevHandle handle, uint32_t seconds) | Sets the watchdog timeout duration.| 59e41f4b71Sopenharmony_ci| int32_t WatchdogGetTimeout(DevHandle handle, uint32_t *seconds) | Obtains the watchdog timeout duration.| 60e41f4b71Sopenharmony_ci| int32_t WatchdogGetStatus(DevHandle handle, int32_t *status) | Obtains the watchdog status.| 61e41f4b71Sopenharmony_ci| int32_t WatchdogFeed(DevHandle handle) | Feeds a watchdog or resets a watchdog timer.| 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci>  **NOTE** 64e41f4b71Sopenharmony_ci> 65e41f4b71Sopenharmony_ci> All watchdog APIs described in this document can be used in kernel mode and user mode. 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci### How to Develop 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ciThe following figure shows how to use the watchdog driver APIs. 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**Figure 2** Using watchdog driver APIs 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci#### Opening a Watchdog 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ciBefore operating a watchdog, you need to use **WatchdogOpen()** to open a watchdog. A system may have multiple watchdogs. You need to specify the ID of the watchdog to open. 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci```c 80e41f4b71Sopenharmony_ciDevHandle WatchdogOpen(int16_t wdtId, DevHandle *handle); 81e41f4b71Sopenharmony_ci``` 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**Table 2** Description of WatchdogOpen 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci| **Parameter**| **Description**| 86e41f4b71Sopenharmony_ci| -------- | -------- | 87e41f4b71Sopenharmony_ci| wdtId | Watchdog ID.| 88e41f4b71Sopenharmony_ci| handle | Pointer to the watchdog device handle obtained.| 89e41f4b71Sopenharmony_ci| **Return Value**| **Description**| 90e41f4b71Sopenharmony_ci| HDF_SUCCESS | The operation is successful.| 91e41f4b71Sopenharmony_ci| Negative value| The operation fails.| 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci```c 94e41f4b71Sopenharmony_ciint16_t wdtId = 0; 95e41f4b71Sopenharmony_ciint32_t ret; 96e41f4b71Sopenharmony_ciDevHandle *handle = NULL; 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ciret = WatchdogOpen(wdtId, handle); // Open watchdog 0. 99e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 100e41f4b71Sopenharmony_ci HDF_LOGE("WatchdogOpen: open watchdog_%hd failed, ret:%d\n", wdtId, ret); 101e41f4b71Sopenharmony_ci return ret; 102e41f4b71Sopenharmony_ci} 103e41f4b71Sopenharmony_ci``` 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci#### Obtaining the Watchdog Status 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci```c 108e41f4b71Sopenharmony_ciint32_t WatchdogGetStatus(DevHandle handle, int32_t *status); 109e41f4b71Sopenharmony_ci``` 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci**Table 3** Description of WatchdogGetStatus 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci| **Parameter**| **Description**| 114e41f4b71Sopenharmony_ci| -------- | -------- | 115e41f4b71Sopenharmony_ci| handle | Watchdog device handle.| 116e41f4b71Sopenharmony_ci| status | Pointer to the watchdog status obtained.| 117e41f4b71Sopenharmony_ci| **Return Value**| **Description**| 118e41f4b71Sopenharmony_ci| HDF_SUCCESS | The operation is successful.| 119e41f4b71Sopenharmony_ci| Negative value| The operation fails.| 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci```c 122e41f4b71Sopenharmony_ciint32_t ret; 123e41f4b71Sopenharmony_ciint32_t status; 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ciret = WatchdogGetStatus(handle, &status); // Obtain the watchdog status. 126e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 127e41f4b71Sopenharmony_ci HDF_LOGE("WatchdogGetStatus: watchdog get status failed, ret:%d\n", ret); 128e41f4b71Sopenharmony_ci return ret; 129e41f4b71Sopenharmony_ci} 130e41f4b71Sopenharmony_ci``` 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci#### Setting the Timeout Duration 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci```c 136e41f4b71Sopenharmony_ciint32_t WatchdogSetTimeout(DevHandle *handle, uint32_t seconds); 137e41f4b71Sopenharmony_ci``` 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**Table 4** Description of WatchdogSetTimeout 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci| **Parameter**| **Description**| 142e41f4b71Sopenharmony_ci| -------- | -------- | 143e41f4b71Sopenharmony_ci| handle | Pointer to the watchdog device handle.| 144e41f4b71Sopenharmony_ci| seconds | Timeout duration to set, in seconds.| 145e41f4b71Sopenharmony_ci| **Return Value**| **Description**| 146e41f4b71Sopenharmony_ci| HDF_SUCCESS | The operation is successful.| 147e41f4b71Sopenharmony_ci| Negative value| The operation fails.| 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci```c 150e41f4b71Sopenharmony_ciint32_t ret; 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ciret = WatchdogSetTimeout(handle, 2); // Set the timeout duration to 2 seconds. 153e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 154e41f4b71Sopenharmony_ci HDF_LOGE("WatchdogSetTimeout: watchdog set timeOut failed, ret:%d\n", ret); 155e41f4b71Sopenharmony_ci return ret; 156e41f4b71Sopenharmony_ci} 157e41f4b71Sopenharmony_ci``` 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci#### Obtaining the Timeout Duration 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci```c 162e41f4b71Sopenharmony_ciint32_t WatchdogGetTimeout(DevHandle *handle, uint32_t *seconds); 163e41f4b71Sopenharmony_ci``` 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci**Table 5** Description of WatchdogGetTimeout 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci| **Parameter**| **Description**| 168e41f4b71Sopenharmony_ci| -------- | -------- | 169e41f4b71Sopenharmony_ci| handle | Pointer to the watchdog device handle.| 170e41f4b71Sopenharmony_ci| seconds | Pointer to the watchdog timeout duration obtained.| 171e41f4b71Sopenharmony_ci| **Return Value**| **Description**| 172e41f4b71Sopenharmony_ci| HDF_SUCCESS | The operation is successful.| 173e41f4b71Sopenharmony_ci| Negative value| The operation fails.| 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci```c 176e41f4b71Sopenharmony_ci int32_t ret; 177e41f4b71Sopenharmony_ci uint32_t timeOut; 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci ret = WatchdogGetTimeout(handle, &timeOut); // Obtain the watchdog timeout duration. 180e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 181e41f4b71Sopenharmony_ci HDF_LOGE("WatchdogGetTimeout: watchdog get timeOut failed, ret:%d\n", ret); 182e41f4b71Sopenharmony_ci return ret; 183e41f4b71Sopenharmony_ci } 184e41f4b71Sopenharmony_ci``` 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci#### Starting a Watchdog 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci```c 189e41f4b71Sopenharmony_ciint32_t WatchdogStart(DevHandle handle); 190e41f4b71Sopenharmony_ci``` 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci**Table 6** Description of WatchdogStart 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci| **Parameter**| **Description**| 195e41f4b71Sopenharmony_ci| -------- | -------- | 196e41f4b71Sopenharmony_ci| handle | Watchdog device handle.| 197e41f4b71Sopenharmony_ci| **Return Value**| **Description**| 198e41f4b71Sopenharmony_ci| HDF_SUCCESS | The operation is successful.| 199e41f4b71Sopenharmony_ci| Negative value| The operation fails.| 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci```c 202e41f4b71Sopenharmony_ciint32_t ret; 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ciret = WatchdogStart(handle); // Start a watchdog. 205e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 206e41f4b71Sopenharmony_ci HDF_LOGE("WatchdogStart: start watchdog failed, ret:%d\n", ret); 207e41f4b71Sopenharmony_ci return ret; 208e41f4b71Sopenharmony_ci} 209e41f4b71Sopenharmony_ci``` 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci#### Feeding a Watchdog 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci```c 214e41f4b71Sopenharmony_ciint32_t WatchdogFeed(DevHandle handle); 215e41f4b71Sopenharmony_ci``` 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci**Table 7** Description of WatchdogFeed 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci| **Parameter**| **Description**| 220e41f4b71Sopenharmony_ci| -------- | -------- | 221e41f4b71Sopenharmony_ci| handle | Watchdog device handle.| 222e41f4b71Sopenharmony_ci| **Return Value**| **Description**| 223e41f4b71Sopenharmony_ci| HDF_SUCCESS | The operation is successful.| 224e41f4b71Sopenharmony_ci| Negative value| The operation fails.| 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci```c 227e41f4b71Sopenharmony_ciint32_t ret; 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ciret = WatchdogFeed (handle); // Feed a watchdog. 230e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 231e41f4b71Sopenharmony_ci HDF_LOGE("WatchdogFeed: feed watchdog failed, ret:%d\n", ret); 232e41f4b71Sopenharmony_ci return ret; 233e41f4b71Sopenharmony_ci} 234e41f4b71Sopenharmony_ci``` 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci#### Stopping a Watchdog 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci```c 239e41f4b71Sopenharmony_ciint32_t WatchdogStop(DevHandle handle); 240e41f4b71Sopenharmony_ci``` 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci**Table 8** Description of WatchdogStop 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci| **Parameter**| **Description**| 245e41f4b71Sopenharmony_ci| -------- | -------- | 246e41f4b71Sopenharmony_ci| handle | Watchdog device handle.| 247e41f4b71Sopenharmony_ci| **Return Value**| **Description**| 248e41f4b71Sopenharmony_ci| HDF_SUCCESS | The operation is successful.| 249e41f4b71Sopenharmony_ci| Negative value| The operation fails.| 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci```c 252e41f4b71Sopenharmony_ciint32_t ret; 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ciret = WatchdogStop(handle); // Stop a watchdog. 255e41f4b71Sopenharmony_ciif (ret != HDF_SUCCESS) { 256e41f4b71Sopenharmony_ci HDF_LOGE("WatchdogStop: stop watchdog failed, ret:%d\n", ret); 257e41f4b71Sopenharmony_ci return ret; 258e41f4b71Sopenharmony_ci} 259e41f4b71Sopenharmony_ci``` 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci#### Closing a Watchdog 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ciAfter all operations are complete, use **WatchdogClose()** to close the watchdog. 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci```c 266e41f4b71Sopenharmony_civoid WatchdogClose(DevHandle handle); 267e41f4b71Sopenharmony_ci``` 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci**Table 9** Description of WatchdogClose 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci| **Parameter**| **Description**| 272e41f4b71Sopenharmony_ci| -------- | -------- | 273e41f4b71Sopenharmony_ci| handle | Watchdog device handle.| 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci```c 276e41f4b71Sopenharmony_ciWatchdogClose(handle); // Close a watchdog. 277e41f4b71Sopenharmony_ci``` 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci## Example 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ciThe following uses the Hi3516D V300 development board as an example to describe how to operate the watchdog. The procedure is as follows: 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci1. Open a watchdog. You need to pass in the watchdog ID. The device handle of the watchdog opened is returned. 284e41f4b71Sopenharmony_ci2. Set the timeout duration for the watchdog. 285e41f4b71Sopenharmony_ci3. Obtain the timeout duration of the watchdog. 286e41f4b71Sopenharmony_ci4. Start the watchdog. 287e41f4b71Sopenharmony_ci5. Feed the watchdog. 288e41f4b71Sopenharmony_ci6. Stop the watchdog. 289e41f4b71Sopenharmony_ci7. Close the watchdog. 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci```c 292e41f4b71Sopenharmony_ci#include "watchdog_if.h" /* Header file of the standard watchdog APIs. */ 293e41f4b71Sopenharmony_ci#include "hdf_log.h" /* Header file of the HDF log APIs. */ 294e41f4b71Sopenharmony_ci#include "osal_time.h" /* Header file of the delay and sleep APIs. */ 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci#define WATCHDOG_TEST_TIMEOUT 2 297e41f4b71Sopenharmony_ci#define WATCHDOG_TEST_FEED_TIME 6 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_cistatic int32_t TestCaseWatchdog(void) 300e41f4b71Sopenharmony_ci{ 301e41f4b71Sopenharmony_ci int32_t i; 302e41f4b71Sopenharmony_ci int32_t ret; 303e41f4b71Sopenharmony_ci int16_t wdtId = 0; 304e41f4b71Sopenharmony_ci int32_t status; 305e41f4b71Sopenharmony_ci uint32_t timeout; 306e41f4b71Sopenharmony_ci DevHandle *handle = NULL; 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci /* Open watchdog 0. */ 309e41f4b71Sopenharmony_ci ret = WatchdogOpen(wdtId, handle); 310e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 311e41f4b71Sopenharmony_ci HDF_LOGE("WatchdogOpen: open watchdog_%hd failed, ret:%d\n", wdtId, ret); 312e41f4b71Sopenharmony_ci return ret; 313e41f4b71Sopenharmony_ci } 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci /* Set the timeout duration. */ 316e41f4b71Sopenharmony_ci ret = WatchdogSetTimeout(handle, WATCHDOG_TEST_TIMEOUT); 317e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 318e41f4b71Sopenharmony_ci HDF_LOGE("%s: set timeout fail! ret:%d\n", __func__, ret); 319e41f4b71Sopenharmony_ci WatchdogClose(handle); 320e41f4b71Sopenharmony_ci return ret; 321e41f4b71Sopenharmony_ci } 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ci /* Obtain the timeout duration. */ 324e41f4b71Sopenharmony_ci ret = WatchdogGetTimeout(handle, &timeout); 325e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 326e41f4b71Sopenharmony_ci HDF_LOGE("%s: get timeout fail! ret:%d\n", __func__, ret); 327e41f4b71Sopenharmony_ci WatchdogClose(handle); 328e41f4b71Sopenharmony_ci return ret; 329e41f4b71Sopenharmony_ci } 330e41f4b71Sopenharmony_ci /* Check whether the timeout duration obtained is the same as the timeout duration set. */ 331e41f4b71Sopenharmony_ci if (timeout != WATCHDOG_TEST_TIMEOUT) { 332e41f4b71Sopenharmony_ci HDF_LOGE("%s: set:%u, but get:%u", __func__, WATCHDOG_TEST_TIMEOUT, timeout); 333e41f4b71Sopenharmony_ci WatchdogClose(handle); 334e41f4b71Sopenharmony_ci return HDF_FAILURE; 335e41f4b71Sopenharmony_ci } 336e41f4b71Sopenharmony_ci HDF_LOGI("%s: read timeout back:%u\n", __func__, timeout); 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci /* Start the watchdog. The timer starts. */ 339e41f4b71Sopenharmony_ci ret = WatchdogStart(handle); 340e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 341e41f4b71Sopenharmony_ci HDF_LOGE("%s: start fail! ret:%d\n", __func__, ret); 342e41f4b71Sopenharmony_ci WatchdogClose(handle); 343e41f4b71Sopenharmony_ci return ret; 344e41f4b71Sopenharmony_ci } 345e41f4b71Sopenharmony_ci /* Obtain the watchdog status and determine whether to start the watchdog. */ 346e41f4b71Sopenharmony_ci status = WATCHDOG_STOP; 347e41f4b71Sopenharmony_ci ret = WatchdogGetStatus(handle, &status); 348e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 349e41f4b71Sopenharmony_ci HDF_LOGE("%s: get status fail! ret:%d", __func__, ret); 350e41f4b71Sopenharmony_ci WatchdogClose(handle); 351e41f4b71Sopenharmony_ci return ret; 352e41f4b71Sopenharmony_ci } 353e41f4b71Sopenharmony_ci if (status != WATCHDOG_START) { 354e41f4b71Sopenharmony_ci HDF_LOGE("%s: status is:%d after start", __func__, status); 355e41f4b71Sopenharmony_ci WatchdogClose(handle); 356e41f4b71Sopenharmony_ci return HDF_FAILURE; 357e41f4b71Sopenharmony_ci } 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci /* Feed the watchdog every other second. */ 360e41f4b71Sopenharmony_ci for (i = 0; i < WATCHDOG_TEST_FEED_TIME; i++) { 361e41f4b71Sopenharmony_ci HDF_LOGI("%s: feeding watchdog %d times... \n", __func__, i); 362e41f4b71Sopenharmony_ci ret = WatchdogFeed(handle); 363e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 364e41f4b71Sopenharmony_ci HDF_LOGE("%s: feed dog fail! ret:%d\n", __func__, ret); 365e41f4b71Sopenharmony_ci WatchdogClose(handle); 366e41f4b71Sopenharmony_ci return ret; 367e41f4b71Sopenharmony_ci } 368e41f4b71Sopenharmony_ci OsalSleep(1); 369e41f4b71Sopenharmony_ci } 370e41f4b71Sopenharmony_ci /* Because the interval for feeding the watchdog is shorter than the timeout duration, the system does not reset, and logs can be printed normally. */ 371e41f4b71Sopenharmony_ci HDF_LOGI("%s: no reset ... feeding test OK!!!\n", __func__); 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci ret = WatchdogStop(handle); 374e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 375e41f4b71Sopenharmony_ci HDF_LOGE("%s: stop fail! ret:%d", __func__, ret); 376e41f4b71Sopenharmony_ci WatchdogClose(handle); 377e41f4b71Sopenharmony_ci return ret; 378e41f4b71Sopenharmony_ci } 379e41f4b71Sopenharmony_ci /* Obtain the watchdog status and determine whether to close the watchdog. */ 380e41f4b71Sopenharmony_ci status = WATCHDOG_START; 381e41f4b71Sopenharmony_ci ret = WatchdogGetStatus(handle, &status); 382e41f4b71Sopenharmony_ci if (ret != HDF_SUCCESS) { 383e41f4b71Sopenharmony_ci HDF_LOGE("%s: get status fail! ret:%d", __func__, ret); 384e41f4b71Sopenharmony_ci WatchdogClose(handle); 385e41f4b71Sopenharmony_ci return ret; 386e41f4b71Sopenharmony_ci } 387e41f4b71Sopenharmony_ci if (status != WATCHDOG_STOP) { 388e41f4b71Sopenharmony_ci HDF_LOGE("%s: status is:%d after stop", __func__, status); 389e41f4b71Sopenharmony_ci WatchdogClose(handle); 390e41f4b71Sopenharmony_ci return HDF_FAILURE; 391e41f4b71Sopenharmony_ci } 392e41f4b71Sopenharmony_ci WatchdogClose(handle); 393e41f4b71Sopenharmony_ci return HDF_SUCCESS; 394e41f4b71Sopenharmony_ci} 395e41f4b71Sopenharmony_ci``` 396