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>
| WatchdogFeed | Feeds a watchdog or resets a watchdog timer.|
</td>
<tdclass="cellrowborder"valign="top"width="40.58%"headers="mcps1.2.4.1.3 "><pid="p17370161911710"><aname="p17370161911710"></a><aname="p17370161911710"></a>Opens a watchdog.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p11611715161713"><aname="p11611715161713"></a><aname="p11611715161713"></a>Closes a watchdog.</p>
The figure below shows how to use the watchdog APIs.
</td>
<tdclass="cellrowborder"valign="top"width="40.58%"headers="mcps1.2.4.1.3 "><pid="p18376517332"><aname="p18376517332"></a><aname="p18376517332"></a>Starts a watchdog.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p19400194633318"><aname="p19400194633318"></a><aname="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.
<tdclass="cellrowborder"valign="top"width="40.58%"headers="mcps1.2.4.1.3 "><pid="p331961319210"><aname="p331961319210"></a><aname="p331961319210"></a>Obtains the watchdog status.</p>
<tdclass="cellrowborder"valign="top"width="40.58%"headers="mcps1.2.4.1.3 "><pid="p62815221125"><aname="p62815221125"></a><aname="p62815221125"></a>Feeds a watchdog, or resets a watchdog timer.</p>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p3138192512815"><aname="p3138192512815"></a><aname="p3138192512815"></a>Failed to open the watchdog.</p>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p16138122512817"><aname="p16138122512817"></a><aname="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>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p7282752412"><aname="p7282752412"></a><aname="p7282752412"></a>Pointer to the watchdog status.</p>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p1231981611712"><aname="p1231981611712"></a><aname="p1231981611712"></a>The watchdog status is obtained.</p>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p93191161174"><aname="p93191161174"></a><aname="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>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p5160172182214"><aname="p5160172182214"></a><aname="p5160172182214"></a>Timeout duration, in seconds.</p>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p151607218222"><aname="p151607218222"></a><aname="p151607218222"></a>The setting is successful.</p>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p71478484238"><aname="p71478484238"></a><aname="p71478484238"></a>Pointer to the timeout duration, in seconds.</p>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p1314824872310"><aname="p1314824872310"></a><aname="p1314824872310"></a>The watchdog status is obtained.</p>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p1314864822311"><aname="p1314864822311"></a><aname="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>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p630754259"><aname="p630754259"></a><aname="p630754259"></a>The watchdog is started.</p>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p0301559254"><aname="p0301559254"></a><aname="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>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p149111435143911"><aname="p149111435143911"></a><aname="p149111435143911"></a>The watchdog is fed.</p>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p1891216356391"><aname="p1891216356391"></a><aname="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>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p7869115192510"><aname="p7869115192510"></a><aname="p7869115192510"></a>The watchdog is stopped.</p>
<tdclass="cellrowborder"valign="top"width="55.010000000000005%"headers="mcps1.2.3.1.2 "><pid="p086945172518"><aname="p086945172518"></a><aname="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.
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<aname="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.
| 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.|
| 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.|
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p124968261413"><aname="p124968261413"></a><aname="p124968261413"></a><strongid="b13481135102819"><aname="b13481135102819"></a><aname="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.
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.3 "><pid="p17071515316"><aname="p17071515316"></a><aname="p17071515316"></a><strongid="b142021397417"><aname="b142021397417"></a><aname="b142021397417"></a>status</strong>: int32_t pointer indicating the watchdog status (started or stopped).</p>
- Add the **deviceNode** information to the **device_info.hcs** file.
</td>
- (Optional) Add the **watchdog_config.hcs** file.
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p2707511312"><aname="p2707511312"></a><aname="p2707511312"></a>Obtains the watchdog status.</p>
- Instantiate **WatchdogMethod** in the **WatchdogCntlr** object.
</td>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p117071316317"><aname="p117071316317"></a><aname="p117071316317"></a><strongid="b136901310133110"><aname="b136901310133110"></a><aname="b136901310133110"></a>wdt</strong>: structure pointer to the Watchdog controller at the core layer.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p170811111319"><aname="p170811111319"></a><aname="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.
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p870841138"><aname="p870841138"></a><aname="p870841138"></a><strongid="b14846151912249"><aname="b14846151912249"></a><aname="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.
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>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p3708121738"><aname="p3708121738"></a><aname="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.
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p2021212409407"><aname="p2021212409407"></a><aname="p2021212409407"></a><strongid="b1521224016409"><aname="b1521224016409"></a><aname="b1521224016409"></a>wdt</strong>: structure pointer to the Watchdog controller at the core layer.</p>
struct HdfDriverEntry g_watchdogDriverEntry = {
<pid="p1870801834"><aname="p1870801834"></a><aname="p1870801834"></a><strongid="b721091763217"><aname="b721091763217"></a><aname="b721091763217"></a>seconds</strong>: input time value, which is of the uint32_t type.</p>
.moduleVersion = 1,
</td>
.Bind = Hi35xxWatchdogBind, // See the Bind function.
.moduleName = "HDF_PLATFORM_WATCHDOG",// (Mandatory) The value must be the same as that of moduleName in the .hcs file.
</td>
};
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p57091717315"><aname="p57091717315"></a><aname="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.
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the component attributes in the **watchdog_config.hcs** file.
</td>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p47091711732"><aname="p47091711732"></a><aname="p47091711732"></a><strongid="b88511419192416"><aname="b88511419192416"></a><aname="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>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.3 "><pid="p57091411632"><aname="p57091411632"></a><aname="p57091411632"></a><strongid="b3906135871316"><aname="b3906135871316"></a><aname="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.
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p17091511139"><aname="p17091511139"></a><aname="p17091511139"></a>Obtains the timeout period of a watchdog.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p570971736"><aname="p570971736"></a><aname="p570971736"></a><strongid="b1854319172417"><aname="b1854319172417"></a><aname="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.
permission = 0644; // Permission to create device nodes for the driver.
</td>
moduleName = "HDF_PLATFORM_WATCHDOG";
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p10709818316"><aname="p10709818316"></a><aname="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.
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.
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.
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.
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.
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
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.
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.