提交 973442c3 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 d46248b1
# Watchdog<a name="EN-US_TOPIC_0000001206372825"></a> # Watchdog
## Overview<a name="section14918241977"></a>
## **Overview**
A watchdog, also called a watchdog timer, is a hardware timing device. If an error occurs in the main program of the system and fails to reset the watchdog timer, the watchdog timer sends a reset signal to restore the system to a normal state.
A 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. 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.
## Available APIs<a name="section1180575010271"></a>
**Table 1** Watchdog APIs ## Available APIs
<a name="table1731550155318"></a> **Table 1** Watchdog APIs
<table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" valign="top" width="26.619999999999997%" id="mcps1.2.4.1.1"><p id="p641050105320"><a name="p641050105320"></a><a name="p641050105320"></a>Capability</p>
</th> | API| Description|
<th class="cellrowborder" valign="top" width="32.800000000000004%" id="mcps1.2.4.1.2"><p id="p54150165315"><a name="p54150165315"></a><a name="p54150165315"></a>Function</p> | -------- | -------- |
</th> | WatchdogOpen | Opens a watchdog.|
<th class="cellrowborder" valign="top" width="40.58%" id="mcps1.2.4.1.3"><p id="p941150145313"><a name="p941150145313"></a><a name="p941150145313"></a>Description</p> | WatchdogClose | Closes a watchdog.|
</th> | WatchdogStart | Starts a watchdog.|
</tr> | WatchdogStop | Stops a watchdog.|
</thead> | WatchdogSetTimeout | Sets the watchdog timeout duration.|
<tbody><tr id="row837081981712"><td class="cellrowborder" rowspan="2" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p681292481718"><a name="p681292481718"></a><a name="p681292481718"></a>Open/Close</p> | WatchdogGetTimeout | Obtains the watchdog timeout duration.|
</td> | WatchdogGetStatus | Obtains the watchdog status.|
<td class="cellrowborder" valign="top" width="32.800000000000004%" headers="mcps1.2.4.1.2 "><p id="p183701419141710"><a name="p183701419141710"></a><a name="p183701419141710"></a>WatchdogOpen</p> | WatchdogFeed | Feeds a watchdog or resets a watchdog timer.|
</td>
<td class="cellrowborder" valign="top" width="40.58%" headers="mcps1.2.4.1.3 "><p id="p17370161911710"><a name="p17370161911710"></a><a name="p17370161911710"></a>Opens a watchdog.</p> > ![](../public_sys-resources/icon-note.gif) **NOTE**
</td> >
</tr> > All watchdog APIs provided in this document can be called only in kernel mode.
<tr id="row5610415171719"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p661171510173"><a name="p661171510173"></a><a name="p661171510173"></a>WatchdogClose</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p11611715161713"><a name="p11611715161713"></a><a name="p11611715161713"></a>Closes a watchdog.</p> ## Usage Guidelines
</td>
</tr>
<tr id="row337105133315"><td class="cellrowborder" rowspan="2" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p07631557153319"><a name="p07631557153319"></a><a name="p07631557153319"></a>Start/Stop</p> ### How to Use
</td>
<td class="cellrowborder" valign="top" width="32.800000000000004%" headers="mcps1.2.4.1.2 "><p id="p163765113337"><a name="p163765113337"></a><a name="p163765113337"></a>WatchdogStart</p> The figure below shows how to use the watchdog APIs.
</td>
<td class="cellrowborder" valign="top" width="40.58%" headers="mcps1.2.4.1.3 "><p id="p18376517332"><a name="p18376517332"></a><a name="p18376517332"></a>Starts a watchdog.</p> Figure 1 Using watchdog APIs
</td>
</tr> ![image](figures/using-watchdog-process.png)
<tr id="row18399184610337"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1740010461335"><a name="p1740010461335"></a><a name="p1740010461335"></a>WatchdogStop</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p19400194633318"><a name="p19400194633318"></a><a name="p19400194633318"></a>Stops a watchdog.</p> ### Opening a Watchdog
</td>
</tr> Use **WatchdogOpen()** to open a watchdog. A system may have multiple watchdogs. You need to specify the ID of the watchdog to open.
<tr id="row34145016535"><td class="cellrowborder" rowspan="2" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p229610227124"><a name="p229610227124"></a><a name="p229610227124"></a>Timeout duration</p>
</td> ```
<td class="cellrowborder" valign="top" width="32.800000000000004%" headers="mcps1.2.4.1.2 "><p id="p8296182221219"><a name="p8296182221219"></a><a name="p8296182221219"></a>WatchdogSetTimeout</p> DevHandle WatchdogOpen(int16_t wdtId);
</td> ```
<td class="cellrowborder" valign="top" width="40.58%" headers="mcps1.2.4.1.3 "><p id="p16297172213125"><a name="p16297172213125"></a><a name="p16297172213125"></a>Sets the watchdog timeout duration.</p>
</td> **Table 2** Description of WatchdogOpen
</tr>
<tr id="row11585016539"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1095722493616"><a name="p1095722493616"></a><a name="p1095722493616"></a>WatchdogGetTimeout</p> | **Parameter**| **Description**|
</td> | -------- | -------- |
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p15297162215122"><a name="p15297162215122"></a><a name="p15297162215122"></a>Obtains the watchdog timeout duration.</p> | wdtId | Watchdog ID.|
</td> | **Return Value**| **Description**|
</tr> | NULL | The operation failed.|
<tr id="row105701653185811"><td class="cellrowborder" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p2571145325819"><a name="p2571145325819"></a><a name="p2571145325819"></a>Status</p> | **DevHandle** pointer| The operation is successful. The pointer to the watchdog device handle is returned.|
</td>
<td class="cellrowborder" valign="top" width="32.800000000000004%" headers="mcps1.2.4.1.2 "><p id="p175711953195814"><a name="p175711953195814"></a><a name="p175711953195814"></a>WatchdogGetStatus</p>
</td>
<td class="cellrowborder" valign="top" width="40.58%" headers="mcps1.2.4.1.3 "><p id="p331961319210"><a name="p331961319210"></a><a name="p331961319210"></a>Obtains the watchdog status.</p>
</td>
</tr>
<tr id="row1028182217215"><td class="cellrowborder" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p182818227214"><a name="p182818227214"></a><a name="p182818227214"></a>Feeding</p>
</td>
<td class="cellrowborder" valign="top" width="32.800000000000004%" headers="mcps1.2.4.1.2 "><p id="p17281223219"><a name="p17281223219"></a><a name="p17281223219"></a>WatchdogFeed</p>
</td>
<td class="cellrowborder" valign="top" width="40.58%" headers="mcps1.2.4.1.3 "><p id="p62815221125"><a name="p62815221125"></a><a name="p62815221125"></a>Feeds a watchdog, or resets a watchdog timer.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>All watchdog functions provided in this document can be called only in kernel mode.
## Usage Guidelines<a name="section10103184312813"></a>
### How to Use<a name="section10181195910815"></a>
The figure below illustrates how to use the APIs.
**Figure 1** Using watchdog driver APIs
![](figures/using-watchdog-process.png "process-of-using-a-watchdog")
### Opening a Watchdog<a name="section66089201107"></a>
Use **WatchdogOpen** to open a watchdog. A system may have multiple watchdogs. You can open the specified watchdog by using the ID.
int32\_t WatchdogOpen\(int16\_t wdtId\);
**Table 2** Description of WatchdogOpen
<a name="table1413702552814"></a>
<table><thead align="left"><tr id="row131371325142819"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p191372254283"><a name="p191372254283"></a><a name="p191372254283"></a><strong id="b9239182472212"><a name="b9239182472212"></a><a name="b9239182472212"></a>Parameter</strong></p>
</th>
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p113819255284"><a name="p113819255284"></a><a name="p113819255284"></a><strong id="b2595142572219"><a name="b2595142572219"></a><a name="b2595142572219"></a>Description</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row813812259282"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p101381625162813"><a name="p101381625162813"></a><a name="p101381625162813"></a>wdtId</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p191381425142813"><a name="p191381425142813"></a><a name="p191381425142813"></a>Watchdog ID.</p>
</td>
</tr>
<tr id="row2138202515281"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p141387252287"><a name="p141387252287"></a><a name="p141387252287"></a><strong id="b185321027172216"><a name="b185321027172216"></a><a name="b185321027172216"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p12138192512281"><a name="p12138192512281"></a><a name="p12138192512281"></a><strong id="b29359286226"><a name="b29359286226"></a><a name="b29359286226"></a>Description</strong></p>
</td>
</tr>
<tr id="row9138182519287"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p5138102532814"><a name="p5138102532814"></a><a name="p5138102532814"></a>NULL</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p3138192512815"><a name="p3138192512815"></a><a name="p3138192512815"></a>Failed to open the watchdog.</p>
</td>
</tr>
<tr id="row15138192518283"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p1850115512916"><a name="p1850115512916"></a><a name="p1850115512916"></a><strong id="b17275323221"><a name="b17275323221"></a><a name="b17275323221"></a>DevHandle</strong> pointer</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p16138122512817"><a name="p16138122512817"></a><a name="p16138122512817"></a>Pointer to the watchdog handle.</p>
</td>
</tr>
</tbody>
</table>
``` ```
DevHandle handle = NULL; DevHandle handle = NULL;
...@@ -129,46 +65,23 @@ if (handle == NULL) { ...@@ -129,46 +65,23 @@ if (handle == NULL) {
} }
``` ```
### Obtaining the Watchdog Status<a name="section786624341011"></a>
### Obtaining the Watchdog Status
int32\_t WatchdogGetStatus\(DevHandle handle, int32\_t \*status\);
```
**Table 3** Description of WatchdogGetStatus int32_t WatchdogGetStatus(DevHandle handle, int32_t *status);
```
<a name="table1018490043"></a>
<table><thead align="left"><tr id="row31848013417"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b8395121072312"><a name="b8395121072312"></a><a name="b8395121072312"></a>Parameter</strong></p> **Table 3** Description of WatchdogGetStatus
</th>
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p11158111316410"><a name="p11158111316410"></a><a name="p11158111316410"></a><strong id="b20193201115238"><a name="b20193201115238"></a><a name="b20193201115238"></a>Description</strong></p> | **Parameter**| **Description**|
</th> | -------- | -------- |
</tr> | handle | Watchdog device handle.|
</thead> | status | Pointer to the watchdog status obtained.|
<tbody><tr id="row3264122711222"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p15264727182211"><a name="p15264727182211"></a><a name="p15264727182211"></a>handle</p> | **Return Value**| **Description**|
</td> | 0 | The operation is successful.|
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p2026452772210"><a name="p2026452772210"></a><a name="p2026452772210"></a>Watchdog handle.</p> | Negative value| The operation failed.|
</td>
</tr>
<tr id="row928111518418"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p4282955412"><a name="p4282955412"></a><a name="p4282955412"></a>status</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p7282752412"><a name="p7282752412"></a><a name="p7282752412"></a>Pointer to the watchdog status.</p>
</td>
</tr>
<tr id="row17393154515328"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p8158313248"><a name="p8158313248"></a><a name="p8158313248"></a><strong id="b12817162152319"><a name="b12817162152319"></a><a name="b12817162152319"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p161591413741"><a name="p161591413741"></a><a name="p161591413741"></a><strong id="b112451923142314"><a name="b112451923142314"></a><a name="b112451923142314"></a>Description</strong></p>
</td>
</tr>
<tr id="row339324593215"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p103191916578"><a name="p103191916578"></a><a name="p103191916578"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p1231981611712"><a name="p1231981611712"></a><a name="p1231981611712"></a>The watchdog status is obtained.</p>
</td>
</tr>
<tr id="row15393184519323"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p531916166716"><a name="p531916166716"></a><a name="p531916166716"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p93191161174"><a name="p93191161174"></a><a name="p93191161174"></a>Failed to obtain the watchdog status.</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
...@@ -181,51 +94,28 @@ if (ret != 0) { ...@@ -181,51 +94,28 @@ if (ret != 0) {
} }
``` ```
### Setting the Timeout Duration<a name="section182386137111"></a>
### Setting the Timeout Duration
int32\_t WatchdogSetTimeout\(PalHandle \*handle, uint32\_t seconds\);
```
**Table 4** Description of WatchdogSetTimeout int32_t WatchdogSetTimeout(DevHandle *handle, uint32_t seconds);
```
<a name="table9159112182210"></a>
<table><thead align="left"><tr id="row1216012212212"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1416017262215"><a name="p1416017262215"></a><a name="p1416017262215"></a><strong id="b16573184672318"><a name="b16573184672318"></a><a name="b16573184672318"></a>Parameter</strong></p> **Table 4** Description of WatchdogSetTimeout
</th>
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p16160182192213"><a name="p16160182192213"></a><a name="p16160182192213"></a><strong id="b8612347182320"><a name="b8612347182320"></a><a name="b8612347182320"></a>Description</strong></p> | **Parameter**| **Description**|
</th> | -------- | -------- |
</tr> | handle | Pointer to the watchdog device handle.|
</thead> | seconds | Timeout duration to set, in seconds.|
<tbody><tr id="row199536232314"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p17685481236"><a name="p17685481236"></a><a name="p17685481236"></a>handle</p> | **Return Value**| **Description**|
</td> | 0 | The operation is successful.|
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p196852811232"><a name="p196852811232"></a><a name="p196852811232"></a>Watchdog handle.</p> | Negative value| The operation failed.|
</td>
</tr>
<tr id="row141601729228"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p191601126226"><a name="p191601126226"></a><a name="p191601126226"></a>seconds</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p5160172182214"><a name="p5160172182214"></a><a name="p5160172182214"></a>Timeout duration, in seconds.</p>
</td>
</tr>
<tr id="row18160192172212"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p101601123222"><a name="p101601123222"></a><a name="p101601123222"></a><strong id="b12598352112317"><a name="b12598352112317"></a><a name="b12598352112317"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p17160192182212"><a name="p17160192182212"></a><a name="p17160192182212"></a><strong id="b145511753122319"><a name="b145511753122319"></a><a name="b145511753122319"></a>Description</strong></p>
</td>
</tr>
<tr id="row171600202220"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p121601226224"><a name="p121601226224"></a><a name="p121601226224"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p151607218222"><a name="p151607218222"></a><a name="p151607218222"></a>The setting is successful.</p>
</td>
</tr>
<tr id="row916012252211"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p19160026224"><a name="p19160026224"></a><a name="p19160026224"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p816092142210"><a name="p816092142210"></a><a name="p816092142210"></a>Setting failed.</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
uint32_t timeOut = 60; uint32_t timeOut = 60;
/* Set the timeout duration, in seconds. */ /* Set the timeout duration to 60 seconds. */
ret = WatchdogSetTimeout(handle, timeOut); ret = WatchdogSetTimeout(handle, timeOut);
if (ret != 0) { if (ret != 0) {
HDF_LOGE("WatchdogSetTimeout: failed, ret %d\n", ret); HDF_LOGE("WatchdogSetTimeout: failed, ret %d\n", ret);
...@@ -233,46 +123,23 @@ if (ret != 0) { ...@@ -233,46 +123,23 @@ if (ret != 0) {
} }
``` ```
### Obtaining the Timeout Duration<a name="section1883310371114"></a>
### Obtaining the Timeout Duration
int32\_t WatchdogGetTimeout\(PalHandle \*handle, uint32\_t \*seconds\);
```
**Table 5** Description of WatchdogGetTimeout int32_t WatchdogGetTimeout(DevHandle *handle, uint32_t *seconds);
```
<a name="table10147164819233"></a>
<table><thead align="left"><tr id="row14147848142313"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p4147124892316"><a name="p4147124892316"></a><a name="p4147124892316"></a><strong id="b1387481413247"><a name="b1387481413247"></a><a name="b1387481413247"></a>Parameter</strong></p> **Table 5** Description of WatchdogGetTimeout
</th>
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p12147144817232"><a name="p12147144817232"></a><a name="p12147144817232"></a><strong id="b7800151515242"><a name="b7800151515242"></a><a name="b7800151515242"></a>Description</strong></p> | **Parameter**| **Description**|
</th> | -------- | -------- |
</tr> | handle | Pointer to the watchdog device handle.|
</thead> | seconds | Pointer to the timeout duration, in seconds.|
<tbody><tr id="row8147124819230"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p21471248142313"><a name="p21471248142313"></a><a name="p21471248142313"></a>handle</p> | **Return Value**| **Description**|
</td> | 0 | The operation is successful.|
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p12147134815233"><a name="p12147134815233"></a><a name="p12147134815233"></a>Watchdog handle.</p> | Negative value| The operation failed.|
</td>
</tr>
<tr id="row514754818232"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p1614713484235"><a name="p1614713484235"></a><a name="p1614713484235"></a>seconds</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p71478484238"><a name="p71478484238"></a><a name="p71478484238"></a>Pointer to the timeout duration, in seconds.</p>
</td>
</tr>
<tr id="row214784814239"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p5147848152314"><a name="p5147848152314"></a><a name="p5147848152314"></a><strong id="b2468182016249"><a name="b2468182016249"></a><a name="b2468182016249"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p914724811236"><a name="p914724811236"></a><a name="p914724811236"></a><strong id="b18272182132419"><a name="b18272182132419"></a><a name="b18272182132419"></a>Description</strong></p>
</td>
</tr>
<tr id="row714744892312"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p1014764832315"><a name="p1014764832315"></a><a name="p1014764832315"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p1314824872310"><a name="p1314824872310"></a><a name="p1314824872310"></a>The watchdog status is obtained.</p>
</td>
</tr>
<tr id="row1514884815230"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p10148114822319"><a name="p10148114822319"></a><a name="p10148114822319"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p1314864822311"><a name="p1314864822311"></a><a name="p1314864822311"></a>Failed to obtain the watchdog status.</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
...@@ -285,41 +152,22 @@ if (ret != 0) { ...@@ -285,41 +152,22 @@ if (ret != 0) {
} }
``` ```
### Starting a Watchdog<a name="section82501405123"></a>
### Starting a Watchdog
int32\_t WatchdogStart\(DevHandle handle\);
```
**Table 6** Description of WatchdogStart int32_t WatchdogStart(DevHandle handle);
```
<a name="table529165182515"></a>
<table><thead align="left"><tr id="row92915122513"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p5292582517"><a name="p5292582517"></a><a name="p5292582517"></a><strong id="b99151951162417"><a name="b99151951162417"></a><a name="b99151951162417"></a>Parameter</strong></p> **Table 6** Description of WatchdogStart
</th>
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p929554258"><a name="p929554258"></a><a name="p929554258"></a><strong id="b121171651142418"><a name="b121171651142418"></a><a name="b121171651142418"></a>Description</strong></p> | **Parameter**| **Description**|
</th> | -------- | -------- |
</tr> | handle | Watchdog device handle.|
</thead> | **Return Value**| **Description**|
<tbody><tr id="row629852250"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p22975122515"><a name="p22975122515"></a><a name="p22975122515"></a>handle</p> | 0 | The operation is successful.|
</td> | Negative value| The operation failed.|
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p7290515256"><a name="p7290515256"></a><a name="p7290515256"></a>Watchdog handle.</p>
</td>
</tr>
<tr id="row183035162514"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p8302511255"><a name="p8302511255"></a><a name="p8302511255"></a><strong id="b1190315442414"><a name="b1190315442414"></a><a name="b1190315442414"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p16307522515"><a name="p16307522515"></a><a name="p16307522515"></a><strong id="b333525652414"><a name="b333525652414"></a><a name="b333525652414"></a>Description</strong></p>
</td>
</tr>
<tr id="row12305552510"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p1730175132513"><a name="p1730175132513"></a><a name="p1730175132513"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p630754259"><a name="p630754259"></a><a name="p630754259"></a>The watchdog is started.</p>
</td>
</tr>
<tr id="row4306516252"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p15304502515"><a name="p15304502515"></a><a name="p15304502515"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p0301559254"><a name="p0301559254"></a><a name="p0301559254"></a>Failed to start the watchdog.</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
...@@ -331,41 +179,22 @@ if (ret != 0) { ...@@ -331,41 +179,22 @@ if (ret != 0) {
} }
``` ```
### Feeding a Watchdog<a name="section3547530101211"></a>
### Feeding a Watchdog
int32\_t WatchdogFeed\(DevHandle handle\);
```
**Table 7** Description of WatchdogFeed int32_t WatchdogFeed(DevHandle handle);
```
<a name="table091163515394"></a>
<table><thead align="left"><tr id="row891133515393"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1911143513918"><a name="p1911143513918"></a><a name="p1911143513918"></a><strong id="b16850010142518"><a name="b16850010142518"></a><a name="b16850010142518"></a>Parameter</strong></p> **Table 7** Description of WatchdogFeed
</th>
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p1191173553917"><a name="p1191173553917"></a><a name="p1191173553917"></a><strong id="b8711511102516"><a name="b8711511102516"></a><a name="b8711511102516"></a>Description</strong></p> | **Parameter**| **Description**|
</th> | -------- | -------- |
</tr> | handle | Watchdog device handle.|
</thead> | **Return Value**| **Description**|
<tbody><tr id="row189111635143918"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p189111435173917"><a name="p189111435173917"></a><a name="p189111435173917"></a>handle</p> | 0 | The operation is successful.|
</td> | Negative value| The operation failed.|
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p11911143511397"><a name="p11911143511397"></a><a name="p11911143511397"></a>Watchdog handle.</p>
</td>
</tr>
<tr id="row15911835173916"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p7911123516396"><a name="p7911123516396"></a><a name="p7911123516396"></a><strong id="b11359914162517"><a name="b11359914162517"></a><a name="b11359914162517"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p169118356399"><a name="p169118356399"></a><a name="p169118356399"></a><strong id="b7180915162512"><a name="b7180915162512"></a><a name="b7180915162512"></a>Description</strong></p>
</td>
</tr>
<tr id="row189119352393"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p1391113513917"><a name="p1391113513917"></a><a name="p1391113513917"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p149111435143911"><a name="p149111435143911"></a><a name="p149111435143911"></a>The watchdog is fed.</p>
</td>
</tr>
<tr id="row5911123520392"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p49111335143920"><a name="p49111335143920"></a><a name="p49111335143920"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p1891216356391"><a name="p1891216356391"></a><a name="p1891216356391"></a>Failed to feed the watchdog.</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
...@@ -377,41 +206,22 @@ if (ret != 0) { ...@@ -377,41 +206,22 @@ if (ret != 0) {
} }
``` ```
### Stopping a Watchdog<a name="section944595841217"></a>
### Stopping a Watchdog
int32\_t WatchdogStop\(DevHandle handle\);
```
**Table 8** Description of WatchdogStop int32_t WatchdogStop(DevHandle handle);
```
<a name="table1286810515254"></a>
<table><thead align="left"><tr id="row28687517259"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p6868185120254"><a name="p6868185120254"></a><a name="p6868185120254"></a><strong id="b204221347152519"><a name="b204221347152519"></a><a name="b204221347152519"></a>Parameter</strong></p> **Table 8** Description of WatchdogStop
</th>
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p15868185114252"><a name="p15868185114252"></a><a name="p15868185114252"></a><strong id="b8153154862516"><a name="b8153154862516"></a><a name="b8153154862516"></a>Description</strong></p> | **Parameter**| **Description**|
</th> | -------- | -------- |
</tr> | handle | Watchdog device handle.|
</thead> | **Return Value**| **Description**|
<tbody><tr id="row1868165114256"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p6869105115256"><a name="p6869105115256"></a><a name="p6869105115256"></a>handle</p> | 0 | The operation is successful.|
</td> | Negative value| The operation failed.|
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p19869951202513"><a name="p19869951202513"></a><a name="p19869951202513"></a>Watchdog handle.</p>
</td>
</tr>
<tr id="row68696510259"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p2869165114256"><a name="p2869165114256"></a><a name="p2869165114256"></a><strong id="b2116105210253"><a name="b2116105210253"></a><a name="b2116105210253"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p158691551142517"><a name="p158691551142517"></a><a name="p158691551142517"></a><strong id="b8888115292518"><a name="b8888115292518"></a><a name="b8888115292518"></a>Description</strong></p>
</td>
</tr>
<tr id="row9869851192516"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p686916516252"><a name="p686916516252"></a><a name="p686916516252"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p7869115192510"><a name="p7869115192510"></a><a name="p7869115192510"></a>The watchdog is stopped.</p>
</td>
</tr>
<tr id="row15869951122519"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p486925112518"><a name="p486925112518"></a><a name="p486925112518"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p086945172518"><a name="p086945172518"></a><a name="p086945172518"></a>Stopping the watchdog failed.</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
...@@ -423,44 +233,38 @@ if (ret != 0) { ...@@ -423,44 +233,38 @@ if (ret != 0) {
} }
``` ```
### Closing a Watchdog<a name="section96561824121311"></a>
If the watchdog is no longer required, call **WatchdogClose** to close the watchdog handle. ### Closing a Watchdog
void WatchdogClose\(DevHandle handle\); If a watchdog is no longer required, call **WatchdogClose()** to close it.
**Table 9** Description of WatchdogClose ```
void WatchdogClose(DevHandle handle);
```
**Table 9** Description of WatchdogClose
| **Parameter**| **Description**|
| -------- | -------- |
| handle | Watchdog device handle.|
<a name="table1017315185320"></a>
<table><thead align="left"><tr id="row417314182327"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p117310184320"><a name="p117310184320"></a><a name="p117310184320"></a><strong id="b97421847122514"><a name="b97421847122514"></a><a name="b97421847122514"></a>Parameter</strong></p>
</th>
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p7173191812324"><a name="p7173191812324"></a><a name="p7173191812324"></a><strong id="b14503748122514"><a name="b14503748122514"></a><a name="b14503748122514"></a>Description</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row1617331823211"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p17173191811326"><a name="p17173191811326"></a><a name="p17173191811326"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p538814308323"><a name="p538814308323"></a><a name="p538814308323"></a>Watchdog handle.</p>
</td>
</tr>
</tbody>
</table>
``` ```
/* Close the watchdog. */ /* Close the watchdog. */
ret = WatchdogClose(handle); ret = WatchdogClose(handle);
``` ```
## Usage Example<a name="section1724514523135"></a>
This example provides a complete process for using a watchdog. ## Example
In this example, open a watchdog, set the timeout duration, and start the watchdog. The following example provides the complete development process.
- Feed the watchdog periodically to ensure that the system is not reset due to timer expiry. 1. Open a watchdog, set the timeout duration, and start the watchdog.
- Stop feeding the watchdog and check whether the system is reset after the timer expires.
Example: 2. Feed the watchdog periodically to ensure that the system is not reset due to timer expiry.
3. Stop feeding the watchdog and check whether the system is reset after the timer expires.
Sample code:
``` ```
#include "watchdog_if.h" #include "watchdog_if.h"
...@@ -481,7 +285,7 @@ static int32_t TestCaseWatchdog(void) ...@@ -481,7 +285,7 @@ static int32_t TestCaseWatchdog(void)
/* Open watchdog 0. */ /* Open watchdog 0. */
handle = WatchdogOpen(0); handle = WatchdogOpen(0);
if (handle == NULL) { if (handle == NULL) {
HDF_LOGE("Open watchdog fail!"); HDF_LOGE("Open watchdog failed!");
return -1; return -1;
} }
...@@ -493,7 +297,7 @@ static int32_t TestCaseWatchdog(void) ...@@ -493,7 +297,7 @@ static int32_t TestCaseWatchdog(void)
return ret; return ret;
} }
/* Obtain the configured timeout duration. */ /* Obtain the timeout duration. */
ret = WatchdogGetTimeout(handle, &timeout); ret = WatchdogGetTimeout(handle, &timeout);
if (ret != HDF_SUCCESS) { if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: get timeout fail! ret:%d\n", __func__, ret); HDF_LOGE("%s: get timeout fail! ret:%d\n", __func__, ret);
...@@ -505,14 +309,14 @@ static int32_t TestCaseWatchdog(void) ...@@ -505,14 +309,14 @@ static int32_t TestCaseWatchdog(void)
/* Start the watchdog. The timer starts. */ /* Start the watchdog. The timer starts. */
ret = WatchdogStart(handle); ret = WatchdogStart(handle);
if (ret != HDF_SUCCESS) { if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: satrt fail! ret:%d\n", __func__, ret); HDF_LOGE("%s: start fail! ret:%d\n", __func__, ret);
WatchdogClose(handle); WatchdogClose(handle);
return ret; return ret;
} }
/* Feed the watchdog every 1s. */ /* Feed the watchdog every other second. */
for (i = 0; i < WATCHDOG_TEST_FEED_TIME; i++) { for (i = 0; i < WATCHDOG_TEST_FEED_TIME; i++) {
HDF_LOGE("%s: feeding watchdog %d times... \n", __func__, i); HDF_LOGI("%s: feeding watchdog %d times... \n", __func__, i);
ret = WatchdogFeed(handle); ret = WatchdogFeed(handle);
if (ret != HDF_SUCCESS) { if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: feed dog fail! ret:%d\n", __func__, ret); HDF_LOGE("%s: feed dog fail! ret:%d\n", __func__, ret);
...@@ -522,17 +326,17 @@ static int32_t TestCaseWatchdog(void) ...@@ -522,17 +326,17 @@ static int32_t TestCaseWatchdog(void)
OsalSleep(1); OsalSleep(1);
} }
/* Because the interval for feeding the watchdog is shorter than the timeout duration, the system does not reset, and logs can be printed normally. */ /* Because the interval for feeding the watchdog is shorter than the timeout duration, the system does not reset, and logs can be printed normally. */
HDF_LOGE("%s: no reset ... feeding test OK!!!\n", __func__); HDF_LOGI("%s: no reset ... feeding test OK!!!\n", __func__);
/* Enable the timer to expire by stopping feeding the watchdog. */ /* Stop feeding the watchdog to make the timer expire. */
for (i = 0; i < WATCHDOG_TEST_FEED_TIME; i++) { for (i = 0; i < WATCHDOG_TEST_FEED_TIME; i++) {
HDF_LOGE("%s: watiting dog buck %d times... \n", __func__, i); HDF_LOGI("%s: waiting dog buck %d times... \n", __func__, i);
OsalSleep(1); OsalSleep(1);
} }
/* The system resets when the timer expires. If the code is correct, the log below is not displayed. */ /* The system resets when the timer expires. Theoretically, this log is not displayed. */
HDF_LOGE("%s: dog has't buck!!! \n", __func__, i); HDF_LOGI("%s: dog hasn't back!!! \n", __func__, i);
WatchdogClose(handle); WatchdogClose(handle);
return -1; return -1;
} }
``` ```
\ No newline at end of file
# Watchdog<a name="EN-US_TOPIC_0000001199821009"></a> # Watchdog
## Overview<a name="section1315827527160117"></a> ## **Overview**
In the Hardware Driver Foundation \(HDF\), the Watchdog \(also called Watchdog timer\) module uses the independent service mode for API adaptation. In this mode, each device independently publishes a device service to handle external access requests. After receiving an access request from an API, the device manager extracts the parameters in the request to call the internal method of the target device. In the independent service mode, the service management capabilities of the HDF Device Manager can be directly used. However, you need to configure a device node for each device, which increases the memory usage. A 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.
**Figure 1** Independent service mode<a name="fig61584136211"></a> In the Hardware Driver Foundation (HDF), the watchdog uses the independent service mode 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.
![](figures/independent-service-mode.png "independent-service-mode-15")
## Available APIs<a name="section1180575010271"></a> **Figure 1** Independent service mode
![image](figures/independent-service-mode.png "Watchdog independent service mode")
## **Available APIs**
**WatchdogMethod**:
WatchdogMethod
``` ```
struct WatchdogMethod { struct WatchdogMethod {
...@@ -25,339 +30,249 @@ struct WatchdogMethod { ...@@ -25,339 +30,249 @@ struct WatchdogMethod {
}; };
``` ```
**Table 1** Callbacks for the members in the WatchdogMethod structure **Table 1** Description of the callback functions in WatchdogMethod
<a name="table1370451732"></a> | Function| Input Parameter| Output Parameter| Return Value| Description|
<table><thead align="left"><tr id="row370511435"><th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.1"><p id="p170681939"><a name="p170681939"></a><a name="p170681939"></a>Callback</p> | -------- | -------- | -------- | -------- | -------- |
</th> | getStatus | **wdt**: structure pointer to the watchdog controller at the core layer.| **status**: int32_t pointer to the watchdog status (started or stopped).| HDF_STATUS| Obtains the watchdog status.|
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.2"><p id="p870641434"><a name="p870641434"></a><a name="p870641434"></a>Input Parameter</p> | start | **wdt**: structure pointer to the watchdog controller at the core layer.| –| HDF_STATUS| Starts a watchdog.|
</th> | stop | **wdt**: structure pointer to the watchdog controller at the core layer.| –| HDF_STATUS | Stops a watchdog.|
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.3"><p id="p27061011739"><a name="p27061011739"></a><a name="p27061011739"></a>Output Parameter</p> | setTimeout | **wdt**: structure pointer to the watchdog controller at the core layer.<br/>**seconds**: Timeout duration to set, in seconds. The value is of the uint32_t type. | – | HDF_STATUS | Sets the timeout duration for a watchdog. |
</th> | getTimeout | **wdt**: structure pointer to the watchdog controller at the core layer.| **seconds**: Pointer to the watchdog timeout duration obtained. The value is of the uint32_t type. | HDF_STATUS| Obtains the timeout duration of a watchdog.|
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.4"><p id="p10707618315"><a name="p10707618315"></a><a name="p10707618315"></a>Return Value</p> | feed | **wdt**: structure pointer to the watchdog controller at the core layer.| –| HDF_STATUS| Feeds a watchdog. |
</th>
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.5"><p id="p37071516316"><a name="p37071516316"></a><a name="p37071516316"></a>Description</p>
</th> ## How to Develop
</tr>
</thead> The watchdog module adaptation involves the following steps:
<tbody><tr id="row18707191835"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p970720118311"><a name="p970720118311"></a><a name="p970720118311"></a>getStatus</p>
</td> 1. Instantiate the driver entry.
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p124968261413"><a name="p124968261413"></a><a name="p124968261413"></a><strong id="b13481135102819"><a name="b13481135102819"></a><a name="b13481135102819"></a>wdt</strong>: structure pointer to the Watchdog controller at the core layer.</p> - Instantiate the **HdfDriverEntry** structure.
</td> - Call **HDF_INIT** to register the **HdfDriverEntry** instance with the HDF.
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p17071515316"><a name="p17071515316"></a><a name="p17071515316"></a><strong id="b142021397417"><a name="b142021397417"></a><a name="b142021397417"></a>status</strong>: int32_t pointer indicating the watchdog status (started or stopped).</p>
</td> 2. Configure attribute files.
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p5707319312"><a name="p5707319312"></a><a name="p5707319312"></a>HDF_STATUS</p> - Add the **deviceNode** information to the **device_info.hcs** file.
</td> - (Optional) Add the **watchdog_config.hcs** file.
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p2707511312"><a name="p2707511312"></a><a name="p2707511312"></a>Obtains the watchdog status.</p>
</td> 3. Instantiate the watchdog controller object.
</tr> - Initialize **WatchdogCntlr**.
<tr id="row27071911538"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p370701533"><a name="p370701533"></a><a name="p370701533"></a>start</p> - Instantiate **WatchdogMethod** in the **WatchdogCntlr** object.
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p117071316317"><a name="p117071316317"></a><a name="p117071316317"></a><strong id="b136901310133110"><a name="b136901310133110"></a><a name="b136901310133110"></a>wdt</strong>: structure pointer to the Watchdog controller at the core layer.</p> > ![](../public_sys-resources/icon-note.gif) **NOTE**
</td> >
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p127071411735"><a name="p127071411735"></a><a name="p127071411735"></a></p> > For details about the functions in **WatchdogMethod**, see [Available APIs](#available-apis).
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p19707111331"><a name="p19707111331"></a><a name="p19707111331"></a>HDF_STATUS</p> 4. Debug the driver.
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p170811111319"><a name="p170811111319"></a><a name="p170811111319"></a>Starts a watchdog.</p> (Optional) For new drivers, verify basic functions, for example, check the information returned after the driver is attached and whether the watchdog timer is successfully set.
</td>
</tr>
<tr id="row17708191130"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p11708113315"><a name="p11708113315"></a><a name="p11708113315"></a>stop</p> ## Development Example
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p870841138"><a name="p870841138"></a><a name="p870841138"></a><strong id="b14846151912249"><a name="b14846151912249"></a><a name="b14846151912249"></a>wdt</strong>: structure pointer to the Watchdog controller at the core layer.</p> The following uses **watchdog_hi35xx.c** as an example to present the information required for implementing device functions.
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p770841533"><a name="p770841533"></a><a name="p770841533"></a></p> 1. Instantiate the driver entry.
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p18708115313"><a name="p18708115313"></a><a name="p18708115313"></a>HDF_STATUS</p> The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p3708121738"><a name="p3708121738"></a><a name="p3708121738"></a>Stops a watchdog.</p> Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
</td>
</tr> Watchdog driver entry example:
<tr id="row107081818310"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p10708181136"><a name="p10708181136"></a><a name="p10708181136"></a>setTimeout</p>
</td> ```
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p2021212409407"><a name="p2021212409407"></a><a name="p2021212409407"></a><strong id="b1521224016409"><a name="b1521224016409"></a><a name="b1521224016409"></a>wdt</strong>: structure pointer to the Watchdog controller at the core layer.</p> struct HdfDriverEntry g_watchdogDriverEntry = {
<p id="p1870801834"><a name="p1870801834"></a><a name="p1870801834"></a><strong id="b721091763217"><a name="b721091763217"></a><a name="b721091763217"></a>seconds</strong>: input time value, which is of the uint32_t type.</p> .moduleVersion = 1,
</td> .Bind = Hi35xxWatchdogBind, // See the Bind function.
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p77081011731"><a name="p77081011731"></a><a name="p77081011731"></a></p> .Init = Hi35xxWatchdogInit, // See the Init function.
</td> .Release = Hi35xxWatchdogRelease, // See the Release function.
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p470871436"><a name="p470871436"></a><a name="p470871436"></a>HDF_STATUS</p> .moduleName = "HDF_PLATFORM_WATCHDOG",// (Mandatory) The value must be the same as that of moduleName in the .hcs file.
</td> };
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p57091717315"><a name="p57091717315"></a><a name="p57091717315"></a>Sets the timeout period (in seconds) for a watchdog. Ensure that the actual watchdog running time complies with this setting.</p> HDF_INIT(g_watchdogDriverEntry);// Call HDF_INIT to register the driver entry with the HDF.
</td> ```
</tr>
<tr id="row3709911938"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p2070911932"><a name="p2070911932"></a><a name="p2070911932"></a>getTimeout</p> 2. Add the **deviceNode** information to the **device_info.hcs** file and configure the component attributes in the **watchdog_config.hcs** file.
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p47091711732"><a name="p47091711732"></a><a name="p47091711732"></a><strong id="b88511419192416"><a name="b88511419192416"></a><a name="b88511419192416"></a>wdt</strong>: structure pointer to the Watchdog controller at the core layer.</p> The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **WatchdogCntlr** members at the core layer.
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p57091411632"><a name="p57091411632"></a><a name="p57091411632"></a><strong id="b3906135871316"><a name="b3906135871316"></a><a name="b3906135871316"></a>seconds</strong>: output time value, which is of the uint32_t type.</p> In this example, there is only one watchdog controller. If there are multiple watchdog controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **watchdog_config** file for each controller.
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p1470941838"><a name="p1470941838"></a><a name="p1470941838"></a>HDF_STATUS</p> - **device_info.hcs** configuration example:
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p17091511139"><a name="p17091511139"></a><a name="p17091511139"></a>Obtains the timeout period of a watchdog.</p>
</td> ```
</tr> root {
<tr id="row1770919112319"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p1270913116313"><a name="p1270913116313"></a><a name="p1270913116313"></a>feed</p> device_info {
</td> match_attr = "hdf_manager";
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p570971736"><a name="p570971736"></a><a name="p570971736"></a><strong id="b1854319172417"><a name="b1854319172417"></a><a name="b1854319172417"></a>wdt</strong>: structure pointer to the Watchdog controller at the core layer.</p> device_watchdog :: device {// Device node.
</td> device0:: deviceNode { // Device node of the driver.
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p67091517315"><a name="p67091517315"></a><a name="p67091517315"></a></p> policy = 1; // Policy for the driver to provide services.
</td> priority = 20; // Driver startup priority.
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p1670915111312"><a name="p1670915111312"></a><a name="p1670915111312"></a>HDF_STATUS</p> permission = 0644; // Permission to create device nodes for the driver.
</td> moduleName = "HDF_PLATFORM_WATCHDOG";
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p10709818316"><a name="p10709818316"></a><a name="p10709818316"></a>Feeds a watchdog. </p> // (Mandatory) Driver name. The value must be the same as that of moduleName in the driver entry structure.
</td> serviceName = "HDF_PLATFORM_WATCHDOG_0";
</tr> // (Mandatory) Unique name of the service published by the driver.
</tbody> deviceMatchAttr = "hisilicon_hi35xx_watchdog_0";
</table> // (Mandatory) Keyword matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver.
}
}
## How to Develop<a name="section477974542160117"></a> }
}
The Watchdog module adaptation involves the following steps: ```
1. Instantiate the driver entry. - **watchdog_config.hcs** configuration example:
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
```
2. Configure attribute files. root {
- Add the **deviceNode** information to the **device\_info.hcs** file. platform {
- \(Optional\) Add the **watchdog\_config.hcs** file. template watchdog_controller {// (Mandatory) Template configuration. In the template, you can configure the common parameters shared by device nodes.
id = 0;
3. Instantiate the Watchdog controller object. match_attr = "";
- Initialize **WatchdogCntlr**. regBase = 0x12050000; // (Mandatory) Used for address mapping.
- Instantiate **WatchdogMethod** in the **WatchdogCntlr** object. regStep = 0x1000; // (Mandatory) Used for address mapping.
}
>![](../public_sys-resources/icon-note.gif) **NOTE** controller_0x12050000 :: watchdog_controller {// (Mandatory) Keyword for matching the private data of the device driver.
match_attr = "hisilicon_hi35xx_watchdog_0"; // (Mandatory) The value must be the same as that of deviceMatchAttr in device_info.hcs.
>For details, see [Available APIs](#available-apis). }
// Configure this parameter when there are multiple watchdogs.
...
4. Debug the driver. }
- \(Optional\) For new drivers, verify basic functions, for example, verify the information returned after the connect operation and whether the watchdog timer is successfully set. }
```
## Development Example<a name="section1832270347160117"></a> 3. Initialize the **WatchdogCntlr** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **WatchdogMethod** in **WatchdogCntlr** (so that the underlying driver functions can be called).
- Defining a custom structure
The following uses **watchdog\_hi35xx.c** as an example to present the contents that need to be provided by the vendor to implement device functions.
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **watchdog_config.hcs** file to initialize the members in the custom structure and passes important parameters, such as the index and the number of pins, to the **WatchdogCntlr** object at the core layer.
1. Instantiate the driver entry. The driver entry must be a global variable of the **HdfDriverEntry** type \(defined in **hdf\_device\_desc.h**\), and the value of **moduleName** must be the same as that in **device\_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
Generally, HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, HDF calls **Release** to release driver resources and exit. ```
struct Hi35xxWatchdog {
- Watchdog driver entry reference struct WatchdogCntlr wdt; // (Mandatory) Carrier that connects the upper and underlying layers. For details, see the following description.
OsalSpinlock lock;
``` volatile unsigned char *regBase;// [Mandatory] Used for address mapping.
struct HdfDriverEntry g_watchdogDriverEntry = { uint32_t phyBase; // (Mandatory) Used for address mapping.
.moduleVersion = 1, uint32_t regStep; // (Mandatory) Used for address mapping.
.Bind = Hi35xxWatchdogBind, // See the Bind function. };
.Init = Hi35xxWatchdogInit, // See the Init function. // WatchdogCntlr is the core layer controller structure. The Init function assigns values to the members of WatchdogCntlr.
.Release = Hi35xxWatchdogRelease, //See the Release function. struct WatchdogCntlr {
.moduleName = "HDF_PLATFORM_WATCHDOG",// (Mandatory) The value must be the same as that of moduleName in the .hcs file. struct IDeviceIoService service;// Driver service.
}; struct HdfDeviceObject *device; // Driver device.
HDF_INIT(g_watchdogDriverEntry);// Call HDF_INIT to register the driver entry with the HDF. OsalSpinlock lock; // This variable is called by the HDF core layer to implement the spinlock function.
``` struct WatchdogMethod *ops; // Callbacks.
int16_t wdtId // ID of the watchdog device.
2. Add the **deviceNode** information to the **device\_info.hcs** file and configure the component attributes in the **watchdog\_config.hcs** file. The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **WatchdogCntlr** members at the core layer. void *priv; // Pointer to the driver's private data.
};
In this example, there is only one Watchdog controller. If there are multiple Watchdog controllers, you need to add the **deviceNode** information to the **device\_info** file and add the corresponding device attributes to the **watchdog\_config** file. ```
- **device\_info.hcs** configuration reference - Instantiating **WatchdogMethod** in **WatchdogCntlr** (other members are initialized by **Init** and **Bind**)
```
root { ```
device_info { static struct WatchdogMethod g_method = {
match_attr = "hdf_manager"; .getStatus = Hi35xxWatchdogGetStatus,
device_watchdog :: device {// Device node .start = Hi35xxWatchdogStart,
device0:: deviceNode {// DeviceNode of the driver .stop = Hi35xxWatchdogStop,
The policy = 1; // The value 1 indicates that the driver publishes kernel-mode services. The value 2 indicates that the driver publishes user-mode services. .setTimeout = Hi35xxWatchdogSetTimeout,
priority = 20; // Driver startup priority .getTimeout = Hi35xxWatchdogGetTimeout,
permission = 0644; // Permission to create device nodes for the driver .feed = Hi35xxWatchdogFeed,
moduleName = "HDF_PLATFORM_WATCHDOG"; };
// (Mandatory) Driver name. The value must be the same as that of moduleName in the driver entry structure. ```
serviceName = "HDF_PLATFORM_WATCHDOG_0";
// (Mandatory) Unique name of the service published by the driver. - **Init** and **Bind** functions
deviceMatchAttr = "hisilicon_hi35xx_watchdog_0";
// (Mandatory) Keyword matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver. Input parameter:
}
} **HdfDeviceObject**, a device object created by the HDF for each driver, holds device-related private data and service APIs.
}
} Return value:
```
HDF_STATUS
- **watchdog\_config.hcs** configuration reference
The table below lists some status. For more information, see **HDF_STATUS** in the /drivers/framework/include/utils/hdf_base.h file.
```
root { **Table 2** HDF_STATUS
platform {
template watchdog_controller {// Template configuration. In the template, you can configure the common parameters shared by service nodes. | Status| Description|
id = 0; | -------- | -------- |
match_attr = ""; | HDF_ERR_INVALID_OBJECT | Failed to locate the watchdog device.|
regBase = 0x12050000; // (Mandatory) Used for address mapping. | HDF_ERR_MALLOC_FAIL | Failed to allocate memory.|
regStep = 0x1000; // (Mandatory) Used for address mapping. | HDF_ERR_IO | I/O error.|
} | HDF_SUCCESS | Initialization successful.|
controller_0x12050000 :: watchdog_controller {// (Mandatory) Keyword for matching the private data of the device driver. | HDF_FAILURE | Initialization failed.|
match_attr = "hisilicon_hi35xx_watchdog_0"; // (Mandatory) The value must be the same as that of deviceMatchAttr in device_info.hcs.
} Function description:
// Configure this parameter when there are multiple watchdogs.
... Initializes the custom structure object and **WatchdogCntlr**, and calls the **WatchdogCntlrAdd** function at the core layer.
}
}
``` ```
// Generally, the Init function initializes the members of the Hi35xxWatchdog structure based on the attribute values in **HdfDeviceObject**.
3. Initialize the **WatchdogCntlr** object at the core layer, including initializing the vendor custom structure \(passing parameters and data\), instantiating **WatchdogMethod** \(used to call underlying functions of the driver\) in **WatchdogCntlr**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\). // In this example, the Bind function initializes the Hi35xxWatchdog structure.
- Custom structure reference static int32_t Hi35xxWatchdogInit(struct HdfDeviceObject *device)
{
To the driver, the custom structure carries parameters and data. The values in the **watchdog\_config.hcs** file are read by HDF, and the structure members are initialized through **DeviceResourceIface**. Some important values, such as the index and the number of pins, are also passed to the **WatchdogCntlr** object at the core layer. (void)device;
return HDF_SUCCESS;
``` }
struct Hi35xxWatchdog {
struct WatchdogCntlr wdt; // (Mandatory) Carrier that connects the upper and underlying layers. For details, see the following description. static int32_t Hi35xxWatchdogBind(struct HdfDeviceObject *device)
OsalSpinlock lock; {
volatile unsigned char *regBase;// [Mandatory] Used for address mapping. int32_t ret;
uint32_t phyBase; // (Mandatory) Used for address mapping. struct Hi35xxWatchdog *hwdt = NULL;
uint32_t regStep; // (Mandatory) Used for address mapping. ...
}; hwdt = (struct Hi35xxWatchdog *)OsalMemCalloc(sizeof(*hwdt));// Apply for memory for the Hi35xxWatchdog structure.
// WatchdogCntlr is the core layer controller structure. Its members are assigned with values by using the Init function. ...
struct WatchdogCntlr { hwdt->regBase = OsalIoRemap(hwdt->phyBase, hwdt->regStep); // Address mapping
struct IDeviceIoService service;// Driver service ...
struct HdfDeviceObject *device; // Drive device hwdt->wdt.priv = (void *)device->property;// (Optional) Assign the device attribute values to priv. However, priv is not called subsequently.
OsalSpinlock lock; // This variable implements the spinlock function. //If the priv member is required, instantiate getPriv() and releasePriv() of WatchdogMethod.
struct WatchdogMethod *ops; // Interface callback hwdt->wdt.ops = &g_method; // (Mandatory) Assign the instantiated objects to the ops members so that the top layer can invoke the WatchdogMethod functions.
int16_t wdtId; // ID of the watchdog device hwdt->wdt.device = device; // (Mandatory) Enable conversion between HdfDeviceObject and WatchdogcCntlr.
void *priv; // Save the pointer. ret = WatchdogCntlrAdd(&hwdt->wdt); // (Mandatory) Call this function to initialize the structure of the core layer. The driver accesses the platform core layer only after a success signal is returned.
}; if (ret != HDF_SUCCESS) { // If the operation fails, release the resources used by Init().
``` OsalIoUnmap((void *)hwdt->regBase);
OsalMemFree(hwdt);
- Instantiate the callback function structure **WatchdogMethod** in **WatchdogCntlr**. Other members are initialized by using the **Init** and **Bind** functions. return ret;
}
``` return HDF_SUCCESS;
static struct WatchdogMethod g_method = { }
.getStatus = Hi35xxWatchdogGetStatus, ```
.start = Hi35xxWatchdogStart,
.stop = Hi35xxWatchdogStop, - **Release** function
.setTimeout = Hi35xxWatchdogSetTimeout,
.getTimeout = Hi35xxWatchdogGetTimeout, Input parameter:
.feed = Hi35xxWatchdogFeed,
}; **HdfDeviceObject**, a device object created by the HDF for each driver, holds device-related private data and service APIs.
```
Return value:
- Init and Bind functions
No value is returned.
Input parameters:
Function description:
**HdfDeviceObject**: device object created by the HDF for each driver. It stores device-related private data and service APIs.
Releases driver resources. This function assigns values to **Release()** in the driver entry structure. When the HDF fails to call the **Init** function to initialize the driver, **Release()** can be called to release driver resources. The **Release()** function must contain the operations for releasing the memory and deleting the controller.
Return values:
All forced conversion operations for obtaining the corresponding object can be successful only when **Init()** has the corresponding value assignment operations.
HDF\_STATUS \(The following table lists some status. For details about other status, see **HDF\_STATUS** in the **//drivers/framework/include/utils/hdf\_base.h** file.\)
**Table 2** Input parameters and return values of the Init and Bind functions ```
static void Hi35xxWatchdogRelease(struct HdfDeviceObject *device)
<a name="table86931033998"></a> {
<table><thead align="left"><tr id="row10694203319911"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1669433319918"><a name="p1669433319918"></a><a name="p1669433319918"></a>Status (Value)</p> struct WatchdogCntlr *wdt = NULL;
</th> struct Hi35xxWatchdog *hwdt = NULL;
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p06945331911"><a name="p06945331911"></a><a name="p06945331911"></a>Description</p> ...
</th> wdt = WatchdogCntlrFromDevice(device);// Use service to convert HdfDeviceObject to WatchdogCntlr.
</tr> // return (device == NULL) ? NULL : (struct WatchdogCntlr *)device->service;
</thead> if (wdt == NULL) {
<tbody><tr id="row869417338918"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p96941433391"><a name="p96941433391"></a><a name="p96941433391"></a>HDF_ERR_INVALID_OBJECT</p> return;
</td> }
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p4694333395"><a name="p4694333395"></a><a name="p4694333395"></a>Failed to locate the watchdog device</p> WatchdogCntlrRemove(wdt); // Core layer function used to execute wdt->device->service = NULL and release cntlr->lock.
</td> hwdt = (struct Hi35xxWatchdog *)wdt; // Convert WatchdogCntlr to HimciHost.
</tr> if (hwdt->regBase != NULL) { // Unmap addresses.
<tr id="row136941833091"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p66941336920"><a name="p66941336920"></a><a name="p66941336920"></a>HDF_ERR_MALLOC_FAIL</p> OsalIoUnmap((void *)hwdt->regBase);
</td> hwdt->regBase = NULL;
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1694133395"><a name="p1694133395"></a><a name="p1694133395"></a>Failed to allocate memory</p> }
</td> OsalMemFree(hwdt); // Release the memory occupied by the vendor-defined objects.
</tr> }
<tr id="row469443317913"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p116951933293"><a name="p116951933293"></a><a name="p116951933293"></a>HDF_ERR_IO</p> ```
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p969511331918"><a name="p969511331918"></a><a name="p969511331918"></a>I/O error</p>
</td>
</tr>
<tr id="row369533318911"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p669511331891"><a name="p669511331891"></a><a name="p669511331891"></a>HDF_SUCCESS</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p136951233699"><a name="p136951233699"></a><a name="p136951233699"></a>Initialization successful</p>
</td>
</tr>
<tr id="row17695633596"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1469583314910"><a name="p1469583314910"></a><a name="p1469583314910"></a>HDF_FAILURE</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p10695193311919"><a name="p10695193311919"></a><a name="p10695193311919"></a>Initialization failed</p>
</td>
</tr>
</tbody>
</table>
Function description:
Initializes the custom structure object and **WatchdogCntlr**, and calls the **WatchdogCntlrAdd** function at the core layer.
```
// Generally, the Init function initializes the members of the Hi35xxWatchdog structure based on the attribute values of the input parameter (HdfDeviceObject).
// In this example, the Bind function initializes the Hi35xxWatchdog structure.
static int32_t Hi35xxWatchdogInit(struct HdfDeviceObject *device)
{
(void)device;
return HDF_SUCCESS;
}
static int32_t Hi35xxWatchdogBind(struct HdfDeviceObject *device)
{
int32_t ret;
struct Hi35xxWatchdog *hwdt = NULL;
...
hwdt = (struct Hi35xxWatchdog *)OsalMemCalloc(sizeof(*hwdt));// Apply for memory for the Hi35xxWatchdog structure.
...
hwdt->regBase = OsalIoRemap(hwdt->phyBase, hwdt->regStep); // Address mapping
...
hwdt->wdt.priv = (void *)device->property;// (Optional) Assign the device attribute values to priv. However, priv is not called subsequently.
//If priv needs to be called, instantiate the getPriv and releasePriv member functions in WatchdogMethod.
hwdt->wdt.ops = &g_method; // (Mandatory) Assign the instantiated objects to the ops member so that the top layer can invoke the WatchdogMethod member functions.
hwdt->wdt.device = device; // (Mandatory) Enable conversion between HdfDeviceObject and WatchdogcCntlr.
ret = WatchdogCntlrAdd(&hwdt->wdt); // (Mandatory) Call this function to initialize the structure of the core layer. The driver accesses the platform core layer only after a success signal is returned.
if (ret != HDF_SUCCESS) {// If the operation fails, release the resources used by the Init function.
OsalIoUnmap((void *)hwdt->regBase);
OsalMemFree(hwdt);
return ret;
}
return HDF_SUCCESS;
}
```
- Release function
Input parameters:
**HdfDeviceObject**: device object created by the HDF for each driver. It stores device-related private data and service APIs.
Return values:
Function description:
Releases the memory and deletes the controller. This function assigns a value to the **Release** API in the driver entry structure. When the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. All forced conversion operations for obtaining the corresponding object can be successful only when the **Init** function has the corresponding value assignment operations.
```
static void Hi35xxWatchdogRelease(struct HdfDeviceObject *device)
{
struct WatchdogCntlr *wdt = NULL;
struct Hi35xxWatchdog *hwdt = NULL;
...
wdt = WatchdogCntlrFromDevice(device);// Convert HdfDeviceObject to WatchdogCntlr by the service member.
//return (device == NULL) ? NULL : (struct WatchdogCntlr *)device->service;
if (wdt == NULL) {
return;
}
WatchdogCntlrRemove(wdt); // Core layer function used to execute wdt->device->service = NULL and release cntlr->lock.
hwdt = (struct Hi35xxWatchdog *)wdt; // Convert WatchdogCntlr to HimciHost.
if (hwdt->regBase != NULL) {// Remove address mapping.
OsalIoUnmap((void *)hwdt->regBase);
hwdt->regBase = NULL;
}
OsalMemFree(hwdt); // Release the memory occupied by the vendor-defined objects.
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册