未验证 提交 3191bf2d 编写于 作者: O openharmony_ci 提交者: Gitee

!4009 【OpenHarmony开源贡献者计划2022】watchdog及UART英文相关格式及表达问题

Merge pull request !4009 from king_he/driver-1a
......@@ -2,27 +2,29 @@
## Overview<a name="section833012453535"></a>
- The Universal Asynchronous Receiver/Transmitter \(UART\) is a universal serial data bus used for asynchronous communication. It enables bi-directional communication between devices in full-duplex mode.
- UART is widely used to print information for debugging or to connect to various external modules such as GPS and Bluetooth.
- A UART is connected to other modules through two wires \(as shown in [Figure 1](#fig68294715408)\) or four wires \(as shown in [Figure 2](#fig179241542163112)\).
- TX: TX pin of the transmitting UART. It is connected to the RX pin of the peer UART.
- RX: RX pin of the receiving UART. It is connected to the TX pin of the peer UART.
- RTS: Request to Send signal pin. It is connected to the CTS pin of the peer UART and is used to indicate whether the local UART is ready to receive data.
- CTS: Clear to Send signal pin. It is connected to the RTS pin of the peer UART and is used to indicate whether the local UART is allowed to send data to the peer end.
**Figure 1** 2-wire UART communication<a name="fig68294715408"></a>
The Universal Asynchronous Receiver/Transmitter \(UART\) is a universal serial data bus used for asynchronous communication. It enables bi-directional communication between devices in full-duplex mode.
UART is widely used to print information for debugging or to connect to various external modules such as GPS and Bluetooth.
A UART is connected to other modules through two wires \(as shown in [Figure 1](#fig68294715408)\) or four wires \(as shown in [Figure 2](#fig179241542163112)\).
- TX: TX pin of the transmitting UART. It is connected to the RX pin of the peer UART.
- RX: RX pin of the receiving UART. It is connected to the TX pin of the peer UART.
- RTS: Request to Send signal pin. It is connected to the CTS pin of the peer UART and is used to indicate whether the local UART is ready to receive data.
- CTS: Clear to Send signal pin. It is connected to the RTS pin of the peer UART and is used to indicate whether the local UART is allowed to send data to the peer end.
**Figure 1** 2-wire UART communication<a name="fig68294715408"></a>
![](figures/2-wire-uart-communication.png "2-wire-uart-communication")
**Figure 2** 4-wire UART communication<a name="fig179241542163112"></a>
**Figure 2** 4-wire UART communication<a name="fig179241542163112"></a>
![](figures/4-wire-uart-communication.png "4-wire-uart-communication")
- The transmitting and receiving UARTs must ensure that they have the same settings on particular attributes such as the baud rate and data format \(start bit, data bit, parity bit, and stop bit\) before they start to communicate. During data transmission, a UART sends data to the peer end over the TX pin and receives data from the peer end over the RX pin. When the size of the buffer used by a UART for storing received data reaches the preset threshold, the RTS signal of the UART changes to **1** \(data cannot be received\), and the peer UART stops sending data to it because its CTS signal does not allow it to send data.
- The UART interface defines a set of common functions for operating a UART port, including obtaining and releasing device handles, reading and writing data of a specified length, and obtaining and setting the baud rate, as well as the device attributes.
The transmitting and receiving UARTs must ensure that they have the same settings on particular attributes such as the baud rate and data format \(start bit, data bit, parity bit, and stop bit\) before they start to communicate. During data transmission, a UART sends data to the peer end over the TX pin and receives data from the peer end over the RX pin. When the size of the buffer used by a UART for storing received data reaches the preset threshold, the RTS signal of the UART changes to **1** \(data cannot be received\), and the peer UART stops sending data to it because its CTS signal does not allow it to send data.
## Available APIs<a name="section1928742202715"></a>
**Table 1** APIs for the UART driver
The UART interface defines a set of common functions for operating a UART port, including obtaining and releasing device handles, reading and writing data of a specified length, and obtaining and setting the baud rate, as well as the device attributes.
**Table 1** APIs for the UART driver
<a name="table1731550155318"></a>
<table><thead align="left"><tr id="row1223152681611"><th class="cellrowborder" valign="top" width="26.619999999999997%" id="mcps1.2.4.1.1"><p id="p210413571619"><a name="p210413571619"></a><a name="p210413571619"></a><strong id="b4100105545211"><a name="b4100105545211"></a><a name="b4100105545211"></a>Capability</strong></p>
......@@ -94,7 +96,7 @@
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>All functions provided in this document can be called only in kernel space.
## Usage Guidelines<a name="section12779050105412"></a>
......@@ -103,16 +105,16 @@
[Figure 3](#fig99673244388) shows the process of using a UART device.
**Figure 3** Process of using a UART device<a name="fig99673244388"></a>
**Figure 3** Process of using a UART device<a name="fig99673244388"></a>
![](figures/process-of-using-a-uart-device.png "process-of-using-a-uart-device")
### Obtaining a UART Device Handle<a name="section124512065617"></a>
Before performing UART communication, call **UartOpen** to obtain a UART device handle. This function returns the pointer to the UART device handle with a specified port number.
Before performing UART communication, call **UartOpen** to obtain a UART device handle. This function returns the pointer to the UART device handle with a specified port number.
DevHandle UartOpen\(uint32\_t port\);
**Table 2** Description of UartOpen
**Table 2** Description of UartOpen
<a name="table14222165114310"></a>
<table><thead align="left"><tr id="row1022175133111"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p13221551153117"><a name="p13221551153117"></a><a name="p13221551153117"></a><strong id="b538194163718"><a name="b538194163718"></a><a name="b538194163718"></a>Parameter</strong></p>
......@@ -144,7 +146,7 @@ DevHandle UartOpen\(uint32\_t port\);
</tbody>
</table>
The following example shows how to obtain a UART device handle based on the assumption that the UART port number is **3**:
The following example shows how to obtain a UART device handle based on the assumption that the UART port number is **3**:
```
DevHandle handle = NULL; /* The UART device handle */
......@@ -162,7 +164,7 @@ After obtaining the UART device handle, set the UART baud rate by calling the fo
int32\_t UartSetBaud\(DevHandle handle, uint32\_t baudRate\);
**Table 3** Description of UartSetBaud
**Table 3** Description of UartSetBaud
<a name="table539135313325"></a>
<table><thead align="left"><tr id="row15391205311323"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p11390453103216"><a name="p11390453103216"></a><a name="p11390453103216"></a><strong id="b0704124143717"><a name="b0704124143717"></a><a name="b0704124143717"></a>Parameter</strong></p>
......@@ -199,7 +201,7 @@ int32\_t UartSetBaud\(DevHandle handle, uint32\_t baudRate\);
</tbody>
</table>
The following example shows how to set the UART baud rate to **9600**:
The following example shows how to set the UART baud rate to **9600**:
```
int32_t ret;
......@@ -216,7 +218,7 @@ After setting the UART baud rate, obtain the current baud rate by calling the fo
int32\_t UartGetBaud\(DevHandle handle, uint32\_t \*baudRate\);
**Table 4** Description of UartGetBaud
**Table 4** Description of UartGetBaud
<a name="table20393185311326"></a>
<table><thead align="left"><tr id="row19392653123215"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p6392105315326"><a name="p6392105315326"></a><a name="p6392105315326"></a><strong id="b13706541173716"><a name="b13706541173716"></a><a name="b13706541173716"></a>Parameter</strong></p>
......@@ -271,7 +273,7 @@ Before performing UART communication, set the UART device attributes by calling
int32\_t UartSetAttribute\(DevHandle handle, struct UartAttribute \*attribute\);
**Table 5** Description of UartSetAttribute
**Table 5** Description of UartSetAttribute
<a name="table1453119335341"></a>
<table><thead align="left"><tr id="row3530433103416"><th class="cellrowborder" valign="top" width="49.980000000000004%" id="mcps1.2.3.1.1"><p id="p1853073310341"><a name="p1853073310341"></a><a name="p1853073310341"></a><strong id="b8706441133719"><a name="b8706441133719"></a><a name="b8706441133719"></a>Parameter</strong></p>
......@@ -333,7 +335,7 @@ After setting the UART device attributes, obtain the current device attributes b
int32\_t UartGetAttribute\(DevHandle handle, struct UartAttribute \*attribute\);
**Table 6** Description of UartGetAttribute
**Table 6** Description of UartGetAttribute
<a name="table17532123316342"></a>
<table><thead align="left"><tr id="row18531193383420"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p85311833143420"><a name="p85311833143420"></a><a name="p85311833143420"></a><strong id="b1770784123715"><a name="b1770784123715"></a><a name="b1770784123715"></a>Parameter</strong></p>
......@@ -388,7 +390,7 @@ Before performing UART communication, set the UART transmission mode by calling
int32\_t UartSetTransMode\(DevHandle handle, enum UartTransMode mode\);
**Table 7** Description of UartSetTransMode
**Table 7** Description of UartSetTransMode
<a name="table131892266313"></a>
<table><thead align="left"><tr id="row018922615318"><th class="cellrowborder" valign="top" width="49.980000000000004%" id="mcps1.2.3.1.1"><p id="p131891826835"><a name="p131891826835"></a><a name="p131891826835"></a><strong id="b197086411379"><a name="b197086411379"></a><a name="b197086411379"></a>Parameter</strong></p>
......@@ -425,7 +427,7 @@ int32\_t UartSetTransMode\(DevHandle handle, enum UartTransMode mode\);
</tbody>
</table>
The following example shows how to set the transmission mode to **UART\_MODE\_RD\_BLOCK**:
The following example shows how to set the transmission mode to **UART\_MODE\_RD\_BLOCK**:
```
int32_t ret;
......@@ -442,7 +444,7 @@ To write data into a UART device, call the following function:
int32\_t UartWrite\(DevHandle handle, uint8\_t \*data, uint32\_t size\);
**Table 8** Description of UartWrite
**Table 8** Description of UartWrite
<a name="table27825111368"></a>
<table><thead align="left"><tr id="row1578171123619"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p078112115360"><a name="p078112115360"></a><a name="p078112115360"></a><strong id="b14708841203711"><a name="b14708841203711"></a><a name="b14708841203711"></a>Parameter</strong></p>
......@@ -502,7 +504,7 @@ To write data into a UART device, call the following function:
int32\_t UartRead\(DevHandle handle, uint8\_t \*data, uint32\_t size\);
**Table 9** Description of UartRead
**Table 9** Description of UartRead
<a name="table162341717123713"></a>
<table><thead align="left"><tr id="row023313171377"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1123331710376"><a name="p1123331710376"></a><a name="p1123331710376"></a><strong id="b970911411374"><a name="b970911411374"></a><a name="b970911411374"></a>Parameter</strong></p>
......@@ -557,7 +559,7 @@ if (ret < 0) {
```
>![](../public_sys-resources/icon-caution.gif) **CAUTION:**
>Data is successfully read from the UART device if a non-negative value is returned. If the return value is **0**, no valid data can be read from the UART device. If the return value is greater than **0**, the return value is the length of the data actually read from the UART device. The length is less than or equal to the value of **size** and does not exceed the maximum length of data to read at a time specified by the UART controller in use.
>Data is successfully read from the UART device if a non-negative value is returned. If the return value is **0**, no valid data can be read from the UART device. If the return value is greater than **0**, the return value is the length of the data actually read from the UART device. The length is less than or equal to the value of **size** and does not exceed the maximum length of data to read at a time specified by the UART controller in use.
### Destroying the UART Device Handle<a name="section1477410521406"></a>
......@@ -567,7 +569,7 @@ void UartClose\(DevHandle handle\);
This function will release the resources previously obtained.
**Table 10** Description of UartClose
**Table 10** Description of UartClose
<a name="table03348317351"></a>
<table><thead align="left"><tr id="row15334837351"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p933411316354"><a name="p933411316354"></a><a name="p933411316354"></a><strong id="b1710184115375"><a name="b1710184115375"></a><a name="b1710184115375"></a>Parameter</strong></p>
......@@ -655,5 +657,4 @@ _ERR:
/* Destroy the UART device handle. */
UartClose(handle);
}
```
```
\ No newline at end of file
......@@ -4,7 +4,7 @@
In the Hardware Driver Foundation \(HDF\), the Universal Asynchronous Receiver/Transmitter \(UART\) 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.
**Figure 1** Independent service mode<a name="fig1474518243468"></a>
**Figure 1** Independent service mode<a name="fig1474518243468"></a>
![](figures/independent-service-mode.png "independent-service-mode-14")
## Available APIs<a name="section752964871810"></a>
......@@ -26,7 +26,7 @@ struct UartHostMethod {
};
```
**Table 1** Callbacks for the members in the UartHostMethod structure
**Table 1** Callbacks for the members in the UartHostMethod structure
<a name="table22862114719"></a>
<table><thead align="left"><tr id="row5297211471"><th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.1"><p id="p12291121134710"><a name="p12291121134710"></a><a name="p12291121134710"></a>Callback</p>
......@@ -167,33 +167,31 @@ struct UartHostMethod {
The UART module adaptation involves the following steps:
1. Instantiate the driver entry.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
2. Configure attribute files.
- Add the **deviceNode** information to the **device\_info.hcs** file.
- \(Optional\) Add the **uart\_config.hcs** file.
- Add the **deviceNode** information to the **device\_info.hcs** file.
- \(Optional\) Add the **uart\_config.hcs** file.
3. Instantiate the UART controller object.
- Initialize **UartHost**.
- Instantiate **UartHostMethod** in the **UartHost** object.
- Initialize **UartHost**.
- Instantiate **UartHostMethod** in the **UartHost** object.
>![](../public_sys-resources/icon-note.gif) **NOTE**
>For details, see [Available APIs](#available-apis).
4. Debug the driver.
- \(Optional\) For new drivers, verify the basic functions, such as the UART control status and response to interrupts.
For details, see [Available APIs](#available-apis).
4. \(Optional\) Debug the driver.
For new drivers, verify the basic functions, such as the UART control status and response to interrupts.
## Development Example<a name="section774610224154520"></a>
The following uses **uart\_hi35xx.c** as an example to present the contents that need to be provided by the vendor to implement device functions.
The following uses **uart\_hi35xx.c** as an example to present the contents that need to be provided by the vendor to implement device functions.
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.
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.
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.
- UART driver entry reference
......@@ -209,11 +207,11 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
HDF_INIT(g_hdfUartDevice);
```
2. Add the **deviceNode** information to the **device\_info.hcs** file and configure the device attributes in the **uart\_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 **UartHost** members at the core layer.
2. Add the **deviceNode** information to the **device\_info.hcs** file and configure the device attributes in the **uart\_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 **UartHost** members at the core layer.
In this example, there is only one UART controller. If there are multiple UART controllers, you need to add the **deviceNode** information to the **device\_info** file and add the corresponding device attributes to the **uart\_config** file.
In this example, there is only one UART controller. If there are multiple UART controllers, you need to add the **deviceNode** information to the **device\_info** file and add the corresponding device attributes to the **uart\_config** file.
- **device\_info.hcs** configuration reference
- **device\_info.hcs** configuration reference
```
root {
......@@ -246,7 +244,7 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
}
```
- **uart\_config.hcs** configuration reference
- **uart\_config.hcs** configuration reference
```
root {
......@@ -278,10 +276,10 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
}
```
3. Initialize the **UartHost** object at the core layer, including initializing the vendor custom structure \(transferring parameters and data\), instantiating **UartHostMethod** \(used to call underlying functions of the driver\) in **UartHost**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\).
3. Initialize the **UartHost** object at the core layer, including initializing the vendor custom structure \(transferring parameters and data\), instantiating **UartHostMethod** \(used to call underlying functions of the driver\) in **UartHost**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\).
- Custom structure reference
To the driver, the custom structure carries parameters and data. The values in the **uart\_config.hcs** file are read by HDF, and the structure members are initialized through **DeviceResourceIface**. Some important values, such as the device number, are also passed to the objects at the core layer.
To the driver, the custom structure carries parameters and data. The values in the **uart\_config.hcs** file are read by HDF, and the structure members are initialized through **DeviceResourceIface**. Some important values, such as the device number, are also passed to the objects at the core layer.
```
struct UartPl011Port {// Structure related to the API
......@@ -314,7 +312,7 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
#define UART_FLG_RD_BLOCK (1 << 2)
RecvNotify recv; // Pointer to the function that receives serial port data
struct UartOps *ops; // Custom function pointer structure. For details, see device/hisilicon/drivers/uart/uart_pl011.c.
void *private; // It stores the pointer to the start address of UartPl011Port for easy invocation.
void *private; // Pointer to the start address of UartPl011Port for easy invocation
};
// UartHost is the controller structure at the core layer. Its members are assigned with values by using the Init function.
......@@ -328,7 +326,7 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
};
```
- Instantiate the callback function structure **UartHostMethod** in **UartHost**. Other members are initialized by using the **Bind** function.
- Instantiate the callback function structure **UartHostMethod** in **UartHost**. Other members are initialized by using the **Bind** function.
```
// Example in pwm_hi35xx.c: instantiate the hook.
......@@ -350,13 +348,13 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
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.\)
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 Bind function
**Table 2** Input parameters and return values of the Bind function
<a name="table69781823185619"></a>
<table><thead align="left"><tr id="row997916234569"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p99801123205616"><a name="p99801123205616"></a><a name="p99801123205616"></a>Status (Value)</p>
......@@ -400,7 +398,7 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
Function description:
Initializes the custom structure object and **UartHost**.
Initializes the custom structure object and **UartHost**.
```
//uart_hi35xx.c
......@@ -430,7 +428,7 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
......@@ -438,7 +436,7 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
Function description:
Initializes the custom structure object and **UartHost**, calls the **artAddDev** function at the core layer, and connects to VFS.
Initializes the custom structure object and **UartHost**, calls the **artAddDev** function at the core layer, and connects to VFS.
```
int32_t HdfUartDeviceInit(struct HdfDeviceObject *device)
......@@ -502,7 +500,7 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
......@@ -510,7 +508,7 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
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.
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.
```
void HdfUartDeviceRelease(struct HdfDeviceObject *device)
......@@ -544,7 +542,4 @@ The following uses **uart\_hi35xx.c** as an example to present the contents th
(void)OsalMemFree(udd);// Release UartDriverData.
host->priv = NULL;
}
```
```
\ No newline at end of file
......@@ -6,7 +6,7 @@ A watchdog, also called a watchdog timer, is a hardware timing device. If an err
## Available APIs<a name="section1180575010271"></a>
**Table 1** Watchdog APIs
**Table 1** Watchdog APIs
<a name="table1731550155318"></a>
<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>
......@@ -70,7 +70,7 @@ A watchdog, also called a watchdog timer, is a hardware timing device. If an err
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>![](../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>
......@@ -79,16 +79,16 @@ A watchdog, also called a watchdog timer, is a hardware timing device. If an err
[Figure 1](#fig430533913392) illustrates the process of using a watchdog.
**Figure 1** Process of using a watchdog<a name="fig430533913392"></a>
**Figure 1** Process of using a watchdog<a name="fig430533913392"></a>
![](figures/process-of-using-a-watchdog.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.
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
**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>
......@@ -133,7 +133,7 @@ if (handle == NULL) {
int32\_t WatchdogGetStatus\(DevHandle handle, int32\_t \*status\);
**Table 3** Description of WatchdogGetStatus
**Table 3** Description of WatchdogGetStatus
<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>
......@@ -185,7 +185,7 @@ if (ret != 0) {
int32\_t WatchdogSetTimeout\(PalHandle \*handle, uint32\_t seconds\);
**Table 4** Description of WatchdogSetTimeout
**Table 4** Description of WatchdogSetTimeout
<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>
......@@ -237,7 +237,7 @@ if (ret != 0) {
int32\_t WatchdogGetTimeout\(PalHandle \*handle, uint32\_t \*seconds\);
**Table 5** Description of WatchdogGetTimeout
**Table 5** Description of WatchdogGetTimeout
<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>
......@@ -289,7 +289,7 @@ if (ret != 0) {
int32\_t WatchdogStart\(DevHandle handle\);
**Table 6** Description of WatchdogStart
**Table 6** Description of WatchdogStart
<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>
......@@ -335,7 +335,7 @@ if (ret != 0) {
int32\_t WatchdogFeed\(DevHandle handle\);
**Table 7** Description of WatchdogFeed
**Table 7** Description of WatchdogFeed
<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>
......@@ -381,7 +381,7 @@ if (ret != 0) {
int32\_t WatchdogStop\(DevHandle handle\);
**Table 8** Description of WatchdogStop
**Table 8** Description of WatchdogStop
<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>
......@@ -425,11 +425,11 @@ if (ret != 0) {
### Closing a Watchdog<a name="section96561824121311"></a>
If the watchdog is no longer required, call **WatchdogClose** to close the watchdog handle.
If the watchdog is no longer required, call **WatchdogClose** to close the watchdog handle.
void WatchdogClose\(DevHandle handle\);
**Table 9** Description of WatchdogClose
**Table 9** Description of WatchdogClose
<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>
......@@ -535,5 +535,4 @@ static int32_t TestCaseWatchdog(void)
WatchdogClose(handle);
return -1;
}
```
```
\ No newline at end of file
......@@ -5,7 +5,7 @@
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.
**Figure 1** Independent service mode<a name="fig61584136211"></a>
**Figure 1** Independent service mode<a name="fig61584136211"></a>
![](figures/independent-service-mode.png "independent-service-mode-15")
## Available APIs<a name="section1180575010271"></a>
......@@ -25,7 +25,7 @@ struct WatchdogMethod {
};
```
**Table 1** Callbacks for the members in the WatchdogMethod structure
**Table 1** Callbacks for the members in the WatchdogMethod structure
<a name="table1370451732"></a>
<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>
......@@ -116,33 +116,31 @@ struct WatchdogMethod {
The Watchdog module adaptation involves the following steps:
1. Instantiate the driver entry.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
2. Configure attribute files.
- Add the **deviceNode** information to the **device\_info.hcs** file.
- \(Optional\) Add the **watchdog\_config.hcs** file.
- Add the **deviceNode** information to the **device\_info.hcs** file.
- \(Optional\) Add the **watchdog\_config.hcs** file.
3. Instantiate the Watchdog controller object.
- Initialize **WatchdogCntlr**.
- Instantiate **WatchdogMethod** in the **WatchdogCntlr** object.
- Initialize **WatchdogCntlr**.
- Instantiate **WatchdogMethod** in the **WatchdogCntlr** object.
>![](../public_sys-resources/icon-note.gif) **NOTE**
For details, see [Available APIs](#available-apis).
>For details, see [Available APIs](#available-apis).
4. \(Optional\) Debug the driver.
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.
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>
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.
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.
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.
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.
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.
- Watchdog driver entry reference
......@@ -157,11 +155,11 @@ The following uses **watchdog\_hi35xx.c** as an example to present the content
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. 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.
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.
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.
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
- **device\_info.hcs** configuration reference
```
root {
......@@ -184,7 +182,7 @@ The following uses **watchdog\_hi35xx.c** as an example to present the content
}
```
- **watchdog\_config.hcs** configuration reference
- **watchdog\_config.hcs** configuration reference
```
root {
......@@ -204,10 +202,10 @@ The following uses **watchdog\_hi35xx.c** as an example to present the content
}
```
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**\).
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**\).
- Custom structure reference
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.
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.
```
struct Hi35xxWatchdog {
......@@ -228,7 +226,7 @@ The following uses **watchdog\_hi35xx.c** as an example to present the content
};
```
- Instantiate the callback function structure **WatchdogMethod** in **WatchdogCntlr**. Other members are initialized by using the **Init** and **Bind** functions.
- Instantiate the callback function structure **WatchdogMethod** in **WatchdogCntlr**. Other members are initialized by using the **Init** and **Bind** functions.
```
static struct WatchdogMethod g_method = {
......@@ -245,13 +243,13 @@ The following uses **watchdog\_hi35xx.c** as an example to present the content
Input parameters:
**HdfDeviceObject**: device object created by the HDF for each driver. It stores device-related private data and service APIs.
**HdfDeviceObject**: device object created by the HDF for each driver. It stores device-related private data and service APIs.
Return values:
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.\)
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
**Table 2** Input parameters and return values of the Init and Bind functions
<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>
......@@ -290,7 +288,7 @@ The following uses **watchdog\_hi35xx.c** as an example to present the content
Function description:
Initializes the custom structure object and **WatchdogCntlr**, and calls the **WatchdogCntlrAdd** function at the core layer.
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).
......@@ -328,7 +326,7 @@ The following uses **watchdog\_hi35xx.c** as an example to present the content
Input parameters:
**HdfDeviceObject**: device object created by the HDF for each driver. It stores device-related private data and service APIs.
**HdfDeviceObject**: device object created by the HDF for each driver. It stores device-related private data and service APIs.
Return values:
......@@ -336,7 +334,7 @@ The following uses **watchdog\_hi35xx.c** as an example to present the content
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.
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)
......@@ -357,7 +355,4 @@ The following uses **watchdog\_hi35xx.c** as an example to present the content
}
OsalMemFree(hwdt); // Release the memory occupied by the vendor-defined objects.
}
```
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册