“0e6527387de2c14529d02f49eabeb4cdea93388f”上不存在“demo-client/git@gitcode.net:paddlepaddle/Serving.git”
未验证 提交 f57d4425 编写于 作者: O openharmony_ci 提交者: Gitee

!3853 #I557JA完成,请审批

Merge pull request !3853 from Annie_wang/OpenHarmony-3.1-Release
...@@ -107,7 +107,9 @@ The following example shows how to implement a distributed data object synchroni ...@@ -107,7 +107,9 @@ The following example shows how to implement a distributed data object synchroni
}); });
} }
} }
local_object.on("change", this.changeCallback);
// To refresh the page in changeCallback, correctly set this.changeCallback.bind(this) in
changeCallback.
``` ```
5. Modify object attributes. The object attributes support basic data types (such as number, Boolean, and string) and complex data types (array and nested basic types). 5. Modify object attributes. The object attributes support basic data types (such as number, Boolean, and string) and complex data types (array and nested basic types).
...@@ -158,9 +160,9 @@ The following example shows how to implement a distributed data object synchroni ...@@ -158,9 +160,9 @@ The following example shows how to implement a distributed data object synchroni
The sample code is as follows: The sample code is as follows:
```js ```js
// Unsubscribe from statusCallback. // Unsubscribe from the online status change callback.
local_object.off("status", statusCallback); local_object.off("status", statusCallback);
// unsubscribe from all status change callbacks. // Unsubscribe from all online status change callbacks.
local_object.off("status"); local_object.off("status");
``` ```
10. Remove a distributed data object from the synchronization network. After the distributed data object is removed from the network, the data changes on the local end will not be synchronized to the remote end. 10. Remove a distributed data object from the synchronization network. After the distributed data object is removed from the network, the data changes on the local end will not be synchronized to the remote end.
...@@ -169,7 +171,12 @@ The following example shows how to implement a distributed data object synchroni ...@@ -169,7 +171,12 @@ The following example shows how to implement a distributed data object synchroni
```js ```js
local_object.setSessionId(""); local_object.setSessionId("");
``` ```
## Development Example
The following example is provided for you to better understand the development of distributed data object:
- [Distributed Notepad](https://gitee.com/openharmony/distributeddatamgr_objectstore/tree/master/samples/distributedNotepad)
When an event occurs on a device, for example, a note is added, the tile or content of a note is changed, or the event list is cleared, the change will be synchronized to other devices in the trusted network by the Notepad app.
...@@ -2264,10 +2264,10 @@ Subscribes to data synchronization completion events. This method uses a synchro ...@@ -2264,10 +2264,10 @@ Subscribes to data synchronization completion events. This method uses a synchro
**Example** **Example**
``` ```js
let kvStore; let kvStore;
kvStore.on('syncComplete', function (data) { kvStore.on('syncComplete', function (data) {
console.log("syncComplete callback call data: " + data); console.log("callback call data: " + data);
}); });
``` ```
...@@ -2291,10 +2291,10 @@ Unsubscribes from data change events. This method uses a synchronous callback to ...@@ -2291,10 +2291,10 @@ Unsubscribes from data change events. This method uses a synchronous callback to
``` ```
let kvStore; let kvStore;
kvStore.on('dataChange', function (data) { kvStore.on('dataChange', function (data) {
console.log("syncComplete callback call data: " + data); console.log("callback call data: " + data);
}); });
kvStore.off('dataChange', function (data) { kvStore.off('dataChange', function (data) {
console.log("syncComplete callback call data: " + data); console.log("callback call data: " + data);
}); });
``` ```
......
...@@ -625,7 +625,7 @@ Asynchronously reads data from a file. This method uses a promise to return the ...@@ -625,7 +625,7 @@ Asynchronously reads data from a file. This method uses a promise to return the
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. |
- Return value - Return value
| Type | Description | | Type | Description |
...@@ -662,7 +662,7 @@ Asynchronously reads data from a file. This method uses a callback to return the ...@@ -662,7 +662,7 @@ Asynchronously reads data from a file. This method uses a callback to return the
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. |
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously. | | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously. |
- Example - Example
...@@ -695,7 +695,7 @@ Synchronously reads data from a file. ...@@ -695,7 +695,7 @@ Synchronously reads data from a file.
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. |
- Return value - Return value
| Type | Description | | Type | Description |
...@@ -867,7 +867,7 @@ Asynchronously writes data into a file. This method uses a promise to return the ...@@ -867,7 +867,7 @@ Asynchronously writes data into a file. This method uses a promise to return the
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.|
- Return value - Return value
| Type | Description | | Type | Description |
...@@ -903,7 +903,7 @@ Asynchronously writes data into a file. This method uses a callback to return th ...@@ -903,7 +903,7 @@ Asynchronously writes data into a file. This method uses a callback to return th
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
- Example - Example
...@@ -935,7 +935,7 @@ Synchronously writes data into a file. ...@@ -935,7 +935,7 @@ Synchronously writes data into a file.
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.|
- Return value - Return value
| Type | Description | | Type | Description |
...@@ -961,7 +961,7 @@ Asynchronously calculates the hash value of a file. This method uses a promise t ...@@ -961,7 +961,7 @@ Asynchronously calculates the hash value of a file. This method uses a promise t
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------ | ---- | ---------------------------------------- | | --------- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Absolute path of the target file. |
| algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.| | algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**.<br/>**sha256** is recommended for security purposes.|
- Return value - Return value
| Type | Description | | Type | Description |
...@@ -990,7 +990,7 @@ Asynchronously calculates the hash value of a file. This method uses a callback ...@@ -990,7 +990,7 @@ Asynchronously calculates the hash value of a file. This method uses a callback
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | --------------------------- | ---- | ---------------------------------------- | | --------- | --------------------------- | ---- | ---------------------------------------- |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Absolute path of the target file. |
| algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.| | algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**.<br/>**sha256** is recommended for security purposes.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the hash value. The hash value is a hexadecimal string consisting of digits and uppercase letters.| | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the hash value. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
- Example - Example
...@@ -1472,10 +1472,10 @@ Asynchronously reads data from a file. This method uses a promise to return the ...@@ -1472,10 +1472,10 @@ Asynchronously reads data from a file. This method uses a promise to return the
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters - Parameters
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.|
- Return value - Return value
| Type | Description | | Type | Description |
...@@ -1509,7 +1509,7 @@ Asynchronously reads data from a file. This method uses a callback to return the ...@@ -1509,7 +1509,7 @@ Asynchronously reads data from a file. This method uses a callback to return the
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.|
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously from the file. | | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously from the file. |
- Example - Example
...@@ -2577,6 +2577,7 @@ Asynchronously stops **watcher**. This method uses a callback to return the resu ...@@ -2577,6 +2577,7 @@ Asynchronously stops **watcher**. This method uses a callback to return the resu
``` ```
## Stream<sup>7+</sup> ## Stream<sup>7+</sup>
File stream. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance. File stream. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance.
...@@ -2721,7 +2722,7 @@ Asynchronously writes data into the stream. This method uses a promise to return ...@@ -2721,7 +2722,7 @@ Asynchronously writes data into the stream. This method uses a promise to return
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. |
- Return value - Return value
| Type | Description | | Type | Description |
...@@ -2753,11 +2754,11 @@ Asynchronously writes data into the stream. This method uses a callback to retur ...@@ -2753,11 +2754,11 @@ Asynchronously writes data into the stream. This method uses a callback to retur
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters - Parameters
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
- Example - Example
```js ```js
...@@ -2788,7 +2789,7 @@ Synchronously writes data into the stream. ...@@ -2788,7 +2789,7 @@ Synchronously writes data into the stream.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. |
- Return value - Return value
| Type | Description | | Type | Description |
...@@ -2818,7 +2819,7 @@ Asynchronously reads data from the stream. This method uses a promise to return ...@@ -2818,7 +2819,7 @@ Asynchronously reads data from the stream. This method uses a promise to return
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. |
- Return value - Return value
| Type | Description | | Type | Description |
...@@ -2853,7 +2854,7 @@ Asynchronously reads data from the stream. This method uses a callback to return ...@@ -2853,7 +2854,7 @@ Asynchronously reads data from the stream. This method uses a callback to return
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. |
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when data is read asynchronously from the stream. | | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when data is read asynchronously from the stream. |
- Example - Example
...@@ -2884,7 +2885,7 @@ Synchronously reads data from the stream. ...@@ -2884,7 +2885,7 @@ Synchronously reads data from the stream.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. |
- Return value - Return value
| Type | Description | | Type | Description |
......
...@@ -14,7 +14,7 @@ import huks from '@ohos.security.huks' ...@@ -14,7 +14,7 @@ import huks from '@ohos.security.huks'
``` ```
## HuksErrorCode ## HuksErrorCode
Enumerates error codes. Enumerates the error codes.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -29,7 +29,7 @@ Enumerates error codes. ...@@ -29,7 +29,7 @@ Enumerates error codes.
| HUKS_ERROR_INSUFFICIENT_DATA | -6 |Insufficient data.| | HUKS_ERROR_INSUFFICIENT_DATA | -6 |Insufficient data.|
| HUKS_ERROR_BUFFER_TOO_SMALL | -7 |Insufficient buffer.| | HUKS_ERROR_BUFFER_TOO_SMALL | -7 |Insufficient buffer.|
| HUKS_ERROR_INSUFFICIENT_MEMORY | -8 |Insufficient memory.| | HUKS_ERROR_INSUFFICIENT_MEMORY | -8 |Insufficient memory.|
| HUKS_ERROR_COMMUNICATION_FAILURE | -9 |Communication failed.| | HUKS_ERROR_COMMUNICATION_FAILURE | -9 |Communication failure.|
| HUKS_ERROR_STORAGE_FAILURE | -10 |Storage failure.| | HUKS_ERROR_STORAGE_FAILURE | -10 |Storage failure.|
| HUKS_ERROR_HARDWARE_FAILURE | -11 |Hardware fault.| | HUKS_ERROR_HARDWARE_FAILURE | -11 |Hardware fault.|
| HUKS_ERROR_ALREADY_EXISTS | -12 |The object already exists.| | HUKS_ERROR_ALREADY_EXISTS | -12 |The object already exists.|
...@@ -91,7 +91,7 @@ Enumerates error codes. ...@@ -91,7 +91,7 @@ Enumerates error codes.
## HuksKeyPurpose ## HuksKeyPurpose
Represents the purpose (usage) of a key. Enumerates the key purposes.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -103,7 +103,7 @@ Represents the purpose (usage) of a key. ...@@ -103,7 +103,7 @@ Represents the purpose (usage) of a key.
| HUKS_KEY_PURPOSE_VERIFY | 8 | The key is used to verify the signed data. | | HUKS_KEY_PURPOSE_VERIFY | 8 | The key is used to verify the signed data. |
| HUKS_KEY_PURPOSE_DERIVE | 16 | The key is used to derive a key. | | HUKS_KEY_PURPOSE_DERIVE | 16 | The key is used to derive a key. |
| HUKS_KEY_PURPOSE_WRAP | 32 | The key is used for encrypted import. | | HUKS_KEY_PURPOSE_WRAP | 32 | The key is used for encrypted import. |
| HUKS_KEY_PURPOSE_UNWRAP | 64 | The key is exported in encrypted mode. | | HUKS_KEY_PURPOSE_UNWRAP | 64 | The key is used for encrypted export. |
| HUKS_KEY_PURPOSE_MAC | 128 | The key is used to generate a message authentication code (MAC). | | HUKS_KEY_PURPOSE_MAC | 128 | The key is used to generate a message authentication code (MAC). |
| HUKS_KEY_PURPOSE_AGREE | 256 | The key is used for key agreement. | | HUKS_KEY_PURPOSE_AGREE | 256 | The key is used for key agreement. |
...@@ -135,8 +135,8 @@ Enumerates the padding algorithms. ...@@ -135,8 +135,8 @@ Enumerates the padding algorithms.
| HUKS_PADDING_OAEP | 1 | Optimal Asymmetric Encryption Padding (OAEP).| | HUKS_PADDING_OAEP | 1 | Optimal Asymmetric Encryption Padding (OAEP).|
| HUKS_PADDING_PSS | 2 | Probabilistic Signature Scheme (PSS).| | HUKS_PADDING_PSS | 2 | Probabilistic Signature Scheme (PSS).|
| HUKS_PADDING_PKCS1_V1_5 | 3 | PKCS1_V1_5.| | HUKS_PADDING_PKCS1_V1_5 | 3 | PKCS1_V1_5.|
| HUKS_PADDING_PKCS5 | 4 | Public Key Cryptography Standards (PKCS)#5.| | HUKS_PADDING_PKCS5 | 4 | Public Key Cryptography Standards (PKCS) #5.|
| HUKS_PADDING_PKCS7 | 5 | PKCS#7| | HUKS_PADDING_PKCS7 | 5 | PKCS #7|
## HuksCipherMode ## HuksCipherMode
...@@ -155,7 +155,7 @@ Enumerates the cipher modes. ...@@ -155,7 +155,7 @@ Enumerates the cipher modes.
## HuksKeySize ## HuksKeySize
Represents the key length. Enumerates the key sizes.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -182,7 +182,7 @@ Represents the key length. ...@@ -182,7 +182,7 @@ Represents the key length.
## HuksKeyAlg ## HuksKeyAlg
Represents the algorithm used by a key. Enumerates the key algorithms.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -244,8 +244,8 @@ Enumerates the tag transfer modes. ...@@ -244,8 +244,8 @@ Enumerates the tag transfer modes.
| Name | Value | Description | | Name | Value | Description |
| -------------------- | ---- | ----------------- | | -------------------- | ---- | ----------------- |
| HUKS_SEND_TYPE_ASYNC | 0 | Send the tag asynchronously.| | HUKS_SEND_TYPE_ASYNC | 0 | The tag is sent asynchronously.|
| HUKS_SEND_TYPE_SYNC | 1 | Send the tag synchronously.| | HUKS_SEND_TYPE_SYNC | 1 | The tag is sent synchronously.|
## HuksTagType ## HuksTagType
...@@ -274,7 +274,7 @@ Enumerates the tags used to invoke parameters. ...@@ -274,7 +274,7 @@ Enumerates the tags used to invoke parameters.
| HUKS_TAG_INVALID | HuksTagType.HUKS_TAG_TYPE_INVALID \| 0 | Invalid tag. | | HUKS_TAG_INVALID | HuksTagType.HUKS_TAG_TYPE_INVALID \| 0 | Invalid tag. |
| HUKS_TAG_ALGORITHM | HUKS_TAG_TYPE_UINT \| 1 | Indicates the algorithm. | | HUKS_TAG_ALGORITHM | HUKS_TAG_TYPE_UINT \| 1 | Indicates the algorithm. |
| HUKS_TAG_PURPOSE | HuksTagType.HUKS_TAG_TYPE_UINT \| 2 | Indicates the purpose of a key. | | HUKS_TAG_PURPOSE | HuksTagType.HUKS_TAG_TYPE_UINT \| 2 | Indicates the purpose of a key. |
| HUKS_TAG_KEY_SIZE | HuksTagType.HUKS_TAG_TYPE_UINT \| 3 | Indicates the key length. | | HUKS_TAG_KEY_SIZE | HuksTagType.HUKS_TAG_TYPE_UINT \| 3 | Indicates the key size. |
| HUKS_TAG_DIGEST | HuksTagType.HUKS_TAG_TYPE_UINT \| 4 | Indicates the digest algorithm. | | HUKS_TAG_DIGEST | HuksTagType.HUKS_TAG_TYPE_UINT \| 4 | Indicates the digest algorithm. |
| HUKS_TAG_PADDING | HuksTagType.HUKS_TAG_TYPE_UINT \| 5 | Indicates the padding algorithm. | | HUKS_TAG_PADDING | HuksTagType.HUKS_TAG_TYPE_UINT \| 5 | Indicates the padding algorithm. |
| HUKS_TAG_BLOCK_MODE | HuksTagType.HUKS_TAG_TYPE_UINT \| 6 | Indicates the cipher mode. | | HUKS_TAG_BLOCK_MODE | HuksTagType.HUKS_TAG_TYPE_UINT \| 6 | Indicates the cipher mode. |
...@@ -321,7 +321,7 @@ Enumerates the tags used to invoke parameters. ...@@ -321,7 +321,7 @@ Enumerates the tags used to invoke parameters.
| HUKS_TAG_ATTESTATION_ID_UDID | HuksTagType.HUKS_TAG_TYPE_BYTES \| 513 | Indicates the device UDID. | | HUKS_TAG_ATTESTATION_ID_UDID | HuksTagType.HUKS_TAG_TYPE_BYTES \| 513 | Indicates the device UDID. |
| HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO | HuksTagType.HUKS_TAG_TYPE_BYTES \| 514 | Indicates the security credential used for the attestation. | | HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO | HuksTagType.HUKS_TAG_TYPE_BYTES \| 514 | Indicates the security credential used for the attestation. |
| HUKS_TAG_ATTESTATION_ID_VERSION_INFO | HuksTagType.HUKS_TAG_TYPE_BYTES \| 515 | Indicates the version information used in the attestation. | | HUKS_TAG_ATTESTATION_ID_VERSION_INFO | HuksTagType.HUKS_TAG_TYPE_BYTES \| 515 | Indicates the version information used in the attestation. |
| HUKS_TAG_IS_KEY_ALIAS | HuksTagType.HUKS_TAG_TYPE_BOOL \| 1001 | Indicates whether to use the tag of the alias passed during key generation.| | HUKS_TAG_IS_KEY_ALIAS | HuksTagType.HUKS_TAG_TYPE_BOOL \| 1001 | Indicates whether to use the alias passed in during key generation.|
| HUKS_TAG_KEY_STORAGE_FLAG | HuksTagType.HUKS_TAG_TYPE_UINT \| 1002 | Indicates the key storage mode. | | HUKS_TAG_KEY_STORAGE_FLAG | HuksTagType.HUKS_TAG_TYPE_UINT \| 1002 | Indicates the key storage mode. |
| HUKS_TAG_IS_ALLOWED_WRAP | HuksTagType.HUKS_TAG_TYPE_BOOL \| 1003 | Reserved. | | HUKS_TAG_IS_ALLOWED_WRAP | HuksTagType.HUKS_TAG_TYPE_BOOL \| 1003 | Reserved. |
| HUKS_TAG_KEY_WRAP_TYPE | HuksTagType.HUKS_TAG_TYPE_UINT \| 1004 | Reserved. | | HUKS_TAG_KEY_WRAP_TYPE | HuksTagType.HUKS_TAG_TYPE_UINT \| 1004 | Reserved. |
...@@ -352,7 +352,7 @@ Enumerates the tags used to invoke parameters. ...@@ -352,7 +352,7 @@ Enumerates the tags used to invoke parameters.
generateKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void generateKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Generates a key. This method uses an asynchronous callback to return the result. Generates a key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -362,7 +362,7 @@ Generates a key. This method uses an asynchronous callback to return the result. ...@@ -362,7 +362,7 @@ Generates a key. This method uses an asynchronous callback to return the result.
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| keyAlias | string | Yes | Alias of the key. | | keyAlias | string | Yes | Alias of the key. |
| options | [HuksOptions](#huksoptions) | Yes | Tags required for generating the key. | | options | [HuksOptions](#huksoptions) | Yes | Tags required for generating the key. |
| callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If any other result is returned, see **HuksResult**.| | callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code defined in **HuksResult** will be returned.|
**Example** **Example**
...@@ -402,7 +402,7 @@ huks.generateKey(keyAlias, options, function (err, data){}); ...@@ -402,7 +402,7 @@ huks.generateKey(keyAlias, options, function (err, data){});
generateKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> generateKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
Generates a key. This method uses a promise to return the result. Generates a key. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -453,7 +453,7 @@ var result = huks.generateKey(keyAlias, options); ...@@ -453,7 +453,7 @@ var result = huks.generateKey(keyAlias, options);
deleteKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void deleteKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Deletes a key. This method uses an asynchronous callback to return the result. Deletes a key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -463,7 +463,7 @@ Deletes a key. This method uses an asynchronous callback to return the result. ...@@ -463,7 +463,7 @@ Deletes a key. This method uses an asynchronous callback to return the result.
| -------- | ----------------------------------------- | ---- | -------------------------------------------------- | | -------- | ----------------------------------------- | ---- | -------------------------------------------------- |
| keyAlias | string | Yes | Key alias passed in when the key was generated. | | keyAlias | string | Yes | Key alias passed in when the key was generated. |
| options | [HuksOptions](#huksoptions) | Yes | Empty object (leave this parameter empty). | | options | [HuksOptions](#huksoptions) | Yes | Empty object (leave this parameter empty). |
| callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.| | callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned.|
**Example** **Example**
...@@ -480,7 +480,7 @@ huks.deleteKey(keyAlias, emptyOptions, function (err, data) {}); ...@@ -480,7 +480,7 @@ huks.deleteKey(keyAlias, emptyOptions, function (err, data) {});
deleteKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> deleteKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
Deletes a key. This method uses a promise to return the result. Deletes a key. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -542,7 +542,7 @@ var result = huks.getSdkVersion(emptyOptions); ...@@ -542,7 +542,7 @@ var result = huks.getSdkVersion(emptyOptions);
importKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void importKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Imports a key. This method uses an asynchronous callback to return the result. Imports a key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -552,7 +552,7 @@ Imports a key. This method uses an asynchronous callback to return the result. ...@@ -552,7 +552,7 @@ Imports a key. This method uses an asynchronous callback to return the result.
| -------- | ------------------------ | ---- | ------------------------------------------------- | | -------- | ------------------------ | ---- | ------------------------------------------------- |
| keyAlias | string | Yes | Key alias, which is used to hold the key pair.| | keyAlias | string | Yes | Key alias, which is used to hold the key pair.|
| options | [HuksOptions](#huksoptions) | Yes | Tags required for the import and key pair to import.| | options | [HuksOptions](#huksoptions) | Yes | Tags required for the import and key pair to import.|
| callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.| | callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned.|
**Example** **Example**
...@@ -600,7 +600,7 @@ huks.importKey(keyAlias, options, function (err, data){}); ...@@ -600,7 +600,7 @@ huks.importKey(keyAlias, options, function (err, data){});
importKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> importKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
Imports a key. This method uses a promise to return the result. Imports a key. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -665,7 +665,7 @@ var result = huks.importKey(keyAlias, huksoptions); ...@@ -665,7 +665,7 @@ var result = huks.importKey(keyAlias, huksoptions);
exportKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void exportKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Exports a key. This method uses an asynchronous callback to return the result. Exports a key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -692,7 +692,7 @@ huks.exportKey(keyAlias, emptyOptions, function (err, data){}); ...@@ -692,7 +692,7 @@ huks.exportKey(keyAlias, emptyOptions, function (err, data){});
exportKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> exportKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
Exports a key. This method uses a promise to return the result. Exports a key. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -707,7 +707,7 @@ Exports a key. This method uses a promise to return the result. ...@@ -707,7 +707,7 @@ Exports a key. This method uses a promise to return the result.
| Type | Description | | Type | Description |
| ----------------------------------- | ------------------------------------------------------------ | | ----------------------------------- | ------------------------------------------------------------ |
| Promise\<[HuksResult](#huksresult)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.<br/>**outData** contains the public key exported.| | Promise\<[HuksResult](#huksresult)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. **outData** contains the public key exported.|
**Example** **Example**
...@@ -724,7 +724,7 @@ var result = huks.exportKey(keyAlias, emptyOptions); ...@@ -724,7 +724,7 @@ var result = huks.exportKey(keyAlias, emptyOptions);
getKeyProperties(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void getKeyProperties(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Obtains key properties. This method uses an asynchronous callback to return the result. Obtains key properties. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -751,7 +751,7 @@ huks.getKeyProperties(keyAlias, emptyOptions, function (err, data){}); ...@@ -751,7 +751,7 @@ huks.getKeyProperties(keyAlias, emptyOptions, function (err, data){});
getKeyProperties(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> getKeyProperties(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
Obtains key properties. This method uses a promise to return the result. Obtains key properties. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -783,7 +783,7 @@ var result = huks.getKeyProperties(keyAlias, emptyOptions); ...@@ -783,7 +783,7 @@ var result = huks.getKeyProperties(keyAlias, emptyOptions);
isKeyExist(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<boolean>) : void isKeyExist(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<boolean>) : void
Checks whether a key exists. This method uses an asynchronous callback to return the result. Checks whether a key exists. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -810,7 +810,7 @@ huks.isKeyExist(keyAlias, emptyOptions, function (err, data){}); ...@@ -810,7 +810,7 @@ huks.isKeyExist(keyAlias, emptyOptions, function (err, data){});
isKeyExist(keyAlias: string, options: HuksOptions) : Promise\<boolean> isKeyExist(keyAlias: string, options: HuksOptions) : Promise\<boolean>
Checks whether a key exists. This method uses a promise to return the result. Checks whether a key exists. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -844,7 +844,7 @@ var result = huks.isKeyExist(keyAlias, emptyOptions); ...@@ -844,7 +844,7 @@ var result = huks.isKeyExist(keyAlias, emptyOptions);
init(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksHandle>) : void init(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksHandle>) : void
Initializes a key. This method uses an asynchronous callback to return the result. Initializes a key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -853,15 +853,15 @@ Initializes a key. This method uses an asynchronous callback to return the resul ...@@ -853,15 +853,15 @@ Initializes a key. This method uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------- | | -------- | ---------------------- | ---- | ------------------------------------- |
| keyAlias | string | Yes | Alias of the target key.| | keyAlias | string | Yes | Alias of the target key.|
| options | [HuksOptions](#huksoptions) | Yes | Parameter set of the **Init** operation.| | options | [HuksOptions](#huksoptions) | Yes | Parameters used for initialization.|
| callback | AsyncCallback\<[HuksHandle](#hukshandle)> | Yes | Callback used to return the handle of the **Init** operation.| | callback | AsyncCallback\<[HuksHandle](#hukshandle)> | Yes | Callback used to return the handle of the initialization operation.|
## huks.init ## huks.init
init(keyAlias: string, options: HuksOptions) : Promise\<HuksHandle> init(keyAlias: string, options: HuksOptions) : Promise\<HuksHandle>
Initializes a key. This method uses a promise to return the result. Initializes a key. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -870,15 +870,15 @@ Initializes a key. This method uses a promise to return the result. ...@@ -870,15 +870,15 @@ Initializes a key. This method uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------- | | -------- | ---------------------- | ---- | ------------------------------------- |
| keyAlias | string | Yes | Alias of the target key.| | keyAlias | string | Yes | Alias of the target key.|
| options | [HuksOptions](#huksoptions) | Yes | Parameter set of the **Init** operation.| | options | [HuksOptions](#huksoptions) | Yes | Parameters used for initialization.|
| promise | Promise\<[HuksHandle](#hukshandle)> | Yes | Promise used to return the handle of the **Init** operation.| | promise | Promise\<[HuksHandle](#hukshandle)> | Yes | Promise used to return the handle of the initialization operation.|
## huks.update ## huks.update
update(handle: number, token?: Uint8Array, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void update(handle: number, token?: Uint8Array, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Updates a key. This method uses an asynchronous callback to return the result. Updates a key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -888,7 +888,7 @@ Updates a key. This method uses an asynchronous callback to return the result. ...@@ -888,7 +888,7 @@ Updates a key. This method uses an asynchronous callback to return the result.
| -------- | ---------------------- | ---- | ------------------------------------- | | -------- | ---------------------- | ---- | ------------------------------------- |
| handle | number | Yes | Handle of the **Update** operation.| | handle | number | Yes | Handle of the **Update** operation.|
| token | Uint8Array | No| Token of the **Update** operation.| | token | Uint8Array | No| Token of the **Update** operation.|
| options | [HuksOptions](#huksoptions) | Yes | Parameter set of the **Update** operation.| | options | [HuksOptions](#huksoptions) | Yes | Parameters of the **Update** operation.|
| callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes| Callback used to return the operation result.| | callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes| Callback used to return the operation result.|
...@@ -896,7 +896,7 @@ Updates a key. This method uses an asynchronous callback to return the result. ...@@ -896,7 +896,7 @@ Updates a key. This method uses an asynchronous callback to return the result.
update(handle: number, token?: Uint8Array, options: HuksOptions) : Promise\<HuksResult> update(handle: number, token?: Uint8Array, options: HuksOptions) : Promise\<HuksResult>
Updates a key. This method uses a promise to return the result. Updates a key. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -906,15 +906,15 @@ Updates a key. This method uses a promise to return the result. ...@@ -906,15 +906,15 @@ Updates a key. This method uses a promise to return the result.
| -------- | ---------------------- | ---- | ------------------------------------- | | -------- | ---------------------- | ---- | ------------------------------------- |
| handle | number | Yes | Handle of the **Update** operation.| | handle | number | Yes | Handle of the **Update** operation.|
| token | Uint8Array | No| Token of the **Update** operation.| | token | Uint8Array | No| Token of the **Update** operation.|
| options | [HuksOptions](#huksoptions) | Yes | Parameter set of the **Update** operation.| | options | [HuksOptions](#huksoptions) | Yes | Parameters of the **Update** operation.|
| promise | Promise\<[HuksResult](#huksresult)> | Yes| Promise used to return the operation result.| | promise | Promise\<[HuksResult](#huksresult)> | Yes| Promise used to return the operation result.|
## huks.finish ## huks.finish
finish(handle: number, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void finish(handle: number, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Completes the key operation and releases resources. This method uses an asynchronous callback to return the result. Completes the key operation and releases resources. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -923,7 +923,7 @@ Completes the key operation and releases resources. This method uses an asynchro ...@@ -923,7 +923,7 @@ Completes the key operation and releases resources. This method uses an asynchro
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------- | | -------- | ---------------------- | ---- | ------------------------------------- |
| handle | number | Yes | Handle of the **Finish** operation.| | handle | number | Yes | Handle of the **Finish** operation.|
| options | [HuksOptions](#huksoptions) | Yes | Parameter set of the **Finish** operation.| | options | [HuksOptions](#huksoptions) | Yes | Parameters of the **Finish** operation.|
| callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes| Callback used to return the operation result.| | callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes| Callback used to return the operation result.|
...@@ -931,7 +931,7 @@ Completes the key operation and releases resources. This method uses an asynchro ...@@ -931,7 +931,7 @@ Completes the key operation and releases resources. This method uses an asynchro
finish(handle: number, options: HuksOptions) : Promise\<HuksResult> finish(handle: number, options: HuksOptions) : Promise\<HuksResult>
Completes the key operation and releases resources. This method uses a promise to return the result. Completes the key operation and releases resources. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -940,7 +940,7 @@ Completes the key operation and releases resources. This method uses a promise t ...@@ -940,7 +940,7 @@ Completes the key operation and releases resources. This method uses a promise t
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------- | | -------- | ---------------------- | ---- | ------------------------------------- |
| handle | number | Yes | Handle of the **Finish** operation.| | handle | number | Yes | Handle of the **Finish** operation.|
| options | [HuksOptions](#huksoptions) | Yes | Parameter set of the **Finish** operation.| | options | [HuksOptions](#huksoptions) | Yes | Parameters of the **Finish** operation.|
| promise | Promise\<[HuksResult](#HuksResult)> | Yes| Promise used to return the operation result.| | promise | Promise\<[HuksResult](#HuksResult)> | Yes| Promise used to return the operation result.|
...@@ -948,7 +948,7 @@ Completes the key operation and releases resources. This method uses a promise t ...@@ -948,7 +948,7 @@ Completes the key operation and releases resources. This method uses a promise t
abort(handle: number, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void abort(handle: number, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Aborts the use of the key. This method uses an asynchronous callback to return the result. Aborts the use of the key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -957,7 +957,7 @@ Aborts the use of the key. This method uses an asynchronous callback to return t ...@@ -957,7 +957,7 @@ Aborts the use of the key. This method uses an asynchronous callback to return t
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------- | | -------- | ---------------------- | ---- | ------------------------------------- |
| handle | number | Yes | Handle of the **Abort** operation.| | handle | number | Yes | Handle of the **Abort** operation.|
| options | [HuksOptions](#huksoptions) | Yes | Parameter set of the **Abort** operation.| | options | [HuksOptions](#huksoptions) | Yes | Parameters of the **Abort** operation.|
| callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes| Callback used to return the operation result.| | callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes| Callback used to return the operation result.|
**Example** **Example**
...@@ -981,13 +981,13 @@ async function routePage() { ...@@ -981,13 +981,13 @@ async function routePage() {
console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`) console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`)
} }
} }
var alias = "HuksDemoRSA"; var keyalias = "HuksDemoRSA";
var properties = new Array(); var properties = new Array();
var options = { var options = {
properties: properties, properties: properties,
inData: new Uint8Array(0) inData: new Uint8Array(0)
}; };
var handle = {}; var handle;
var resultMessage = ""; var resultMessage = "";
async function generateKey() { async function generateKey() {
properties[0] = { properties[0] = {
...@@ -1010,7 +1010,7 @@ async function generateKey() { ...@@ -1010,7 +1010,7 @@ async function generateKey() {
tag: huks.HuksTag.HUKS_TAG_DIGEST, tag: huks.HuksTag.HUKS_TAG_DIGEST,
value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
}; };
huks.generateKey(alias, options); huks.generateKey(keyalias, options);
} }
function stringToUint8Array(str) { function stringToUint8Array(str) {
var arr = []; var arr = [];
...@@ -1021,19 +1021,14 @@ function stringToUint8Array(str) { ...@@ -1021,19 +1021,14 @@ function stringToUint8Array(str) {
return tmpUint8Array; return tmpUint8Array;
} }
async function huksInit() { async function huksInit() {
await huks.init(alias, options).then((data) => { await huks.init(keyalias, options).then((data) => {
console.log(`test init data: ${JSON.stringify(data)}`); console.log(`test init data: ${JSON.stringify(data)}`);
handle = { handle = data.handle;
"handle1": data.handle1,
"handle2": data.handle2
};
}).catch((err) => { }).catch((err) => {
console.log("test init err information: " + JSON.stringify(err)) console.log("test init err information: " + JSON.stringify(err))
}) })
} }
async function huksUpdate() { async function huksUpdate() {
let count = 2;
for (let i = 0; i < count; i++) {
options.inData = stringToUint8Array("huksHmacTest"); options.inData = stringToUint8Array("huksHmacTest");
await huks.update(handle, options).then((data) => { await huks.update(handle, options).then((data) => {
if (data.errorCode === 0) { if (data.errorCode === 0) {
...@@ -1041,11 +1036,8 @@ async function huksUpdate() { ...@@ -1041,11 +1036,8 @@ async function huksUpdate() {
} else { } else {
resultMessage += "update fail!"; resultMessage += "update fail!";
} }
}).catch((err) => {
resultMessage += "update times: " + count + (i + 1) + " fail catch errorMessage:" + JSON.stringify(err) + " "
}); });
console.log(resultMessage); console.log(resultMessage);
}
} }
function huksFinish() { function huksFinish() {
options.inData = stringToUint8Array("HuksDemoHMAC"); options.inData = stringToUint8Array("HuksDemoHMAC");
...@@ -1068,7 +1060,7 @@ async function huksAbort() { ...@@ -1068,7 +1060,7 @@ async function huksAbort() {
resultMessage = "abort fail errorCode: " + data.errorCode; resultMessage = "abort fail errorCode: " + data.errorCode;
} }
}).catch((err) => { }).catch((err) => {
resultMessage = "Failed to abort the use of the key. catch errorMessage:" + JSON.stringify(err) resultMessage = "Failed to abort the use of the key. catch errorMessage:" + JSON.stringify(err)
}); });
console.log(resultMessage); console.log(resultMessage);
} }
...@@ -1110,7 +1102,7 @@ struct Index { ...@@ -1110,7 +1102,7 @@ struct Index {
generateKey() generateKey()
}) })
Button() { Button() {
Text('huksInit') Text('Init')
.fontSize(25) .fontSize(25)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
...@@ -1124,7 +1116,7 @@ struct Index { ...@@ -1124,7 +1116,7 @@ struct Index {
huksInit() huksInit()
}) })
Button() { Button() {
Text('huksUpdate') Text('Update')
.fontSize(25) .fontSize(25)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
...@@ -1138,7 +1130,7 @@ struct Index { ...@@ -1138,7 +1130,7 @@ struct Index {
huksUpdate() huksUpdate()
}) })
Button() { Button() {
Text('huksFinish') Text('Finish')
.fontSize(25) .fontSize(25)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
...@@ -1152,7 +1144,7 @@ struct Index { ...@@ -1152,7 +1144,7 @@ struct Index {
huksFinish() huksFinish()
}) })
Button() { Button() {
Text('huksAbort') Text('Abort')
.fontSize(25) .fontSize(25)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
...@@ -1176,7 +1168,7 @@ struct Index { ...@@ -1176,7 +1168,7 @@ struct Index {
abort(handle: number, options: HuksOptions) : Promise\<HuksResult>; abort(handle: number, options: HuksOptions) : Promise\<HuksResult>;
Aborts the use of the key. This method uses a promise to return the result. Aborts the use of the key. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -1185,7 +1177,7 @@ Aborts the use of the key. This method uses a promise to return the result. ...@@ -1185,7 +1177,7 @@ Aborts the use of the key. This method uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------- | | -------- | ---------------------- | ---- | ------------------------------------- |
| handle | number | Yes | Handle of the **Abort** operation.| | handle | number | Yes | Handle of the **Abort** operation.|
| options | [HuksOptions](#huksoptions) | Yes | Parameter set of the **Abort** operation.| | options | [HuksOptions](#huksoptions) | Yes | Parameters of the **Abort** operation.|
| promise | Promise\<[HuksResult](#huksresult)> | Yes| Promise used to return the operation result.| | promise | Promise\<[HuksResult](#huksresult)> | Yes| Promise used to return the operation result.|
**Example** **Example**
...@@ -1210,13 +1202,13 @@ async function routePage() { ...@@ -1210,13 +1202,13 @@ async function routePage() {
} }
} }
var alias = "HuksDemoRSA"; var keyalias = "HuksDemoRSA";
var properties = new Array(); var properties = new Array();
var options = { var options = {
properties: properties, properties: properties,
inData: new Uint8Array(0) inData: new Uint8Array(0)
}; };
var handle = {}; var handle;
var resultMessage = ""; var resultMessage = "";
function stringToUint8Array(str) { function stringToUint8Array(str) {
var arr = []; var arr = [];
...@@ -1248,17 +1240,14 @@ async function generateKey() { ...@@ -1248,17 +1240,14 @@ async function generateKey() {
tag: huks.HuksTag.HUKS_TAG_DIGEST, tag: huks.HuksTag.HUKS_TAG_DIGEST,
value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
}; };
huks.generateKey(alias, options, function (err, data) { }); huks.generateKey(keyalias, options, function (err, data) { });
} }
async function huksInit() { async function huksInit() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
huks.init(alias, options, async function (err, data) { huks.init(keyalias, options, async function (err, data) {
if (data.errorCode === 0) { if (data.errorCode === 0) {
resultMessage = "Initialization successful!" resultMessage = "Initialization successful!"
handle = { handle = data.handle;
"handle1": data.handle1,
"handle2": data.handle2
}
} else { } else {
resultMessage = "init fail errorCode: " + data.errorCode resultMessage = "init fail errorCode: " + data.errorCode
} }
...@@ -1267,8 +1256,6 @@ async function huksInit() { ...@@ -1267,8 +1256,6 @@ async function huksInit() {
} }
async function huksUpdate() { async function huksUpdate() {
let count = 2;
for (let i = 0; i < count; i++) {
options.inData = stringToUint8Array("huksHmacTest"); options.inData = stringToUint8Array("huksHmacTest");
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
huks.update(handle, options, function (err, data) { huks.update(handle, options, function (err, data) {
...@@ -1280,7 +1267,7 @@ async function huksUpdate() { ...@@ -1280,7 +1267,7 @@ async function huksUpdate() {
}); });
}); });
console.log(resultMessage); console.log(resultMessage);
}
} }
async function huksFinish() { async function huksFinish() {
...@@ -1341,7 +1328,7 @@ struct Index { ...@@ -1341,7 +1328,7 @@ struct Index {
generateKey() generateKey()
}) })
Button() { Button() {
Text('huksInit') Text('Init')
.fontSize(25) .fontSize(25)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
...@@ -1355,7 +1342,7 @@ struct Index { ...@@ -1355,7 +1342,7 @@ struct Index {
huksInit() huksInit()
}) })
Button() { Button() {
Text('huksUpdate') Text('Update')
.fontSize(25) .fontSize(25)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
...@@ -1369,7 +1356,7 @@ struct Index { ...@@ -1369,7 +1356,7 @@ struct Index {
huksUpdate() huksUpdate()
}) })
Button() { Button() {
Text('huksFinish') Text('Finish')
.fontSize(25) .fontSize(25)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
...@@ -1383,7 +1370,7 @@ struct Index { ...@@ -1383,7 +1370,7 @@ struct Index {
huksFinish() huksFinish()
}) })
Button() { Button() {
Text('huksAbort') Text('Abort')
.fontSize(25) .fontSize(25)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
...@@ -1435,7 +1422,7 @@ Defines the HUKS handle structure. ...@@ -1435,7 +1422,7 @@ Defines the HUKS handle structure.
| ---------- | ---------------- | ---- | -------- | | ---------- | ---------------- | ---- | -------- |
| errorCode | number | Yes | Error code.| | errorCode | number | Yes | Error code.|
| handle | number | Yes| Value of the handle.| | handle | number | Yes| Value of the handle.|
| token | Uint8Array | No| Reserved field.| | token | Uint8Array | No| Reserved.|
## HuksResult ## HuksResult
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> >
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module are system APIs and cannot be called by third-party applications. > - API version 9 is a canary release for trial use. The APIs of this version may be unstable.
## Modules to Import ## Modules to Import
...@@ -15,7 +15,7 @@ import storagestatistics from "@ohos.storageStatistics"; ...@@ -15,7 +15,7 @@ import storagestatistics from "@ohos.storageStatistics";
getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
Asynchronously obtains the total space of the specified volume. This method uses a promise to return the result. Asynchronously obtains the total space of the specified volume. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
...@@ -46,7 +46,7 @@ Asynchronously obtains the total space of the specified volume. This method uses ...@@ -46,7 +46,7 @@ Asynchronously obtains the total space of the specified volume. This method uses
getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void
Asynchronously obtains the total space of the specified volume. This method uses a callback to return the result. Asynchronously obtains the total space of the specified volume. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
...@@ -62,7 +62,7 @@ Asynchronously obtains the total space of the specified volume. This method uses ...@@ -62,7 +62,7 @@ Asynchronously obtains the total space of the specified volume. This method uses
```js ```js
let uuid = ""; let uuid = "";
storagestatistics.getTotalSizeOfVolume(uuid, function(error, number){ storagestatistics.getTotalSizeOfVolume(uuid, function(error, number){
// Do something // Do something.
console.info("getTotalSizeOfVolume successfully:"+ number); console.info("getTotalSizeOfVolume successfully:"+ number);
}); });
``` ```
...@@ -73,7 +73,7 @@ Asynchronously obtains the total space of the specified volume. This method uses ...@@ -73,7 +73,7 @@ Asynchronously obtains the total space of the specified volume. This method uses
getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
Asynchronously obtains the available space of the specified volume. This method uses a promise to return the result. Asynchronously obtains the available space of the specified volume. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
...@@ -105,7 +105,7 @@ Asynchronously obtains the available space of the specified volume. This method ...@@ -105,7 +105,7 @@ Asynchronously obtains the available space of the specified volume. This method
getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void
Asynchronously obtains the available space of the specified volume. This method uses a callback to return the result. Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
...@@ -121,7 +121,75 @@ Asynchronously obtains the available space of the specified volume. This method ...@@ -121,7 +121,75 @@ Asynchronously obtains the available space of the specified volume. This method
```js ```js
let uuid = ""; let uuid = "";
storagestatistics.getFreeSizeOfVolume(uuid, function(error, number){ storagestatistics.getFreeSizeOfVolume(uuid, function(error, number){
// Do something // Do something.
console.info("getFreeSizeOfVolume successfully:"+ number); console.info("getFreeSizeOfVolume successfully:"+ number);
}); });
``` ```
## storagestatistics.getBundleStats<sup>9+</sup>
getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
Asynchronously obtains app information. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
- Parameters
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------- |
| packageName | string | Yes | Bundle name of the app.|
- Return value
| Type | Description |
| ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats)&gt; | Promise used to return the app information.|
- Example
```js
let packageName = "";
storagestatistics.getBundleStats(packageName).then(function(BundleStats){
console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
}).catch(function(err){
console.info("getBundleStats failed with error:"+ err);
});
```
## storagestatistics.getBundleStats<sup>9+</sup>
getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;): void
Asynchronously obtains app information. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
- Parameters
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| packageName | string | Yes | Bundle name of the app.|
| callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | Yes | Callback invoked to return the app information.|
- Example
```js
let packageName = "";
storagestatistics.getBundleStats(packageName, function(error, BundleStats){
// Do something.
console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
});
```
## BundleStats<sup>9+</sup>
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
### Attributes
| Name | Type | Description |
| --------- | ------ | -------------- |
| appSize<sup>9+</sup> | number | Size of the app. |
| cacheSize<sup>9+</sup> | number | Cache size of the app. |
| dataSize<sup>9+</sup> | number | Total data size of the app.|
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> >
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 9.
> - The APIs of this module are system APIs and cannot be called by third-party applications. > - API version 9 is a canary release for trial use. The APIs of this version may be unstable.
## Modules to Import ## Modules to Import
......
...@@ -246,7 +246,7 @@ The process of signing a HAP is as follows: ...@@ -246,7 +246,7 @@ The process of signing a HAP is as follows:
> >
> For security purposes, the ECC algorithm is recommended for generating key pairs for application signing signatures. The RSA algorithm is not recommended.<br/> > For security purposes, the ECC algorithm is recommended for generating key pairs for application signing signatures. The RSA algorithm is not recommended.<br/>
> You are advised to place the HAP, profile, KS file **OpenHarmony.p12**, root CA certificate, intermediate CA certificate, and hapsigner in the same directory for easy operation. > You are advised to place the HAP, profile, KS file **OpenHarmony.p12**, root CA certificate, intermediate CA certificate, and hapsigner in the same directory for easy operation.
> The **developtools_hapsigner/autosign/result/** directory has the following files:<br/>-&nbsp;OpenHarmony KS file **OpenHarmony.p12** <br/>-&nbsp;Root CA certificate **rootCA.cer**<br/>-&nbsp;Intermediate CA certificate **subCA.cer**<br/>-&nbsp;Profile signing certificate **OpenHarmonyProfileRelease.pem** > The [**developtools_hapsigner/autosign/result**](https://gitee.com/openharmony/developtools_hapsigner/tree/master/autosign/result) directory has the following files:<br/>-&nbsp;OpenHarmony KS file **OpenHarmony.p12** <br/>-&nbsp;Root CA certificate **rootCA.cer**<br/>-&nbsp;Intermediate CA certificate **subCA.cer**<br/>-&nbsp;Profile signing certificate **OpenHarmonyProfileRelease.pem**
**1. Generate a key pair for the application signing certificate.** **1. Generate a key pair for the application signing certificate.**
......
# GPIO<a name="EN-US_TOPIC_0000001206171135"></a> # GPIO
## Overview<a name="section1635911016188"></a> ## Overview
Generally, a general-purpose input/output \(GPIO\) controller manages all GPIO pins by group. Each group of GPIO pins is associated with one or more registers. The GPIO pins are operated by reading data from and writing data to the registers. A general-purpose input/output (GPIO) controller manages all GPIO pins by group. Each group of GPIO pins is associated with one or more registers. The GPIO controller manages the pins by reading data from and writing data to the registers.
The GPIO APIs define a set of standard functions for performing operations on GPIO pins, including: The GPIO APIs define a set of standard functions for performing operations on GPIO pins, including:
- Setting the pin direction, which can be input or output \(High impedance is not supported currently.\) - Setting the pin direction, which can be input or output (high impedance is not supported currently)
- Reading and writing level values, which can be low or high - Reading and writing level values, which can be low or high
- Setting an interrupt service routine \(ISR\) function and interrupt trigger mode for a pin
- Enabling or disabling a pin interrupt - Setting an interrupt service routine (ISR) function and interrupt trigger mode for a pin
## Available APIs<a name="section589913442203"></a> - Enabling or disabling pin interrupts
**Table 1** APIs available for the GPIO driver
## Available APIs
<a name="table89681075215"></a>
<table><thead align="left"><tr id="row996807162115"><th class="cellrowborder" valign="top" width="19.74%" id="mcps1.2.4.1.1"><p id="p296817716212"><a name="p296817716212"></a><a name="p296817716212"></a>Capability</p> **Table 1** GPIO driver APIs
</th>
<th class="cellrowborder" valign="top" width="32.36%" id="mcps1.2.4.1.2"><p id="p596897172119"><a name="p596897172119"></a><a name="p596897172119"></a>Function</p> | Category| Description|
</th> | -------- | -------- |
<th class="cellrowborder" valign="top" width="47.9%" id="mcps1.2.4.1.3"><p id="p39681677213"><a name="p39681677213"></a><a name="p39681677213"></a>Description</p> | GPIO read/write| -&nbsp;**GpioRead**: reads the pin level.<br>-&nbsp;**GpioWrite**: writes the pin level.|
</th> | GPIO settings| -&nbsp;**GpioSetDir**: sets the pin direction.<br>-&nbsp;**GpioGetDir**: obtains the pin direction.|
</tr> | GPIO interrupt settings| -&nbsp;**GpioSetIrq**: sets the ISR function for a GPIO pin.<br>-&nbsp;**GpioUnsetIrq**: cancels the setting of the ISR function for a GPIO pin.<br>-&nbsp;**GpioEnableIrq**: enables interrupts for a pin.<br>-&nbsp;**GpioDisableIrq**: disables interrupts for a pin.|
</thead>
<tbody><tr id="row896847202113"><td class="cellrowborder" rowspan="2" valign="top" width="19.74%" headers="mcps1.2.4.1.1 "><p id="p1796814719210"><a name="p1796814719210"></a><a name="p1796814719210"></a>GPIO read/write</p> > ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**<br/>
</td> > All APIs described in this document can be called only in the kernel space.
<td class="cellrowborder" valign="top" width="32.36%" headers="mcps1.2.4.1.2 "><p id="p39683732112"><a name="p39683732112"></a><a name="p39683732112"></a>GpioRead</p>
</td>
<td class="cellrowborder" valign="top" width="47.9%" headers="mcps1.2.4.1.3 "><p id="p59687710219"><a name="p59687710219"></a><a name="p59687710219"></a>Reads the level value of a GPIO pin.</p> ## Usage Guidelines
</td>
</tr>
<tr id="row17968872212"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p396812722116"><a name="p396812722116"></a><a name="p396812722116"></a>GpioWrite</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p396814715219"><a name="p396814715219"></a><a name="p396814715219"></a>Writes the level value of a GPIO pin.</p>
</td>
</tr>
<tr id="row129681576218"><td class="cellrowborder" rowspan="2" valign="top" width="19.74%" headers="mcps1.2.4.1.1 "><p id="p1496813782116"><a name="p1496813782116"></a><a name="p1496813782116"></a>GPIO settings</p>
</td>
<td class="cellrowborder" valign="top" width="32.36%" headers="mcps1.2.4.1.2 "><p id="p29688742119"><a name="p29688742119"></a><a name="p29688742119"></a>GpioSetDir</p>
</td>
<td class="cellrowborder" valign="top" width="47.9%" headers="mcps1.2.4.1.3 "><p id="p179682792111"><a name="p179682792111"></a><a name="p179682792111"></a>Sets the direction for a GPIO pin.</p>
</td>
</tr>
<tr id="row1196817715217"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p896827182120"><a name="p896827182120"></a><a name="p896827182120"></a>GpioGetDir</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p39689792111"><a name="p39689792111"></a><a name="p39689792111"></a>Obtains the direction for a GPIO pin.</p>
</td>
</tr>
<tr id="row69682071217"><td class="cellrowborder" rowspan="4" valign="top" width="19.74%" headers="mcps1.2.4.1.1 "><p id="p296818714213"><a name="p296818714213"></a><a name="p296818714213"></a>GPIO interrupt settings</p>
</td>
<td class="cellrowborder" valign="top" width="32.36%" headers="mcps1.2.4.1.2 "><p id="p1396916710216"><a name="p1396916710216"></a><a name="p1396916710216"></a>GpioSetIrq</p>
</td>
<td class="cellrowborder" valign="top" width="47.9%" headers="mcps1.2.4.1.3 "><p id="p99693712113"><a name="p99693712113"></a><a name="p99693712113"></a>Sets the ISR function for a GPIO pin.</p>
</td>
</tr>
<tr id="row4969117172110"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p119692079215"><a name="p119692079215"></a><a name="p119692079215"></a>GpioUnSetIrq</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1996916792114"><a name="p1996916792114"></a><a name="p1996916792114"></a>Cancels the setting of the ISR function for a GPIO pin.</p>
</td>
</tr>
<tr id="row396907112117"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p109694717216"><a name="p109694717216"></a><a name="p109694717216"></a>GpioEnableIrq</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p2969473216"><a name="p2969473216"></a><a name="p2969473216"></a>Enables a GPIO interrupt.</p>
</td>
</tr>
<tr id="row14969117152113"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18969157182116"><a name="p18969157182116"></a><a name="p18969157182116"></a>GpioDisableIrq</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p19690710214"><a name="p19690710214"></a><a name="p19690710214"></a>Disables a GPIO interrupt.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>All functions provided in this document can be called only in kernel mode.
## Usage Guidelines<a name="section259614242196"></a>
### How to Use<a name="section103477714216"></a>
The GPIO APIs use the GPIO pin number to specify a pin. [Figure 1](#fig16151101653713) shows the general process of using a GPIO.
**Figure 1** Process of using a GPIO<a name="fig16151101653713"></a>
![](figures/process-of-using-a-gpio.png "process-of-using-a-gpio")
### Determining a GPIO Pin Number<a name="section370083272117"></a>
The method for converting GPIO pin numbers varies according to the GPIO controller model, parameters, and controller driver of different system on chips \(SoCs\).
- Hi3516DV300
A controller manages 12 groups of GPIO pins. Each group contains 8 GPIO pins.
GPIO pin number = GPIO group index \(0–11\) x Number of GPIO pins in each group \(8\) + Offset in the group
Example: GPIO number of GPIO10\_3 = 10 x 8 + 3 = 83
- Hi3518EV300
A controller manages 10 groups of GPIO pins. Each group contains 10 GPIO pins.
GPIO pin number = GPIO group index \(0–9\) x Number of GPIO pins in each group \(10\) + Offset in the group
Example: GPIO pin number of GPIO7\_3 = 7 x 10 + 3 = 73
### Using APIs to Operate GPIO Pins<a name="section13604050132118"></a>
- Set the direction for a GPIO pin.
Before performing read/write operations on a GPIO pin, call the following function to set the direction:
int32\_t GpioSetDir\(uint16\_t gpio, uint16\_t dir\);
**Table 2** Description of GpioSetDir
<a name="table63111557616"></a>
<table><tbody><tr id="row17311165469"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p53110515616"><a name="p53110515616"></a><a name="p53110515616"></a><strong id="b1142022718160"><a name="b1142022718160"></a><a name="b1142022718160"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p5311454616"><a name="p5311454616"></a><a name="p5311454616"></a><strong id="b93161228141614"><a name="b93161228141614"></a><a name="b93161228141614"></a>Description</strong></p>
</td>
</tr>
<tr id="row0312151666"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p1431265763"><a name="p1431265763"></a><a name="p1431265763"></a>gpio</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p83121553613"><a name="p83121553613"></a><a name="p83121553613"></a>GPIO pin number.</p>
</td>
</tr>
<tr id="row11312151619"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p173121451664"><a name="p173121451664"></a><a name="p173121451664"></a>dir</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p153122520615"><a name="p153122520615"></a><a name="p153122520615"></a>Direction to set.</p>
</td>
</tr>
<tr id="row165937126386"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p83111453613"><a name="p83111453613"></a><a name="p83111453613"></a><strong id="b42491732121614"><a name="b42491732121614"></a><a name="b42491732121614"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p83111151165"><a name="p83111151165"></a><a name="p83111151165"></a><strong id="b1116336166"><a name="b1116336166"></a><a name="b1116336166"></a>Description</strong></p>
</td>
</tr>
<tr id="row205931212123817"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p18312151463"><a name="p18312151463"></a><a name="p18312151463"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p103124517618"><a name="p103124517618"></a><a name="p103124517618"></a>Succeeded in setting the direction for a GPIO pin.</p>
</td>
</tr>
<tr id="row75931212153818"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p23121951261"><a name="p23121951261"></a><a name="p23121951261"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p153121553610"><a name="p153121553610"></a><a name="p153121553610"></a>Failed to set the direction for a GPIO pin.</p>
</td>
</tr>
</tbody>
</table>
- Read or write the level value for a GPIO pin.
To read the level value of a GPIO pin, call the following function:
int32\_t GpioRead\(uint16\_t gpio, uint16\_t \*val\);
**Table 3** Description of GpioRead
<a name="table20347743174816"></a>
<table><tbody><tr id="row17348144394816"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p19348164313481"><a name="p19348164313481"></a><a name="p19348164313481"></a><strong id="b4862227121610"><a name="b4862227121610"></a><a name="b4862227121610"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p134810432488"><a name="p134810432488"></a><a name="p134810432488"></a><strong id="b677332841611"><a name="b677332841611"></a><a name="b677332841611"></a>Description</strong></p>
</td>
</tr>
<tr id="row134874324814"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p183481437485"><a name="p183481437485"></a><a name="p183481437485"></a>gpio</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p43481043194819"><a name="p43481043194819"></a><a name="p43481043194819"></a>GPIO pin number.</p>
</td>
</tr>
<tr id="row20348343144815"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p1534864310480"><a name="p1534864310480"></a><a name="p1534864310480"></a>val</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p13689159154815"><a name="p13689159154815"></a><a name="p13689159154815"></a>Pointer to the level value.</p>
</td>
</tr>
<tr id="row19348043154813"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p1234812431480"><a name="p1234812431480"></a><a name="p1234812431480"></a><strong id="b10599632101619"><a name="b10599632101619"></a><a name="b10599632101619"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p434894334814"><a name="p434894334814"></a><a name="p434894334814"></a><strong id="b236513361617"><a name="b236513361617"></a><a name="b236513361617"></a>Description</strong></p>
</td>
</tr>
<tr id="row3348184311486"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p1934854315487"><a name="p1934854315487"></a><a name="p1934854315487"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p103481943114814"><a name="p103481943114814"></a><a name="p103481943114814"></a>Succeeded in reading the level value.</p>
</td>
</tr>
<tr id="row23485436482"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p1134834310486"><a name="p1134834310486"></a><a name="p1134834310486"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p93491343144815"><a name="p93491343144815"></a><a name="p93491343144815"></a>Failed to read the level value.</p>
</td>
</tr>
</tbody>
</table>
To write the level value for a GPIO pin, call the following function:
int32\_t GpioWrite\(uint16\_t gpio, uint16\_t val\);
**Table 4** Description of GpioWrite
<a name="table1214911207520"></a>
<table><tbody><tr id="row6149720175218"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p18149132005216"><a name="p18149132005216"></a><a name="p18149132005216"></a><strong id="b19864427181615"><a name="b19864427181615"></a><a name="b19864427181615"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p16149220145216"><a name="p16149220145216"></a><a name="p16149220145216"></a><strong id="b4774132861616"><a name="b4774132861616"></a><a name="b4774132861616"></a>Description</strong></p>
</td>
</tr>
<tr id="row16149102014526"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p31495206527"><a name="p31495206527"></a><a name="p31495206527"></a>gpio</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p1014972085212"><a name="p1014972085212"></a><a name="p1014972085212"></a>GPIO pin number.</p>
</td>
</tr>
<tr id="row3149112095214"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p1815072011528"><a name="p1815072011528"></a><a name="p1815072011528"></a>val</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p1931618337524"><a name="p1931618337524"></a><a name="p1931618337524"></a>Level value to write.</p>
</td>
</tr>
<tr id="row1115062015220"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p10150172015218"><a name="p10150172015218"></a><a name="p10150172015218"></a><strong id="b760183221611"><a name="b760183221611"></a><a name="b760183221611"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p1150192015527"><a name="p1150192015527"></a><a name="p1150192015527"></a><strong id="b14366123310160"><a name="b14366123310160"></a><a name="b14366123310160"></a>Description</strong></p>
</td>
</tr>
<tr id="row111503202526"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p171501320205216"><a name="p171501320205216"></a><a name="p171501320205216"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p15150102017522"><a name="p15150102017522"></a><a name="p15150102017522"></a>Succeeded in writing the level value.</p>
</td>
</tr>
<tr id="row1615002018528"><td class="cellrowborder" valign="top" width="48.120000000000005%"><p id="p15150182045212"><a name="p15150182045212"></a><a name="p15150182045212"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%"><p id="p13150320105212"><a name="p13150320105212"></a><a name="p13150320105212"></a>Failed to write the level value.</p>
</td>
</tr>
</tbody>
</table>
Example:
```
int32_t ret;
uint16_t val;
/* Set the output direction for GPIO3. */
ret = GpioSetDir(3, GPIO_DIR_OUT);
if (ret != 0) {
HDF_LOGE("GpioSerDir: failed, ret %d\n", ret);
return;
}
/* Write the low level GPIO_VAL_LOW for GPIO3. */
ret = GpioWrite(3, GPIO_VAL_LOW);
if (ret != 0) {
HDF_LOGE("GpioWrite: failed, ret %d\n", ret);
return;
}
/* Set the input direction for GPIO6. */
ret = GpioSetDir(6, GPIO_DIR_IN);
if (ret != 0) {
HDF_LOGE("GpioSetDir: failed, ret %d\n", ret);
return;
}
/* Read the level value of GPIO6. */
ret = GpioRead(6, &val);
```
- Set the ISR function for a GPIO pin.
To set the ISR function for a GPIO pin, call the following function:
int32\_t GpioSetIrq\(uint16\_t gpio, uint16\_t mode, GpioIrqFunc func, void \*arg\);
**Table 5** Description of GpioSetIrq
<a name="table16804111812466"></a>
<table><tbody><tr id="row880401834615"><td class="cellrowborder" valign="top" width="48.54%"><p id="p380491819469"><a name="p380491819469"></a><a name="p380491819469"></a><strong id="b0865192761614"><a name="b0865192761614"></a><a name="b0865192761614"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p48041318114619"><a name="p48041318114619"></a><a name="p48041318114619"></a><strong id="b1477520282162"><a name="b1477520282162"></a><a name="b1477520282162"></a>Description</strong></p>
</td>
</tr>
<tr id="row19805181812465"><td class="cellrowborder" valign="top" width="48.54%"><p id="p11805101874611"><a name="p11805101874611"></a><a name="p11805101874611"></a>gpio</p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p6805181818461"><a name="p6805181818461"></a><a name="p6805181818461"></a>GPIO pin number.</p>
</td>
</tr>
<tr id="row1080541817469"><td class="cellrowborder" valign="top" width="48.54%"><p id="p580541864611"><a name="p580541864611"></a><a name="p580541864611"></a>mode</p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p380511180463"><a name="p380511180463"></a><a name="p380511180463"></a>Interrupt trigger mode.</p>
</td>
</tr>
<tr id="row83541951134617"><td class="cellrowborder" valign="top" width="48.54%"><p id="p5355351104610"><a name="p5355351104610"></a><a name="p5355351104610"></a>func</p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p11355551174619"><a name="p11355551174619"></a><a name="p11355551174619"></a>ISR function to set.</p>
</td>
</tr>
<tr id="row6593577469"><td class="cellrowborder" valign="top" width="48.54%"><p id="p165985724619"><a name="p165985724619"></a><a name="p165985724619"></a>arg</p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p559185784619"><a name="p559185784619"></a><a name="p559185784619"></a>Pointer to the parameters passed to the ISR function.</p>
</td>
</tr>
<tr id="row16299193210587"><td class="cellrowborder" valign="top" width="48.54%"><p id="p7804101884614"><a name="p7804101884614"></a><a name="p7804101884614"></a><strong id="b126021932131615"><a name="b126021932131615"></a><a name="b126021932131615"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p680441818466"><a name="p680441818466"></a><a name="p680441818466"></a><strong id="b836716339162"><a name="b836716339162"></a><a name="b836716339162"></a>Description</strong></p>
</td>
</tr>
<tr id="row12299632125817"><td class="cellrowborder" valign="top" width="48.54%"><p id="p1180511189465"><a name="p1180511189465"></a><a name="p1180511189465"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p180521812465"><a name="p180521812465"></a><a name="p180521812465"></a>Succeeded in setting the ISR function for a GPIO pin.</p>
</td>
</tr>
<tr id="row029833235815"><td class="cellrowborder" valign="top" width="48.54%"><p id="p1080591814468"><a name="p1080591814468"></a><a name="p1080591814468"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p18805141884611"><a name="p18805141884611"></a><a name="p18805141884611"></a>Failed to set the ISR function for a GPIO pin.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-caution.gif) **CAUTION:**
>Only one ISR function can be set for a GPIO pin at a time. If **GpioSetIrq** is called repeatedly, the previous IRS function will be replaced.
If the ISR function is no longer required, call the following function to cancel the setting:
int32\_t GpioUnSetIrq\(uint16\_t gpio\);
**Table 6** Description of GpioUnSetIrq
<a name="table1157224664316"></a>
<table><tbody><tr id="row175721546174317"><td class="cellrowborder" valign="top" width="48.54%"><p id="p16572144694311"><a name="p16572144694311"></a><a name="p16572144694311"></a><strong id="b16866132761617"><a name="b16866132761617"></a><a name="b16866132761617"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p185721461435"><a name="p185721461435"></a><a name="p185721461435"></a><strong id="b1377613282167"><a name="b1377613282167"></a><a name="b1377613282167"></a>Description</strong></p>
</td>
</tr>
<tr id="row1257284664318"><td class="cellrowborder" valign="top" width="48.54%"><p id="p95721946144317"><a name="p95721946144317"></a><a name="p95721946144317"></a>gpio</p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p1557313464439"><a name="p1557313464439"></a><a name="p1557313464439"></a>GPIO pin number.</p>
</td>
</tr>
<tr id="row1857324618435"><td class="cellrowborder" valign="top" width="48.54%"><p id="p1257344624314"><a name="p1257344624314"></a><a name="p1257344624314"></a><strong id="b1160353241610"><a name="b1160353241610"></a><a name="b1160353241610"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p457384611439"><a name="p457384611439"></a><a name="p457384611439"></a><strong id="b133681833151617"><a name="b133681833151617"></a><a name="b133681833151617"></a>Description</strong></p>
</td>
</tr>
<tr id="row357318466439"><td class="cellrowborder" valign="top" width="48.54%"><p id="p1573164616438"><a name="p1573164616438"></a><a name="p1573164616438"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p857384614319"><a name="p857384614319"></a><a name="p857384614319"></a>Succeeded in canceling the ISR function.</p>
</td>
</tr>
<tr id="row18573124610433"><td class="cellrowborder" valign="top" width="48.54%"><p id="p165731146134311"><a name="p165731146134311"></a><a name="p165731146134311"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="51.459999999999994%"><p id="p6573164613437"><a name="p6573164613437"></a><a name="p6573164613437"></a>Failed to cancel the ISR function.</p>
</td>
</tr>
</tbody>
</table>
After the ISR function is set, call the following function to enable a GPIO interrupt:
int32\_t GpioEnableIrq\(uint16\_t gpio\);
**Table 7** Description of GpioEnableIrq
<a name="table26659291568"></a>
<table><tbody><tr id="row866632919566"><td class="cellrowborder" valign="top" width="50%"><p id="p066642985615"><a name="p066642985615"></a><a name="p066642985615"></a><strong id="b108661927171614"><a name="b108661927171614"></a><a name="b108661927171614"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="p566613293568"><a name="p566613293568"></a><a name="p566613293568"></a><strong id="b10777228121617"><a name="b10777228121617"></a><a name="b10777228121617"></a>Description</strong></p>
</td>
</tr>
<tr id="row19666029165620"><td class="cellrowborder" valign="top" width="50%"><p id="p16660295566"><a name="p16660295566"></a><a name="p16660295566"></a>gpio</p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="p1566632916566"><a name="p1566632916566"></a><a name="p1566632916566"></a>GPIO pin number.</p>
</td>
</tr>
<tr id="row84182176010"><td class="cellrowborder" valign="top" width="50%"><p id="p1566652915566"><a name="p1566652915566"></a><a name="p1566652915566"></a><strong id="b160443201612"><a name="b160443201612"></a><a name="b160443201612"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="p966642917562"><a name="p966642917562"></a><a name="p966642917562"></a><strong id="b12369193319162"><a name="b12369193319162"></a><a name="b12369193319162"></a>Description</strong></p>
</td>
</tr>
<tr id="row154188171403"><td class="cellrowborder" valign="top" width="50%"><p id="p1866610292563"><a name="p1866610292563"></a><a name="p1866610292563"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="p13666182975613"><a name="p13666182975613"></a><a name="p13666182975613"></a>Succeeded in enabling a GPIO interrupt.</p>
</td>
</tr>
<tr id="row1041891720012"><td class="cellrowborder" valign="top" width="50%"><p id="p766642911562"><a name="p766642911562"></a><a name="p766642911562"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="p1566652995613"><a name="p1566652995613"></a><a name="p1566652995613"></a>Failed to enable a GPIO interrupt.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-caution.gif) **CAUTION:**
>The configured ISR function can be responded only after the GPIO interrupt is enabled.
Use the following function to disable the GPIO interrupt:
int32\_t GpioDisableIrq\(uint16\_t gpio\);
**Table 8** Description of GpioDisableIrq
<a name="table186682041918"></a>
<table><tbody><tr id="row186684413116"><td class="cellrowborder" valign="top" width="50%"><p id="p866844916"><a name="p866844916"></a><a name="p866844916"></a><strong id="b88678273169"><a name="b88678273169"></a><a name="b88678273169"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="p46681413119"><a name="p46681413119"></a><a name="p46681413119"></a><strong id="b2077772812169"><a name="b2077772812169"></a><a name="b2077772812169"></a>Description</strong></p>
</td>
</tr>
<tr id="row4668243113"><td class="cellrowborder" valign="top" width="50%"><p id="p46681141919"><a name="p46681141919"></a><a name="p46681141919"></a>gpio</p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="p136681241311"><a name="p136681241311"></a><a name="p136681241311"></a>GPIO pin number.</p>
</td>
</tr>
<tr id="row066884412"><td class="cellrowborder" valign="top" width="50%"><p id="p566824015"><a name="p566824015"></a><a name="p566824015"></a><strong id="b16605123251612"><a name="b16605123251612"></a><a name="b16605123251612"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="p1766974515"><a name="p1766974515"></a><a name="p1766974515"></a><strong id="b1237063341617"><a name="b1237063341617"></a><a name="b1237063341617"></a>Description</strong></p>
</td>
</tr>
<tr id="row156694410112"><td class="cellrowborder" valign="top" width="50%"><p id="p14669141214"><a name="p14669141214"></a><a name="p14669141214"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="p1266934818"><a name="p1266934818"></a><a name="p1266934818"></a>Succeeded in disabling a GPIO interrupt.</p>
</td>
</tr>
<tr id="row176691543117"><td class="cellrowborder" valign="top" width="50%"><p id="p7669941716"><a name="p7669941716"></a><a name="p7669941716"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p id="p4669164219"><a name="p4669164219"></a><a name="p4669164219"></a>Failed to disable a GPIO interrupt.</p>
</td>
</tr>
</tbody>
</table>
Example:
```
/* ISR function */
*/
int32_t MyCallBackFunc(uint16_t gpio, void *data)
{
HDF_LOGI("%s: gpio:%u interrupt service in! data=%p\n", __func__, gpio, data);
return 0;
}
int32_t ret;
/* Set the ISR function to MyCallBackFunc, the parameter to NULL, and the interrupt trigger mode to rising edge. */
ret = GpioSetIrq(3, OSAL_IRQF_TRIGGER_RISING, MyCallBackFunc, NULL);
if (ret != 0) {
HDF_LOGE("GpioSetIrq: failed, ret %d\n", ret);
return;
}
/* Enable an interrupt for GPIO3. */
ret = GpioEnableIrq(3);
if (ret != 0) {
HDF_LOGE("GpioEnableIrq: failed, ret %d\n", ret);
return;
}
/* Disable the interrupt for GPIO3. */
ret = GpioDisableIrq(3);
if (ret != 0) {
HDF_LOGE("GpioDisableIrq: failed, ret %d\n", ret);
return;
}
/* Cancel the ISR function for GPIO3. */
ret = GpioUnSetIrq(3);
if (ret != 0) {
HDF_LOGE("GpioUnSetIrq: failed, ret %d\n", ret);
return;
}
```
### How to Use
## Usage Example<a name="section25941262111"></a> The figure below <xref href="#fig16151101653713" idp:producemode_text="auto" class="- topic/xref " id="xref5621703302"></xref> shows the general GPIO development process. In the APIs, a GPIO pin is specified by the pin number.
In this example, we test the interrupt trigger of a GPIO pin as follows: Set the ISR function for the pin, set the trigger mode to rising edge and failing edge, write high and low levels to the pin alternately to generate level fluctuation, and observe the execution of the ISR function. **Figure 1** GPIO development process
Select an idle GPIO pin. This example uses a Hi3516D V300 development board and GPIO pin GPIO10\_3, which is numbered GPIO83. ![](figures/process-of-using-a-gpio.png "process-of-using-a-gpio")
You can select an idle GPIO pin based on the development board and schematic diagram.
### Determining the GPIO Pin Number
The method for determining the GPIO pin number varies depending on the GPIO controller model, parameters, and controller driver of the system on chip (SoC).
- Hi3516DV300
A controller manages 12 groups of GPIO pins. Each group contains 8 GPIO pins. The group index ranges from 0 to 11.
GPIO pin number = GPIO group index x Number of GPIO pins in each group + Offset in the group
Example: GPIO number of GPIO10_3 = 10 x 8 + 3 = 83
- Hi3518EV300
A controller manages 10 groups of GPIO pins. Each group contains 10 GPIO pins. The group index ranges from 0 to 9.
GPIO pin number = GPIO group index x Number of GPIO pins in each group + Offset in the group
Example: GPIO pin number of GPIO7_3 = 7 x 10 + 3 = 73
### Using APIs to Operate GPIO Pins
- Set the GPIO pin direction.
Before performing read/write operations on a GPIO pin, call **GpioSetDir** to set the pin direction.
int32_t GpioSetDir(uint16_t gpio, uint16_t dir);
**Table 2** Description of GpioSetDir
| **Parameter**| **Description**|
| -------- | -------- |
| gpio | GPIO pin number.|
| dir | Direction to set.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
- Read or write the pin level.
Call **GpioRead** to read the level of a GPIO pin.
int32_t GpioRead(uint16_t gpio, uint16_t \*val);
**Table 3** Description of GpioRead
| **Parameter**| **Description**|
| -------- | -------- |
| gpio | GPIO pin number.|
| val | Pointer to the level value to read.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
Call **GpioWrite** to write the level value for a GPIO pin.
int32_t GpioWrite(uint16_t gpio, uint16_t val);
**Table 4** Description of GpioWrite
| **Parameter**| **Description**|
| -------- | -------- |
| gpio | GPIO pin number.|
| val | Level value to write.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
Sample code:
```
int32_t ret;
uint16_t val;
/* Set the direction of GPIO pin 3 to output. */
ret = GpioSetDir(3, GPIO_DIR_OUT);
if (ret != 0) {
HDF_LOGE("GpioSerDir: failed, ret %d\n", ret);
return;
}
/* Write the low level GPIO_VAL_LOW for GPIO pin 3. */
ret = GpioWrite(3, GPIO_VAL_LOW);
if (ret != 0) {
HDF_LOGE("GpioWrite: failed, ret %d\n", ret);
return;
}
/* Set the direction of GPIO pin 6 to input. */
ret = GpioSetDir(6, GPIO_DIR_IN);
if (ret != 0) {
HDF_LOGE("GpioSetDir: failed, ret %d\n", ret);
return;
}
/* Read the level value of GPIO pin 6. */
ret = GpioRead(6, &val);
```
- Set the ISR function for a GPIO pin.
Call **GpioSetIrq** to set the ISR function for a GPIO pin.
int32_t GpioSetIrq(uint16_t gpio, uint16_t mode, GpioIrqFunc func, void \*arg);
**Table 5** Description of GpioSetIrq
| **Parameter**| **Description**|
| -------- | -------- |
| gpio | GPIO pin number.|
| mode | Interrupt trigger mode.|
| func | ISR function to set.|
| arg | Pointer to the parameters passed to the ISR function.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
> ![icon-caution.gif](../public_sys-resources/icon-caution.gif)**CAUTION**<br/>
> Only one ISR function can be set for a GPIO pin at a time. If **GpioSetIrq** is called repeatedly, the previous IRS function will be replaced.
If the ISR function is no longer required, call **GpioUnsetIrq** to cancel it.
int32_t GpioUnsetIrq(uint16_t gpio, void \*arg);
**Table 6** Description of GpioUnsetIrq
| **Parameter**| **Description**|
| -------- | -------- |
| gpio | GPIO pin number.|
| arg | Pointer to the GPIO interrupt parameters.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
After the ISR function is set, call **GpioEnableIrq** to enable interrupts for the GPIO pin.
int32_t GpioEnableIrq(uint16_t gpio);
**Table 7** Description of GpioEnableIrq
| **Parameter**| **Description**|
| -------- | -------- |
| gpio | GPIO pin number.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
> ![icon-caution.gif](../public_sys-resources/icon-caution.gif)**CAUTION**<br/>
> The configured ISR function can be responded only after interrupts are enabled for the GPIO pin.
You can call **GpioDisableIrq** to disable interrupts for the pin.
int32_t GpioDisableIrq(uint16_t gpio);
**Table 8** Description of GpioDisableIrq
| **Parameter**| **Description**|
| -------- | -------- |
| gpio | GPIO pin number.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
Sample code:
```
/* ISR function */
int32_t MyCallBackFunc(uint16_t gpio, void *data)
{
HDF_LOGI("%s: gpio:%u interrupt service in! data=%p\n", __func__, gpio, data);
return 0;
}
int32_t ret;
/* Set the ISR function to MyCallBackFunc, with input parameter of NULL and the interrupt trigger mode of rising edge. */
ret = GpioSetIrq(3, OSAL_IRQF_TRIGGER_RISING, MyCallBackFunc, NULL);
if (ret != 0) {
HDF_LOGE("GpioSetIrq: failed, ret %d\n", ret);
return;
}
/* Enable interrupts for GPIO pin 3. */
ret = GpioEnableIrq(3);
if (ret != 0) {
HDF_LOGE("GpioEnableIrq: failed, ret %d\n", ret);
return;
}
/* Disable interrupts for GPIO pin 3. */
ret = GpioDisableIrq(3);
if (ret != 0) {
HDF_LOGE("GpioDisableIrq: failed, ret %d\n", ret);
return;
}
/* Cancel the ISR function for GPIO pin 3. */
ret = GpioUnsetIrq(3, NULL);
if (ret != 0) {
HDF_LOGE("GpioUnSetIrq: failed, ret %d\n", ret);
return;
}
```
## Example
The following example shows how to trigger an interrupt for a GPIO pin. The procedure is as follows:
1. Select an idle GPIO pin. This example uses a Hi3516D V300 development board and pin GPIO10_3 as an example. The pin number of GPIO10_3 is 83. You can select an idle GPIO pin as required.
2. Set an ISR function.
3. Set the interrupt trigger mode to edge triggering, and enable high and low levels to be written to the pin alternately to trigger the interrupt.
4. Observe the execution of the ISR function.
The sample code is as follows:
``` ```
#include "gpio_if.h" #include "gpio_if.h"
...@@ -488,7 +266,7 @@ static uint32_t g_irqCnt; ...@@ -488,7 +266,7 @@ static uint32_t g_irqCnt;
static int32_t TestCaseGpioIrqHandler(uint16_t gpio, void *data) static int32_t TestCaseGpioIrqHandler(uint16_t gpio, void *data)
{ {
HDF_LOGE("%s: irq triggered! on gpio:%u, data=%p", __func__, gpio, data); HDF_LOGE("%s: irq triggered! on gpio:%u, data=%p", __func__, gpio, data);
g_irqCnt++; /* If the ISR function is triggered, the number of global interrupts is incremented by 1. */ g_irqCnt++; /* If the IRQ function is triggered, the global interrupt counter is incremented by 1. */
return GpioDisableIrq(gpio); return GpioDisableIrq(gpio);
} }
...@@ -498,24 +276,24 @@ static int32_t TestCaseGpioIrqEdge(void) ...@@ -498,24 +276,24 @@ static int32_t TestCaseGpioIrqEdge(void)
int32_t ret; int32_t ret;
uint16_t valRead; uint16_t valRead;
uint16_t mode; uint16_t mode;
uint16_t gpio = 83; /* Number of the GPIO pin to test */ uint16_t gpio = 83; // Number of the GPIO pin to test
uint32_t timeout; uint32_t timeout;
/* Set the output direction for the pin. */ /* Set the pin direction to output. */
ret = GpioSetDir(gpio, GPIO_DIR_OUT); ret = GpioSetDir(gpio, GPIO_DIR_OUT);
if (ret != HDF_SUCCESS) { if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: set dir fail! ret:%d\n", __func__, ret); HDF_LOGE("%s: set dir fail! ret:%d\n", __func__, ret);
return ret; return ret;
} }
/* Disable the interrupt of the pin. */ /* Disable interrupts of the pin. */
ret = GpioDisableIrq(gpio); ret = GpioDisableIrq(gpio);
if (ret != HDF_SUCCESS) { if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: disable irq fail! ret:%d\n", __func__, ret); HDF_LOGE("%s: disable irq fail! ret:%d\n", __func__, ret);
return ret; return ret;
} }
/* Set the ISR function for the pin. The trigger mode is both rising edge and falling edge. */ /* Set the IRR function for the pin. The trigger mode is both rising edge and falling edge. */
mode = OSAL_IRQF_TRIGGER_RISING | OSAL_IRQF_TRIGGER_FALLING; mode = OSAL_IRQF_TRIGGER_RISING | OSAL_IRQF_TRIGGER_FALLING;
HDF_LOGE("%s: mode:%0x\n", __func__, mode); HDF_LOGE("%s: mode:%0x\n", __func__, mode);
ret = GpioSetIrq(gpio, mode, TestCaseGpioIrqHandler, NULL); ret = GpioSetIrq(gpio, mode, TestCaseGpioIrqHandler, NULL);
...@@ -524,7 +302,7 @@ static int32_t TestCaseGpioIrqEdge(void) ...@@ -524,7 +302,7 @@ static int32_t TestCaseGpioIrqEdge(void)
return ret; return ret;
} }
/* Enable the interrupt for this pin. */ /* Enable interrupts for the pin. */
ret = GpioEnableIrq(gpio); ret = GpioEnableIrq(gpio);
if (ret != HDF_SUCCESS) { if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: enable irq fail! ret:%d\n", __func__, ret); HDF_LOGE("%s: enable irq fail! ret:%d\n", __func__, ret);
...@@ -532,9 +310,9 @@ static int32_t TestCaseGpioIrqEdge(void) ...@@ -532,9 +310,9 @@ static int32_t TestCaseGpioIrqEdge(void)
return ret; return ret;
} }
g_irqCnt = 0; /* Reset the global counter. */ g_irqCnt = 0; /* Reset the global interrupt counter. */
timeout = 0; /* Reset the waiting time. */ timeout = 0; /* Clear the waiting time. */
/* Wait for the ISR function of this pin to trigger. The timeout duration is 1000 ms. */ /* Wait for the IRQ function to trigger for this pin. The timeout duration is 1000 ms. */
while (g_irqCnt <= 0 && timeout < 1000) { while (g_irqCnt <= 0 && timeout < 1000) {
(void)GpioRead(gpio, &valRead); (void)GpioRead(gpio, &valRead);
(void)GpioWrite(gpio, (valRead == GPIO_VAL_LOW) ? GPIO_VAL_HIGH : GPIO_VAL_LOW); (void)GpioWrite(gpio, (valRead == GPIO_VAL_LOW) ? GPIO_VAL_HIGH : GPIO_VAL_LOW);
...@@ -542,8 +320,7 @@ static int32_t TestCaseGpioIrqEdge(void) ...@@ -542,8 +320,7 @@ static int32_t TestCaseGpioIrqEdge(void)
OsalMDelay(200); /* wait for irq trigger */ OsalMDelay(200); /* wait for irq trigger */
timeout += 200; timeout += 200;
} }
(void)GpioUnSetIrq(gpio); (void)GpioUnsetIrq(gpio, NULL);
return (g_irqCnt > 0) ? HDF_SUCCESS : HDF_FAILURE; return (g_irqCnt > 0) ? HDF_SUCCESS : HDF_FAILURE;
} }
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册