You need to sign in or sign up before continuing.
未验证 提交 55e3b7ca 编写于 作者: O openharmony_ci 提交者: Gitee

!4294 #I57OCC完成+修改断链问题

Merge pull request !4294 from Annie_wang/OpenHarmony-3.1-Release
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## When to Use ## When to Use
The distributed data objects allow data across devices to be processed like local variables by shielding complex data interaction between devices. For the devices that form a Super Device, when data in the distributed data object of an application is added, deleted, or modified on a device, the data for the same application is also updated on the other devices. The devices can listen for the data changes and online and offline states of other devices. The distributed data objects support basic data types, such as number, string, and Boolean, as well as complex data types, such as array and nested basic types. The distributed data objects allow data across devices to be processed like local variables by shielding complex data interaction between devices. For the devices that form a Super Device, when data in the distributed data object of an application is added, deleted, or modified on a device, the data for the same application is also updated on the other devices. The devices can listen for the data changes and online and offline status of other devices. The distributed data objects support basic data types, such as number, string, and Boolean, as well as complex data types, such as array and nested basic types.
## Available APIs ## Available APIs
...@@ -15,7 +15,7 @@ Call **createDistributedObject()** to create a distributed data object instance. ...@@ -15,7 +15,7 @@ Call **createDistributedObject()** to create a distributed data object instance.
**Table 1** API for creating a distributed data object instance **Table 1** API for creating a distributed data object instance
| Package| API| Description| | Package| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.<br>- &nbsp;**source**: attributes of the **distributedObject** set.<br>- &nbsp;**DistributedObject**: returns the distributed object created.| | ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.<br>-&nbsp;**source**: attributes of the **distributedObject** set.<br>-&nbsp;**DistributedObject**: returns the distributed object created.|
### Generating a Session ID ### Generating a Session ID
...@@ -28,12 +28,12 @@ Call **genSessionId()** to generate a session ID randomly. The generated session ...@@ -28,12 +28,12 @@ Call **genSessionId()** to generate a session ID randomly. The generated session
### Setting a SessionID for Distributed Data Objects ### Setting a SessionID for Distributed Data Objects
Call setSessionId() to set the session ID for a distributed data object. The session ID is a unique identifier for one collaboration across devices. The distributed data objects to be synchronized must be associated with the same session ID. Call **setSessionId()** to set a session ID for a distributed data object. The session ID is a unique identifier for one collaboration across devices. The distributed data objects to be synchronized must be associated with the same session ID.
**Table 3** API for setting a session ID **Table 3** API for setting a session ID
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| DistributedDataObject | setSessionId(sessionId?: string): boolean | Sets a session ID for distributed data objects.<br>&nbsp;**sessionId**: ID of a distributed object in a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.| | DistributedDataObject | setSessionId(sessionId?: string): boolean | Sets a session ID for distributed data objects.<br>&nbsp;**sessionId**: session ID of a distributed object in a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.|
### Observing Data Changes ### Observing Data Changes
...@@ -43,7 +43,7 @@ Call **on()** to subscribe to data changes of a distributed data object. When th ...@@ -43,7 +43,7 @@ Call **on()** to subscribe to data changes of a distributed data object. When th
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Subscribes to data changes.| | DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Subscribes to data changes.|
| DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Unsubscribes from data changes. Callback used to return changes of the distributed object. If this parameter is not specified, all callbacks related to data changes will be unregistered.| | DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Unsubscribes from data changes. <br>**Callback**: specifies callback used to return changes of the distributed data object. If this parameter is not specified, all callbacks related to data changes will be unregistered.|
### Observing Online or Offline Status ### Observing Online or Offline Status
...@@ -90,10 +90,10 @@ The following example shows how to implement a distributed data object synchroni ...@@ -90,10 +90,10 @@ The following example shows how to implement a distributed data object synchroni
var remote_object = distributedObject.createDistributedObject({name:undefined, age:undefined, isVis:true, var remote_object = distributedObject.createDistributedObject({name:undefined, age:undefined, isVis:true,
parent:undefined, list:undefined}); parent:undefined, list:undefined});
remote_object.setSessionId(sessionId); remote_object.setSessionId(sessionId);
// After obtaining that the device status goes online, the remote object synchronizes data. That is, name changes to jack and age to 18. // After learning that the device goes online, the remote object synchronizes data. That is, name changes to jack and age to 18.
``` ```
4. Observe the data changes of the distributed data object. Subscribe to data changes of the remote end. When the data is the peer end changes, a callback will be called to return the data changes. 4. Observe the data changes of the distributed data object. You can subscribe to data changes of the remote object. When the data in the remote object changes, a callback will be called to return the data changes.
The sample code is as follows: The sample code is as follows:
...@@ -107,9 +107,9 @@ The following example shows how to implement a distributed data object synchroni ...@@ -107,9 +107,9 @@ The following example shows how to implement a distributed data object synchroni
}); });
} }
} }
// To refresh the page in changeCallback, correctly set this.changeCallback.bind(this) in // To refresh the page in changeCallback, correctly bind (this) to the changeCallback.
changeCallback. local_object.on("change", this.changeCallback.bind(this));
``` ```
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).
...@@ -123,7 +123,7 @@ The following example shows how to implement a distributed data object synchroni ...@@ -123,7 +123,7 @@ The following example shows how to implement a distributed data object synchroni
local_object.list = [{mother:"jack mom"}, {father:"jack Dad"}]; local_object.list = [{mother:"jack mom"}, {father:"jack Dad"}];
``` ```
> ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**<br/> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> For the distributed data object of the complex type, only the root attribute can be modified. The subordinate attributes cannot be modified. Example: > For the distributed data object of the complex type, only the root attribute can be modified. The subordinate attributes cannot be modified. Example:
```js ```js
// Supported modification. // Supported modification.
...@@ -142,7 +142,7 @@ The following example shows how to implement a distributed data object synchroni ...@@ -142,7 +142,7 @@ 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 changeCallback. // Unsubscribe from the specified data change callback.
local_object.off("change", changeCallback); local_object.off("change", changeCallback);
// Unsubscribe from all data change callbacks. // Unsubscribe from all data change callbacks.
local_object.off("change"); local_object.off("change");
...@@ -156,27 +156,27 @@ The following example shows how to implement a distributed data object synchroni ...@@ -156,27 +156,27 @@ The following example shows how to implement a distributed data object synchroni
local_object.on("status", this.statusCallback); local_object.on("status", this.statusCallback);
``` ```
9. Unsubscribe from the status changes of the distributed data object. You can specify the callback to unsubscribe from. If you do not specify the callback, all status change callbacks will be unsubscribe from. 9. Unsubscribe from the status changes of the distributed data object. You can specify the callback to unsubscribe from. If you do not specify the callback, this API unsubscribes from all callbacks of this distributed data object.
The sample code is as follows: The sample code is as follows:
```js ```js
// Unsubscribe from the online status change callback. // Unsubscribe from the specified status change callback.
local_object.off("status", statusCallback); local_object.off("status", statusCallback);
// Unsubscribe from all online status change callbacks. // Unsubscribe from all 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. Data changes on the local object will not be synchronized to the removed distributed data object.
The sample code is as follows: The sample code is as follows:
```js ```js
local_object.setSessionId(""); local_object.setSessionId("");
``` ```
## Development Example ## Samples
The following example is provided for you to better understand the development of distributed data object: The following example is provided for you to better understand the development of distributed data objects:
- [Distributed Notepad](https://gitee.com/openharmony/distributeddatamgr_objectstore/tree/master/samples/distributedNotepad) - [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. When an event of the Notepad app occurs on a device, such as 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.
...@@ -2,24 +2,24 @@ ...@@ -2,24 +2,24 @@
## When to Use ## When to Use
The Distributed Data Service (DDS) implements synchronization of application data across user devices. When data is added, deleted, or modified for an application on a device, the same application on another device can obtain the updated data. The DDS applies to the distributed gallery, messages, Contacts, and file manager. The Distributed Data Service (DDS) implements synchronization of application data across user devices. When data is added, deleted, or modified for an application on a device, the same application on another device can obtain the updated data. The DDS applies to the distributed gallery, messages, contacts, and file manager.
## Available APIs ## Available APIs
The table below describes the APIs provided by the OpenHarmony DDS module. The table below describes the APIs provided by the OpenHarmony DDS module.
**Table 1** APIs provided by the DDS **Table 1** APIs provided by the DDS
| Category | API | Description | | Category | API | Description |
| -------------------------- | ------------------------------------------------------------ | ----------------------------------------------- | | -------------------------- | ------------------------------------------------------------ | ----------------------------------------------- |
| Creating a distributed database | createKVManager(config:&nbsp;KVManagerConfig,&nbsp;callback:&nbsp;AsyncCallback&lt;KVManager&gt;):&nbsp;void<br>createKVManager(config:&nbsp;KVManagerConfig):&nbsp;Promise&lt;KVManager> | Creates a **KVManager** object for database management.| | Creating a distributed database | createKVManager(config:&nbsp;KVManagerConfig,&nbsp;callback:&nbsp;AsyncCallback&lt;KVManager&gt;):&nbsp;void<br>createKVManager(config:&nbsp;KVManagerConfig):&nbsp;Promise&lt;KVManager> | Creates a **KVManager** object for database management.|
| Obtaining a distributed KV store | getKVStore&lt;T&nbsp;extends&nbsp;KVStore&gt;(storeId:&nbsp;string,&nbsp;options:&nbsp;Options,&nbsp;callback:&nbsp;AsyncCallback&lt;T&gt;):&nbsp;void<br>getKVStore&lt;T&nbsp;extends&nbsp;KVStore&gt;(storeId:&nbsp;string,&nbsp;options:&nbsp;Options):&nbsp;Promise&lt;T&gt; | Obtains the KV store with the specified **Options** and **storeId**.| | Obtaining a distributed KV store | getKVStore&lt;T&nbsp;extends&nbsp;KVStore&gt;(storeId:&nbsp;string,&nbsp;options:&nbsp;Options,&nbsp;callback:&nbsp;AsyncCallback&lt;T&gt;):&nbsp;void<br>getKVStore&lt;T&nbsp;extends&nbsp;KVStore&gt;(storeId:&nbsp;string,&nbsp;options:&nbsp;Options):&nbsp;Promise&lt;T&gt; | Obtains the KV store with the specified **Options** and **storeId**.|
| Managing data in a distributed KV store| put(key:&nbsp;string,&nbsp;value:&nbsp;Uint8Array&nbsp;\|&nbsp;string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;boolean,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void<br>put(key:&nbsp;string,&nbsp;value:&nbsp;Uint8Array&nbsp;\|&nbsp;string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;boolean):&nbsp;Promise&lt;void> | Inserts or updates data. | | Managing data in a distributed KV store| put(key:&nbsp;string,&nbsp;value:&nbsp;Uint8Array&nbsp;\|&nbsp;string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;boolean,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void<br>put(key:&nbsp;string,&nbsp;value:&nbsp;Uint8Array&nbsp;\|&nbsp;string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;boolean):&nbsp;Promise&lt;void> | Inserts and updates data. |
| Managing data in a distributed KV store| delete(key:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void<br>delete(key:&nbsp;string):&nbsp;Promise&lt;void> | Deletes data. | | Managing data in a distributed KV store| delete(key:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void<br>delete(key:&nbsp;string):&nbsp;Promise&lt;void> | Deletes data. |
| Managing data in a distributed KV store| get(key:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;Uint8Array&nbsp;\|&nbsp;string&nbsp;\|&nbsp;boolean&nbsp;\|&nbsp;number&gt;):&nbsp;void<br>get(key:&nbsp;string):&nbsp;Promise&lt;Uint8Array&nbsp;\|&nbsp;string&nbsp;\|&nbsp;boolean&nbsp;\|&nbsp;number> | Queries data. | | Managing data in a distributed KV store| get(key:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;Uint8Array&nbsp;\|&nbsp;string&nbsp;\|&nbsp;boolean&nbsp;\|&nbsp;number&gt;):&nbsp;void<br>get(key:&nbsp;string):&nbsp;Promise&lt;Uint8Array&nbsp;\|&nbsp;string&nbsp;\|&nbsp;boolean&nbsp;\|&nbsp;number> | Queries data. |
| Subscribing to changes in the distributed data | on(event:&nbsp;'dataChange',&nbsp;type:&nbsp;SubscribeType,&nbsp;observer:&nbsp;Callback&lt;ChangeNotification&gt;):&nbsp;void<br>on(event:&nbsp;'syncComplete',&nbsp;syncCallback:&nbsp;Callback&lt;Array&lt;[string,&nbsp;number]&gt;&gt;):&nbsp;void | Subscribes to data changes in the KV store. | | Subscribing to changes in the distributed data | on(event:&nbsp;'dataChange',&nbsp;type:&nbsp;SubscribeType,&nbsp;observer:&nbsp;Callback&lt;ChangeNotification&gt;):&nbsp;void<br>on(event:&nbsp;'syncComplete',&nbsp;syncCallback:&nbsp;Callback&lt;Array&lt;[string,&nbsp;number]&gt;&gt;):&nbsp;void | Subscribes to data changes in the KV store. |
| Synchronizing data across devices | sync(deviceIdList:&nbsp;string[],&nbsp;mode:&nbsp;SyncMode,&nbsp;allowedDelayMs?:&nbsp;number):&nbsp;void | Triggers database synchronization in manual mode. | | Synchronizing data across devices | sync(deviceIdList:&nbsp;string[],&nbsp;mode:&nbsp;SyncMode,&nbsp;allowedDelayMs?:&nbsp;number):&nbsp;void | Triggers database synchronization in manual mode. |
...@@ -63,7 +63,7 @@ The following uses a single KV store as an example to describe the development p ...@@ -63,7 +63,7 @@ The following uses a single KV store as an example to describe the development p
3. Create and obtain a single KV store. 3. Create and obtain a single KV store.
1. Declare the ID of the single KV store to create. 1. Declare the ID of the single KV store to create.
2. Create a single KV store. You are advised to disable automatic synchronization (**autoSync:false**) and call **sync** if a synchronization is required. 2. Create a single KV store. You are advised to disable automatic synchronization (**autoSync:false**) and call **sync** when a synchronization is required.
The sample code is as follows: The sample code is as follows:
```js ```js
...@@ -159,7 +159,7 @@ The following uses a single KV store as an example to describe the development p ...@@ -159,7 +159,7 @@ The following uses a single KV store as an example to describe the development p
deviceManager.createDeviceManager("bundleName", (err, value) => { deviceManager.createDeviceManager("bundleName", (err, value) => {
if (!err) { if (!err) {
devManager = value; devManager = value;
// get deviceIds // Obtain deviceIds.
let deviceIds = []; let deviceIds = [];
if (devManager != null) { if (devManager != null) {
var devices = devManager.getTrustedDeviceListSync(); var devices = devManager.getTrustedDeviceListSync();
...@@ -177,5 +177,5 @@ The following uses a single KV store as an example to describe the development p ...@@ -177,5 +177,5 @@ The following uses a single KV store as an example to describe the development p
``` ```
## Samples ## Samples
The following samples are provided to help you better understand the distributed data development: The following samples are provided to help you better understand the distributed data development:
- [`KvStore`: distributed database (eTS) (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/Kvstore) - [`KvStore`: Distributed Data Management (eTS) (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/Kvstore)
- [Distributed Database](https://gitee.com/openharmony/codelabs/tree/master/Data/JsDistributedData) - [Distributed Data Service](https://gitee.com/openharmony/codelabs/tree/master/Data/JsDistributedData)
...@@ -116,8 +116,8 @@ The RDB provides **RdbPredicates** for you to set database operation conditions. ...@@ -116,8 +116,8 @@ The RDB provides **RdbPredicates** for you to set database operation conditions.
A result set can be regarded as a row of data in the queried results. It allows you to traverse and access the data you have queried. The following table describes the external APIs of **ResultSet**. A result set can be regarded as a row of data in the queried results. It allows you to traverse and access the data you have queried. The following table describes the external APIs of **ResultSet**.
> ![icon-notice.gif](../public_sys-resources/icon-notice.gif) **NOTICE**<br/> > ![icon-notice.gif](public_sys-resources/icon-notice.gif) **NOTICE**<br>
> After a result set is used, you must call the **close()** method to close it explicitly.** > After a result set is used, you must call the **close()** method to close it explicitly.
**Table 7** APIs for using the result set **Table 7** APIs for using the result set
...@@ -306,3 +306,8 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -306,3 +306,8 @@ You can obtain the distributed table name for a remote device based on the local
let tableName = rdbStore.obtainDistributedTableName(deviceId, "test"); let tableName = rdbStore.obtainDistributedTableName(deviceId, "test");
let resultSet = rdbStore.querySql("SELECT * FROM " + tableName) let resultSet = rdbStore.querySql("SELECT * FROM " + tableName)
``` ```
## Samples
The following samples are provided for you to better understand the RDB development:
- [`Rdb`: eTS RDB (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/Rdb)
- [`DistributedRdb`: eTS Distributed Relational Database (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/DistributedRdb)
- [Relational Database](https://gitee.com/openharmony/codelabs/tree/master/Data/JSRelationshipData)
# DataAbilityPredicates # DataAbilityPredicates
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
> The initial APIs of this module are supported since API version 7. 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 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -22,6 +22,7 @@ Creates an **RdbPredicates** object based on a **DataAabilityPredicates** object ...@@ -22,6 +22,7 @@ Creates an **RdbPredicates** object based on a **DataAabilityPredicates** object
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| name | string | Yes| Table name in the RDB store.| | name | string | Yes| Table name in the RDB store.|
......
# Distributed Data Object # Distributed Data Object
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br> > **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.
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
import distributedObject from '@ohos.data.distributedDataObject'; import distributedObject from '@ohos.data.distributedDataObject';
``` ```
## distributedDataObject.createDistributedObject ## distributedDataObject.createDistributedObject
createDistributedObject(source: object): DistributedObject createDistributedObject(source: object): DistributedObject
......
...@@ -29,11 +29,12 @@ Obtains a relational database (RDB) store. This API uses an asynchronous callbac ...@@ -29,11 +29,12 @@ Obtains a relational database (RDB) store. This API uses an asynchronous callbac
```js ```js
const STORE_CONFIG = { name: "RdbTest.db"} const STORE_CONFIG = { name: "RdbTest.db"}
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) { data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) {
rdbStore.executeSql(SQL_CREATE_TABLE, null, function() { if (err) {
console.info('create table done.') console.info("Failed to get RdbStore, err: " + err)
}) return
}
console.log("Got RdbStore successfully.")
}) })
``` ```
## data_rdb.getRdbStore ## data_rdb.getRdbStore
...@@ -61,17 +62,11 @@ Obtains an RDB store. This API uses a promise to return the result. You can set ...@@ -61,17 +62,11 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
```js ```js
const STORE_CONFIG = { name: "RdbTest.db" } const STORE_CONFIG = { name: "RdbTest.db" }
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" let promise = data_rdb.getRdbStore(STORE_CONFIG, 1);
let promisegetRdb = data_rdb.getRdbStore(STORE_CONFIG, 1); promise.then(async (rdbStore) => {
promisegetRdb.then(async (rdbStore) => { console.log("Got RdbStore successfully.")
let promiseExecSql = rdbStore.executeSql(SQL_CREATE_TABLE, null)
promiseExecSql.then(() => {
console.info('executeSql creat done.')
}).catch((err) => {
console.log("executeSql creat err.")
})
}).catch((err) => { }).catch((err) => {
console.log("getRdbStore err.") console.log("Failed to get RdbStore, err: " + err)
}) })
``` ```
...@@ -97,11 +92,12 @@ Obtains a relational database (RDB) store. This API uses an asynchronous callbac ...@@ -97,11 +92,12 @@ Obtains a relational database (RDB) store. This API uses an asynchronous callbac
```js ```js
const STORE_CONFIG = { name: "RdbTest.db"} const STORE_CONFIG = { name: "RdbTest.db"}
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) { data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) {
rdbStore.executeSql(SQL_CREATE_TABLE, null, function() { if (err) {
console.info('create table done.') console.info("Failed to get RdbStore, err: " + err)
}) return
}
console.log("Got RdbStore successfully.")
}) })
``` ```
...@@ -131,17 +127,11 @@ Obtains an RDB store. This API uses a promise to return the result. You can set ...@@ -131,17 +127,11 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
```js ```js
const STORE_CONFIG = { name: "RdbTest.db" } const STORE_CONFIG = { name: "RdbTest.db" }
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1);
let promisegetRdb = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1); promise.then(async (rdbStore) => {
promisegetRdb.then(async (rdbStore) => { console.log("Got RdbStore successfully.")
let promiseExecSql = rdbStore.executeSql(SQL_CREATE_TABLE, null)
promiseExecSql.then(() => {
console.info('executeSql creat done.')
}).catch((err) => {
console.log("executeSql creat err.")
})
}).catch((err) => { }).catch((err) => {
console.log("getRdbStore err.") console.log("Failed to get RdbStore, err: " + err)
}) })
``` ```
...@@ -160,11 +150,15 @@ Deletes an RDB store. This API uses a callback to return the result. ...@@ -160,11 +150,15 @@ Deletes an RDB store. This API uses a callback to return the result.
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example** **Example**
```js ```js
data_rdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) { data_rdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) {
console.info('delete store done.') if (err) {
}) console.info("Failed to delete RdbStore, err: " + err)
``` return
}
console.log("Deleted RdbStore successfully.")
})
```
## data_rdb.deleteRdbStore ## data_rdb.deleteRdbStore
deleteRdbStore(name: string): Promise&lt;void&gt; deleteRdbStore(name: string): Promise&lt;void&gt;
...@@ -184,14 +178,14 @@ Deletes an RDB store. This API uses a promise to return the result. ...@@ -184,14 +178,14 @@ Deletes an RDB store. This API uses a promise to return the result.
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let promisedeleteRdb = data_rdb.deleteRdbStore("RdbTest.db") let promise = data_rdb.deleteRdbStore("RdbTest.db")
promisedeleteRdb.then(()=>{ promise.then(()=>{
console.info('delete store done.') console.log("Deleted RdbStore successfully.")
}).catch((err) => { }).catch((err) => {
console.log("deleteRdbStore err.") console.info("Failed to delete RdbStore, err: " + err)
}) })
``` ```
## data_rdb.deleteRdbStore<sup>8+</sup> ## data_rdb.deleteRdbStore<sup>8+</sup>
...@@ -209,11 +203,15 @@ Deletes an RDB store. This API uses a callback to return the result. ...@@ -209,11 +203,15 @@ Deletes an RDB store. This API uses a callback to return the result.
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example** **Example**
```js ```js
data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) { data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) {
console.info('delete store done.') if (err) {
}) console.info("Failed to delete RdbStore, err: " + err)
``` return
}
console.log("Deleted RdbStore successfully.")
})
```
## data_rdb.deleteRdbStore<sup>8+</sup> ## data_rdb.deleteRdbStore<sup>8+</sup>
...@@ -235,14 +233,14 @@ Deletes an RDB store. This API uses a promise to return the result. ...@@ -235,14 +233,14 @@ Deletes an RDB store. This API uses a promise to return the result.
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let promisedeleteRdb = data_rdb.deleteRdbStore("RdbTest.db") let promise = data_rdb.deleteRdbStore("RdbTest.db")
promisedeleteRdb.then(()=>{ promise.then(()=>{
console.info('delete store done.') console.log("Deleted RdbStore successfully.")
}).catch((err) => { }).catch((err) => {
console.log("deleteRdbStore err.") console.info("Failed to delete RdbStore, err: " + err)
}) })
``` ```
## RdbPredicates ## RdbPredicates
...@@ -265,9 +263,9 @@ A constructor used to create an **RdbPredicates** object. ...@@ -265,9 +263,9 @@ A constructor used to create an **RdbPredicates** object.
| name | string | Yes| Database table name.| | name | string | Yes| Database table name.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
``` ```
### inDevices<sup>8+</sup> ### inDevices<sup>8+</sup>
...@@ -289,10 +287,10 @@ Specifies a remote device on the network during distributed database synchroniza ...@@ -289,10 +287,10 @@ Specifies a remote device on the network during distributed database synchroniza
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.inDevices(['12345678abcde']) predicates.inDevices(['12345678abcde'])
``` ```
### inAllDevices<sup>8+</sup> ### inAllDevices<sup>8+</sup>
...@@ -309,10 +307,10 @@ Connects to all remote devices on the network during distributed database synchr ...@@ -309,10 +307,10 @@ Connects to all remote devices on the network during distributed database synchr
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.inAllDevices() predicates.inAllDevices()
``` ```
### equalTo ### equalTo
...@@ -335,10 +333,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -335,10 +333,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "lisi") predicates.equalTo("NAME", "lisi")
``` ```
### notEqualTo ### notEqualTo
...@@ -362,10 +360,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -362,10 +360,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notEqualTo("NAME", "lisi") predicates.notEqualTo("NAME", "lisi")
``` ```
### beginWrap ### beginWrap
...@@ -383,15 +381,15 @@ Adds a left parenthesis to the **RdbPredicates**. ...@@ -383,15 +381,15 @@ Adds a left parenthesis to the **RdbPredicates**.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "lisi") predicates.equalTo("NAME", "lisi")
.beginWrap() .beginWrap()
.equalTo("AGE", 18) .equalTo("AGE", 18)
.or() .or()
.equalTo("SALARY", 200.5) .equalTo("SALARY", 200.5)
.endWrap() .endWrap()
``` ```
### endWrap ### endWrap
...@@ -409,15 +407,15 @@ Adds a right parenthesis to the **RdbPredicates**. ...@@ -409,15 +407,15 @@ Adds a right parenthesis to the **RdbPredicates**.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "lisi") predicates.equalTo("NAME", "lisi")
.beginWrap() .beginWrap()
.equalTo("AGE", 18) .equalTo("AGE", 18)
.or() .or()
.equalTo("SALARY", 200.5) .equalTo("SALARY", 200.5)
.endWrap() .endWrap()
``` ```
### or ### or
...@@ -435,12 +433,12 @@ Adds the OR condition to the **RdbPredicates**. ...@@ -435,12 +433,12 @@ Adds the OR condition to the **RdbPredicates**.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
.or() .or()
.equalTo("NAME", "Rose") .equalTo("NAME", "Rose")
``` ```
### and ### and
...@@ -458,12 +456,12 @@ Adds the AND condition to the **RdbPredicates**. ...@@ -458,12 +456,12 @@ Adds the AND condition to the **RdbPredicates**.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
.and() .and()
.equalTo("SALARY", 200.5) .equalTo("SALARY", 200.5)
``` ```
### contains ### contains
...@@ -486,10 +484,10 @@ Sets the **RdbPredicates** to match a string containing the specified value. ...@@ -486,10 +484,10 @@ Sets the **RdbPredicates** to match a string containing the specified value.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.contains("NAME", "os") predicates.contains("NAME", "os")
``` ```
### beginsWith ### beginsWith
...@@ -513,10 +511,10 @@ Sets the **RdbPredicates** to match a string that starts with the specified valu ...@@ -513,10 +511,10 @@ Sets the **RdbPredicates** to match a string that starts with the specified valu
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.beginsWith("NAME", "os") predicates.beginsWith("NAME", "os")
``` ```
### endsWith ### endsWith
...@@ -540,10 +538,10 @@ Sets the **RdbPredicates** to match a string that ends with the specified value. ...@@ -540,10 +538,10 @@ Sets the **RdbPredicates** to match a string that ends with the specified value.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.endsWith("NAME", "se") predicates.endsWith("NAME", "se")
``` ```
### isNull ### isNull
...@@ -566,10 +564,10 @@ Sets the **RdbPredicates** to match the field whose value is null. ...@@ -566,10 +564,10 @@ Sets the **RdbPredicates** to match the field whose value is null.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
- Example - Example
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.isNull("NAME") predicates.isNull("NAME")
``` ```
### isNotNull ### isNotNull
...@@ -592,10 +590,10 @@ Sets the **RdbPredicates** to match the field whose value is not null. ...@@ -592,10 +590,10 @@ Sets the **RdbPredicates** to match the field whose value is not null.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.isNotNull("NAME") predicates.isNotNull("NAME")
``` ```
### like ### like
...@@ -619,10 +617,10 @@ Sets the **RdbPredicates** to match a string that is similar to the specified va ...@@ -619,10 +617,10 @@ Sets the **RdbPredicates** to match a string that is similar to the specified va
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.like("NAME", "%os%") predicates.like("NAME", "%os%")
``` ```
### glob ### glob
...@@ -646,10 +644,10 @@ Sets the **RdbPredicates** to match the specified string. ...@@ -646,10 +644,10 @@ Sets the **RdbPredicates** to match the specified string.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.glob("NAME", "?h*g") predicates.glob("NAME", "?h*g")
``` ```
### between ### between
...@@ -674,10 +672,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -674,10 +672,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.between("AGE", 10, 50) predicates.between("AGE", 10, 50)
``` ```
### notBetween ### notBetween
...@@ -702,10 +700,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -702,10 +700,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notBetween("AGE", 10, 50) predicates.notBetween("AGE", 10, 50)
``` ```
### greaterThan ### greaterThan
...@@ -728,10 +726,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -728,10 +726,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.greaterThan("AGE", 18) predicates.greaterThan("AGE", 18)
``` ```
### lessThan ### lessThan
...@@ -755,10 +753,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -755,10 +753,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.lessThan("AGE", 20) predicates.lessThan("AGE", 20)
``` ```
### greaterThanOrEqualTo ### greaterThanOrEqualTo
...@@ -783,10 +781,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -783,10 +781,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.greaterThanOrEqualTo("AGE", 18) predicates.greaterThanOrEqualTo("AGE", 18)
``` ```
### lessThanOrEqualTo ### lessThanOrEqualTo
...@@ -811,10 +809,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -811,10 +809,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.lessThanOrEqualTo("AGE", 20) predicates.lessThanOrEqualTo("AGE", 20)
``` ```
### orderByAsc ### orderByAsc
...@@ -838,10 +836,10 @@ Sets the **RdbPredicates** to match the column with values sorted in ascending o ...@@ -838,10 +836,10 @@ Sets the **RdbPredicates** to match the column with values sorted in ascending o
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.orderByAsc("NAME") predicates.orderByAsc("NAME")
``` ```
### orderByDesc ### orderByDesc
...@@ -865,10 +863,10 @@ Sets the **RdbPredicates** to match the column with values sorted in descending ...@@ -865,10 +863,10 @@ Sets the **RdbPredicates** to match the column with values sorted in descending
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.orderByDesc("AGE") predicates.orderByDesc("AGE")
``` ```
### distinct ### distinct
...@@ -886,17 +884,17 @@ Sets the **RdbPredicates** to filter out duplicate records. ...@@ -886,17 +884,17 @@ Sets the **RdbPredicates** to filter out duplicate records.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").distinct("NAME") predicates.equalTo("NAME", "Rose").distinct("NAME")
let promisequery = rdbStore.query(predicates, ["NAME"]) let promise = rdbStore.query(predicates, ["NAME"])
promisequery.then((resultSet) => { promise.then((resultSet) => {
console.log("resultSet column names:" + resultSet.columnNames) console.log("resultSet column names:" + resultSet.columnNames)
console.log("resultSet column count:" + resultSet.columnCount) console.log("resultSet column count:" + resultSet.columnCount)
}).catch((err) => { }).catch((err) => {
console.log("query err.") console.log("query err.")
}) })
``` ```
### limitAs ### limitAs
...@@ -919,10 +917,10 @@ Sets the **RdbPredicates** to specify the maximum number of records. ...@@ -919,10 +917,10 @@ Sets the **RdbPredicates** to specify the maximum number of records.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").limitAs(3) predicates.equalTo("NAME", "Rose").limitAs(3)
``` ```
### offsetAs ### offsetAs
...@@ -945,10 +943,10 @@ Sets the **RdbPredicates** to specify the start position of the returned result. ...@@ -945,10 +943,10 @@ Sets the **RdbPredicates** to specify the start position of the returned result.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").offsetAs(3) predicates.equalTo("NAME", "Rose").offsetAs(3)
``` ```
### groupBy ### groupBy
...@@ -971,10 +969,10 @@ Sets the **RdbPredicates** to group rows that have the same value into summary r ...@@ -971,10 +969,10 @@ Sets the **RdbPredicates** to group rows that have the same value into summary r
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.groupBy(["AGE", "NAME"]) predicates.groupBy(["AGE", "NAME"])
``` ```
### indexedBy ### indexedBy
...@@ -997,10 +995,10 @@ Sets the **RdbPredicates** object to specify the index column. ...@@ -997,10 +995,10 @@ Sets the **RdbPredicates** object to specify the index column.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.indexedBy("SALARY_INDEX") predicates.indexedBy("SALARY_INDEX")
``` ```
### in ### in
...@@ -1025,10 +1023,10 @@ Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueTy ...@@ -1025,10 +1023,10 @@ Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueTy
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.in("AGE", [18, 20]) predicates.in("AGE", [18, 20])
``` ```
### notIn ### notIn
...@@ -1053,10 +1051,10 @@ Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueTy ...@@ -1053,10 +1051,10 @@ Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueTy
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notIn("NAME", ["Lisa", "Rose"]) predicates.notIn("NAME", ["Lisa", "Rose"])
``` ```
## RdbStore ## RdbStore
...@@ -1080,17 +1078,21 @@ Inserts a row of data into a table. This API uses a callback to return the resul ...@@ -1080,17 +1078,21 @@ Inserts a row of data into a table. This API uses a callback to return the resul
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
**Example** **Example**
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Lisa", "NAME": "Lisa",
"AGE": 18, "AGE": 18,
"SALARY": 100.5, "SALARY": 100.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} }
rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) { rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) {
console.log("insert first done: " + ret) if (err) {
}) console.info("Failed to insert data, err: " + err)
``` return
}
console.log("Insert first done: " + ret)
})
```
### insert ### insert
...@@ -1113,20 +1115,20 @@ Inserts a row of data into a table. This API uses a promise to return the result ...@@ -1113,20 +1115,20 @@ Inserts a row of data into a table. This API uses a promise to return the result
| Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| | Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
**Example** **Example**
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Lisa", "NAME": "Lisa",
"AGE": 18, "AGE": 18,
"SALARY": 100.5, "SALARY": 100.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} }
let promiseinsert = rdbStore.insert("EMPLOYEE", valueBucket) let promise = rdbStore.insert("EMPLOYEE", valueBucket)
promiseinsert.then(async (ret) => { promise.then(async (ret) => {
console.log("insert first done: " + ret) console.log("Insert first done: " + ret)
}).catch((err) => { }).catch((err) => {
console.log("insert err.") console.log("Failed to insert data, err: " + err)
}) })
``` ```
### update ### update
...@@ -1145,18 +1147,23 @@ Updates data in the database based on the specified RdbPredicates object. This A ...@@ -1145,18 +1147,23 @@ Updates data in the database based on the specified RdbPredicates object. This A
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of rows updated.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of rows updated.|
**Example** **Example**
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Rose", "NAME": "Rose",
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} }
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
rdbStore.update(valueBucket, predicates, function (err, ret) { rdbStore.update(valueBucket, predicates, function (err, ret) {
console.log("updated row count: " + ret)}) if (err) {
``` console.info("Failed to update data, err: " + err)
return
}
console.log("Updated row count: " + ret)
})
```
### update ### update
...@@ -1179,22 +1186,22 @@ Updates data in the database based on the specified RdbPredicates object. This A ...@@ -1179,22 +1186,22 @@ Updates data in the database based on the specified RdbPredicates object. This A
| Promise&lt;number&gt; | Promise used to return the number of rows updated.| | Promise&lt;number&gt; | Promise used to return the number of rows updated.|
**Example** **Example**
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Rose", "NAME": "Rose",
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} }
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
let promiseupdate = rdbStore.update(valueBucket, predicates) let promise = rdbStore.update(valueBucket, predicates)
promiseupdate.then(async (ret) => { promise.then(async (ret) => {
console.log("updated row count: " + ret) console.log("Updated row count: " + ret)
}).catch((err) => { }).catch((err) => {
console.log("update err.") console.info("Failed to update data, err: " + err)
}) })
``` ```
### delete ### delete
...@@ -1213,13 +1220,17 @@ Deletes data from the database based on the specified RdbPredicates object. This ...@@ -1213,13 +1220,17 @@ Deletes data from the database based on the specified RdbPredicates object. This
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
rdbStore.delete(predicates, function (err, rows) { rdbStore.delete(predicates, function (err, rows) {
console.log("delete rows: " + rows) if (err) {
}) console.info("Failed to delete data, err: " + err)
``` return
}
console.log("Delete rows: " + rows)
})
```
### delete ### delete
...@@ -1241,16 +1252,16 @@ Deletes data from the database based on the specified RdbPredicates object. This ...@@ -1241,16 +1252,16 @@ Deletes data from the database based on the specified RdbPredicates object. This
| Promise&lt;number&gt; | Promise used to return the number of rows updated.| | Promise&lt;number&gt; | Promise used to return the number of rows updated.|
**Example** **Example**
```js ```js
let predicatesdelete = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicatesdelete.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
let promisedelete = rdbStore.delete(predicates) let promise = rdbStore.delete(predicates)
promisedelete.then((rows) => { promise.then((rows) => {
console.log("delete rows: " + rows) console.log("Delete rows: " + rows)
}).catch((err) => { }).catch((err) => {
console.log("delete err.") console.info("Failed to delete data, err: " + err)
}) })
``` ```
### query ### query
...@@ -1269,14 +1280,18 @@ Queries data in the database based on specified conditions. This API uses a call ...@@ -1269,14 +1280,18 @@ Queries data in the database based on specified conditions. This API uses a call
| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose")
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
console.log("resultSet column names:" + resultSet.columnNames) if (err) {
console.log("resultSet column count:" + resultSet.columnCount) console.info("Query failed, err: " + err)
}) return
``` }
console.log("resultSet column names:" + resultSet.columnNames)
console.log("resultSet column count:" + resultSet.columnCount)
})
```
### query ### query
...@@ -1302,12 +1317,12 @@ Queries data in the database based on specified conditions. This API uses a prom ...@@ -1302,12 +1317,12 @@ Queries data in the database based on specified conditions. This API uses a prom
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose")
let promisequery = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
promisequery.then((resultSet) => { promise.then((resultSet) => {
console.log("resultSet column names:" + resultSet.columnNames) console.log("resultSet column names:" + resultSet.columnNames)
console.log("resultSet column count:" + resultSet.columnCount) console.log("resultSet column count:" + resultSet.columnCount)
}).catch((err) => { }).catch((err) => {
console.log("query err.") console.info("Query failed, err: " + err)
}) })
``` ```
...@@ -1328,12 +1343,16 @@ Queries data in the RDB store using the specified SQL statement. This API uses a ...@@ -1328,12 +1343,16 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example** **Example**
```js ```js
rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) { rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
console.log("resultSet column names:" + resultSet.columnNames) if (err) {
console.log("resultSet column count:" + resultSet.columnCount) console.info("Query failed, err: " + err)
}) return
``` }
console.log("resultSet column names:" + resultSet.columnNames)
console.log("resultSet column count:" + resultSet.columnCount)
})
```
### querySql<sup>8+</sup> ### querySql<sup>8+</sup>
...@@ -1356,15 +1375,15 @@ Queries data in the RDB store using the specified SQL statement. This API uses a ...@@ -1356,15 +1375,15 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
| Promise&lt;[ResultSet](../apis/js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| | Promise&lt;[ResultSet](../apis/js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example** **Example**
```js ```js
let promisequerySql = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo']) let promise = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'])
promisequerySql.then((resultSet) => { promise.then((resultSet) => {
console.log("resultSet column names:" + resultSet.columnNames) console.log("resultSet column names:" + resultSet.columnNames)
console.log("resultSet column count:" + resultSet.columnCount) console.log("resultSet column count:" + resultSet.columnCount)
}).catch((err) => { }).catch((err) => {
console.log("querySql err.") console.info("Query failed, err: " + err)
}) })
``` ```
### executeSql ### executeSql
...@@ -1383,11 +1402,16 @@ Runs the SQL statement that contains the specified parameters but does not retur ...@@ -1383,11 +1402,16 @@ Runs the SQL statement that contains the specified parameters but does not retur
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example** **Example**
```js ```js
rdbStore.executeSql("DELETE FROM EMPLOYEE", null, function () { const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
console.info('delete done.') rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) {
}) if (err) {
``` console.info("executeSql failed, err: " + err)
return
}
console.info('create table done.')
})
```
### executeSql ### executeSql
...@@ -1410,14 +1434,15 @@ Runs the SQL statement that contains the specified parameters but does not retur ...@@ -1410,14 +1434,15 @@ Runs the SQL statement that contains the specified parameters but does not retur
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let promiseexecuteSql = rdbStore.executeSql("DELETE FROM EMPLOYEE") const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
promiseexecuteSql.then(() => { let promise = rdbStore.executeSql(SQL_CREATE_TABLE)
console.info('delete done.') promise.then(() => {
}).catch((err) => { console.info('create table done.')
console.log("executeSql err.") }).catch((err) => {
}) console.info("ExecuteSql failed, err: " + err)
``` })
```
### beginTransaction<sup>8+</sup> ### beginTransaction<sup>8+</sup>
...@@ -1429,17 +1454,21 @@ Starts the transaction before executing an SQL statement. ...@@ -1429,17 +1454,21 @@ Starts the transaction before executing an SQL statement.
**Example** **Example**
```js ```js
rdbStore.beginTransaction() rdbStore.beginTransaction()
const valueBucket = { const valueBucket = {
"name": "lisi", "name": "lisi",
"age": 18, "age": 18,
"salary": 100.5, "salary": 100.5,
"blobType": new Uint8Array([1, 2, 3]), "blobType": new Uint8Array([1, 2, 3]),
} }
rdbStore.insert("test", valueBucket, function (err, ret) { rdbStore.insert("test", valueBucket, function (err, ret) {
console.log("insert done: " + ret) if (err) {
}) console.info("Failed to insert data, err: " + err)
rdbStore.commit() return
}
console.log("Inserted data successfully: " + ret)
})
rdbStore.commit()
``` ```
...@@ -1453,18 +1482,22 @@ Commits the executed SQL statements. ...@@ -1453,18 +1482,22 @@ Commits the executed SQL statements.
**Example** **Example**
```js ```js
rdbStore.beginTransaction() rdbStore.beginTransaction()
const valueBucket = { const valueBucket = {
"name": "lisi", "name": "lisi",
"age": 18, "age": 18,
"salary": 100.5, "salary": 100.5,
"blobType": new Uint8Array([1, 2, 3]), "blobType": new Uint8Array([1, 2, 3]),
} }
rdbStore.insert("test", valueBucket, function (err, ret) { rdbStore.insert("test", valueBucket, function (err, ret) {
console.log("insert done: " + ret) if (err) {
}) console.info("Failed to insert data, err: " + err)
rdbStore.commit() return
}
console.log("Inserted data successfully: " + ret)
})
rdbStore.commit()
``` ```
...@@ -1478,22 +1511,26 @@ Rolls back the SQL statements that have been executed. ...@@ -1478,22 +1511,26 @@ Rolls back the SQL statements that have been executed.
**Example** **Example**
```js ```js
try { try {
rdbStore.beginTransaction() rdbStore.beginTransaction()
const valueBucket = { const valueBucket = {
"id": 1, "id": 1,
"name": "lisi", "name": "lisi",
"age": 18, "age": 18,
"salary": 100.5, "salary": 100.5,
"blobType": new Uint8Array([1, 2, 3]), "blobType": new Uint8Array([1, 2, 3]),
} }
rdbStore.insert("test", valueBucket, function (err, ret) { rdbStore.insert("test", valueBucket, function (err, ret) {
console.log("insert done: " + ret) if (err) {
}) console.info("Failed to insert data, err: " + err)
rdbStore.commit() return
} catch (e) { }
rdbStore.rollBack() console.log("Inserted data successfully: " + ret)
} })
rdbStore.commit()
} catch (e) {
rdbStore.rollBack()
}
``` ```
...@@ -1512,14 +1549,14 @@ Sets a list of distributed tables. This API uses a callback to return the result ...@@ -1512,14 +1549,14 @@ Sets a list of distributed tables. This API uses a callback to return the result
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example** **Example**
```js ```js
rdbStore.setDistributedTables(["EMPLOYEE"], function (err) { rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
if (err) { if (err) {
console.info('setDistributedTables failed.') console.info('setDistributedTables failed, err: ' + err)
return return
} }
console.info('setDistributedTables success.') console.info('setDistributedTables successful.')
}) })
``` ```
...@@ -1542,14 +1579,14 @@ Sets a list of distributed tables. This API uses a promise to return the result. ...@@ -1542,14 +1579,14 @@ Sets a list of distributed tables. This API uses a promise to return the result.
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let promiseset = rdbStore.setDistributedTables(["EMPLOYEE"]) let promise = rdbStore.setDistributedTables(["EMPLOYEE"])
promiseset.then(() => { promise.then(() => {
console.info("setDistributedTables success.") console.info("setDistributedTables successful.")
}).catch((err) => { }).catch((err) => {
console.info("setDistributedTables failed.") console.info("setDistributedTables failed, err: " + err)
}) })
``` ```
### obtainDistributedTableName<sup>8+</sup> ### obtainDistributedTableName<sup>8+</sup>
...@@ -1567,15 +1604,15 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -1567,15 +1604,15 @@ Obtains the distributed table name for a remote device based on the local table
| callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| | callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the result. If the operation succeeds, the distributed table name of the remote device is returned.|
**Example** **Example**
```js ```js
rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) { rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) {
if (err) { if (err) {
console.info('obtainDistributedTableName failed.') console.info('obtainDistributedTableName failed, err: ' + err)
return return
} }
console.info('obtainDistributedTableName success, tableName=.' + tableName) console.info('obtainDistributedTableName successful, tableName=.' + tableName)
}) })
``` ```
### obtainDistributedTableName<sup>8+</sup> ### obtainDistributedTableName<sup>8+</sup>
...@@ -1598,14 +1635,14 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -1598,14 +1635,14 @@ Obtains the distributed table name for a remote device based on the local table
| Promise&lt;string&gt; | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| | Promise&lt;string&gt; | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.|
**Example** **Example**
```js ```js
let promiseDistr = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE") let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE")
promiseDistr.then((tableName) => { promise.then((tableName) => {
console.info('obtainDistributedTableName success, tableName=' + tableName) console.info('obtainDistributedTableName successful, tableName=' + tableName)
}).catch((err) => { }).catch((err) => {
console.info('obtainDistributedTableName failed.') console.info('obtainDistributedTableName failed, err: ' + err)
}) })
``` ```
### sync<sup>8+</sup> ### sync<sup>8+</sup>
...@@ -1623,20 +1660,20 @@ Synchronizes data between devices. This API uses a callback to return the result ...@@ -1623,20 +1660,20 @@ Synchronizes data between devices. This API uses a callback to return the result
| callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes| Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | | callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes| Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example** **Example**
```js ```js
let predicate = new rdb.RdbPredicates('EMPLOYEE') let predicates = new rdb.RdbPredicates('EMPLOYEE')
predicate.inDevices(['12345678abcde']) predicates.inDevices(['12345678abcde'])
rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate, function (err, result) { rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
if (err) { if (err) {
console.log('sync failed') console.log('sync failed, err: ' + err)
return return
} }
console.log('sync done.') console.log('sync done.')
for (let i = 0; i < result.length; i++) { for (let i = 0; i < result.length; i++) {
console.log('device=' + result[i][0] + ' status=' + result[i][1]) console.log('device=' + result[i][0] + ' status=' + result[i][1])
} }
}) })
``` ```
### sync<sup>8+</sup> ### sync<sup>8+</sup>
...@@ -1660,19 +1697,19 @@ Synchronizes data between devices. This API uses a promise to return the result. ...@@ -1660,19 +1697,19 @@ Synchronizes data between devices. This API uses a promise to return the result.
| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | | Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example** **Example**
```js ```js
let predicatesync = new data_rdb.RdbPredicates('EMPLOYEE') let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
predicatesync.inDevices(['12345678abcde']) predicates.inDevices(['12345678abcde'])
let promisesync = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicatesync) let promise = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates)
promisesync.then((result) =>{ promise.then((result) =>{
console.log('sync done.') console.log('sync done.')
for (let i = 0; i < result.length; i++) { for (let i = 0; i < result.length; i++) {
console.log('device=' + result[i][0] + ' status=' + result[i][1]) console.log('device=' + result[i][0] + ' status=' + result[i][1])
} }
}).catch((err) => { }).catch((err) => {
console.log('sync failed') console.log('sync failed')
}) })
``` ```
### on('dataChange')<sup>8+</sup> ### on('dataChange')<sup>8+</sup>
...@@ -1691,18 +1728,18 @@ Registers an observer for this RDB store. When the data in the RDB store changes ...@@ -1691,18 +1728,18 @@ Registers an observer for this RDB store. When the data in the RDB store changes
| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Observer that listens for the data changes in the RDB store.| | observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Observer that listens for the data changes in the RDB store.|
**Example** **Example**
```js ```js
function storeObserver(devices) { function storeObserver(devices) {
for (let i = 0; i < devices.length; i++) { for (let i = 0; i < devices.length; i++) {
console.log('device=' + devices[i] + ' data changed') console.log('device=' + devices[i] + ' data changed')
} }
} }
try { try {
rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
} catch (err) { } catch (err) {
console.log('register observer failed') console.log('Failed to register observer')
} }
``` ```
### off('dataChange')<sup>8+</sup> ### off('dataChange')<sup>8+</sup>
...@@ -1721,19 +1758,18 @@ Deletes the specified observer of the RDB store. This API uses a callback to ret ...@@ -1721,19 +1758,18 @@ Deletes the specified observer of the RDB store. This API uses a callback to ret
| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Data change observer registered.| | observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Data change observer registered.|
**Example** **Example**
```js
```js function storeObserver(devices) {
function storeObserver(devices) { for (let i = 0; i < devices.length; i++) {
for (let i = 0; i < devices.length; i++) { console.log('device=' + devices[i] + ' data changed')
console.log('device=' + devices[i] + ' data changed') }
} }
} try {
try { rdbStore.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
rdbStore.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) } catch (err) {
} catch (err) { console.log('Failed to unregister observer')
console.log('unregister observer failed') }
} ```
```
## StoreConfig ## StoreConfig
......
# Result Set # Result Set
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
> The initial APIs of this module are supported since API version 7. 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 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
Lightweight storage provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value (KV) pairs. Keys are of the string type, and values can be of the number, string, or Boolean type. Lightweight storage provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value (KV) pairs. Keys are of the string type, and values can be of the number, string, or Boolean type.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
> >
> - The initial APIs of this module are supported since API version 6. 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 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> >
> - The APIs of this module are no longer maintained since API Version 9. You are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md). >
## Modules to Import ## Modules to Import
...@@ -30,7 +30,7 @@ import dataStorage from '@ohos.data.storage'; ...@@ -30,7 +30,7 @@ import dataStorage from '@ohos.data.storage';
getStorageSync(path: string): Storage getStorageSync(path: string): Storage
Reads a file and loads the data to the **Storage** instance in synchronous mode. Reads the specified file and load its data to the **Storage** instance for data operations.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -67,7 +67,7 @@ Reads a file and loads the data to the **Storage** instance in synchronous mode. ...@@ -67,7 +67,7 @@ Reads a file and loads the data to the **Storage** instance in synchronous mode.
getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void
Reads a file and loads the data to the **Storage** instance. This API uses an asynchronous callback to return the execution result. Reads the specified file and loads its data to the **Storage** instance for data operations. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -105,7 +105,7 @@ Reads a file and loads the data to the **Storage** instance. This API uses an as ...@@ -105,7 +105,7 @@ Reads a file and loads the data to the **Storage** instance. This API uses an as
getStorage(path: string): Promise&lt;Storage&gt; getStorage(path: string): Promise&lt;Storage&gt;
Reads a file and loads the data to the **Storage** instance. This API uses a promise to return the execution result. Reads the specified file and loads its data to the **Storage** instance for data operations. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -146,7 +146,7 @@ Reads a file and loads the data to the **Storage** instance. This API uses a pro ...@@ -146,7 +146,7 @@ Reads a file and loads the data to the **Storage** instance. This API uses a pro
deleteStorageSync(path: string): void deleteStorageSync(path: string): void
Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a synchronous mode. Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -165,7 +165,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -165,7 +165,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void
Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses an asynchronous callback to return the execution result. Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -191,7 +191,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -191,7 +191,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
deleteStorage(path: string): Promise&lt;void&gt; deleteStorage(path: string): Promise&lt;void&gt;
Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a promise to return the execution result. Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -222,8 +222,6 @@ removeStorageFromCacheSync(path: string): void ...@@ -222,8 +222,6 @@ removeStorageFromCacheSync(path: string): void
Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
...@@ -241,9 +239,7 @@ This API uses a synchronous mode. ...@@ -241,9 +239,7 @@ This API uses a synchronous mode.
removeStorageFromCache(path: string, callback: AsyncCallback&lt;void&gt;): void removeStorageFromCache(path: string, callback: AsyncCallback&lt;void&gt;): void
Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -269,9 +265,7 @@ This API uses an asynchronous callback to return the result. ...@@ -269,9 +265,7 @@ This API uses an asynchronous callback to return the result.
removeStorageFromCache(path: string): Promise&lt;void&gt; removeStorageFromCache(path: string): Promise&lt;void&gt;
Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -307,8 +301,6 @@ getSync(key: string, defValue: ValueType): ValueType ...@@ -307,8 +301,6 @@ getSync(key: string, defValue: ValueType): ValueType
Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
...@@ -333,9 +325,7 @@ This API uses a synchronous mode. ...@@ -333,9 +325,7 @@ This API uses a synchronous mode.
get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void
Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -362,9 +352,7 @@ This API uses an asynchronous callback to return the result. ...@@ -362,9 +352,7 @@ This API uses an asynchronous callback to return the result.
get(key: string, defValue: ValueType): Promise&lt;ValueType&gt; get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -397,8 +385,6 @@ putSync(key: string, value: ValueType): void ...@@ -397,8 +385,6 @@ putSync(key: string, value: ValueType): void
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
...@@ -417,9 +403,7 @@ This API uses a synchronous mode. ...@@ -417,9 +403,7 @@ This API uses a synchronous mode.
put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -446,9 +430,7 @@ This API uses an asynchronous callback to return the result. ...@@ -446,9 +430,7 @@ This API uses an asynchronous callback to return the result.
put(key: string, value: ValueType): Promise&lt;void&gt; put(key: string, value: ValueType): Promise&lt;void&gt;
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -480,8 +462,6 @@ hasSync(key: string): boolean ...@@ -480,8 +462,6 @@ hasSync(key: string): boolean
Checks whether the storage object contains data with a given key. Checks whether the storage object contains data with a given key.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
...@@ -507,9 +487,7 @@ This API uses a synchronous mode. ...@@ -507,9 +487,7 @@ This API uses a synchronous mode.
has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean
Checks whether the storage object contains data with a given key. Checks whether the storage object contains data with a given key. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -542,9 +520,7 @@ This API uses an asynchronous callback to return the result. ...@@ -542,9 +520,7 @@ This API uses an asynchronous callback to return the result.
has(key: string): Promise&lt;boolean&gt; has(key: string): Promise&lt;boolean&gt;
Checks whether the storage object contains data with a given key. Checks whether the storage object contains data with a given key. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -577,8 +553,6 @@ deleteSync(key: string): void ...@@ -577,8 +553,6 @@ deleteSync(key: string): void
Deletes data with the specified key from this storage object. Deletes data with the specified key from this storage object.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
...@@ -592,13 +566,11 @@ This API uses a synchronous mode. ...@@ -592,13 +566,11 @@ This API uses a synchronous mode.
``` ```
### deletej ### delete
delete(key: string, callback: AsyncCallback&lt;void&gt;): void delete(key: string, callback: AsyncCallback&lt;void&gt;): void
Deletes data with the specified key from this storage object. Deletes data with the specified key from this storage object. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -624,9 +596,7 @@ This API uses an asynchronous callback to return the result. ...@@ -624,9 +596,7 @@ This API uses an asynchronous callback to return the result.
delete(key: string): Promise&lt;void&gt; delete(key: string): Promise&lt;void&gt;
Deletes data with the specified key from this storage object. Deletes data with the specified key from this storage object. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -657,8 +627,6 @@ flushSync(): void ...@@ -657,8 +627,6 @@ flushSync(): void
Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Example** **Example**
...@@ -671,9 +639,7 @@ This API uses a synchronous mode. ...@@ -671,9 +639,7 @@ This API uses a synchronous mode.
flush(callback: AsyncCallback&lt;void&gt;): void flush(callback: AsyncCallback&lt;void&gt;): void
Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -698,9 +664,7 @@ This API uses an asynchronous callback to return the result. ...@@ -698,9 +664,7 @@ This API uses an asynchronous callback to return the result.
flush(): Promise&lt;void&gt; flush(): Promise&lt;void&gt;
Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -726,8 +690,6 @@ clearSync(): void ...@@ -726,8 +690,6 @@ clearSync(): void
Clears this **Storage** object. Clears this **Storage** object.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Example** **Example**
...@@ -740,9 +702,7 @@ This API uses a synchronous mode. ...@@ -740,9 +702,7 @@ This API uses a synchronous mode.
clear(callback: AsyncCallback&lt;void&gt;): void clear(callback: AsyncCallback&lt;void&gt;): void
Clears this **Storage** object. Clears this **Storage** object. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -767,9 +727,7 @@ This API uses an asynchronous callback to return the result. ...@@ -767,9 +727,7 @@ This API uses an asynchronous callback to return the result.
clear(): Promise&lt;void&gt; clear(): Promise&lt;void&gt;
Clears this **Storage** object. Clears this **Storage** object. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Distributed data management provides collaboration between databases of different devices for applications. The APIs provided by distributed data management can be used to save data to the distributed database and perform operations such as adding, deleting, modifying, and querying data in the distributed database. Distributed data management provides collaboration between databases of different devices for applications. The APIs provided by distributed data management can be used to save data to the distributed database and perform operations such as adding, deleting, modifying, and querying data in the distributed database.
>![](../../public_sys-resources/icon-note.gif) **NOTE**<br/> >**NOTE**<br/>
>The initial APIs of this module are supported since API version 7. 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 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -2922,6 +2922,7 @@ These value types can be used only by internal applications. ...@@ -2922,6 +2922,7 @@ These value types can be used only by internal applications.
| BOOLEAN |4 |Boolean. | | BOOLEAN |4 |Boolean. |
| DOUBLE |5 |Double (double-precision floating point). | | DOUBLE |5 |Double (double-precision floating point). |
## SingleKVStore ## SingleKVStore
Provides methods to query and synchronize data in a single KV store. This class inherits from **KVStore**. Before calling any method in **SingleKVStore**, you must use [getKVStore](#getkvstore) to obtain a **SingleKVStore** object. Provides methods to query and synchronize data in a single KV store. This class inherits from **KVStore**. Before calling any method in **SingleKVStore**, you must use [getKVStore](#getkvstore) to obtain a **SingleKVStore** object.
...@@ -3447,7 +3448,7 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API us ...@@ -3447,7 +3448,7 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API us
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| resultSet |[KvStoreResultSet](#kvstoreresultset8) | Yes |**KvStoreResultSet** object to close. | | resultSet |[KvStoreResultSet](#kvstoreresultset8) | Yes |**KvStoreResultSet** object to close. |
| callback |AsyncCallback&lt;void&gt; | Yes |Callback used to return the execution result. | | callback |AsyncCallback&lt;void&gt; | Yes |Callback used to return the result. |
**Example** **Example**
......
# Data Storage # Data Storage
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
> >
> - The APIs of this module are no longer maintained since API Version 6, and you are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API Version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md). > - The APIs of this module are no longer maintained since API Version 6, and you are advised to use [`@ohos.data.storage`](js-apis-data-storage.md).
> >
> - The initial APIs of this module are supported since API version 3. 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 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -67,7 +67,7 @@ Sets the value in the cache based on the specified key. ...@@ -67,7 +67,7 @@ Sets the value in the cache based on the specified key.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the value to set.| | key | string | Yes| Key of the data to set.|
| value | string | Yes| New value to set. The maximum length is 128 bytes.| | value | string | Yes| New value to set. The maximum length is 128 bytes.|
| success | Function | No| Called when **storage.set()** is successful.| | success | Function | No| Called when **storage.set()** is successful.|
| fail | Function | No| Called when **storage.set()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.| | fail | Function | No| Called when **storage.set()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
......
...@@ -157,7 +157,7 @@ The following two comment formats are supported: ...@@ -157,7 +157,7 @@ The following two comment formats are supported:
*/ */
``` ```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**<br/>
> Multi-line comments cannot be nested. > Multi-line comments cannot be nested.
...@@ -301,7 +301,7 @@ root { ...@@ -301,7 +301,7 @@ root {
} }
``` ```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**<br/>
> The keyword **delete** cannot be used to delete nodes or attributes in the same HCS file. In an HCS file, you can directly delete unnecessary attributes. > The keyword **delete** cannot be used to delete nodes or attributes in the same HCS file. In an HCS file, you can directly delete unnecessary attributes.
......
...@@ -50,17 +50,17 @@ Based on the attributes of the pins, interfaces on the touchscreens can be class ...@@ -50,17 +50,17 @@ Based on the attributes of the pins, interfaces on the touchscreens can be class
The interfaces shown in the figure are described as follows: The interfaces shown in the figure are described as follows:
1. **Power interfaces** - **Power interfaces**
- LDO\_1P8: 1.8 V digital circuits - LDO\_1P8: 1.8 V digital circuits
- LDO\_3P3: 3.3 V analog circuits - LDO\_3P3: 3.3 V analog circuits
Generally, the touchscreen driver IC is separated from the LCD driver IC. In this case, the touchscreen driver IC requires both 1.8 V and 3.3 V power supplies. Nowadays, the touchscreen driver IC and LCD driver IC can be integrated. Therefore, the touchscreen, requires only the 1.8 V power supply, and the 3.3 V power required internally is supplied by the LCD VSP power \(typical value: 5.5 V\) in the driver IC. Generally, the touchscreen driver IC is separated from the LCD driver IC. In this case, the touchscreen driver IC requires both 1.8 V and 3.3 V power supplies. Nowadays, the touchscreen driver IC and LCD driver IC can be integrated. Therefore, the touchscreen, requires only the 1.8 V power supply, and the 3.3 V power required internally is supplied by the LCD VSP power \(typical value: 5.5 V\) in the driver IC.
2. **I/O control interfaces** - **I/O control interfaces**
- RESET: reset pin, which is used to reset the driver IC on the host when suspending or resuming the system. - RESET: reset pin, which is used to reset the driver IC on the host when suspending or resuming the system.
- INT: interrupt pin, which needs to be set to the input direction and pull-up status during driver initialization. After detecting an external touch signal, the driver triggers the interrupt by operating the interrupt pin. The driver reads the touch reporting data in the ISR function. - INT: interrupt pin, which needs to be set to the input direction and pull-up status during driver initialization. After detecting an external touch signal, the driver triggers the interrupt by operating the interrupt pin. The driver reads the touch reporting data in the ISR function.
3. **Communications interfaces** - **Communications interfaces**
- I2C: Since only a small amount of touch data is reported by the touchscreen, I2C is used to transmit the reported data. For details about the I2C protocol and interfaces, see [I2C](driver-platform-i2c-des.md#section5361140416). - I2C: Since only a small amount of touch data is reported by the touchscreen, I2C is used to transmit the reported data. For details about the I2C protocol and interfaces, see [I2C](driver-platform-i2c-des.md#section5361140416).
- SPI: In addition to touch reporting data coordinates, some vendors need to obtain basic capacitance data. Therefore, Serial Peripheral Interface \(SPI\) is used to transmit such huge amount of data. For details about the SPI protocol and interfaces, see [SPI](driver-platform-spi-des.md#section193356154511). - SPI: In addition to touch reporting data coordinates, some vendors need to obtain basic capacitance data. Therefore, Serial Peripheral Interface \(SPI\) is used to transmit such huge amount of data. For details about the SPI protocol and interfaces, see [SPI](driver-platform-spi-des.md#section193356154511).
...@@ -88,7 +88,7 @@ Perform the following steps: ...@@ -88,7 +88,7 @@ Perform the following steps:
1. Add the touchscreen driver-related descriptions. 1. Add the touchscreen driver-related descriptions.
Currently, the input driver is developed based on the HDF and is loaded and started by the HDF. Register the driver information, such as whether to load the driver and the loading priority in the configuration file. Then, the HDF starts the registered driver modules one by one. For details about the driver configuration, see [Driver Development](driver-hdf-development.md#how-to-develop). Currently, the input driver is developed based on the HDF and is loaded and started by the HDF. Register the driver information, such as whether to load the driver and the loading priority in the configuration file. Then, the HDF starts the registered driver modules one by one. For details about the driver configuration, see [How to Develop](../driver/driver-hdf-development.md#how-to-develop).
2. Complete the board-level configuration and private data configuration of the touchscreen. 2. Complete the board-level configuration and private data configuration of the touchscreen.
......
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
## Overview<a name="section1"></a> ## Overview<a name="section1"></a>
- An analog-to-digital converter (ADC) is a device that converts analog signals into digital signals. An analog-to-digital converter (ADC) is a device that converts analog signals into digital signals.
- The ADC APIs provide a set of common functions for ADC data transfer, including: The ADC APIs provide a set of common functions for ADC data transfer, including:
- Opening or closing an ADC device - Opening or closing an ADC device
- Obtaining the analog-to-digital (AD) conversion result
**Figure 1** ADC physical connection<a name="fig1"></a> - Obtaining the analog-to-digital (AD) conversion result
**Figure 1** ADC physical connection<br/>
![](figures/ADC_physical_connection.png "ADC_physical_connection") ![](figures/ADC_physical_connection.png "ADC_physical_connection")
...@@ -51,11 +52,11 @@ ...@@ -51,11 +52,11 @@
### How to Use<a name="section4"></a> ### How to Use<a name="section4"></a>
[Figure 2](#fig2) shows how an ADC device works. The figure below illustrates how to use the APIs.
**Figure 2** Using ADC driver APIs<br/>
**Figure 2** How ADC works<a name="fig2"></a> ![](figures/using-ADC-process.png "using-ADC-process.png")
![](figures/ADC_flowchart.png "ADC_flowchart")
### Opening an ADC Device<a name="section5"></a> ### Opening an ADC Device<a name="section5"></a>
......
...@@ -42,7 +42,8 @@ The DAC module is divided into the following layers: ...@@ -42,7 +42,8 @@ The DAC module is divided into the following layers:
- The core layer provides the capabilities of binding, initializing, and releasing devices. - The core layer provides the capabilities of binding, initializing, and releasing devices.
- The adaptation layer implements other functions. - The adaptation layer implements other functions.
![](../public_sys-resources/icon-note.gif)NOTE<br/>The core layer can call the functions of the interface layer and uses the hook to call functions of the adaptation layer. In this way, the adaptation layer can indirectly call the functions of the interface layer, but the interface layer cannot call the functions of the adaptation layer. >![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>The core layer can call the functions of the interface layer and uses the hook to call functions of the adaptation layer. In this way, the adaptation layer can indirectly call the functions of the interface layer, but the interface layer cannot call the functions of the adaptation layer.
**Figure 1** Unified service mode **Figure 1** Unified service mode
...@@ -68,15 +69,15 @@ The table below describes the APIs of the DAC module. For more details, see API ...@@ -68,15 +69,15 @@ The table below describes the APIs of the DAC module. For more details, see API
| :------------------------------------------------------------| :------------ | | :------------------------------------------------------------| :------------ |
| DevHandle DacOpen(uint32_t number) | Opens a DAC device. | | DevHandle DacOpen(uint32_t number) | Opens a DAC device. |
| void DacClose(DevHandle handle) | Closes a DAC device. | | void DacClose(DevHandle handle) | Closes a DAC device. |
| int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val) | Sets the target DA value. | | int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val) | Sets a target DA value. |
### How to Develop ### How to Develop
The figure below illustrates the process of using a DAC device. The figure below illustrates how to use the APIs.
**Figure 2** Process of using a DAC device **Figure 2** Using DAC driver APIs<br/>
![](figures/process-of-using-DAC.png "Process of using a DAC") ![](figures/using-DAC-process.png "using-DAC-process.png")
#### Opening a DAC Device #### Opening a DAC Device
...@@ -88,10 +89,10 @@ DevHandle DacOpen(uint32_t number); ...@@ -88,10 +89,10 @@ DevHandle DacOpen(uint32_t number);
**Table 2** Description of DacOpen **Table 2** Description of DacOpen
| **Parameter** | Description | | **Parameter** | Description |
| ---------- | ----------------- | | ---------- | ----------------- |
| number | DAC device number. | | number | DAC device number. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| NULL | Failed to open the DAC device. | | NULL | Failed to open the DAC device. |
| Device handle | Handle of the DAC device opened.| | Device handle | Handle of the DAC device opened.|
...@@ -110,7 +111,7 @@ if (dacHandle == NULL) { ...@@ -110,7 +111,7 @@ if (dacHandle == NULL) {
} }
``` ```
#### Setting the Target DA Value #### Setting a Target DA Value
``` ```
int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val); int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val);
...@@ -119,7 +120,7 @@ int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val); ...@@ -119,7 +120,7 @@ int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val);
**Table 3** Description of DacWrite **Table 3** Description of DacWrite
| **Parameter** | Description | | **Parameter** | Description |
| ---------- | -------------- | | ---------- | -------------- |
| handle | DAC device handle. | | handle | DAC device handle. |
| channel | DAC channel number. | | channel | DAC channel number. |
...@@ -148,7 +149,7 @@ void DacClose(DevHandle handle); ...@@ -148,7 +149,7 @@ void DacClose(DevHandle handle);
**Table 4** Description of DacClose **Table 4** Description of DacClose
| **Parameter** | Description | | **Parameter** | Description |
| ---------- | -------------- | | ---------- | -------------- |
| handle | DAC device handle. | | handle | DAC device handle. |
| **Return Value**| **Description**| | **Return Value**| **Description**|
...@@ -208,4 +209,4 @@ static int32_t TestCaseDac(void) ...@@ -208,4 +209,4 @@ static int32_t TestCaseDac(void)
return 0; return 0;
} }
``` ```
\ No newline at end of file
# GPIO # GPIO<a name="EN-US_TOPIC_0000001206171135"></a>
## Overview ## Overview<a name="section1635911016188"></a>
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. 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.
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
- Setting an interrupt service routine \(ISR\) function and interrupt trigger mode for a pin
- Enabling or disabling interrupts for a pin
## Available APIs<a name="section589913442203"></a>
**Table 1** APIs available for the GPIO driver
<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>
</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>
</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>
</th>
</tr>
</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>
</td>
<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>
</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 GPIO interrupts for a pin.</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 GPIO interrupts for a pin.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>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. The figure below illustrates how to use the APIs.
**Figure 1** Using GPIO driver APIs
![](figures/using-gpio-process.png "using-gpio-process.png")
### Determining the GPIO Pin Number<a name="section370083272117"></a>
The method for converting GPIO pin numbers varies depending on the GPIO controller model, parameters, and controller driver of different system on chips \(SoCs\).
- Reading and writing level values, which can be low or high - Hi3516DV300
- Setting an interrupt service routine (ISR) function and interrupt trigger mode for a pin
- Enabling or disabling pin interrupts
## Available APIs
**Table 1** GPIO driver APIs
| Category| Description|
| -------- | -------- |
| GPIO read/write| -&nbsp;**GpioRead**: reads the pin level.<br>-&nbsp;**GpioWrite**: writes the pin level.|
| GPIO settings| -&nbsp;**GpioSetDir**: sets the pin direction.<br>-&nbsp;**GpioGetDir**: obtains the pin direction.|
| 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.|
> ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**<br/>
> All APIs described in this document can be called only in the kernel space.
## Usage Guidelines
### How to Use
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.
**Figure 1** GPIO development process
![](figures/process-of-using-a-gpio.png "process-of-using-a-gpio") A controller manages 12 groups of GPIO pins. Each group contains 8 GPIO pins.
GPIO pin number = GPIO group index x Number of GPIO pins in each group + Offset in the group
### Determining the GPIO Pin Number The group index ranges from 0 to 11.
Example:
GPIO pin 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
The group index ranges from 0 to 9.
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 **GpioSetDir**() 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>The operation is successful.</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>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
- Read or write the level value for a GPIO pin.
Call **GpioRead**() to read the level value of a GPIO pin.
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>The operation is successful.</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>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
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
<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>The operation is successful.</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>The operation failed.</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.
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
<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>The operation is successful.</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>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
>![](../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 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>The operation is successful.</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>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
After the ISR function is set, call **GpioEnableIrq()** to enable interrupts.
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>The operation is successful.</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>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-caution.gif) **CAUTION**<br/>
>The configured ISR function can be responded only after the GPIO interrupt is enabled.
Call **GpioDisableIrq()** to disable interrupts.
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>The operation is successful.</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>The operation failed.</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;
}
```
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 ## Usage Example<a name="section25941262111"></a>
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 The procedure is as follows:
Example: GPIO number of GPIO10_3 = 10 x 8 + 3 = 83 1. Select an idle GPIO pin.
- Hi3518EV300 This example uses pin GPIO10\_3 on a Hi3516D V300 development board as an example. The pin number is 83. You can select an idle GPIO pin as required.
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 2. Set the ISR function for the pin, with the trigger mode of rising edge and failing edge.
Example: GPIO pin number of GPIO7_3 = 7 x 10 + 3 = 73 3. Write high and low levels to the pin alternately, and observe the execution of the ISR function.
### 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"
...@@ -266,7 +503,7 @@ static uint32_t g_irqCnt; ...@@ -266,7 +503,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 IRQ function is triggered, the global interrupt counter is incremented by 1. */ g_irqCnt++; /* If the ISR function is triggered, the number of global interrupts is incremented by 1. */
return GpioDisableIrq(gpio); return GpioDisableIrq(gpio);
} }
...@@ -276,24 +513,24 @@ static int32_t TestCaseGpioIrqEdge(void) ...@@ -276,24 +513,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 pin direction to output. */ /* Set the output direction for the pin. */
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 interrupts of the pin. */ /* Disable the interrupt 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 IRR function for the pin. The trigger mode is both rising edge and falling edge. */ /* Set the ISR 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);
...@@ -302,7 +539,7 @@ static int32_t TestCaseGpioIrqEdge(void) ...@@ -302,7 +539,7 @@ static int32_t TestCaseGpioIrqEdge(void)
return ret; return ret;
} }
/* Enable interrupts for the pin. */ /* Enable the interrupt for this 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);
...@@ -310,9 +547,9 @@ static int32_t TestCaseGpioIrqEdge(void) ...@@ -310,9 +547,9 @@ static int32_t TestCaseGpioIrqEdge(void)
return ret; return ret;
} }
g_irqCnt = 0; /* Reset the global interrupt counter. */ g_irqCnt = 0; /* Reset the global counter. */
timeout = 0; /* Clear the waiting time. */ timeout = 0; /* Reset the waiting time. */
/* Wait for the IRQ function to trigger for this pin. The timeout duration is 1000 ms. */ /* Wait for the ISR function of this pin to trigger. 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);
...@@ -320,7 +557,7 @@ static int32_t TestCaseGpioIrqEdge(void) ...@@ -320,7 +557,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, NULL); (void)GpioUnSetIrq(gpio);
return (g_irqCnt > 0) ? HDF_SUCCESS : HDF_FAILURE; return (g_irqCnt > 0) ? HDF_SUCCESS : HDF_FAILURE;
} }
``` ```
\ No newline at end of file
...@@ -2,19 +2,20 @@ ...@@ -2,19 +2,20 @@
## Overview<a name="section5361140416"></a> ## Overview<a name="section5361140416"></a>
- The Inter-Integrated Circuit \(I2C\) is a simple, bidirectional, and synchronous serial bus that uses merely two wires. The Inter-Integrated Circuit \(I2C\) is a simple, bidirectional, and synchronous serial bus that uses merely two wires.
- In an I2C communication, one controller communicates with one or more devices through the serial data line \(SDA\) and serial clock line \(SCL\), as shown in [Figure 1](#fig1135561232714).
- I2C data transfer must begin with a **START** condition and end with a **STOP** condition. Data is transmitted byte-by-byte from the most significant bit to the least significant bit. In an I2C communication, one controller communicates with one or more devices through the serial data line \(SDA\) and serial clock line \(SCL\), as shown in [Figure 1](#fig1135561232714).
- Each I2C node is recognized by a unique address and can serve as either a controller or a device. When the controller needs to communicate with a device, it writes the device address to the bus through broadcast. A device matching this address sends a response to set up a data transfer channel.
- The I2C APIs define a set of common functions for I2C data transfer, including: I2C data transfer must begin with a **START** condition and end with a **STOP** condition. Data is transmitted byte-by-byte from the most significant bit to the least significant bit.
- I2C controller management: opening or closing an I2C controller Each I2C node is recognized by a unique address and can serve as either a controller or a device. When the controller needs to communicate with a device, it writes the device address to the bus through broadcast. A device matching this address sends a response to set up a data transfer channel.
- I2C message transfer: custom transfer by using a message array
**Figure 1** Physical connection diagram for I2C<a name="fig1135561232714"></a> The I2C APIs define a set of common functions for I2C data transfer, including:
![](figures/physical-connection-diagram-for-i2c.png "physical-connection-diagram-for-i2c")
- I2C controller management: opening or closing an I2C controller
- I2C message transfer: custom transfer by using a message array
**Figure 1** Physical connection diagram for I2C<br/>![](figures/physical-connection-diagram-for-i2c.png "physical-connection-diagram-for-i2c")
## Available APIs<a name="section545869122317"></a> ## Available APIs<a name="section545869122317"></a>
...@@ -52,21 +53,22 @@ ...@@ -52,21 +53,22 @@
</tbody> </tbody>
</table> </table>
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE**<br/>
>All functions provided in this document can be called only in kernel mode. >All functions provided in this document can be called only in kernel mode.
## Usage Guidelines<a name="section1695201514281"></a> ## Usage Guidelines<a name="section1695201514281"></a>
### How to Use<a name="section1338373417288"></a> ### How to Use<a name="section1338373417288"></a>
[Figure 2](#fig183017194234) illustrates the process of an I2C device. The figure below illustrates how to use the APIs.
**Figure 2** Process of using an I2C device<a name="fig183017194234"></a> **Figure 2** Using I2C driver APIs
![](figures/process-of-using-an-i2c-device.png "process-of-using-an-i2c-device")
![](figures/using-i2c-process.png "process-of-using-an-i2c-device")
### Opening an I2C Controller<a name="section13751110132914"></a> ### Opening an I2C Controller<a name="section13751110132914"></a>
Call the following function to open an I2C controller: Call the **I2cOpen()** function to open an I2C controller.
DevHandle I2cOpen\(int16\_t number\); DevHandle I2cOpen\(int16\_t number\);
...@@ -117,7 +119,7 @@ if (i2cHandle == NULL) { ...@@ -117,7 +119,7 @@ if (i2cHandle == NULL) {
### Performing I2C Communication<a name="section9202183372916"></a> ### Performing I2C Communication<a name="section9202183372916"></a>
Use the following function for message transfer: Call the **I2cTransfer()** function to transfer messages.
int32\_t I2cTransfer\(DevHandle handle, struct I2cMsg \*msgs, int16\_t count\); int32\_t I2cTransfer\(DevHandle handle, struct I2cMsg \*msgs, int16\_t count\);
...@@ -186,15 +188,14 @@ if (ret != 2) { ...@@ -186,15 +188,14 @@ if (ret != 2) {
} }
``` ```
>![](../public_sys-resources/icon-caution.gif) **CAUTION:** >![](../public_sys-resources/icon-caution.gif) **CAUTION**<br/>
>- The device address in the **I2cMsg** structure does not contain the read/write flag bit. The read/write information is transferred by the read/write control bit in the member variable **flags**. >- The device address in the **I2cMsg** structure does not contain the read/write flag bit. The read/write information is transferred by the read/write control bit in the member variable **flags**.
>- The **I2cTransfer** function does not limit the number of message structures, which is determined by the I2C controller. >- The **I2cTransfer** function does not limit the number of message structures and the data length of each message structure, which are determined by the I2C controller.
>- The **I2cTransfer** function does not limit the data length of each message structure, which is determined by the I2C controller.
>- The **I2cTransfer** function may cause the system to sleep and therefore cannot be called in the interrupt context. >- The **I2cTransfer** function may cause the system to sleep and therefore cannot be called in the interrupt context.
### Closing an I2C Controller<a name="section19481164133018"></a> ### Closing an I2C Controller<a name="section19481164133018"></a>
Call the following function to close the I2C controller after the communication is complete: Call the **I2cClose()** function to close the I2C controller after the communication is complete.
void I2cClose\(DevHandle \*handle\); void I2cClose\(DevHandle \*handle\);
...@@ -209,12 +210,13 @@ void I2cClose\(DevHandle \*handle\); ...@@ -209,12 +210,13 @@ void I2cClose\(DevHandle \*handle\);
</thead> </thead>
<tbody><tr id="row1926109193116"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p105419317318"><a name="p105419317318"></a><a name="p105419317318"></a>handle</p> <tbody><tr id="row1926109193116"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p105419317318"><a name="p105419317318"></a><a name="p105419317318"></a>handle</p>
</td> </td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1213245577"><a name="p1213245577"></a><a name="p1213245577"></a>Handle of an I2C controller.</p> <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1213245577"><a name="p1213245577"></a><a name="p1213245577"></a>Handle of the I2C controller to close.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
``` ```
I2cClose(i2cHandle); /* Close the I2C controller. */ I2cClose(i2cHandle); /* Close the I2C controller. */
``` ```
...@@ -233,7 +235,7 @@ This example shows a simple register read/write operation on TouchPad on a Hi351 ...@@ -233,7 +235,7 @@ This example shows a simple register read/write operation on TouchPad on a Hi351
In this example, first we reset Touch IC. \(The development board supplies power to Touch IC by default after being powered on, and this use case does not consider the power supply\). Then, we perform a read/write operation on an internal register to test whether the I2C channel is normal. In this example, first we reset Touch IC. \(The development board supplies power to Touch IC by default after being powered on, and this use case does not consider the power supply\). Then, we perform a read/write operation on an internal register to test whether the I2C channel is normal.
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE** <br/>
>The example focuses on I2C device access and verifies the I2C channel. The read and write values of the device register are not concerned. The behavior caused by the read and write operations on the register is determined by the device itself. >The example focuses on I2C device access and verifies the I2C channel. The read and write values of the device register are not concerned. The behavior caused by the read and write operations on the register is determined by the device itself.
Example: Example:
......
...@@ -59,12 +59,11 @@ The figure below shows a simplified CSI. The D-PHY transmits data by using one p ...@@ -59,12 +59,11 @@ The figure below shows a simplified CSI. The D-PHY transmits data by using one p
### How to Use<a name="section2.1_MIPI_CSIDes"></a> ### How to Use<a name="section2.1_MIPI_CSIDes"></a>
The figure below shows the process of using a MIPI CSI device. The figure below illustrates how to use the APIs.
**Figure 2** MIPI CSI usage process<a name="fig2_MIPI_CSIDes"></a> **Figure 2** Using MIPI CSI driver APIs
![](figures/using-MIPI-CSI-process.png)
![](figures/process-of-using-MIPI-CSI.png)
### Opening the MIPI CSI Controller Operation Handle<a name="section2.2_MIPI_CSIDes"></a> ### Opening the MIPI CSI Controller Operation Handle<a name="section2.2_MIPI_CSIDes"></a>
......
# MIPI DSI<a name="EN-US_TOPIC_0000001160971534"></a> # MIPI DSI
## Overview<a name="section16806142183217"></a> ## Overview
- The Display Serial Interface \(DSI\) is a specification stipulated by the Mobile Industry Processor Interface \(MIPI\) Alliance, aiming to reduce the cost of display controllers in a mobile device. It defines a serial bus and communication protocol among the host, the source of image data, and the target device. In this way, the DSI can send pixel data or commands to peripherals \(usually LCDs or similar display devices\) in serial mode, or reads information such as status and pixel from the peripherals. The Display Serial Interface \(DSI\) is a specification stipulated by the Mobile Industry Processor Interface \(MIPI\) Alliance, aiming to reduce the cost of display controllers in a mobile device. It defines a serial bus and communication protocol among the host, the source of image data, and the target device. In this way, the DSI can send pixel data or commands to peripherals \(usually LCDs or similar display devices\) in serial mode, or reads information such as status and pixel from the peripherals.
- MIPI DSI is capable of working in both high speed \(HS\) mode and low power \(LP\) mode. All data lanes can only travel from the DSI host to a peripheral in HS mode, except the first data lane, which can also receive data such as status information and pixels from the peripheral in LP mode. The clock lane is dedicated to transmitting synchronization clock signals in HS mode. MIPI DSI is capable of working in both high speed \(HS\) mode and low power \(LP\) mode. All data lanes can only travel from the DSI host to a peripheral in HS mode, except the first data lane, which can also receive data such as status information and pixels from the peripheral in LP mode. The clock lane is dedicated to transmitting synchronization clock signals in HS mode.
- [Figure 1](#fig1122611461203) shows a simplified DSI interface. Conceptually, a DSI-compliant interface has the same features as interfaces complying with DBI-2 and DPI-2 standards. It sends pixels or commands to a peripheral and can read status or pixel information from the peripheral. The main difference is that the DSI serializes all pixel data, commands, and events that, in traditional interfaces, are conveyed to and from the peripheral on a parallel data bus with additional control signals. [Figure 1](#fig1122611461203) shows a simplified DSI interface. Conceptually, a DSI-compliant interface has the same features as interfaces complying with DBI-2 and DPI-2 standards. It sends pixels or commands to a peripheral and can read status or pixel information from the peripheral. The main difference is that the DSI serializes all pixel data, commands, and events that, in traditional interfaces, are conveyed to and from the peripheral on a parallel data bus with additional control signals.
**Figure 1** DSI transmitting and receiving interface<a name="fig1122611461203"></a> **Figure 1** DSI transmitting and receiving interface<a name="fig1122611461203"></a>
![](figures/dsi-transmitting-and-receiving-interface.png "dsi-transmitting-and-receiving-interface") ![](figures/dsi-transmitting-and-receiving-interface.png "dsi-transmitting-and-receiving-interface")
## Available APIs<a name="section12720125432316"></a> ## Available APIs
**Table 1** APIs for MIPI DSI **Table 1** APIs for MIPI DSI
<a name="table4199102313245"></a> <a name="table4199102313245"></a>
<table><thead align="left"><tr id="row1619910238244"><th class="cellrowborder" valign="top" width="26.619999999999997%" id="mcps1.2.4.1.1"><p id="p141991023182411"><a name="p141991023182411"></a><a name="p141991023182411"></a>Capability</p> <table><thead align="left"><tr id="row1619910238244"><th class="cellrowborder" valign="top" width="26.619999999999997%" id="mcps1.2.4.1.1"><p id="p141991023182411"><a name="p141991023182411"></a><a name="p141991023182411"></a>Capability</p>
...@@ -75,25 +75,25 @@ ...@@ -75,25 +75,25 @@
</tbody> </tbody>
</table> </table>
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE**<br> All functions described in this document can be called only in kernel space.
>All functions described in this document can be called only in kernel space.
## Usage Guidelines<a name="section037231715335"></a> ## Usage Guidelines
### How to Use<a name="section49299119344"></a> ### How to Use
[Figure 2](#fig129103491241) shows the process of using a MIPI DSI device. The figure below illustrates how to use the APIs.
**Figure 2** Process of using a MIPI DSI device<a name="fig129103491241"></a> **Figure 2** Using MIPI DSI driver APIs
![](figures/process-of-using-a-mipi-dsi-device.png)
![](figures/using-mipi-dsi-process.png)
### Obtaining a MIPI DSI Device Handle<a name="section5126155683811"></a> ### Obtaining a MIPI DSI Device Handle<a name="section5126155683811"></a>
Before performing MIPI DSI communication, obtain a MIPI DSI device handle by calling **MipiDsiOpen**. This function returns a MIPI DSI device handle with a specified channel ID. Before performing MIPI DSI communication, obtain a MIPI DSI device handle by calling **MipiDsiOpen**. This function returns a MIPI DSI device handle with a specified channel ID.
DevHandle MipiDsiOpen\(uint8\_t id\); DevHandle MipiDsiOpen\(uint8\_t id\);
**Table 2** Description of **MipiDsiOpen** **Table 2** Description of **MipiDsiOpen**
<a name="table7603619123820"></a> <a name="table7603619123820"></a>
<table><thead align="left"><tr id="row1060351914386"><th class="cellrowborder" valign="top" width="20.66%" id="mcps1.2.3.1.1"><p id="p14603181917382"><a name="p14603181917382"></a><a name="p14603181917382"></a><strong id="b824620346298"><a name="b824620346298"></a><a name="b824620346298"></a>Parameter</strong></p> <table><thead align="left"><tr id="row1060351914386"><th class="cellrowborder" valign="top" width="20.66%" id="mcps1.2.3.1.1"><p id="p14603181917382"><a name="p14603181917382"></a><a name="p14603181917382"></a><strong id="b824620346298"><a name="b824620346298"></a><a name="b824620346298"></a>Parameter</strong></p>
...@@ -125,7 +125,7 @@ DevHandle MipiDsiOpen\(uint8\_t id\); ...@@ -125,7 +125,7 @@ DevHandle MipiDsiOpen\(uint8\_t id\);
</tbody> </tbody>
</table> </table>
The following example shows how to obtain a MIPI DSI device handle with the channel ID **0**: The following example shows how to obtain a MIPI DSI device handle with the channel ID **0**:
``` ```
DevHandle mipiDsiHandle = NULL; /* Device handle */ DevHandle mipiDsiHandle = NULL; /* Device handle */
...@@ -145,7 +145,7 @@ if (mipiDsiHandle == NULL) { ...@@ -145,7 +145,7 @@ if (mipiDsiHandle == NULL) {
int32\_t MipiDsiSetCfg\(DevHandle handle, struct MipiCfg \*cfg\); int32\_t MipiDsiSetCfg\(DevHandle handle, struct MipiCfg \*cfg\);
**Table 3** Description of **MipiDsiSetCfg** **Table 3** Description of **MipiDsiSetCfg**
<a name="table10692555281"></a> <a name="table10692555281"></a>
<table><thead align="left"><tr id="row116914559288"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1169195516288"><a name="p1169195516288"></a><a name="p1169195516288"></a><strong id="b1804534152914"><a name="b1804534152914"></a><a name="b1804534152914"></a>Parameter</strong></p> <table><thead align="left"><tr id="row116914559288"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1169195516288"><a name="p1169195516288"></a><a name="p1169195516288"></a><strong id="b1804534152914"><a name="b1804534152914"></a><a name="b1804534152914"></a>Parameter</strong></p>
...@@ -213,7 +213,7 @@ if (ret != 0) { ...@@ -213,7 +213,7 @@ if (ret != 0) {
int32\_t MipiDsiGetCfg\(DevHandle handle, struct MipiCfg \*cfg\); int32\_t MipiDsiGetCfg\(DevHandle handle, struct MipiCfg \*cfg\);
**Table 4** Description of **MipiDsiGetCfg** **Table 4** Description of **MipiDsiGetCfg**
<a name="table7709554280"></a> <a name="table7709554280"></a>
<table><thead align="left"><tr id="row670115515282"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p470205515287"><a name="p470205515287"></a><a name="p470205515287"></a><strong id="b14806334142912"><a name="b14806334142912"></a><a name="b14806334142912"></a>Parameter</strong></p> <table><thead align="left"><tr id="row670115515282"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p470205515287"><a name="p470205515287"></a><a name="p470205515287"></a><strong id="b14806334142912"><a name="b14806334142912"></a><a name="b14806334142912"></a>Parameter</strong></p>
...@@ -267,7 +267,7 @@ if (ret != HDF_SUCCESS) { ...@@ -267,7 +267,7 @@ if (ret != HDF_SUCCESS) {
int32\_t MipiDsiTx\(PalHandle handle, struct DsiCmdDesc \*cmd\); int32\_t MipiDsiTx\(PalHandle handle, struct DsiCmdDesc \*cmd\);
**Table 5** Description of **MipiDsiTx** **Table 5** Description of **MipiDsiTx**
<a name="table1018490043"></a> <a name="table1018490043"></a>
<table><thead align="left"><tr id="row31848013417"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b1280873492913"><a name="b1280873492913"></a><a name="b1280873492913"></a>Parameter</strong></p> <table><thead align="left"><tr id="row31848013417"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b1280873492913"><a name="b1280873492913"></a><a name="b1280873492913"></a>Parameter</strong></p>
...@@ -335,7 +335,7 @@ HdfFree(cmd); ...@@ -335,7 +335,7 @@ HdfFree(cmd);
int32\_t MipiDsiRx\(DevHandle handle, struct DsiCmdDesc \*cmd, uint32\_t readLen, uint8\_t \*out\); int32\_t MipiDsiRx\(DevHandle handle, struct DsiCmdDesc \*cmd, uint32\_t readLen, uint8\_t \*out\);
**Table 6** Description of **MipiDsiRx** **Table 6** Description of **MipiDsiRx**
<a name="table223910318361"></a> <a name="table223910318361"></a>
<table><thead align="left"><tr id="row924033173613"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p16240143143611"><a name="p16240143143611"></a><a name="p16240143143611"></a><strong id="b19809334172910"><a name="b19809334172910"></a><a name="b19809334172910"></a>Parameter</strong></p> <table><thead align="left"><tr id="row924033173613"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p16240143143611"><a name="p16240143143611"></a><a name="p16240143143611"></a><strong id="b19809334172910"><a name="b19809334172910"></a><a name="b19809334172910"></a>Parameter</strong></p>
...@@ -417,9 +417,9 @@ After the MIPI DSI communication, release the MIPI DSI device handle by calling ...@@ -417,9 +417,9 @@ After the MIPI DSI communication, release the MIPI DSI device handle by calling
void MipiDsiClose\(DevHandle handle\); void MipiDsiClose\(DevHandle handle\);
This function releases the resources requested by **MipiDsiOpen**. This function releases the resources requested by **MipiDsiOpen**.
**Table 7** Description of **MipiDsiClose** **Table 7** Description of **MipiDsiClose**
<a name="table72517953115"></a> <a name="table72517953115"></a>
<table><thead align="left"><tr id="row1525793312"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p115402031153111"><a name="p115402031153111"></a><a name="p115402031153111"></a><strong id="b1487612133120"><a name="b1487612133120"></a><a name="b1487612133120"></a>Parameter</strong></p> <table><thead align="left"><tr id="row1525793312"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p115402031153111"><a name="p115402031153111"></a><a name="p115402031153111"></a><strong id="b1487612133120"><a name="b1487612133120"></a><a name="b1487612133120"></a>Parameter</strong></p>
...@@ -536,5 +536,4 @@ void PalMipiDsiTestSample(void) ...@@ -536,5 +536,4 @@ void PalMipiDsiTestSample(void)
/* Release the MIPI DSI device handle. */ /* Release the MIPI DSI device handle. */
MipiDsiClose(handle); MipiDsiClose(handle);
} }
``` ```
\ No newline at end of file
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
### Pin<a name="section2"></a> ### Pin<a name="section2"></a>
- The pin, also called pin controller, manages pin resources of system on a chip (SoC) vendors and provides the pin multiplexing function. The pin module, also called pin controller, manages pin resources of system on a chip (SoC) vendors and provides the pin multiplexing function.
- The pin module defines a set of common methods for managing pins, including: The module defines a set of common methods for managing pins, including:
- Obtaining or releasing the pin description handle: The kernel compares the pin name passed in with the pin names of each controller in the linked list. If a match is found, a pin description handle is obtained. After the operation on the pin is complete, the pin description handle will be released. - Obtaining or releasing the pin description handle: The kernel compares the pin name passed in with the pin names of each controller in the linked list. If a match is found, a pin description handle is obtained. After the operation on the pin is complete, the pin description handle will be released.
- Setting or obtaining the pull type of a pin: The pull type can be pull-up, pull-down, or floating. - Setting or obtaining the pull type of a pin: The pull type can be pull-up, pull-down, or floating.
- Setting or obtaining the pull strength of a pin: You can set the pull strength as required. - Setting or obtaining the pull strength of a pin: You can set the pull strength as required.
- Setting or obtaining the functions of a pin to implement pin multiplexing - Setting or obtaining the functions of a pin to implement pin multiplexing
### Basic Concepts<a name="section3"></a> ### Basic Concepts<a name="section3"></a>
Pin, as a software concept, provides APIs for uniformly managing the pins from different SoC vendors, providing the pin multiplexing function, and configuring the electrical features of pins. Pin, as a software concept, provides APIs for uniformly managing the pins from different SoC vendors, providing the pin multiplexing function, and configuring the electrical features of pins.
...@@ -52,7 +52,7 @@ The table below describes the APIs of the pin module. For more details, see API ...@@ -52,7 +52,7 @@ The table below describes the APIs of the pin module. For more details, see API
**Table 1** Pin driver APIs **Table 1** Pin driver APIs
<a name="table1"></a> <a name="table1"></a>
| **API** | **Description** | | **API** | **Description** |
| ------------------------------------------------------------ | ---------------- | | ------------------------------------------------------------ | ---------------- |
| DevHandle PinGet(const char *pinName); | Obtains the pin description handle.| | DevHandle PinGet(const char *pinName); | Obtains the pin description handle.|
| void PinPut(DevHandle handle); | Releases the pin description handle.| | void PinPut(DevHandle handle); | Releases the pin description handle.|
...@@ -68,10 +68,11 @@ The table below describes the APIs of the pin module. For more details, see API ...@@ -68,10 +68,11 @@ The table below describes the APIs of the pin module. For more details, see API
### How to Develop<a name="section9"></a> ### How to Develop<a name="section9"></a>
The figure below shows the process. The figure below illustrates how to use the APIs.
**Figure 2** Process of using the pin module<a name="fig2"></a> **Figure 2** Using the pin driver APIs
![](figures/process-of-using-pin.png "Process of using the pin module")
![](figures/using-pin-process.png "Process of using the pin module")
#### Obtaining the Pin Description Handle #### Obtaining the Pin Description Handle
...@@ -88,7 +89,7 @@ DevHandle PinGet(const char *pinName); ...@@ -88,7 +89,7 @@ DevHandle PinGet(const char *pinName);
| Parameter | Description | | Parameter | Description |
| ---------- | ----------------------- | | ---------- | ----------------------- |
| pinName | Pointer to the pin name. | | pinName | Pointer to the pin name. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| NULL | Failed to obtain the pin description handle.| | NULL | Failed to obtain the pin description handle.|
| handle | Pin description handle obtained. | | handle | Pin description handle obtained. |
...@@ -120,9 +121,9 @@ int32_t PinSetPull(DevHandle handle, enum PinPullType pullType); ...@@ -120,9 +121,9 @@ int32_t PinSetPull(DevHandle handle, enum PinPullType pullType);
| ---------- | ----------------------- | | ---------- | ----------------------- |
| handle | Pin description handle. | | handle | Pin description handle. |
| pullType | Pull type to set. | | pullType | Pull type to set. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful.| | 0 | The operation is successful.|
| Negative value | The operation fails.| | Negative value | The operation failed.|
Example: Set the pull type to pull-up. Example: Set the pull type to pull-up.
...@@ -154,9 +155,9 @@ int32_t PinGetPull(DevHandle handle, enum PinPullType *pullType); ...@@ -154,9 +155,9 @@ int32_t PinGetPull(DevHandle handle, enum PinPullType *pullType);
| ---------- | ------------------------- | | ---------- | ------------------------- |
| handle | Pin description handle. | | handle | Pin description handle. |
| pullType | Pointer to the pull type obtained.| | pullType | Pointer to the pull type obtained.|
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation fails. | | Negative value | The operation failed. |
Example: Obtain the pull type of a pin. Example: Obtain the pull type of a pin.
...@@ -187,9 +188,9 @@ int32_t PinSetStrength(DevHandle handle, uint32_t strength); ...@@ -187,9 +188,9 @@ int32_t PinSetStrength(DevHandle handle, uint32_t strength);
| ---------- | ----------------------- | | ---------- | ----------------------- |
| handle | Pin description handle. | | handle | Pin description handle. |
| strength | Pull strength to set. | | strength | Pull strength to set. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful.| | 0 | The operation is successful.|
| Negative value | The operation fails.| | Negative value | The operation failed.|
Example: Set the pull strength of the pin to 2. Example: Set the pull strength of the pin to 2.
...@@ -221,9 +222,9 @@ int32_t PinGetStrength(DevHandle handle, uint32_t *strength); ...@@ -221,9 +222,9 @@ int32_t PinGetStrength(DevHandle handle, uint32_t *strength);
| ---------- | ------------------------- | | ---------- | ------------------------- |
| handle | Pin description handle. | | handle | Pin description handle. |
| strength | Pointer to the pull strength obtained.| | strength | Pointer to the pull strength obtained.|
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation fails. | | Negative value | The operation failed. |
Example: Obtain the pull strength of a pin. Example: Obtain the pull strength of a pin.
...@@ -256,9 +257,9 @@ int32_t PinSetFunc(DevHandle handle, const char *funcName); ...@@ -256,9 +257,9 @@ int32_t PinSetFunc(DevHandle handle, const char *funcName);
| ---------- | ------------------- | | ---------- | ------------------- |
| handle | Pin description handle. | | handle | Pin description handle. |
| funcName | Pointer to the pin function to set. | | funcName | Pointer to the pin function to set. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful.| | 0 | The operation is successful.|
| Negative value | The operation fails.| | Negative value | The operation failed.|
Example: Set the pin function to LSADC_CH1 (ADC channel 1). Example: Set the pin function to LSADC_CH1 (ADC channel 1).
...@@ -289,9 +290,9 @@ int32_t PinGetFunc(DevHandle handle, const char **funcName); ...@@ -289,9 +290,9 @@ int32_t PinGetFunc(DevHandle handle, const char **funcName);
| ---------- | --------------------- | | ---------- | --------------------- |
| handle | Pin description handle. | | handle | Pin description handle. |
| funcName | Pointer to the function name obtained.| | funcName | Pointer to the function name obtained.|
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation fails. | | Negative value | The operation failed. |
Example: Obtain the pin function. Example: Obtain the pin function.
...@@ -406,4 +407,4 @@ ERR: ...@@ -406,4 +407,4 @@ ERR:
/* Release the pin description handle. */ /* Release the pin description handle. */
PinPut(handle); PinPut(handle);
return ret; return ret;
} }
\ No newline at end of file
...@@ -48,11 +48,11 @@ Pulse width modulation (PWM) is a technology that digitally encodes analog signa ...@@ -48,11 +48,11 @@ Pulse width modulation (PWM) is a technology that digitally encodes analog signa
### How to Use ### How to Use
The figure below shows the general process of using the PWM. The figure below illustrates how to use the APIs.
**Figure 1** Process of using the PWM module **Figure 1** Using the PWM driver APIs
![](figures/process-of-using-PWM.png) ![](figures/using-PWM-process.png)
### Opening a PWM Device Handle ### Opening a PWM Device Handle
...@@ -71,7 +71,7 @@ DevHandle PwmOpen(uint32_t num); ...@@ -71,7 +71,7 @@ DevHandle PwmOpen(uint32_t num);
| num | PWM device number. | | num | PWM device number. |
| **Return Value** | **Description** | | **Return Value** | **Description** |
| handle | Handle of the PWM device obtained.| | handle | Handle of the PWM device obtained.|
| NULL | The operation fails. | | NULL | The operation failed. |
Example: Open the device handle of PWM device 0. Example: Open the device handle of PWM device 0.
...@@ -126,7 +126,7 @@ int32_t PwmEnable(DevHandle handle); ...@@ -126,7 +126,7 @@ int32_t PwmEnable(DevHandle handle);
| handle | PWM device handle. | | handle | PWM device handle. |
| **Return Value** | **Description** | | **Return Value** | **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative number | The operation fails. | | Negative number | The operation failed. |
``` ```
...@@ -156,7 +156,7 @@ int32_t PwmDisable(DevHandle handle); ...@@ -156,7 +156,7 @@ int32_t PwmDisable(DevHandle handle);
| handle | PWM device handle. | | handle | PWM device handle. |
| **Return Value** | **Description** | | **Return Value** | **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative number | The operation fails. | | Negative number | The operation failed. |
``` ```
...@@ -187,7 +187,7 @@ int32_t PwmSetPeriod(DevHandle handle, uint32_t period); ...@@ -187,7 +187,7 @@ int32_t PwmSetPeriod(DevHandle handle, uint32_t period);
| period | PWM period to set, in ns.| | period | PWM period to set, in ns.|
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative number | The operation fails. | | Negative number | The operation failed. |
``` ```
...@@ -218,7 +218,7 @@ int32_t PwmSetDuty(DevHandle handle, uint32_t duty); ...@@ -218,7 +218,7 @@ int32_t PwmSetDuty(DevHandle handle, uint32_t duty);
| duty | Time that the signal is in the ON state, in ns.| | duty | Time that the signal is in the ON state, in ns.|
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative number | The operation fails. | | Negative number | The operation failed. |
``` ```
...@@ -249,7 +249,7 @@ int32_t PwmSetPolarity(DevHandle handle, uint8_t polarity); ...@@ -249,7 +249,7 @@ int32_t PwmSetPolarity(DevHandle handle, uint8_t polarity);
| polarity | Polarity to set, which can be **PWM\_NORMAL\_POLARITY** or **PWM\_INVERTED\_POLARITY**.| | polarity | Polarity to set, which can be **PWM\_NORMAL\_POLARITY** or **PWM\_INVERTED\_POLARITY**.|
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative number | The operation fails. | | Negative number | The operation failed. |
``` ```
...@@ -280,7 +280,7 @@ int32_t PwmSetConfig(DevHandle handle, struct PwmConfig *config); ...@@ -280,7 +280,7 @@ int32_t PwmSetConfig(DevHandle handle, struct PwmConfig *config);
| \*config | Pointer to PWM parameters. | | \*config | Pointer to PWM parameters. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative number | The operation fails. | | Negative number | The operation failed. |
``` ```
...@@ -317,7 +317,7 @@ int32_t PwmGetConfig(DevHandle handle, struct PwmConfig *config); ...@@ -317,7 +317,7 @@ int32_t PwmGetConfig(DevHandle handle, struct PwmConfig *config);
| \*config | Pointer to PWM parameters. | | \*config | Pointer to PWM parameters. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative number | The operation fails. | | Negative number | The operation failed. |
``` ```
......
...@@ -42,7 +42,8 @@ The regulator module is divided into the following layers: ...@@ -42,7 +42,8 @@ The regulator module is divided into the following layers:
- The core layer provides the capabilities of binding, initializing, and releasing devices. - The core layer provides the capabilities of binding, initializing, and releasing devices.
- The adaptation layer implements other functions. - The adaptation layer implements other functions.
![](../public_sys-resources/icon-note.gif)NOTE<br/>The core layer can call the functions of the interface layer and uses the hook to call functions of the adaptation layer. In this way, the adaptation layer can indirectly call the functions of the interface layer, but the interface layer cannot call the functions of the adaptation layer. > ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**<br/>
> The core layer can call the functions of the interface layer and uses the hook to call functions of the adaptation layer. In this way, the adaptation layer can indirectly call the functions of the interface layer, but the interface layer cannot call the functions of the adaptation layer.
**Figure 1** Unified service mode **Figure 1** Unified service mode
...@@ -84,11 +85,11 @@ Regulators are used to: ...@@ -84,11 +85,11 @@ Regulators are used to:
During the OS startup process, the driver management module loads the regulator driver based on the configuration file. Then, the regulator driver detects the regulator devices and initializes the driver. During the OS startup process, the driver management module loads the regulator driver based on the configuration file. Then, the regulator driver detects the regulator devices and initializes the driver.
The figure below illustrates the process of using a regulator. The figure below illustrates how to use the APIs.
**Figure 2** Process of using a regulator **Figure 2** Using regulator driver APIs
![](figures/process-of-using-regulator.png) ![](figures/using-regulator-process.png)
#### Opening a Regulator Device Handle #### Opening a Regulator Device Handle
...@@ -105,7 +106,7 @@ DevHandle RegulatorOpen(const char *name); ...@@ -105,7 +106,7 @@ DevHandle RegulatorOpen(const char *name);
| name | Name of the target regulator. | | name | Name of the target regulator. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| handle | The regulator device handle is returned if the operation is successful.| | handle | The regulator device handle is returned if the operation is successful.|
| NULL | The operation fails. | | NULL | The operation failed. |
...@@ -155,7 +156,7 @@ int32_t RegulatorEnable(DevHandle handle); ...@@ -155,7 +156,7 @@ int32_t RegulatorEnable(DevHandle handle);
| handle | Device handle of the target regulator.| | handle | Device handle of the target regulator.|
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation fails. | | Negative value | The operation failed. |
...@@ -184,7 +185,7 @@ int32_t RegulatorDisable(DevHandle handle); ...@@ -184,7 +185,7 @@ int32_t RegulatorDisable(DevHandle handle);
| handle | Device handle of the target regulator.| | handle | Device handle of the target regulator.|
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation fails. | | Negative value | The operation failed. |
``` ```
int32_t ret; int32_t ret;
...@@ -212,7 +213,7 @@ int32_t RegulatorForceDisable(DevHandle handle); ...@@ -212,7 +213,7 @@ int32_t RegulatorForceDisable(DevHandle handle);
| handle | Device handle of the target regulator.| | handle | Device handle of the target regulator.|
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation fails. | | Negative value | The operation failed. |
``` ```
int32_t ret; int32_t ret;
...@@ -241,7 +242,7 @@ int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv); ...@@ -241,7 +242,7 @@ int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv);
| maxUv | Maximum voltage to set. | | maxUv | Maximum voltage to set. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation fails. | | Negative value | The operation failed. |
``` ```
int32_t ret; int32_t ret;
...@@ -272,7 +273,7 @@ int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage); ...@@ -272,7 +273,7 @@ int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage);
| *voltage | Pointer to the regulator voltage information. | | *voltage | Pointer to the regulator voltage information. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation fails. | | Negative value | The operation failed. |
``` ```
int32_t ret; int32_t ret;
...@@ -302,7 +303,7 @@ int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa); ...@@ -302,7 +303,7 @@ int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa);
| maxUa | Maximum current to set. | | maxUa | Maximum current to set. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation fails. | | Negative value | The operation failed. |
``` ```
int32_t ret; int32_t ret;
...@@ -332,7 +333,7 @@ int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent); ...@@ -332,7 +333,7 @@ int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent);
| *regCurrent | Pointer to the regulator current information. | | *regCurrent | Pointer to the regulator current information. |
| **Return Value** | **Description** | | **Return Value** | **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation fails. | | Negative value | The operation failed. |
``` ```
int32_t ret; int32_t ret;
...@@ -361,7 +362,7 @@ int32_t RegulatorGetStatus(DevHandle handle, uint32_t *status); ...@@ -361,7 +362,7 @@ int32_t RegulatorGetStatus(DevHandle handle, uint32_t *status);
| *status | Pointer to the regulator status information. | | *status | Pointer to the regulator status information. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation fails. | | Negative value | The operation failed. |
``` ```
int32_t ret; int32_t ret;
......
...@@ -6,7 +6,7 @@ The real-time clock \(RTC\) driver provides precise real time for the operating ...@@ -6,7 +6,7 @@ The real-time clock \(RTC\) driver provides precise real time for the operating
## Available APIs<a name="section20331159102519"></a> ## Available APIs<a name="section20331159102519"></a>
**Table 1** APIs provided by the RTC driver **Table 1** APIs provided by the RTC driver
<a name="table1731550155318"></a> <a name="table1731550155318"></a>
<table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" valign="top" width="21.902190219021904%" id="mcps1.2.4.1.1"><p id="p641050105320"><a name="p641050105320"></a><a name="p641050105320"></a><strong id="b17744818255"><a name="b17744818255"></a><a name="b17744818255"></a>Capability</strong></p> <table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" valign="top" width="21.902190219021904%" id="mcps1.2.4.1.1"><p id="p641050105320"><a name="p641050105320"></a><a name="p641050105320"></a><strong id="b17744818255"><a name="b17744818255"></a><a name="b17744818255"></a>Capability</strong></p>
...@@ -95,7 +95,7 @@ The real-time clock \(RTC\) driver provides precise real time for the operating ...@@ -95,7 +95,7 @@ The real-time clock \(RTC\) driver provides precise real time for the operating
</tbody> </tbody>
</table> </table>
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>All functions provided in this document can be called only in kernel mode. >All functions provided in this document can be called only in kernel mode.
## Usage Guidelines<a name="section20636145604113"></a> ## Usage Guidelines<a name="section20636145604113"></a>
...@@ -104,21 +104,21 @@ The real-time clock \(RTC\) driver provides precise real time for the operating ...@@ -104,21 +104,21 @@ The real-time clock \(RTC\) driver provides precise real time for the operating
During the OS startup, the HDF loads the RTC driver based on the configuration file. The RTC driver detects the RTC component and initializes the driver. During the OS startup, the HDF loads the RTC driver based on the configuration file. The RTC driver detects the RTC component and initializes the driver.
[Figure 1](#fig1610020107333) illustrates the process of using an RTC device. The figure below illustrates how to use the APIs.
**Figure 1** Process of using an RTC device<a name="fig1610020107333"></a> **Figure 1** Process of using an RTC device
![](figures/process-of-using-an-rtc-device.png "process-of-using-an-rtc-device") ![](figures/using-rtc-process.png "process-of-using-an-rtc-device")
### Creating an RTC Device Handle<a name="section1131212144310"></a> ### Opening the RTC Device Handle<a name="section1131212144310"></a>
After the RTC driver is loaded, you can use the API provided by the HDF and call APIs of the RTC driver. After the RTC driver is loaded, you can use the API provided by the HDF and call APIs of the RTC driver.
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>Currently, only one RTC device is supported in the OS. >Currently, only one RTC device is supported in the OS.
DevHandle RtcOpen\(void\); DevHandle RtcOpen\(void\);
**Table 2** Description of RtcOpen **Table 2** Description of RtcOpen
<a name="table1380712985611"></a> <a name="table1380712985611"></a>
<table><tbody><tr id="row580722985616"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1280722911565"><a name="p1280722911565"></a><a name="p1280722911565"></a><strong id="b748651620573"><a name="b748651620573"></a><a name="b748651620573"></a>Parameter</strong></p> <table><tbody><tr id="row580722985616"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1280722911565"><a name="p1280722911565"></a><a name="p1280722911565"></a><strong id="b748651620573"><a name="b748651620573"></a><a name="b748651620573"></a>Parameter</strong></p>
...@@ -138,17 +138,18 @@ DevHandle RtcOpen\(void\); ...@@ -138,17 +138,18 @@ DevHandle RtcOpen\(void\);
</tr> </tr>
<tr id="row2808192935615"><td class="cellrowborder" valign="top" width="21.45%"><p id="p380852915567"><a name="p380852915567"></a><a name="p380852915567"></a>handle</p> <tr id="row2808192935615"><td class="cellrowborder" valign="top" width="21.45%"><p id="p380852915567"><a name="p380852915567"></a><a name="p380852915567"></a>handle</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p26881319114110"><a name="p26881319114110"></a><a name="p26881319114110"></a>Returns the if the operation is successful.</p> <td class="cellrowborder" valign="top" width="78.55%"><p id="p26881319114110"><a name="p26881319114110"></a><a name="p26881319114110"></a>The operation is successful.</p>
</td> </td>
</tr> </tr>
<tr id="row4808142945615"><td class="cellrowborder" valign="top" width="21.45%"><p id="p188084291561"><a name="p188084291561"></a><a name="p188084291561"></a>NULL</p> <tr id="row4808142945615"><td class="cellrowborder" valign="top" width="21.45%"><p id="p188084291561"><a name="p188084291561"></a><a name="p188084291561"></a>NULL</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p780852912566"><a name="p780852912566"></a><a name="p780852912566"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.55%"><p id="p780852912566"><a name="p780852912566"></a><a name="p780852912566"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
``` ```
DevHandle handle = NULL; DevHandle handle = NULL;
...@@ -161,11 +162,11 @@ if (handle == NULL) { ...@@ -161,11 +162,11 @@ if (handle == NULL) {
### Releasing the RTC Device Handle<a name="section10744117144314"></a> ### Releasing the RTC Device Handle<a name="section10744117144314"></a>
You can call the following function to release the RTC device handle, thereby releasing resources of the device: You can call **RtcClose()** function to release the RTC device handle, thereby releasing resources of the device.
void RtcClose\(DevHandle handle\); void RtcClose\(DevHandle handle\);
**Table 3** Description of RtcClose **Table 3** Description of RtcClose
<a name="table37525421510"></a> <a name="table37525421510"></a>
<table><tbody><tr id="row10752134216114"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1075217421019"><a name="p1075217421019"></a><a name="p1075217421019"></a><strong id="b229461765710"><a name="b229461765710"></a><a name="b229461765710"></a>Parameter</strong></p> <table><tbody><tr id="row10752134216114"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1075217421019"><a name="p1075217421019"></a><a name="p1075217421019"></a><strong id="b229461765710"><a name="b229461765710"></a><a name="b229461765710"></a>Parameter</strong></p>
...@@ -186,13 +187,13 @@ void RtcClose\(DevHandle handle\); ...@@ -186,13 +187,13 @@ void RtcClose\(DevHandle handle\);
RtcClose(handle); RtcClose(handle);
``` ```
### Registering RtcAlarmCallback<a name="section14839440184320"></a> ### Registering RtcAlarmCallback
After the OS is started, call the following function to register **RtcAlarmCallback**, which will be invoked when an alarm is generated at the specified time: After the OS is started, call the following function to register **RtcAlarmCallback**, which will be invoked when an alarm is generated at the specified time:
int32\_t RtcRegisterAlarmCallback\(DevHandle handle, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb\); int32\_t RtcRegisterAlarmCallback\(DevHandle handle, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb\);
**Table 4** Description of RtcRegisterAlarmCallback **Table 4** Description of RtcRegisterAlarmCallback
<a name="table7603619123820"></a> <a name="table7603619123820"></a>
<table><thead align="left"><tr id="row1060351914386"><th class="cellrowborder" valign="top" width="21.36%" id="mcps1.2.3.1.1"><p id="p14603181917382"><a name="p14603181917382"></a><a name="p14603181917382"></a><strong id="b4295161718571"><a name="b4295161718571"></a><a name="b4295161718571"></a>Parameter</strong></p> <table><thead align="left"><tr id="row1060351914386"><th class="cellrowborder" valign="top" width="21.36%" id="mcps1.2.3.1.1"><p id="p14603181917382"><a name="p14603181917382"></a><a name="p14603181917382"></a><strong id="b4295161718571"><a name="b4295161718571"></a><a name="b4295161718571"></a>Parameter</strong></p>
...@@ -228,13 +229,13 @@ int32\_t RtcRegisterAlarmCallback\(DevHandle handle, enum RtcAlarmIndex alarmInd ...@@ -228,13 +229,13 @@ int32\_t RtcRegisterAlarmCallback\(DevHandle handle, enum RtcAlarmIndex alarmInd
</tr> </tr>
<tr id="row1241081213303"><td class="cellrowborder" valign="top" width="21.36%" headers="mcps1.2.3.1.1 "><p id="p1123362173010"><a name="p1123362173010"></a><a name="p1123362173010"></a>Negative value</p> <tr id="row1241081213303"><td class="cellrowborder" valign="top" width="21.36%" headers="mcps1.2.3.1.1 "><p id="p1123362173010"><a name="p1123362173010"></a><a name="p1123362173010"></a>Negative value</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.64%" headers="mcps1.2.3.1.2 "><p id="p1723362153010"><a name="p1723362153010"></a><a name="p1723362153010"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.64%" headers="mcps1.2.3.1.2 "><p id="p1723362153010"><a name="p1723362153010"></a><a name="p1723362153010"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
The following is an example of registering **RtcAlarmCallback** for processing alarm **RTC\_ALARM\_INDEX\_A**: The following is an example of registering **RtcAlarmCallback** for processing alarm **RTC\_ALARM\_INDEX\_A**:
``` ```
/* Register an RTC alarm callback. */ /* Register an RTC alarm callback. */
...@@ -257,15 +258,15 @@ if (ret != 0) { ...@@ -257,15 +258,15 @@ if (ret != 0) {
} }
``` ```
### Performing RTC-related Operations<a name="section161927578433"></a> ### Performing RTC-related Operations
- Reading RTC time - Reading RTC time
Call the following function to read time information from the RTC driver, including the year, month, the day of the week, day, hour, minute, second, and millisecond: Call the **RtcReadTime()** function to read time information from the RTC driver, including the year, month, the day of the week, day, hour, minute, second, and millisecond.
int32\_t RtcReadTime\(DevHandle handle, struct RtcTime \*time\); int32\_t RtcReadTime\(DevHandle handle, struct RtcTime \*time\);
**Table 5** Description of RtcReadTime **Table 5** Description of RtcReadTime
<a name="table1018490043"></a> <a name="table1018490043"></a>
<table><tbody><tr id="row31848013417"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b10296717125710"><a name="b10296717125710"></a><a name="b10296717125710"></a>Parameter</strong></p> <table><tbody><tr id="row31848013417"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b10296717125710"><a name="b10296717125710"></a><a name="b10296717125710"></a>Parameter</strong></p>
...@@ -295,7 +296,7 @@ int32\_t RtcReadTime\(DevHandle handle, struct RtcTime \*time\); ...@@ -295,7 +296,7 @@ int32\_t RtcReadTime\(DevHandle handle, struct RtcTime \*time\);
</tr> </tr>
<tr id="row15393184519323"><td class="cellrowborder" valign="top" width="21.45%"><p id="p13521182309"><a name="p13521182309"></a><a name="p13521182309"></a>Negative value</p> <tr id="row15393184519323"><td class="cellrowborder" valign="top" width="21.45%"><p id="p13521182309"><a name="p13521182309"></a><a name="p13521182309"></a>Negative value</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p1035216186309"><a name="p1035216186309"></a><a name="p1035216186309"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.55%"><p id="p1035216186309"><a name="p1035216186309"></a><a name="p1035216186309"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -314,11 +315,11 @@ if (ret != 0) { ...@@ -314,11 +315,11 @@ if (ret != 0) {
- Setting RTC time - Setting RTC time
Call the following function to set the RTC time: Call the **RtcWriteTime()** function to set the RTC time.
int32\_t RtcWriteTime\(DevHandle handle, struct RtcTime \*time\); int32\_t RtcWriteTime\(DevHandle handle, struct RtcTime \*time\);
**Table 6** Description of RtcWriteTime **Table 6** Description of RtcWriteTime
<a name="table223910318361"></a> <a name="table223910318361"></a>
<table><tbody><tr id="row924033173613"><td class="cellrowborder" valign="top" width="21.54%"><p id="p16240143143611"><a name="p16240143143611"></a><a name="p16240143143611"></a><strong id="b17297111720576"><a name="b17297111720576"></a><a name="b17297111720576"></a>Parameter</strong></p> <table><tbody><tr id="row924033173613"><td class="cellrowborder" valign="top" width="21.54%"><p id="p16240143143611"><a name="p16240143143611"></a><a name="p16240143143611"></a><strong id="b17297111720576"><a name="b17297111720576"></a><a name="b17297111720576"></a>Parameter</strong></p>
...@@ -348,14 +349,14 @@ int32\_t RtcWriteTime\(DevHandle handle, struct RtcTime \*time\); ...@@ -348,14 +349,14 @@ int32\_t RtcWriteTime\(DevHandle handle, struct RtcTime \*time\);
</tr> </tr>
<tr id="row024153123616"><td class="cellrowborder" valign="top" width="21.54%"><p id="p5602191619300"><a name="p5602191619300"></a><a name="p5602191619300"></a>Negative value</p> <tr id="row024153123616"><td class="cellrowborder" valign="top" width="21.54%"><p id="p5602191619300"><a name="p5602191619300"></a><a name="p5602191619300"></a>Negative value</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p12602131643015"><a name="p12602131643015"></a><a name="p12602131643015"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.46%"><p id="p12602131643015"><a name="p12602131643015"></a><a name="p12602131643015"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week. >The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
``` ```
int32_t ret; int32_t ret;
...@@ -378,11 +379,11 @@ if (ret != 0) { ...@@ -378,11 +379,11 @@ if (ret != 0) {
- Reading the RTC alarm time - Reading the RTC alarm time
Call the following function to read the alarm time: Call the **RtcReadAlarm()** function to read the alarm time.
int32\_t RtcReadAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime \*time\); int32\_t RtcReadAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime \*time\);
**Table 7** Description of RtcReadAlarm **Table 7** Description of RtcReadAlarm
<a name="table11342203111420"></a> <a name="table11342203111420"></a>
<table><tbody><tr id="row133429310140"><td class="cellrowborder" valign="top" width="21.54%"><p id="p9886411201416"><a name="p9886411201416"></a><a name="p9886411201416"></a><strong id="b152971517185720"><a name="b152971517185720"></a><a name="b152971517185720"></a>Parameter</strong></p> <table><tbody><tr id="row133429310140"><td class="cellrowborder" valign="top" width="21.54%"><p id="p9886411201416"><a name="p9886411201416"></a><a name="p9886411201416"></a><strong id="b152971517185720"><a name="b152971517185720"></a><a name="b152971517185720"></a>Parameter</strong></p>
...@@ -417,7 +418,7 @@ int32\_t RtcReadAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct R ...@@ -417,7 +418,7 @@ int32\_t RtcReadAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct R
</tr> </tr>
<tr id="row016911915461"><td class="cellrowborder" valign="top" width="21.54%"><p id="p6833213133013"><a name="p6833213133013"></a><a name="p6833213133013"></a>Negative value</p> <tr id="row016911915461"><td class="cellrowborder" valign="top" width="21.54%"><p id="p6833213133013"><a name="p6833213133013"></a><a name="p6833213133013"></a>Negative value</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p168341213143015"><a name="p168341213143015"></a><a name="p168341213143015"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.46%"><p id="p168341213143015"><a name="p168341213143015"></a><a name="p168341213143015"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -436,11 +437,11 @@ if (ret != 0) { ...@@ -436,11 +437,11 @@ if (ret != 0) {
- Setting RTC alarm time - Setting RTC alarm time
Call the following function to set the RTC alarm time based on the alarm index: Call the **RtcWriteAlarm()** function to set the RTC alarm time based on the alarm index.
int32\_t RtcWriteAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime \*time\); int32\_t RtcWriteAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime \*time\);
**Table 8** Description of RtcWriteAlarm **Table 8** Description of RtcWriteAlarm
<a name="table107922162179"></a> <a name="table107922162179"></a>
<table><tbody><tr id="row14793316131710"><td class="cellrowborder" valign="top" width="21.62%"><p id="p1891718412183"><a name="p1891718412183"></a><a name="p1891718412183"></a><strong id="b029811725716"><a name="b029811725716"></a><a name="b029811725716"></a>Parameter</strong></p> <table><tbody><tr id="row14793316131710"><td class="cellrowborder" valign="top" width="21.62%"><p id="p1891718412183"><a name="p1891718412183"></a><a name="p1891718412183"></a><strong id="b029811725716"><a name="b029811725716"></a><a name="b029811725716"></a>Parameter</strong></p>
...@@ -475,14 +476,14 @@ int32\_t RtcWriteAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct ...@@ -475,14 +476,14 @@ int32\_t RtcWriteAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct
</tr> </tr>
<tr id="row1686918225483"><td class="cellrowborder" valign="top" width="21.62%"><p id="p16246181033012"><a name="p16246181033012"></a><a name="p16246181033012"></a>Negative value</p> <tr id="row1686918225483"><td class="cellrowborder" valign="top" width="21.62%"><p id="p16246181033012"><a name="p16246181033012"></a><a name="p16246181033012"></a>Negative value</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p3246111019309"><a name="p3246111019309"></a><a name="p3246111019309"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p3246111019309"><a name="p3246111019309"></a><a name="p3246111019309"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week. >The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
``` ```
int32_t ret; int32_t ret;
...@@ -505,11 +506,11 @@ if (ret != 0) { ...@@ -505,11 +506,11 @@ if (ret != 0) {
- Enabling or disabling alarm interrupts - Enabling or disabling alarm interrupts
Before performing alarm operations, use the following function to enable alarm interrupts, so that **RtcAlarmCallback** will be called when the alarm is not generated upon a timeout: Before performing alarm operations, use the **RtcAlarmInterruptEnable()** function to enable alarm interrupts, so that **RtcAlarmCallback** will be called when the alarm is not generated upon a timeout.
int32\_t RtcAlarmInterruptEnable\(DevHandle handle, enum RtcAlarmIndex alarmIndex, uint8\_t enable\); int32\_t RtcAlarmInterruptEnable\(DevHandle handle, enum RtcAlarmIndex alarmIndex, uint8\_t enable\);
**Table 9** Description of RtcAlarmInterruptEnable **Table 9** Description of RtcAlarmInterruptEnable
<a name="table1934615314159"></a> <a name="table1934615314159"></a>
<table><tbody><tr id="row5346853171519"><td class="cellrowborder" valign="top" width="21.36%"><p id="p143464533153"><a name="p143464533153"></a><a name="p143464533153"></a><strong id="b829913171576"><a name="b829913171576"></a><a name="b829913171576"></a>Parameter</strong></p> <table><tbody><tr id="row5346853171519"><td class="cellrowborder" valign="top" width="21.36%"><p id="p143464533153"><a name="p143464533153"></a><a name="p143464533153"></a><strong id="b829913171576"><a name="b829913171576"></a><a name="b829913171576"></a>Parameter</strong></p>
...@@ -544,7 +545,7 @@ int32\_t RtcAlarmInterruptEnable\(DevHandle handle, enum RtcAlarmIndex alarmInde ...@@ -544,7 +545,7 @@ int32\_t RtcAlarmInterruptEnable\(DevHandle handle, enum RtcAlarmIndex alarmInde
</tr> </tr>
<tr id="row2347115321514"><td class="cellrowborder" valign="top" width="21.36%"><p id="p324855163018"><a name="p324855163018"></a><a name="p324855163018"></a>Negative value</p> <tr id="row2347115321514"><td class="cellrowborder" valign="top" width="21.36%"><p id="p324855163018"><a name="p324855163018"></a><a name="p324855163018"></a>Negative value</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p7248857302"><a name="p7248857302"></a><a name="p7248857302"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.64%"><p id="p7248857302"><a name="p7248857302"></a><a name="p7248857302"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -562,11 +563,11 @@ if (ret != 0) { ...@@ -562,11 +563,11 @@ if (ret != 0) {
- Reading RTC external frequency - Reading RTC external frequency
Call the following function to read the frequency of the external crystal oscillator connected to the RTC driver: Call the **RtcGetFreq()** function to read the frequency of the external crystal oscillator connected to the RTC driver.
int32\_t RtcGetFreq\(DevHandle handle, uint32\_t \*freq\); int32\_t RtcGetFreq\(DevHandle handle, uint32\_t \*freq\);
**Table 10** Description of RtcGetFreq **Table 10** Description of RtcGetFreq
<a name="table125881625185"></a> <a name="table125881625185"></a>
<table><tbody><tr id="row1458811241816"><td class="cellrowborder" valign="top" width="21.36%"><p id="p658820241813"><a name="p658820241813"></a><a name="p658820241813"></a><strong id="b3300217175712"><a name="b3300217175712"></a><a name="b3300217175712"></a>Parameter</strong></p> <table><tbody><tr id="row1458811241816"><td class="cellrowborder" valign="top" width="21.36%"><p id="p658820241813"><a name="p658820241813"></a><a name="p658820241813"></a><strong id="b3300217175712"><a name="b3300217175712"></a><a name="b3300217175712"></a>Parameter</strong></p>
...@@ -596,7 +597,7 @@ int32\_t RtcGetFreq\(DevHandle handle, uint32\_t \*freq\); ...@@ -596,7 +597,7 @@ int32\_t RtcGetFreq\(DevHandle handle, uint32\_t \*freq\);
</tr> </tr>
<tr id="row135892261811"><td class="cellrowborder" valign="top" width="21.36%"><p id="p152692538292"><a name="p152692538292"></a><a name="p152692538292"></a>Negative value</p> <tr id="row135892261811"><td class="cellrowborder" valign="top" width="21.36%"><p id="p152692538292"><a name="p152692538292"></a><a name="p152692538292"></a>Negative value</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p327015313294"><a name="p327015313294"></a><a name="p327015313294"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.64%"><p id="p327015313294"><a name="p327015313294"></a><a name="p327015313294"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -615,11 +616,11 @@ if (ret != 0) { ...@@ -615,11 +616,11 @@ if (ret != 0) {
- Setting the frequency of the external crystal oscillator connected to the RTC driver - Setting the frequency of the external crystal oscillator connected to the RTC driver
Call the following function to set the frequency of the external crystal oscillator connected to the RTC driver: Call the **RtcSetFreq()** function to set the frequency of the external crystal oscillator connected to the RTC driver.
int32\_t RtcSetFreq\(DevHandle handle, uint32\_t freq\); int32\_t RtcSetFreq\(DevHandle handle, uint32\_t freq\);
**Table 11** Description of RtcSetFreq **Table 11** Description of RtcSetFreq
<a name="table1170124316209"></a> <a name="table1170124316209"></a>
<table><tbody><tr id="row270119432202"><td class="cellrowborder" valign="top" width="21.36%"><p id="p127011343132010"><a name="p127011343132010"></a><a name="p127011343132010"></a><strong id="b130031711578"><a name="b130031711578"></a><a name="b130031711578"></a>Parameter</strong></p> <table><tbody><tr id="row270119432202"><td class="cellrowborder" valign="top" width="21.36%"><p id="p127011343132010"><a name="p127011343132010"></a><a name="p127011343132010"></a><strong id="b130031711578"><a name="b130031711578"></a><a name="b130031711578"></a>Parameter</strong></p>
...@@ -649,7 +650,7 @@ int32\_t RtcSetFreq\(DevHandle handle, uint32\_t freq\); ...@@ -649,7 +650,7 @@ int32\_t RtcSetFreq\(DevHandle handle, uint32\_t freq\);
</tr> </tr>
<tr id="row10702194313201"><td class="cellrowborder" valign="top" width="21.36%"><p id="p165182216306"><a name="p165182216306"></a><a name="p165182216306"></a>Negative value</p> <tr id="row10702194313201"><td class="cellrowborder" valign="top" width="21.36%"><p id="p165182216306"><a name="p165182216306"></a><a name="p165182216306"></a>Negative value</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p651815219302"><a name="p651815219302"></a><a name="p651815219302"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.64%"><p id="p651815219302"><a name="p651815219302"></a><a name="p651815219302"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -668,11 +669,11 @@ if (ret != 0) { ...@@ -668,11 +669,11 @@ if (ret != 0) {
- Resetting the RTC driver - Resetting the RTC driver
Call the following function to perform a reset on the RTC driver \(after the reset, the registers are restored to the default values\): Call the **RtcReset()** function to perform a reset on the RTC driver \(after the reset, the registers are restored to the default values\).
int32\_t RtcReset\(DevHandle handle\); int32\_t RtcReset\(DevHandle handle\);
**Table 12** Description of RtcReset **Table 12** Description of RtcReset
<a name="table398973152517"></a> <a name="table398973152517"></a>
<table><tbody><tr id="row179899311254"><td class="cellrowborder" valign="top" width="21.36%"><p id="p199899314257"><a name="p199899314257"></a><a name="p199899314257"></a><strong id="b1330101719577"><a name="b1330101719577"></a><a name="b1330101719577"></a>Parameter</strong></p> <table><tbody><tr id="row179899311254"><td class="cellrowborder" valign="top" width="21.36%"><p id="p199899314257"><a name="p199899314257"></a><a name="p199899314257"></a><strong id="b1330101719577"><a name="b1330101719577"></a><a name="b1330101719577"></a>Parameter</strong></p>
...@@ -697,7 +698,7 @@ int32\_t RtcReset\(DevHandle handle\); ...@@ -697,7 +698,7 @@ int32\_t RtcReset\(DevHandle handle\);
</tr> </tr>
<tr id="row16990133152516"><td class="cellrowborder" valign="top" width="21.36%"><p id="p17536173573015"><a name="p17536173573015"></a><a name="p17536173573015"></a>Negative value</p> <tr id="row16990133152516"><td class="cellrowborder" valign="top" width="21.36%"><p id="p17536173573015"><a name="p17536173573015"></a><a name="p17536173573015"></a>Negative value</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p1153623503014"><a name="p1153623503014"></a><a name="p1153623503014"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.64%"><p id="p1153623503014"><a name="p1153623503014"></a><a name="p1153623503014"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -715,11 +716,11 @@ if (ret != 0) { ...@@ -715,11 +716,11 @@ if (ret != 0) {
- Reading the configuration of a custom RTC register - Reading the configuration of a custom RTC register
Call the following function to read the configuration of a custom RTC register based on the register index \(one index corresponds to one byte of the configuration value\): Call the **RtcReadReg()** function to read the configuration of a custom RTC register based on the register index \(one index corresponds to one byte of the configuration value\):
int32\_t RtcReadReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t \*value\); int32\_t RtcReadReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t \*value\);
**Table 13** Description of RtcReadReg **Table 13** Description of RtcReadReg
<a name="table1624674153319"></a> <a name="table1624674153319"></a>
<table><tbody><tr id="row92469423320"><td class="cellrowborder" valign="top" width="21.62%"><p id="p102461548331"><a name="p102461548331"></a><a name="p102461548331"></a><strong id="b73024170576"><a name="b73024170576"></a><a name="b73024170576"></a>Parameter</strong></p> <table><tbody><tr id="row92469423320"><td class="cellrowborder" valign="top" width="21.62%"><p id="p102461548331"><a name="p102461548331"></a><a name="p102461548331"></a><strong id="b73024170576"><a name="b73024170576"></a><a name="b73024170576"></a>Parameter</strong></p>
...@@ -754,7 +755,7 @@ int32\_t RtcReadReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t \*value\); ...@@ -754,7 +755,7 @@ int32\_t RtcReadReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t \*value\);
</tr> </tr>
<tr id="row1424719410333"><td class="cellrowborder" valign="top" width="21.62%"><p id="p112477417335"><a name="p112477417335"></a><a name="p112477417335"></a>Negative value</p> <tr id="row1424719410333"><td class="cellrowborder" valign="top" width="21.62%"><p id="p112477417335"><a name="p112477417335"></a><a name="p112477417335"></a>Negative value</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p7247547338"><a name="p7247547338"></a><a name="p7247547338"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p7247547338"><a name="p7247547338"></a><a name="p7247547338"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -774,11 +775,11 @@ if (ret != 0) { ...@@ -774,11 +775,11 @@ if (ret != 0) {
- Setting the configuration of a custom RTC register - Setting the configuration of a custom RTC register
Call the following function to configure a register based on the specified register index \(one index corresponds to one byte of the configuration value\): Call the **RtcWriteReg()** function to configure a register based on the specified register index \(one index corresponds to one byte of the configuration value\).
int32\_t RtcWriteReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t value\); int32\_t RtcWriteReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t value\);
**Table 14** Description of RtcWriteReg **Table 14** Description of RtcWriteReg
<a name="table1072216482360"></a> <a name="table1072216482360"></a>
<table><tbody><tr id="row187221648133611"><td class="cellrowborder" valign="top" width="21.62%"><p id="p2722184823617"><a name="p2722184823617"></a><a name="p2722184823617"></a><strong id="b530321795712"><a name="b530321795712"></a><a name="b530321795712"></a>Parameter</strong></p> <table><tbody><tr id="row187221648133611"><td class="cellrowborder" valign="top" width="21.62%"><p id="p2722184823617"><a name="p2722184823617"></a><a name="p2722184823617"></a><strong id="b530321795712"><a name="b530321795712"></a><a name="b530321795712"></a>Parameter</strong></p>
...@@ -813,7 +814,7 @@ int32\_t RtcWriteReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t value\); ...@@ -813,7 +814,7 @@ int32\_t RtcWriteReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t value\);
</tr> </tr>
<tr id="row127231848123615"><td class="cellrowborder" valign="top" width="21.62%"><p id="p197231148173613"><a name="p197231148173613"></a><a name="p197231148173613"></a>Negative value</p> <tr id="row127231848123615"><td class="cellrowborder" valign="top" width="21.62%"><p id="p197231148173613"><a name="p197231148173613"></a><a name="p197231148173613"></a>Negative value</p>
</td> </td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p16723134823618"><a name="p16723134823618"></a><a name="p16723134823618"></a>The operation fails.</p> <td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p16723134823618"><a name="p16723134823618"></a><a name="p16723134823618"></a>The operation failed.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -838,7 +839,7 @@ This section describes the process of using RTC APIs: ...@@ -838,7 +839,7 @@ This section describes the process of using RTC APIs:
1. During the OS startup, the HDF identifies the RTC component in the system. 1. During the OS startup, the HDF identifies the RTC component in the system.
2. The HDF initializes and creates the RTC device. 2. The HDF initializes and creates the RTC device.
3. You can perform operations on the RTC device by calling different APIs. 3. You can perform operations on the RTC device by calling different APIs.
4. Call the **RtcClose** function to release the device handle and device resources. 4. Call the **RtcClose** function to release the device handle and device resources.
Example: Example:
...@@ -926,5 +927,4 @@ void RtcTestSample(void) ...@@ -926,5 +927,4 @@ void RtcTestSample(void)
/* Release the RTC device handle. */ /* Release the RTC device handle. */
RtcClose(handle); RtcClose(handle);
} }
``` ```
\ No newline at end of file
# SDIO<a name="EN-US_TOPIC_0000001160653028"></a> # SDIO
## Overview<a name="section1155271783811"></a> ## Overview<a name="section1155271783811"></a>
- Secure Digital Input/Output \(SDIO\) is a peripheral interface evolved from the Secure Digital \(SD\) memory card interface. The SDIO interface is compatible with SD memory cards and can be connected to devices that support the SDIO interface. Secure Digital Input/Output \(SDIO\) is a peripheral interface evolved from the Secure Digital \(SD\) memory card interface. The SDIO interface is compatible with SD memory cards and can be connected to devices that support the SDIO interface.
- SDIO is widely used. Currently, many smartphones support SDIO, and many SDIO peripherals are developed for connections to smartphones. Common SDIO peripherals include WLAN, GPS, cameras, and Bluetooth.
- The SDIO bus has two ends, named host and device. All communication starts when the host sends a command. The device can communicate with the host as long as it can parse the command of the host. An SDIO host can connect to multiple devices, as shown in the figure below.
- CLK signal: clock signal sent from the host to the device SDIO is widely used. Currently, many smartphones support SDIO, and many SDIO peripherals are developed for connections to smartphones. Common SDIO peripherals include WLAN, GPS, cameras, and Bluetooth.
- VDD signal: power signal
- VSS signal: ground signal
- D0-3 signal: four data lines. The DAT1 signal cable is multiplexed as the interrupt line. In 1-bit mode, DAT0 is used to transmit data. In 4-bit mode, DAT0 to DAT3 are used to transmit data.
- CMD signal: used by the host to send commands and the device to respond to commands.
**Figure 1** Connections between the host and devices in SDIO<a name="fig1185316527498"></a> The SDIO bus has two ends, named host and device. All communication starts when the host sends a command. The device can communicate with the host as long as it can parse the command of the host. An SDIO host can connect to multiple devices, as shown in the figure below.
- CLK signal: clock signal sent from the host to the device
- VDD signal: power signal
- VSS signal: ground signal
- D0-3 signal: four data lines. The DAT1 signal cable is multiplexed as the interrupt line. In 1-bit mode, DAT0 is used to transmit data. In 4-bit mode, DAT0 to DAT3 are used to transmit data.
- CMD signal: used by the host to send commands and the device to respond to commands.
**Figure 1** Connections between the host and devices in SDIO
![](figures/en-us_image_0000001160971556.png) ![](figures/en-us_image_0000001160971556.png)
- The SDIO interface defines a set of common methods for operating an SDIO device, including opening and closing an SDIO controller, exclusively claiming and releasing the host, enabling and disabling devices, claiming and releasing an SDIO IRQ, reading and writing data based on SDIO, and obtaining and setting common information. The SDIO interface defines a set of common methods for operating an SDIO device, including opening and closing an SDIO controller, exclusively claiming and releasing the host, enabling and disabling devices, claiming and releasing an SDIO IRQ, reading and writing data based on SDIO, and obtaining and setting common information.
## Available APIs<a name="section12601496259"></a> ## Available APIs<a name="section12601496259"></a>
**Table 1** APIs available for the SDIO driver **Table 1** APIs available for the SDIO driver
<a name="table1731550155318"></a> <a name="table1731550155318"></a>
<table><thead align="left"><tr id="row1625342317507"><th class="cellrowborder" valign="top" width="21.07%" id="mcps1.2.4.1.1"><p id="p1779183435016"><a name="p1779183435016"></a><a name="p1779183435016"></a>Capability</p> <table><thead align="left"><tr id="row1625342317507"><th class="cellrowborder" valign="top" width="21.07%" id="mcps1.2.4.1.1"><p id="p1779183435016"><a name="p1779183435016"></a><a name="p1779183435016"></a>Capability</p>
...@@ -141,27 +141,29 @@ ...@@ -141,27 +141,29 @@
</tbody> </tbody>
</table> </table>
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE:**<br>
>All functions provided in this document can be called only in kernel mode. >All functions provided in this document can be called only in kernel mode.
## Usage Guidelines<a name="section1878939192515"></a> ## Usage Guidelines<a name="section1878939192515"></a>
### How to Use<a name="section1490685512255"></a> ### How to Use<a name="section1490685512255"></a>
[Figure 2](#fig1343742311264) illustrates the process of using an SDIO. The figure below illustrates how to use the APIs.
**Figure 2** Using SDIO driver APIs
**Figure 2** Process of using an SDIO<a name="fig1343742311264"></a>
![](figures/en-us_image_0000001206291517.png) ![](figures/using-SDIO-process.png)
### Opening an SDIO Controller<a name="section10782428132616"></a> ### Opening an SDIO Controller<a name="section10782428132616"></a>
Before performing SDIO communication, obtain the device handle of an SDIO controller by calling **SdioOpen**. This function returns the device handle of the SDIO controller with a specified bus number. Before performing SDIO communication, obtain the device handle of an SDIO controller by calling **SdioOpen**. This function returns the device handle of the SDIO controller with a specified bus number.
DevHandle SdioOpen\(int16\_t mmcBusNum, struct SdioFunctionConfig \*config\); DevHandle SdioOpen\(int16\_t mmcBusNum, struct SdioFunctionConfig \*config\);
**Table 2** Parameters and return values of SdioOpen **Table 2** Parameters and return values of SdioOpen
<a name="table1036944152712"></a> <a name="table1036944152712"></a>
<table><thead align="left"><tr id="row4370114192717"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p737074112720"><a name="p737074112720"></a><a name="p737074112720"></a>Parameter</p> <table><thead align="left"><tr id="row4370114192717"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p737074112720"><a name="p737074112720"></a><a name="p737074112720"></a>Parameter</p>
...@@ -219,7 +221,7 @@ After obtaining the device handle of an SDIO controller, exclusively claim the h ...@@ -219,7 +221,7 @@ After obtaining the device handle of an SDIO controller, exclusively claim the h
void SdioClaimHost\(DevHandle handle\); void SdioClaimHost\(DevHandle handle\);
**Table 3** Parameter description of SdioClaimHost **Table 3** Parameter description of SdioClaimHost
<a name="table192822447271"></a> <a name="table192822447271"></a>
<table><thead align="left"><tr id="row192829443279"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1128284452713"><a name="p1128284452713"></a><a name="p1128284452713"></a>Parameter</p> <table><thead align="left"><tr id="row192829443279"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1128284452713"><a name="p1128284452713"></a><a name="p1128284452713"></a>Parameter</p>
...@@ -248,7 +250,7 @@ Before accessing a register, enable the SDIO device. ...@@ -248,7 +250,7 @@ Before accessing a register, enable the SDIO device.
int32\_t SdioEnableFunc\(DevHandle handle\); int32\_t SdioEnableFunc\(DevHandle handle\);
**Table 4** Parameters and return values of SdioEnableFunc **Table 4** Parameters and return values of SdioEnableFunc
<a name="table144881047485"></a> <a name="table144881047485"></a>
<table><thead align="left"><tr id="row8487204184815"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1648611415486"><a name="p1648611415486"></a><a name="p1648611415486"></a>Parameter</p> <table><thead align="left"><tr id="row8487204184815"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1648611415486"><a name="p1648611415486"></a><a name="p1648611415486"></a>Parameter</p>
...@@ -297,7 +299,7 @@ Before SDIO communication, claim an SDIO IRQ. ...@@ -297,7 +299,7 @@ Before SDIO communication, claim an SDIO IRQ.
int32\_t SdioClaimIrq\(DevHandle handle, SdioIrqHandler \*handler\); int32\_t SdioClaimIrq\(DevHandle handle, SdioIrqHandler \*handler\);
**Table 5** Parameters and return values of SdioClaimIrq **Table 5** Parameters and return values of SdioClaimIrq
<a name="table1149014114815"></a> <a name="table1149014114815"></a>
<table><thead align="left"><tr id="row114891042488"><th class="cellrowborder" valign="top" width="49.980000000000004%" id="mcps1.2.3.1.1"><p id="p1348864164811"><a name="p1348864164811"></a><a name="p1348864164811"></a>Parameter</p> <table><thead align="left"><tr id="row114891042488"><th class="cellrowborder" valign="top" width="49.980000000000004%" id="mcps1.2.3.1.1"><p id="p1348864164811"><a name="p1348864164811"></a><a name="p1348864164811"></a>Parameter</p>
...@@ -357,13 +359,13 @@ if (ret != 0) { ...@@ -357,13 +359,13 @@ if (ret != 0) {
### Performing SDIO Communication<a name="section85661522153420"></a> ### Performing SDIO Communication<a name="section85661522153420"></a>
- Incrementally write a given length of data into the SDIO device. - Incrementally write a given length of data into the SDIO device.
The corresponding function is as follows: The corresponding function is as follows:
int32\_t SdioWriteBytes\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\); int32\_t SdioWriteBytes\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\);
**Table 6** Parameters and return values of SdioWriteBytes **Table 6** Parameters and return values of SdioWriteBytes
<a name="table6887174174111"></a> <a name="table6887174174111"></a>
<table><thead align="left"><tr id="row10887144111419"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p181381751164113"><a name="p181381751164113"></a><a name="p181381751164113"></a>Parameter</p> <table><thead align="left"><tr id="row10887144111419"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p181381751164113"><a name="p181381751164113"></a><a name="p181381751164113"></a>Parameter</p>
...@@ -423,13 +425,13 @@ if (ret != 0) { ...@@ -423,13 +425,13 @@ if (ret != 0) {
} }
``` ```
- Incrementally read a given length of data from the SDIO device. - Incrementally read a given length of data from the SDIO device.
The corresponding function is as follows: The corresponding function is as follows:
int32\_t SdioReadBytes\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\); int32\_t SdioReadBytes\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\);
**Table 7** Parameters and return values of SdioReadBytes **Table 7** Parameters and return values of SdioReadBytes
<a name="table5783755152110"></a> <a name="table5783755152110"></a>
<table><thead align="left"><tr id="row19783355162116"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p635754142212"><a name="p635754142212"></a><a name="p635754142212"></a>Parameter</p> <table><thead align="left"><tr id="row19783355162116"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p635754142212"><a name="p635754142212"></a><a name="p635754142212"></a>Parameter</p>
...@@ -489,13 +491,13 @@ if (ret != 0) { ...@@ -489,13 +491,13 @@ if (ret != 0) {
} }
``` ```
- Write a given length of data into the fixed address of an SDIO device. - Write a given length of data into the fixed address of an SDIO device.
The corresponding function is as follows: The corresponding function is as follows:
int32\_t SdioWriteBytesToFixedAddr\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size, uint32\_t scatterLen\); int32\_t SdioWriteBytesToFixedAddr\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size, uint32\_t scatterLen\);
**Table 8** Parameters and return values of SdioWriteBytesToFixedAddr **Table 8** Parameters and return values of SdioWriteBytesToFixedAddr
<a name="table1982918113010"></a> <a name="table1982918113010"></a>
<table><thead align="left"><tr id="row1582911114010"><th class="cellrowborder" valign="top" width="48.43%" id="mcps1.2.3.1.1"><p id="p28301411903"><a name="p28301411903"></a><a name="p28301411903"></a>Parameter</p> <table><thead align="left"><tr id="row1582911114010"><th class="cellrowborder" valign="top" width="48.43%" id="mcps1.2.3.1.1"><p id="p28301411903"><a name="p28301411903"></a><a name="p28301411903"></a>Parameter</p>
...@@ -560,13 +562,13 @@ if (ret != 0) { ...@@ -560,13 +562,13 @@ if (ret != 0) {
} }
``` ```
- Read a given length of data from the fixed address of an SDIO device. - Read a given length of data from the fixed address of an SDIO device.
The corresponding function is as follows: The corresponding function is as follows:
int32\_t SdioReadBytesFromFixedAddr\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size, uint32\_t scatterLen\); int32\_t SdioReadBytesFromFixedAddr\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size, uint32\_t scatterLen\);
**Table 9** Parameters and return values of SdioReadBytesFromFixedAddr **Table 9** Parameters and return values of SdioReadBytesFromFixedAddr
<a name="table2724132220115"></a> <a name="table2724132220115"></a>
<table><thead align="left"><tr id="row8724142214115"><th class="cellrowborder" valign="top" width="48.699999999999996%" id="mcps1.2.3.1.1"><p id="p16752055131112"><a name="p16752055131112"></a><a name="p16752055131112"></a>Parameter</p> <table><thead align="left"><tr id="row8724142214115"><th class="cellrowborder" valign="top" width="48.699999999999996%" id="mcps1.2.3.1.1"><p id="p16752055131112"><a name="p16752055131112"></a><a name="p16752055131112"></a>Parameter</p>
...@@ -632,13 +634,13 @@ if (ret != 0) { ...@@ -632,13 +634,13 @@ if (ret != 0) {
``` ```
- Writes a given length of data into the address space of SDIO function 0. - Writes a given length of data into the address space of SDIO function 0.
Currently, only 1-byte data can be written. The corresponding function is as follows: Currently, only 1-byte data can be written. The corresponding function is as follows:
int32\_t SdioWriteBytesToFunc0\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\); int32\_t SdioWriteBytesToFunc0\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\);
**Table 10** Parameters and return values of SdioWriteBytesToFunc0 **Table 10** Parameters and return values of SdioWriteBytesToFunc0
<a name="table5339151811112"></a> <a name="table5339151811112"></a>
<table><thead align="left"><tr id="row2033991881120"><th class="cellrowborder" valign="top" width="49.94%" id="mcps1.2.3.1.1"><p id="p1116916499117"><a name="p1116916499117"></a><a name="p1116916499117"></a>Parameter</p> <table><thead align="left"><tr id="row2033991881120"><th class="cellrowborder" valign="top" width="49.94%" id="mcps1.2.3.1.1"><p id="p1116916499117"><a name="p1116916499117"></a><a name="p1116916499117"></a>Parameter</p>
...@@ -697,13 +699,13 @@ if (ret != 0) { ...@@ -697,13 +699,13 @@ if (ret != 0) {
} }
``` ```
- Reads a given length of data from the address space of SDIO function 0. - Reads a given length of data from the address space of SDIO function 0.
Currently, only 1-byte data can be read. The corresponding function is as follows: Currently, only 1-byte data can be read. The corresponding function is as follows:
int32\_t SdioReadBytesFromFunc0\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\); int32\_t SdioReadBytesFromFunc0\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\);
**Table 11** Parameters and return values of SdioReadBytesFromFunc0 **Table 11** Parameters and return values of SdioReadBytesFromFunc0
<a name="table1071931161814"></a> <a name="table1071931161814"></a>
<table><thead align="left"><tr id="row771918171819"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p71291418171813"><a name="p71291418171813"></a><a name="p71291418171813"></a>Parameter</p> <table><thead align="left"><tr id="row771918171819"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p71291418171813"><a name="p71291418171813"></a><a name="p71291418171813"></a>Parameter</p>
...@@ -768,7 +770,7 @@ After the SDIO communication, release the SDIO IRQ. ...@@ -768,7 +770,7 @@ After the SDIO communication, release the SDIO IRQ.
int32\_t SdioReleaseIrq\(DevHandle handle\); int32\_t SdioReleaseIrq\(DevHandle handle\);
**Table 12** Parameters and return values of SdioReleaseIrq **Table 12** Parameters and return values of SdioReleaseIrq
<a name="table165006412481"></a> <a name="table165006412481"></a>
<table><thead align="left"><tr id="row15499849482"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1549964114814"><a name="p1549964114814"></a><a name="p1549964114814"></a>Parameter</p> <table><thead align="left"><tr id="row15499849482"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1549964114814"><a name="p1549964114814"></a><a name="p1549964114814"></a>Parameter</p>
...@@ -817,7 +819,7 @@ After the SDIO communication, disable the SDIO device. ...@@ -817,7 +819,7 @@ After the SDIO communication, disable the SDIO device.
int32\_t SdioDisableFunc\(DevHandle handle\); int32\_t SdioDisableFunc\(DevHandle handle\);
**Table 13** Parameters and return values of SdioDisableFunc **Table 13** Parameters and return values of SdioDisableFunc
<a name="table25012415481"></a> <a name="table25012415481"></a>
<table><thead align="left"><tr id="row1050010474810"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p05002419488"><a name="p05002419488"></a><a name="p05002419488"></a>Parameter</p> <table><thead align="left"><tr id="row1050010474810"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p05002419488"><a name="p05002419488"></a><a name="p05002419488"></a>Parameter</p>
...@@ -866,7 +868,7 @@ After the SDIO communication, release the exclusively claimed host. ...@@ -866,7 +868,7 @@ After the SDIO communication, release the exclusively claimed host.
void SdioReleaseHost\(DevHandle handle\); void SdioReleaseHost\(DevHandle handle\);
**Table 14** Parameter description of SdioReleaseHost **Table 14** Parameter description of SdioReleaseHost
<a name="table1350214164813"></a> <a name="table1350214164813"></a>
<table><thead align="left"><tr id="row6502134194814"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p18501945486"><a name="p18501945486"></a><a name="p18501945486"></a>Parameter</p> <table><thead align="left"><tr id="row6502134194814"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p18501945486"><a name="p18501945486"></a><a name="p18501945486"></a>Parameter</p>
...@@ -897,7 +899,7 @@ void SdioClose\(DevHandle handle\); ...@@ -897,7 +899,7 @@ void SdioClose\(DevHandle handle\);
This function releases the resources requested. This function releases the resources requested.
**Table 15** Parameter description of SdioClose **Table 15** Parameter description of SdioClose
<a name="table950324124815"></a> <a name="table950324124815"></a>
<table><thead align="left"><tr id="row1050213424819"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p18502134194818"><a name="p18502134194818"></a><a name="p18502134194818"></a>Parameter</p> <table><thead align="left"><tr id="row1050213424819"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p18502134194818"><a name="p18502134194818"></a><a name="p18502134194818"></a>Parameter</p>
...@@ -1047,5 +1049,4 @@ ENABLE_ERR: ...@@ -1047,5 +1049,4 @@ ENABLE_ERR:
/* Close an SDIO controller. */ /* Close an SDIO controller. */
SdioClose(handle); SdioClose(handle);
} }
``` ```
\ No newline at end of file
...@@ -2,46 +2,46 @@ ...@@ -2,46 +2,46 @@
## Overview<a name="section193356154511"></a> ## Overview<a name="section193356154511"></a>
- Serial Peripheral Interface \(SPI\) is a serial bus specification used for high-speed, full-duplex, and synchronous communication. Serial Peripheral Interface \(SPI\) is a serial bus specification used for high-speed, full-duplex, and synchronous communication.
- SPI is developed by Motorola. It is commonly used for communication with flash memory, real-time clocks, sensors, and analog-to-digital \(A/D\) converters. SPI is developed by Motorola. It is commonly used for communication with flash memory, real-time clocks, sensors, and analog-to-digital \(A/D\) converters.
- SPI works in controller/device mode. Generally, there is one SPI controller that controls one or more SPI devices. They are connected via four wires: SPI works in controller/device mode. Generally, there is one SPI controller that controls one or more SPI devices. They are connected via four wires:
- SCLK: clock signals output from the SPI controller - SCLK: clock signals output from the SPI controller
- MOSI: data output from the SPI controller and input into an SPI device - MOSI: data output from the SPI controller and input into an SPI device
- MISO: data output from an SPI device and input into the SPI controller - MISO: data output from an SPI device and input into the SPI controller
- CS: signals enabled by an SPI device and controlled by the SPI controller - CS: signals enabled by an SPI device and controlled by the SPI controller
- [Figure 1](#fig89085710359) shows the connection between one SPI controller and two SPI devices \(device A and device B\). In this figure, device A and device B share three pins \(SCLK, MISO, and MOSI\) of the controller. CS0 of device A and CS1 of device B are connected to CS0 and CS1 of the controller, respectively. [Figure 1](#fig89085710359) shows the connection between one SPI controller and two SPI devices \(device A and device B\). In this figure, device A and device B share three pins \(SCLK, MISO, and MOSI\) of the controller. CS0 of device A and CS1 of device B are connected to CS0 and CS1 of the controller, respectively.
**Figure 1** SPI controller/device connection<a name="fig89085710359"></a> **Figure 1** SPI controller/device connection<a name="fig89085710359"></a>
![](figures/spi-controller-device-connection.png "spi-controller-device-connection") ![](figures/spi-controller-device-connection.png "spi-controller-device-connection")
- SPI communication is usually initiated by the SPI controller and is operated as follows: SPI communication is usually initiated by the SPI controller and is operated as follows:
1. A single SPI device is selected at a time via the CS to communicate with the SPI controller. 1. A single SPI device is selected at a time via the CS to communicate with the SPI controller.
2. Clock signals are provided for the selected SPI device via the SCLK. 2. Clock signals are provided for the selected SPI device via the SCLK.
3. The SPI controller sends data to SPI devices via the MOSI, and receives data from SPI devices via the MISO. 3. The SPI controller sends data to SPI devices via the MOSI, and receives data from SPI devices via the MISO.
- SPI can work in one of the following four modes, equivalent to one of the four possible states for Clock Polarity \(CPOL\) and Clock Phase \(CPHA\): - SPI can work in one of the following four modes, equivalent to one of the four possible states for Clock Polarity \(CPOL\) and Clock Phase \(CPHA\):
- If both CPOL and CPHA are **0**, the clock signal level is low in the idle state and data is sampled on the first clock edge. - If both CPOL and CPHA are **0**, the clock signal level is low in the idle state and data is sampled on the first clock edge.
- If CPOL is **0** and CPHA is **1**, the clock signal level is low in the idle state and data is sampled on the second clock edge. - If CPOL is **0** and CPHA is **1**, the clock signal level is low in the idle state and data is sampled on the second clock edge.
- If CPOL is **1** and CPHA is **0**, the clock signal level is high in the idle state and data is sampled on the first clock edge. - If CPOL is **1** and CPHA is **0**, the clock signal level is high in the idle state and data is sampled on the first clock edge.
- If both CPOL and CPHA are **1**, the clock signal level is high in the idle state and data is sampled on the second clock edge. - If both CPOL and CPHA are **1**, the clock signal level is high in the idle state and data is sampled on the second clock edge.
- SPI defines a set of common functions for operating an SPI device, including those for: - SPI defines a set of common functions for operating an SPI device, including those for:
- Obtaining and releasing the handle of an SPI device. - Obtaining and releasing the handle of an SPI device.
- Reading or writing data of a specified length from or into an SPI device. - Reading or writing data of a specified length from or into an SPI device.
- Customizing data reading or writing via **SpiMsg**. - Customizing data reading or writing via **SpiMsg**.
- Obtaining and setting SPI device configuration parameters. - Obtaining and setting SPI device configuration parameters.
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>Currently, these functions are only applicable in the communication initiated by the SPI controller. >Currently, these functions are only applicable in the communication initiated by the SPI controller.
## Available APIs<a name="section1325964832615"></a> ## Available APIs<a name="section1325964832615"></a>
**Table 1** APIs for the SPI driver **Table 1** APIs for the SPI driver
<a name="table1731550155318"></a> <a name="table1731550155318"></a>
<table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" align="left" valign="top" width="20.857914208579142%" id="mcps1.2.4.1.1"><p id="p641050105320"><a name="p641050105320"></a><a name="p641050105320"></a><strong id="b17365506414"><a name="b17365506414"></a><a name="b17365506414"></a>Capability</strong></p> <table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" align="left" valign="top" width="20.857914208579142%" id="mcps1.2.4.1.1"><p id="p641050105320"><a name="p641050105320"></a><a name="p641050105320"></a><strong id="b17365506414"><a name="b17365506414"></a><a name="b17365506414"></a>Capability</strong></p>
...@@ -104,18 +104,18 @@ ...@@ -104,18 +104,18 @@
### How to Use<a name="section32846814820"></a> ### How to Use<a name="section32846814820"></a>
[Figure 2](#fig1586912310348) shows the process of using an SPI device. The figure below illustrates how to use the APIs.
**Figure 2** Process of using an SPI device<a name="fig1586912310348"></a> **Figure 2** Using SPI driver APIs<a name="fig1586912310348"></a>
![](figures/process-of-using-an-spi-device.png "process-of-using-an-spi-device") ![](figures/using-spi-process.png "process-of-using-an-spi-device")
### Obtaining an SPI Device Handle<a name="section1927265711481"></a> ### Obtaining an SPI Device Handle<a name="section1927265711481"></a>
Before performing SPI communication, obtain an SPI device handle by calling **SpiOpen**. This function returns an SPI device handle with a specified bus number and CS number. Before performing SPI communication, obtain an SPI device handle by calling **SpiOpen**. This function returns an SPI device handle with a specified bus number and CS number.
DevHandle SpiOpen\(const struct SpiDevInfo \*info\); DevHandle SpiOpen\(const struct SpiDevInfo \*info\);
**Table 2** Description of SpiOpen **Table 2** Description of SpiOpen
<a name="table7603619123820"></a> <a name="table7603619123820"></a>
<table><tbody><tr id="row1060351914386"><td class="cellrowborder" valign="top" width="50%"><p id="p14603181917382"><a name="p14603181917382"></a><a name="p14603181917382"></a><strong id="b139290298482"><a name="b139290298482"></a><a name="b139290298482"></a>Parameter</strong></p> <table><tbody><tr id="row1060351914386"><td class="cellrowborder" valign="top" width="50%"><p id="p14603181917382"><a name="p14603181917382"></a><a name="p14603181917382"></a><strong id="b139290298482"><a name="b139290298482"></a><a name="b139290298482"></a>Parameter</strong></p>
...@@ -146,7 +146,7 @@ DevHandle SpiOpen\(const struct SpiDevInfo \*info\); ...@@ -146,7 +146,7 @@ DevHandle SpiOpen\(const struct SpiDevInfo \*info\);
</tbody> </tbody>
</table> </table>
The following example shows how to obtain an SPI device handle based on the assumption that both the bus number and CS number of the SPI device are **0**. The following example shows how to obtain an SPI device handle based on the assumption that both the bus number and CS number of the SPI device are **0**.
``` ```
struct SpiDevInfo spiDevinfo; /* SPI device descriptor */ struct SpiDevInfo spiDevinfo; /* SPI device descriptor */
...@@ -168,7 +168,7 @@ After obtaining the SPI device handle, obtain the SPI device configuration param ...@@ -168,7 +168,7 @@ After obtaining the SPI device handle, obtain the SPI device configuration param
int32\_t SpiGetCfg\(DevHandle handle, struct SpiCfg \*cfg\); int32\_t SpiGetCfg\(DevHandle handle, struct SpiCfg \*cfg\);
**Table 3** Description of SpiGetCfg **Table 3** Description of SpiGetCfg
<a name="table14209152141313"></a> <a name="table14209152141313"></a>
<table><tbody><tr id="row1420918529133"><td class="cellrowborder" valign="top" width="50%"><p id="p42091852141314"><a name="p42091852141314"></a><a name="p42091852141314"></a><strong id="b6279123012486"><a name="b6279123012486"></a><a name="b6279123012486"></a>Parameter</strong></p> <table><tbody><tr id="row1420918529133"><td class="cellrowborder" valign="top" width="50%"><p id="p42091852141314"><a name="p42091852141314"></a><a name="p42091852141314"></a><strong id="b6279123012486"><a name="b6279123012486"></a><a name="b6279123012486"></a>Parameter</strong></p>
...@@ -219,7 +219,7 @@ After obtaining the SPI device handle, set SPI device configuration parameters b ...@@ -219,7 +219,7 @@ After obtaining the SPI device handle, set SPI device configuration parameters b
int32\_t SpiSetCfg\(DevHandle handle, struct SpiCfg \*cfg\); int32\_t SpiSetCfg\(DevHandle handle, struct SpiCfg \*cfg\);
**Table 4** Description of SpiSetCfg **Table 4** Description of SpiSetCfg
<a name="table219052945210"></a> <a name="table219052945210"></a>
<table><tbody><tr id="row14191192918522"><td class="cellrowborder" valign="top" width="50%"><p id="p17424155016529"><a name="p17424155016529"></a><a name="p17424155016529"></a><strong id="b11281163011480"><a name="b11281163011480"></a><a name="b11281163011480"></a>Parameter</strong></p> <table><tbody><tr id="row14191192918522"><td class="cellrowborder" valign="top" width="50%"><p id="p17424155016529"><a name="p17424155016529"></a><a name="p17424155016529"></a><strong id="b11281163011480"><a name="b11281163011480"></a><a name="b11281163011480"></a>Parameter</strong></p>
...@@ -276,7 +276,7 @@ To write data into an SPI device only once, call the following function: ...@@ -276,7 +276,7 @@ To write data into an SPI device only once, call the following function:
int32\_t SpiWrite\(DevHandle handle, uint8\_t \*buf, uint32\_t len\); int32\_t SpiWrite\(DevHandle handle, uint8\_t \*buf, uint32\_t len\);
**Table 5** Description of SpiWrite **Table 5** Description of SpiWrite
<a name="table1018490043"></a> <a name="table1018490043"></a>
<table><tbody><tr id="row31848013417"><td class="cellrowborder" valign="top" width="50%"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b42810303484"><a name="b42810303484"></a><a name="b42810303484"></a>Parameter</strong></p> <table><tbody><tr id="row31848013417"><td class="cellrowborder" valign="top" width="50%"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b42810303484"><a name="b42810303484"></a><a name="b42810303484"></a>Parameter</strong></p>
...@@ -333,7 +333,7 @@ To read data from an SPI device only once, call the following function: ...@@ -333,7 +333,7 @@ To read data from an SPI device only once, call the following function:
int32\_t SpiRead\(DevHandle handle, uint8\_t \*buf, uint32\_t len\); int32\_t SpiRead\(DevHandle handle, uint8\_t \*buf, uint32\_t len\);
**Table 6** Description of SpiRead **Table 6** Description of SpiRead
<a name="table0265191412124"></a> <a name="table0265191412124"></a>
<table><tbody><tr id="row42651914141213"><td class="cellrowborder" valign="top" width="50%"><p id="p1483184123"><a name="p1483184123"></a><a name="p1483184123"></a><strong id="b528223019480"><a name="b528223019480"></a><a name="b528223019480"></a>Parameter</strong></p> <table><tbody><tr id="row42651914141213"><td class="cellrowborder" valign="top" width="50%"><p id="p1483184123"><a name="p1483184123"></a><a name="p1483184123"></a><strong id="b528223019480"><a name="b528223019480"></a><a name="b528223019480"></a>Parameter</strong></p>
...@@ -390,7 +390,7 @@ To launch a custom transfer, call the following function: ...@@ -390,7 +390,7 @@ To launch a custom transfer, call the following function:
int32\_t SpiTransfer\(DevHandle handle, struct SpiMsg \*msgs, uint32\_t count\); int32\_t SpiTransfer\(DevHandle handle, struct SpiMsg \*msgs, uint32\_t count\);
**Table 7** Description of SpiTransfer **Table 7** Description of SpiTransfer
<a name="table1934414174212"></a> <a name="table1934414174212"></a>
<table><tbody><tr id="row1134415176216"><td class="cellrowborder" valign="top" width="50%"><p id="p13295152320217"><a name="p13295152320217"></a><a name="p13295152320217"></a><strong id="b1628393012482"><a name="b1628393012482"></a><a name="b1628393012482"></a>Parameter</strong></p> <table><tbody><tr id="row1134415176216"><td class="cellrowborder" valign="top" width="50%"><p id="p13295152320217"><a name="p13295152320217"></a><a name="p13295152320217"></a><strong id="b1628393012482"><a name="b1628393012482"></a><a name="b1628393012482"></a>Parameter</strong></p>
...@@ -457,7 +457,7 @@ void SpiClose\(DevHandle handle\); ...@@ -457,7 +457,7 @@ void SpiClose\(DevHandle handle\);
This function will release the resources previously obtained. This function will release the resources previously obtained.
**Table 8** Description of SpiClose **Table 8** Description of SpiClose
<a name="table72517953115"></a> <a name="table72517953115"></a>
<table><tbody><tr id="row1525793312"><td class="cellrowborder" valign="top" width="50%"><p id="p115402031153111"><a name="p115402031153111"></a><a name="p115402031153111"></a><strong id="b1728493044820"><a name="b1728493044820"></a><a name="b1728493044820"></a>Parameter</strong></p> <table><tbody><tr id="row1525793312"><td class="cellrowborder" valign="top" width="50%"><p id="p115402031153111"><a name="p115402031153111"></a><a name="p115402031153111"></a><strong id="b1728493044820"><a name="b1728493044820"></a><a name="b1728493044820"></a>Parameter</strong></p>
...@@ -545,5 +545,4 @@ err: ...@@ -545,5 +545,4 @@ err:
/* Destroy the SPI device handle. */ /* Destroy the SPI device handle. */
SpiClose(spiHandle); SpiClose(spiHandle);
} }
``` ```
\ No newline at end of file
...@@ -2,27 +2,29 @@ ...@@ -2,27 +2,29 @@
## Overview<a name="section833012453535"></a> ## Overview<a name="section833012453535"></a>
- The Universal Asynchronous Receiver/Transmitter \(UART\) is a universal serial data bus used for asynchronous communication. It enables bi-directional communication between devices in full-duplex mode. The Universal Asynchronous Receiver/Transmitter \(UART\) is a universal serial data bus used for asynchronous communication. It enables bi-directional communication between devices in full-duplex mode.
- UART is widely used to print information for debugging or to connect to various external modules such as GPS and Bluetooth. UART is widely used to print information for debugging or to connect to various external modules such as GPS and Bluetooth.
- A UART is connected to other modules through two wires \(as shown in [Figure 1](#fig68294715408)\) or four wires \(as shown in [Figure 2](#fig179241542163112)\). A UART is connected to other modules through two wires \(as shown in [Figure 1](#fig68294715408)\) or four wires \(as shown in [Figure 2](#fig179241542163112)\).
- TX: TX pin of the transmitting UART. It is connected to the RX pin of the peer UART. - TX: TX pin of the transmitting UART. It is connected to the RX pin of the peer UART.
- RX: RX pin of the receiving UART. It is connected to the TX pin of the peer UART. - RX: RX pin of the receiving UART. It is connected to the TX pin of the peer UART.
- RTS: Request to Send signal pin. It is connected to the CTS pin of the peer UART and is used to indicate whether the local UART is ready to receive data. - RTS: Request to Send signal pin. It is connected to the CTS pin of the peer UART and is used to indicate whether the local UART is ready to receive data.
- CTS: Clear to Send signal pin. It is connected to the RTS pin of the peer UART and is used to indicate whether the local UART is allowed to send data to the peer end. - CTS: Clear to Send signal pin. It is connected to the RTS pin of the peer UART and is used to indicate whether the local UART is allowed to send data to the peer end.
**Figure 1** 2-wire UART communication<a name="fig68294715408"></a> **Figure 1** 2-wire UART communication<a name="fig68294715408"></a>
![](figures/2-wire-uart-communication.png "2-wire-uart-communication") ![](figures/2-wire-uart-communication.png "2-wire-uart-communication")
**Figure 2** 4-wire UART communication<a name="fig179241542163112"></a> **Figure 2** 4-wire UART communication<a name="fig179241542163112"></a>
![](figures/4-wire-uart-communication.png "4-wire-uart-communication") ![](figures/4-wire-uart-communication.png "4-wire-uart-communication")
- The transmitting and receiving UARTs must ensure that they have the same settings on particular attributes such as the baud rate and data format \(start bit, data bit, parity bit, and stop bit\) before they start to communicate. During data transmission, a UART sends data to the peer end over the TX pin and receives data from the peer end over the RX pin. When the size of the buffer used by a UART for storing received data reaches the preset threshold, the RTS signal of the UART changes to **1** \(data cannot be received\), and the peer UART stops sending data to it because its CTS signal does not allow it to send data. The transmitting and receiving UARTs must ensure that they have the same settings on particular attributes such as the baud rate and data format \(start bit, data bit, parity bit, and stop bit\) before they start to communicate. During data transmission, a UART sends data to the peer end over the TX pin and receives data from the peer end over the RX pin. When the size of the buffer used by a UART for storing received data reaches the preset threshold, the RTS signal of the UART changes to **1** \(data cannot be received\), and the peer UART stops sending data to it because its CTS signal does not allow it to send data.
- The UART interface defines a set of common functions for operating a UART port, including obtaining and releasing device handles, reading and writing data of a specified length, and obtaining and setting the baud rate, as well as the device attributes.
## Available APIs<a name="section1928742202715"></a> ## Available APIs<a name="section1928742202715"></a>
**Table 1** APIs for the UART driver The UART interface defines a set of common functions for operating a UART port, including obtaining and releasing device handles, reading and writing data of a specified length, and obtaining and setting the baud rate, as well as the device attributes.
**Table 1** APIs for the UART driver
<a name="table1731550155318"></a> <a name="table1731550155318"></a>
<table><thead align="left"><tr id="row1223152681611"><th class="cellrowborder" valign="top" width="26.619999999999997%" id="mcps1.2.4.1.1"><p id="p210413571619"><a name="p210413571619"></a><a name="p210413571619"></a><strong id="b4100105545211"><a name="b4100105545211"></a><a name="b4100105545211"></a>Capability</strong></p> <table><thead align="left"><tr id="row1223152681611"><th class="cellrowborder" valign="top" width="26.619999999999997%" id="mcps1.2.4.1.1"><p id="p210413571619"><a name="p210413571619"></a><a name="p210413571619"></a><strong id="b4100105545211"><a name="b4100105545211"></a><a name="b4100105545211"></a>Capability</strong></p>
...@@ -94,25 +96,25 @@ ...@@ -94,25 +96,25 @@
</tbody> </tbody>
</table> </table>
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>All functions provided in this document can be called only in kernel space. >All functions provided in this document can be called only in kernel space.
## Usage Guidelines<a name="section12779050105412"></a> ## Usage Guidelines<a name="section12779050105412"></a>
### How to Use<a name="section1858116395510"></a> ### How to Use<a name="section1858116395510"></a>
[Figure 3](#fig99673244388) shows the process of using a UART device. The figure below illustrates how to use the APIs.
**Figure 3** Process of using a UART device<a name="fig99673244388"></a> **Figure 3** Using UART driver APIs<a name="fig99673244388"></a>
![](figures/process-of-using-a-uart-device.png "process-of-using-a-uart-device") ![](figures/using-uart-process.png "process-of-using-a-uart-device")
### Obtaining a UART Device Handle<a name="section124512065617"></a> ### Obtaining a UART Device Handle<a name="section124512065617"></a>
Before performing UART communication, call **UartOpen** to obtain a UART device handle. This function returns the pointer to the UART device handle with a specified port number. Before performing UART communication, call **UartOpen** to obtain a UART device handle. This function returns the pointer to the UART device handle with a specified port number.
DevHandle UartOpen\(uint32\_t port\); DevHandle UartOpen\(uint32\_t port\);
**Table 2** Description of UartOpen **Table 2** Description of UartOpen
<a name="table14222165114310"></a> <a name="table14222165114310"></a>
<table><thead align="left"><tr id="row1022175133111"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p13221551153117"><a name="p13221551153117"></a><a name="p13221551153117"></a><strong id="b538194163718"><a name="b538194163718"></a><a name="b538194163718"></a>Parameter</strong></p> <table><thead align="left"><tr id="row1022175133111"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p13221551153117"><a name="p13221551153117"></a><a name="p13221551153117"></a><strong id="b538194163718"><a name="b538194163718"></a><a name="b538194163718"></a>Parameter</strong></p>
...@@ -144,7 +146,7 @@ DevHandle UartOpen\(uint32\_t port\); ...@@ -144,7 +146,7 @@ DevHandle UartOpen\(uint32\_t port\);
</tbody> </tbody>
</table> </table>
The following example shows how to obtain a UART device handle based on the assumption that the UART port number is **3**: The following example shows how to obtain a UART device handle based on the assumption that the UART port number is **3**:
``` ```
DevHandle handle = NULL; /* The UART device handle */ DevHandle handle = NULL; /* The UART device handle */
...@@ -162,7 +164,7 @@ After obtaining the UART device handle, set the UART baud rate by calling the fo ...@@ -162,7 +164,7 @@ After obtaining the UART device handle, set the UART baud rate by calling the fo
int32\_t UartSetBaud\(DevHandle handle, uint32\_t baudRate\); int32\_t UartSetBaud\(DevHandle handle, uint32\_t baudRate\);
**Table 3** Description of UartSetBaud **Table 3** Description of UartSetBaud
<a name="table539135313325"></a> <a name="table539135313325"></a>
<table><thead align="left"><tr id="row15391205311323"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p11390453103216"><a name="p11390453103216"></a><a name="p11390453103216"></a><strong id="b0704124143717"><a name="b0704124143717"></a><a name="b0704124143717"></a>Parameter</strong></p> <table><thead align="left"><tr id="row15391205311323"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p11390453103216"><a name="p11390453103216"></a><a name="p11390453103216"></a><strong id="b0704124143717"><a name="b0704124143717"></a><a name="b0704124143717"></a>Parameter</strong></p>
...@@ -199,7 +201,7 @@ int32\_t UartSetBaud\(DevHandle handle, uint32\_t baudRate\); ...@@ -199,7 +201,7 @@ int32\_t UartSetBaud\(DevHandle handle, uint32\_t baudRate\);
</tbody> </tbody>
</table> </table>
The following example shows how to set the UART baud rate to **9600**: The following example shows how to set the UART baud rate to **9600**:
``` ```
int32_t ret; int32_t ret;
...@@ -216,7 +218,7 @@ After setting the UART baud rate, obtain the current baud rate by calling the fo ...@@ -216,7 +218,7 @@ After setting the UART baud rate, obtain the current baud rate by calling the fo
int32\_t UartGetBaud\(DevHandle handle, uint32\_t \*baudRate\); int32\_t UartGetBaud\(DevHandle handle, uint32\_t \*baudRate\);
**Table 4** Description of UartGetBaud **Table 4** Description of UartGetBaud
<a name="table20393185311326"></a> <a name="table20393185311326"></a>
<table><thead align="left"><tr id="row19392653123215"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p6392105315326"><a name="p6392105315326"></a><a name="p6392105315326"></a><strong id="b13706541173716"><a name="b13706541173716"></a><a name="b13706541173716"></a>Parameter</strong></p> <table><thead align="left"><tr id="row19392653123215"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p6392105315326"><a name="p6392105315326"></a><a name="p6392105315326"></a><strong id="b13706541173716"><a name="b13706541173716"></a><a name="b13706541173716"></a>Parameter</strong></p>
...@@ -271,7 +273,7 @@ Before performing UART communication, set the UART device attributes by calling ...@@ -271,7 +273,7 @@ Before performing UART communication, set the UART device attributes by calling
int32\_t UartSetAttribute\(DevHandle handle, struct UartAttribute \*attribute\); int32\_t UartSetAttribute\(DevHandle handle, struct UartAttribute \*attribute\);
**Table 5** Description of UartSetAttribute **Table 5** Description of UartSetAttribute
<a name="table1453119335341"></a> <a name="table1453119335341"></a>
<table><thead align="left"><tr id="row3530433103416"><th class="cellrowborder" valign="top" width="49.980000000000004%" id="mcps1.2.3.1.1"><p id="p1853073310341"><a name="p1853073310341"></a><a name="p1853073310341"></a><strong id="b8706441133719"><a name="b8706441133719"></a><a name="b8706441133719"></a>Parameter</strong></p> <table><thead align="left"><tr id="row3530433103416"><th class="cellrowborder" valign="top" width="49.980000000000004%" id="mcps1.2.3.1.1"><p id="p1853073310341"><a name="p1853073310341"></a><a name="p1853073310341"></a><strong id="b8706441133719"><a name="b8706441133719"></a><a name="b8706441133719"></a>Parameter</strong></p>
...@@ -333,7 +335,7 @@ After setting the UART device attributes, obtain the current device attributes b ...@@ -333,7 +335,7 @@ After setting the UART device attributes, obtain the current device attributes b
int32\_t UartGetAttribute\(DevHandle handle, struct UartAttribute \*attribute\); int32\_t UartGetAttribute\(DevHandle handle, struct UartAttribute \*attribute\);
**Table 6** Description of UartGetAttribute **Table 6** Description of UartGetAttribute
<a name="table17532123316342"></a> <a name="table17532123316342"></a>
<table><thead align="left"><tr id="row18531193383420"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p85311833143420"><a name="p85311833143420"></a><a name="p85311833143420"></a><strong id="b1770784123715"><a name="b1770784123715"></a><a name="b1770784123715"></a>Parameter</strong></p> <table><thead align="left"><tr id="row18531193383420"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p85311833143420"><a name="p85311833143420"></a><a name="p85311833143420"></a><strong id="b1770784123715"><a name="b1770784123715"></a><a name="b1770784123715"></a>Parameter</strong></p>
...@@ -388,7 +390,7 @@ Before performing UART communication, set the UART transmission mode by calling ...@@ -388,7 +390,7 @@ Before performing UART communication, set the UART transmission mode by calling
int32\_t UartSetTransMode\(DevHandle handle, enum UartTransMode mode\); int32\_t UartSetTransMode\(DevHandle handle, enum UartTransMode mode\);
**Table 7** Description of UartSetTransMode **Table 7** Description of UartSetTransMode
<a name="table131892266313"></a> <a name="table131892266313"></a>
<table><thead align="left"><tr id="row018922615318"><th class="cellrowborder" valign="top" width="49.980000000000004%" id="mcps1.2.3.1.1"><p id="p131891826835"><a name="p131891826835"></a><a name="p131891826835"></a><strong id="b197086411379"><a name="b197086411379"></a><a name="b197086411379"></a>Parameter</strong></p> <table><thead align="left"><tr id="row018922615318"><th class="cellrowborder" valign="top" width="49.980000000000004%" id="mcps1.2.3.1.1"><p id="p131891826835"><a name="p131891826835"></a><a name="p131891826835"></a><strong id="b197086411379"><a name="b197086411379"></a><a name="b197086411379"></a>Parameter</strong></p>
...@@ -425,7 +427,7 @@ int32\_t UartSetTransMode\(DevHandle handle, enum UartTransMode mode\); ...@@ -425,7 +427,7 @@ int32\_t UartSetTransMode\(DevHandle handle, enum UartTransMode mode\);
</tbody> </tbody>
</table> </table>
The following example shows how to set the transmission mode to **UART\_MODE\_RD\_BLOCK**: The following example shows how to set the transmission mode to **UART\_MODE\_RD\_BLOCK**:
``` ```
int32_t ret; int32_t ret;
...@@ -442,7 +444,7 @@ To write data into a UART device, call the following function: ...@@ -442,7 +444,7 @@ To write data into a UART device, call the following function:
int32\_t UartWrite\(DevHandle handle, uint8\_t \*data, uint32\_t size\); int32\_t UartWrite\(DevHandle handle, uint8\_t \*data, uint32\_t size\);
**Table 8** Description of UartWrite **Table 8** Description of UartWrite
<a name="table27825111368"></a> <a name="table27825111368"></a>
<table><thead align="left"><tr id="row1578171123619"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p078112115360"><a name="p078112115360"></a><a name="p078112115360"></a><strong id="b14708841203711"><a name="b14708841203711"></a><a name="b14708841203711"></a>Parameter</strong></p> <table><thead align="left"><tr id="row1578171123619"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p078112115360"><a name="p078112115360"></a><a name="p078112115360"></a><strong id="b14708841203711"><a name="b14708841203711"></a><a name="b14708841203711"></a>Parameter</strong></p>
...@@ -502,7 +504,7 @@ To write data into a UART device, call the following function: ...@@ -502,7 +504,7 @@ To write data into a UART device, call the following function:
int32\_t UartRead\(DevHandle handle, uint8\_t \*data, uint32\_t size\); int32\_t UartRead\(DevHandle handle, uint8\_t \*data, uint32\_t size\);
**Table 9** Description of UartRead **Table 9** Description of UartRead
<a name="table162341717123713"></a> <a name="table162341717123713"></a>
<table><thead align="left"><tr id="row023313171377"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1123331710376"><a name="p1123331710376"></a><a name="p1123331710376"></a><strong id="b970911411374"><a name="b970911411374"></a><a name="b970911411374"></a>Parameter</strong></p> <table><thead align="left"><tr id="row023313171377"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1123331710376"><a name="p1123331710376"></a><a name="p1123331710376"></a><strong id="b970911411374"><a name="b970911411374"></a><a name="b970911411374"></a>Parameter</strong></p>
...@@ -557,7 +559,7 @@ if (ret < 0) { ...@@ -557,7 +559,7 @@ if (ret < 0) {
``` ```
>![](../public_sys-resources/icon-caution.gif) **CAUTION:** >![](../public_sys-resources/icon-caution.gif) **CAUTION:**
>Data is successfully read from the UART device if a non-negative value is returned. If the return value is **0**, no valid data can be read from the UART device. If the return value is greater than **0**, the return value is the length of the data actually read from the UART device. The length is less than or equal to the value of **size** and does not exceed the maximum length of data to read at a time specified by the UART controller in use. >Data is successfully read from the UART device if a non-negative value is returned. If the return value is **0**, no valid data can be read from the UART device. If the return value is greater than **0**, the return value is the length of the data actually read from the UART device. The length is less than or equal to the value of **size** and does not exceed the maximum length of data to read at a time specified by the UART controller in use.
### Destroying the UART Device Handle<a name="section1477410521406"></a> ### Destroying the UART Device Handle<a name="section1477410521406"></a>
...@@ -567,7 +569,7 @@ void UartClose\(DevHandle handle\); ...@@ -567,7 +569,7 @@ void UartClose\(DevHandle handle\);
This function will release the resources previously obtained. This function will release the resources previously obtained.
**Table 10** Description of UartClose **Table 10** Description of UartClose
<a name="table03348317351"></a> <a name="table03348317351"></a>
<table><thead align="left"><tr id="row15334837351"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p933411316354"><a name="p933411316354"></a><a name="p933411316354"></a><strong id="b1710184115375"><a name="b1710184115375"></a><a name="b1710184115375"></a>Parameter</strong></p> <table><thead align="left"><tr id="row15334837351"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p933411316354"><a name="p933411316354"></a><a name="p933411316354"></a><strong id="b1710184115375"><a name="b1710184115375"></a><a name="b1710184115375"></a>Parameter</strong></p>
...@@ -655,5 +657,4 @@ _ERR: ...@@ -655,5 +657,4 @@ _ERR:
/* Destroy the UART device handle. */ /* Destroy the UART device handle. */
UartClose(handle); UartClose(handle);
} }
``` ```
\ No newline at end of file
...@@ -6,7 +6,7 @@ A watchdog, also called a watchdog timer, is a hardware timing device. If an err ...@@ -6,7 +6,7 @@ A watchdog, also called a watchdog timer, is a hardware timing device. If an err
## Available APIs<a name="section1180575010271"></a> ## Available APIs<a name="section1180575010271"></a>
**Table 1** Watchdog APIs **Table 1** Watchdog APIs
<a name="table1731550155318"></a> <a name="table1731550155318"></a>
<table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" valign="top" width="26.619999999999997%" id="mcps1.2.4.1.1"><p id="p641050105320"><a name="p641050105320"></a><a name="p641050105320"></a>Capability</p> <table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" valign="top" width="26.619999999999997%" id="mcps1.2.4.1.1"><p id="p641050105320"><a name="p641050105320"></a><a name="p641050105320"></a>Capability</p>
...@@ -70,25 +70,25 @@ A watchdog, also called a watchdog timer, is a hardware timing device. If an err ...@@ -70,25 +70,25 @@ A watchdog, also called a watchdog timer, is a hardware timing device. If an err
</tbody> </tbody>
</table> </table>
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>All watchdog functions provided in this document can be called only in kernel mode. >All watchdog functions provided in this document can be called only in kernel mode.
## Usage Guidelines<a name="section10103184312813"></a> ## Usage Guidelines<a name="section10103184312813"></a>
### How to Use<a name="section10181195910815"></a> ### How to Use<a name="section10181195910815"></a>
[Figure 1](#fig430533913392) illustrates the process of using a watchdog. The figure below illustrates how to use the APIs.
**Figure 1** Process of using a watchdog<a name="fig430533913392"></a> **Figure 1** Using watchdog driver APIs
![](figures/process-of-using-a-watchdog.png "process-of-using-a-watchdog") ![](figures/using-watchdog-process.png "process-of-using-a-watchdog")
### Opening a Watchdog<a name="section66089201107"></a> ### Opening a Watchdog<a name="section66089201107"></a>
Use **WatchdogOpen** to open a watchdog. A system may have multiple watchdogs. You can open the specified watchdog by using the ID. Use **WatchdogOpen** to open a watchdog. A system may have multiple watchdogs. You can open the specified watchdog by using the ID.
int32\_t WatchdogOpen\(int16\_t wdtId\); int32\_t WatchdogOpen\(int16\_t wdtId\);
**Table 2** Description of WatchdogOpen **Table 2** Description of WatchdogOpen
<a name="table1413702552814"></a> <a name="table1413702552814"></a>
<table><thead align="left"><tr id="row131371325142819"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p191372254283"><a name="p191372254283"></a><a name="p191372254283"></a><strong id="b9239182472212"><a name="b9239182472212"></a><a name="b9239182472212"></a>Parameter</strong></p> <table><thead align="left"><tr id="row131371325142819"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p191372254283"><a name="p191372254283"></a><a name="p191372254283"></a><strong id="b9239182472212"><a name="b9239182472212"></a><a name="b9239182472212"></a>Parameter</strong></p>
...@@ -133,7 +133,7 @@ if (handle == NULL) { ...@@ -133,7 +133,7 @@ if (handle == NULL) {
int32\_t WatchdogGetStatus\(DevHandle handle, int32\_t \*status\); int32\_t WatchdogGetStatus\(DevHandle handle, int32\_t \*status\);
**Table 3** Description of WatchdogGetStatus **Table 3** Description of WatchdogGetStatus
<a name="table1018490043"></a> <a name="table1018490043"></a>
<table><thead align="left"><tr id="row31848013417"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b8395121072312"><a name="b8395121072312"></a><a name="b8395121072312"></a>Parameter</strong></p> <table><thead align="left"><tr id="row31848013417"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b8395121072312"><a name="b8395121072312"></a><a name="b8395121072312"></a>Parameter</strong></p>
...@@ -185,7 +185,7 @@ if (ret != 0) { ...@@ -185,7 +185,7 @@ if (ret != 0) {
int32\_t WatchdogSetTimeout\(PalHandle \*handle, uint32\_t seconds\); int32\_t WatchdogSetTimeout\(PalHandle \*handle, uint32\_t seconds\);
**Table 4** Description of WatchdogSetTimeout **Table 4** Description of WatchdogSetTimeout
<a name="table9159112182210"></a> <a name="table9159112182210"></a>
<table><thead align="left"><tr id="row1216012212212"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1416017262215"><a name="p1416017262215"></a><a name="p1416017262215"></a><strong id="b16573184672318"><a name="b16573184672318"></a><a name="b16573184672318"></a>Parameter</strong></p> <table><thead align="left"><tr id="row1216012212212"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1416017262215"><a name="p1416017262215"></a><a name="p1416017262215"></a><strong id="b16573184672318"><a name="b16573184672318"></a><a name="b16573184672318"></a>Parameter</strong></p>
...@@ -237,7 +237,7 @@ if (ret != 0) { ...@@ -237,7 +237,7 @@ if (ret != 0) {
int32\_t WatchdogGetTimeout\(PalHandle \*handle, uint32\_t \*seconds\); int32\_t WatchdogGetTimeout\(PalHandle \*handle, uint32\_t \*seconds\);
**Table 5** Description of WatchdogGetTimeout **Table 5** Description of WatchdogGetTimeout
<a name="table10147164819233"></a> <a name="table10147164819233"></a>
<table><thead align="left"><tr id="row14147848142313"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p4147124892316"><a name="p4147124892316"></a><a name="p4147124892316"></a><strong id="b1387481413247"><a name="b1387481413247"></a><a name="b1387481413247"></a>Parameter</strong></p> <table><thead align="left"><tr id="row14147848142313"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p4147124892316"><a name="p4147124892316"></a><a name="p4147124892316"></a><strong id="b1387481413247"><a name="b1387481413247"></a><a name="b1387481413247"></a>Parameter</strong></p>
...@@ -289,7 +289,7 @@ if (ret != 0) { ...@@ -289,7 +289,7 @@ if (ret != 0) {
int32\_t WatchdogStart\(DevHandle handle\); int32\_t WatchdogStart\(DevHandle handle\);
**Table 6** Description of WatchdogStart **Table 6** Description of WatchdogStart
<a name="table529165182515"></a> <a name="table529165182515"></a>
<table><thead align="left"><tr id="row92915122513"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p5292582517"><a name="p5292582517"></a><a name="p5292582517"></a><strong id="b99151951162417"><a name="b99151951162417"></a><a name="b99151951162417"></a>Parameter</strong></p> <table><thead align="left"><tr id="row92915122513"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p5292582517"><a name="p5292582517"></a><a name="p5292582517"></a><strong id="b99151951162417"><a name="b99151951162417"></a><a name="b99151951162417"></a>Parameter</strong></p>
...@@ -335,7 +335,7 @@ if (ret != 0) { ...@@ -335,7 +335,7 @@ if (ret != 0) {
int32\_t WatchdogFeed\(DevHandle handle\); int32\_t WatchdogFeed\(DevHandle handle\);
**Table 7** Description of WatchdogFeed **Table 7** Description of WatchdogFeed
<a name="table091163515394"></a> <a name="table091163515394"></a>
<table><thead align="left"><tr id="row891133515393"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1911143513918"><a name="p1911143513918"></a><a name="p1911143513918"></a><strong id="b16850010142518"><a name="b16850010142518"></a><a name="b16850010142518"></a>Parameter</strong></p> <table><thead align="left"><tr id="row891133515393"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1911143513918"><a name="p1911143513918"></a><a name="p1911143513918"></a><strong id="b16850010142518"><a name="b16850010142518"></a><a name="b16850010142518"></a>Parameter</strong></p>
...@@ -381,7 +381,7 @@ if (ret != 0) { ...@@ -381,7 +381,7 @@ if (ret != 0) {
int32\_t WatchdogStop\(DevHandle handle\); int32\_t WatchdogStop\(DevHandle handle\);
**Table 8** Description of WatchdogStop **Table 8** Description of WatchdogStop
<a name="table1286810515254"></a> <a name="table1286810515254"></a>
<table><thead align="left"><tr id="row28687517259"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p6868185120254"><a name="p6868185120254"></a><a name="p6868185120254"></a><strong id="b204221347152519"><a name="b204221347152519"></a><a name="b204221347152519"></a>Parameter</strong></p> <table><thead align="left"><tr id="row28687517259"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p6868185120254"><a name="p6868185120254"></a><a name="p6868185120254"></a><strong id="b204221347152519"><a name="b204221347152519"></a><a name="b204221347152519"></a>Parameter</strong></p>
...@@ -425,11 +425,11 @@ if (ret != 0) { ...@@ -425,11 +425,11 @@ if (ret != 0) {
### Closing a Watchdog<a name="section96561824121311"></a> ### Closing a Watchdog<a name="section96561824121311"></a>
If the watchdog is no longer required, call **WatchdogClose** to close the watchdog handle. If the watchdog is no longer required, call **WatchdogClose** to close the watchdog handle.
void WatchdogClose\(DevHandle handle\); void WatchdogClose\(DevHandle handle\);
**Table 9** Description of WatchdogClose **Table 9** Description of WatchdogClose
<a name="table1017315185320"></a> <a name="table1017315185320"></a>
<table><thead align="left"><tr id="row417314182327"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p117310184320"><a name="p117310184320"></a><a name="p117310184320"></a><strong id="b97421847122514"><a name="b97421847122514"></a><a name="b97421847122514"></a>Parameter</strong></p> <table><thead align="left"><tr id="row417314182327"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p117310184320"><a name="p117310184320"></a><a name="p117310184320"></a><strong id="b97421847122514"><a name="b97421847122514"></a><a name="b97421847122514"></a>Parameter</strong></p>
...@@ -535,5 +535,4 @@ static int32_t TestCaseWatchdog(void) ...@@ -535,5 +535,4 @@ static int32_t TestCaseWatchdog(void)
WatchdogClose(handle); WatchdogClose(handle);
return -1; return -1;
} }
``` ```
\ No newline at end of file
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
- Kernel Debugging - Kernel Debugging
- [Memory Debugging](kernel-mini-memory-debug.md) - [Memory Debugging](kernel-mini-memory-debug.md)
- [Memory Information Statistics](kernel-mini-memory-debug-mes.md) - [Memory Information Statistics](kernel-mini-memory-debug-mes.md)
- [Memory Leak Check](kernel-mini-imemory-debug-det.md) - [Memory Leak Check](kernel-mini-memory-debug-det.md)
- [Memory Corruption Check](kernel-mini-memory-debug-cet.md) - [Memory Corruption Check](kernel-mini-memory-debug-cet.md)
- [Exception Debugging](kernel-mini-memory-exception.md) - [Exception Debugging](kernel-mini-memory-exception.md)
- [Trace](kernel-mini-memory-trace.md) - [Trace](kernel-mini-memory-trace.md)
...@@ -180,5 +180,4 @@ ...@@ -180,5 +180,4 @@
- [Enhanced Swap](kernel-standard-mm-eswap.md) - [Enhanced Swap](kernel-standard-mm-eswap.md)
- [Task Scheduling](kernel-standard-sched.md) - [Task Scheduling](kernel-standard-sched.md)
- [Related Thread Group](kernel-standard-sched-rtg.md) - [Related Thread Group](kernel-standard-sched-rtg.md)
- [Lightweight CPU Isolation](kernel-standard-sched-cpuisolation.md) - [Lightweight CPU Isolation](kernel-standard-sched-cpuisolation.md)
\ No newline at end of file
\ No newline at end of file
...@@ -4,19 +4,19 @@ ...@@ -4,19 +4,19 @@
Dynamic memory management allows memory blocks of any size to be allocated from a large contiguous memory \(memory pool or heap memory\) configured in the system based on user demands when memory resources are sufficient. The memory block can be released for further use when not required. Compared with static memory management, dynamic memory management allows memory allocation on demand but causes fragmentation of memory. Dynamic memory management allows memory blocks of any size to be allocated from a large contiguous memory \(memory pool or heap memory\) configured in the system based on user demands when memory resources are sufficient. The memory block can be released for further use when not required. Compared with static memory management, dynamic memory management allows memory allocation on demand but causes fragmentation of memory.
The dynamic memory of the OpenHarmony LiteOS-M has optimized the memory space partitioning based on the Two-Level Segregate Fit \(TLSF\) algorithm to achieve higher performance and minimize fragmentation. [Figure 1](#fig1179964042818) shows the core algorithm of the dynamic memory. The dynamic memory of the OpenHarmony LiteOS-M has optimized the memory space partitioning based on the Two-Level Segregate Fit \(TLSF\) algorithm to achieve higher performance and minimize fragmentation. The figure below shows the core algorithm of the dynamic memory.
**Figure 1** Dynamic memory algorithm for mini systems **Figure 1** Dynamic memory algorithm for mini systems
![](figures/dynamic-memory-algorithm-for-mini-systems.png "dynamic-memory-algorithm-for-mini-systems") ![](figures/dynamic-memory-algorithm-for-mini-systems.png "dynamic-memory-algorithm-for-mini-systems")
Multiple free lists are used for management based on the size of the free memory block. The free memory blocks are divided into two parts: \[4, 127\] and \[2<sup>7</sup>, 2<sup>31</sup>\], as indicated by the size class in [Figure 1](#fig1179964042818). Multiple free lists are used for management based on the size of the free memory block. The free memory blocks are divided into two parts: \[4, 127\] and \[2<sup>7</sup>, 2<sup>31</sup>\], as indicated by the size class in the above figure.
1. The memory in the range of \[4, 127\] \(lower part in [Figure 1](#fig1179964042818)\) is divided into 31 parts. The size of the memory block corresponding to each part is a multiple of 4 bytes. Each part corresponds to a free list and a bit that indicates whether the free list is empty. The value **1** indicates that the free list is not empty. There are 31 bits corresponding to the 31 memory parts in the range of \[4, 127\]. 1. The memory in the range of \[4, 127\] \(lower part in the above figure) is divided into 31 parts. The size of the memory block corresponding to each part is a multiple of 4 bytes. Each part corresponds to a free list and a bit that indicates whether the free list is empty. The value **1** indicates that the free list is not empty. There are 31 bits corresponding to the 31 memory parts in the range of \[4, 127\].
2. The memory greater than 127 bytes is managed in power of two increments. The size of each range is \[2^n, 2^\(n+1\)-1\], where n is an integer in \[7, 30\]. This range is divided into 24 parts, each of which is further divided into 8 second-level \(L2\) ranges, as shown in Size Class and Size SubClass in the upper part of [Figure 1](#fig1179964042818). Each L2 range corresponds to a free list and a bit that indicates whether the free list is empty. There are a total of 192 \(24 x 8\) L2 ranges, corresponding to 192 free lists and 192 bits. 2. The memory greater than 127 bytes is managed in power of two increments. The size of each range is \[2^n, 2^\(n+1\)-1\], where n is an integer in \[7, 30\]. This range is divided into 24 parts, each of which is further divided into 8 second-level \(L2\) ranges, as shown in Size Class and Size SubClass in the upper part of the above figure. Each L2 range corresponds to a free list and a bit that indicates whether the free list is empty. There are a total of 192 \(24 x 8\) L2 ranges, corresponding to 192 free lists and 192 bits.
For example, insert 40-byte free memory to a free list. The 40-byte free memory corresponds to the 10th free list in the range of \[40, 43\], and the 10th bit indicates the use of the free list. The system inserts the 40-byte free memory to the 10th free list and determines whether to update the bitmap flag. When 40-byte memory is requested, the system obtains the free list corresponding to the memory block of the requested size based on the bitmap flag, and then obtains a free memory node from the free list. If the size of the allocated node is greater than the memory requested, the system splits the node and inserts the remaining node to the free list. If 580-byte free memory needs to be inserted to a free list, the 580-byte free memory corresponds to the 47th \(31 + 2 x 8\) free list in L2 range \[2^9, 2^9+2^6\], and the 47th bit indicates the use of the free list. The system inserts the 580-byte free memory to the 47th free list and determines whether to update the bitmap flag. When 580-byte memory is requested, the system obtains the free list corresponding to the memory block of the requested size based on the bitmap flag, and then obtains a free memory node from the free list. If the size of the allocated node is greater than the memory requested, the system splits the node and inserts the remaining node to the free list. If the corresponding free list is empty, the system checks for a free list meeting the requirements in a larger memory range. In actual application, the system can locate the free list that meets the requirements at a time. For example, insert 40-byte free memory to a free list. The 40-byte free memory corresponds to the 10th free list in the range of \[40, 43\], and the 10th bit indicates the use of the free list. The system inserts the 40-byte free memory to the 10th free list and determines whether to update the bitmap flag. When 40-byte memory is requested, the system obtains the free list corresponding to the memory block of the requested size based on the bitmap flag, and then obtains a free memory node from the free list. If the size of the allocated node is greater than the memory requested, the system splits the node and inserts the remaining node to the free list. If 580-byte free memory needs to be inserted to a free list, the 580-byte free memory corresponds to the 47th \(31 + 2 x 8\) free list in L2 range \[2^9, 2^9+2^6\], and the 47th bit indicates the use of the free list. The system inserts the 580-byte free memory to the 47th free list and determines whether to update the bitmap flag. When 580-byte memory is requested, the system obtains the free list corresponding to the memory block of the requested size based on the bitmap flag, and then obtains a free memory node from the free list. If the size of the allocated node is greater than the memory requested, the system splits the node and inserts the remaining node to the free list. If the corresponding free list is empty, the system checks for a free list meeting the requirements in a larger memory range. In actual application, the system can locate the free list that meets the requirements at a time.
[Figure 2](#fig10997102213017) shows the memory management structure. The figure below shows the memory management structure.
**Figure 2** Dynamic memory management structure for mini systems **Figure 2** Dynamic memory management structure for mini systems
![](figures/dynamic-memory-management-structure-for-mini-systems.png "dynamic-memory-management-structure-for-mini-systems") ![](figures/dynamic-memory-management-structure-for-mini-systems.png "dynamic-memory-management-structure-for-mini-systems")
...@@ -30,7 +30,7 @@ For example, insert 40-byte free memory to a free list. The 40-byte free memory ...@@ -30,7 +30,7 @@ For example, insert 40-byte free memory to a free list. The 40-byte free memory
There are three types of nodes: free node, used node, and end node. Each memory node maintains the size and use flag of the memory node and a pointer to the previous memory node in the memory pool. The free nodes and used nodes have a data area, but the end node has no data area. There are three types of nodes: free node, used node, and end node. Each memory node maintains the size and use flag of the memory node and a pointer to the previous memory node in the memory pool. The free nodes and used nodes have a data area, but the end node has no data area.
The off-chip physical memory needs to be used because the on-chip RAMs of some chips cannot meet requirements. The OpenHarmony LiteOS-M kernel can logically combine multiple discontiguous memory regions so that users are unaware of the discontiguous memory regions in the underlying layer. The OpenHarmony LiteOS-M kernel memory module inserts discontiguous memory regions into a free list as free memory nodes and marks the discontiguous parts as virtual memory nodes that have been used. In this way, the discontinuous memory regions are logically combined as a unified memory pool. [Figure 3](#fig18471556115917) shows how the discontiguous memory regions are logically integrated. The off-chip physical memory needs to be used because the on-chip RAMs of some chips cannot meet requirements. The OpenHarmony LiteOS-M kernel can logically combine multiple discontiguous memory regions so that users are unaware of the discontiguous memory regions in the underlying layer. The OpenHarmony LiteOS-M kernel memory module inserts discontiguous memory regions into a free list as free memory nodes and marks the discontiguous parts as virtual memory nodes that have been used. In this way, the discontinuous memory regions are logically combined as a unified memory pool. The figure below shows how the discontiguous memory regions are logically integrated.
**Figure 3** Integrating discontiguous memory regions **Figure 3** Integrating discontiguous memory regions
![](figures/integrating-discontiguous-memory-regions.png "integrating-discontiguous-memory-regions") ![](figures/integrating-discontiguous-memory-regions.png "integrating-discontiguous-memory-regions")
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
The OpenHarmony LiteOS-M kernel is a lightweight operating system \(OS\) kernel designed for the IoT field. It features small size, low power consumption, and high performance. The LiteOS-M kernel has simple code structure, including the minimum function set, kernel abstraction layer \(KAL\), optional components, and project directory. It supports the Hardware Driver Foundation \(HDF\), which provides unified driver standards and access mode for device vendors to simplify porting of drivers and allow one-time development for multi-device deployment. The OpenHarmony LiteOS-M kernel is a lightweight operating system \(OS\) kernel designed for the IoT field. It features small size, low power consumption, and high performance. The LiteOS-M kernel has simple code structure, including the minimum function set, kernel abstraction layer \(KAL\), optional components, and project directory. It supports the Hardware Driver Foundation \(HDF\), which provides unified driver standards and access mode for device vendors to simplify porting of drivers and allow one-time development for multi-device deployment.
The OpenHarmony LiteOS-M kernel architecture consists of the hardware layer and hardware-irrelevant layers, as shown in [Figure 1](#fig1287712172318). The hardware layer is classified based on the compiler toolchain and chip architecture, and provides a unified Hardware Abstraction Layer \(HAL\) interface to improve hardware adaptation and facilitate the expansion of various types of AIoT hardware and compilation toolchains. The other modules are irrelevant to the hardware. The basic kernel module provides basic kernel capabilities. The extended modules provide capabilities of components, such as the network and file systems, as well as exception handling and debug tools. The KAL provides unified standard APIs. The OpenHarmony LiteOS-M kernel architecture consists of the hardware layer and hardware-irrelevant layers, as shown in the figure below. The hardware layer is classified based on the compiler toolchain and chip architecture, and provides a unified Hardware Abstraction Layer \(HAL\) interface to improve hardware adaptation and facilitate the expansion of various types of AIoT hardware and compilation toolchains. The other modules are irrelevant to the hardware. The basic kernel module provides basic kernel capabilities. The extended modules provide capabilities of components, such as the network and file systems, as well as exception handling and debug tools. The KAL provides unified standard APIs.
**Figure 1** Kernel architecture **Figure 1** Kernel architecture
![](figures/kernel-architecture.png "kernel-architecture") ![](figures/kernel-architecture.png "kernel-architecture")
...@@ -48,11 +48,11 @@ The CPU architecture includes two layers: general architecture definition layer ...@@ -48,11 +48,11 @@ The CPU architecture includes two layers: general architecture definition layer
</tbody> </tbody>
</table> </table>
LiteOS-M supports mainstream architectures, such as ARM Cortex-M3, ARM Cortex-M4, ARM Cortex-M7, ARM Cortex-M33, and RISC-V. If you need to expand the CPU architecture, see [Chip Architecture Adaptation](../porting/porting-chip-kernel-overview.md#section137431650339). LiteOS-M supports mainstream architectures, such as ARM Cortex-M3, ARM Cortex-M4, ARM Cortex-M7, ARM Cortex-M33, and RISC-V. If you need to expand the CPU architecture, see [Chip Architecture Adaptation](../porting/porting-chip-kernel-overview.md#section137431650339).
### Working Principles ### Working Principles
Configure the system clock and number of ticks per second in the **target\_config.h** file of the development board. Configure the task, memory, inter-process communication \(IPC\), and exception handling modules based on service requirements. When the system boots, the modules are initialized based on the configuration. The kernel startup process includes peripheral initialization, system clock configuration, kernel initialization, and OS boot. For details, see [Figure 2](#fig74259220441). Configure the system clock and number of ticks per second in the **target\_config.h** file of the development board. Configure the task, memory, inter-process communication \(IPC\), and exception handling modules based on service requirements. When the system boots, the modules are initialized based on the configuration. The kernel startup process includes peripheral initialization, system clock configuration, kernel initialization, and OS boot, as shown in the figure below.
**Figure 2** Kernel startup process **Figure 2** Kernel startup process
![](figures/kernel-startup-process.png "kernel-startup-process") ![](figures/kernel-startup-process.png "kernel-startup-process")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册