未验证 提交 0f390741 编写于 作者: O openharmony_ci 提交者: Gitee

!13065 【翻译完成】#I5ZK8S

Merge pull request !13065 from Annie_wang/PR10751
......@@ -4,78 +4,69 @@
### Function
An analog-to-digital converter (ADC) is a device that converts analog signals into digital signals.
An analog-to-digital converter (ADC) converts analog signals into digital signals for storage and computing. In addition to the power cable and ground cable, the ADC requires only one cable to connect to the target device. The following figure shows the physical connection of the ADC.
**Figure 1** ADC physical connection
![](figures/ADC_physical_connection.png "ADC_physical_connection")
The ADC module provides a set of APIs to complete AD conversion, including:
The ADC APIs provide a set of common functions for ADC data transfer, including:
- Opening or closing an ADC device
- Obtaining the analog-to-digital (AD) conversion result
### Basic Concepts
The ADC converts analog parameters into digital parameters for easy storage and computing. The technical specifications of the ADC include the following:
- Resolution
The number of binary bits that can be converted by an ADC. A greater number of bits indicates a higher resolution.
- Conversion error
Difference between the actual and theoretical digital values output by an ADC. It is expressed by a multiple of the least significant bit. Generally, the maximum output error is used.
- Transition time
Time required by an ADC to perform a complete conversion.
### Working Principles
In the Hardware Driver Foundation (HDF), the ADC module uses the unified service mode for API adaptation. In this mode, a service is used as the ADC manager to handle external access requests in a unified manner. The unified service mode applies when the system has multiple device objects of the same type. If the independent service mode is used in this case, more device nodes need to be configured and more memory resources will be consumed.
The ADC module is divided into the following layers:
- Interface layer: provides APIs for opening or closing a device and writing data.
- Core layer: provides the capabilities of binding, initializing, and releasing devices.
- Adaptation layer: implements driver-specific functions.
In addition to the power and ground cables, the ADC requires only one cable to connect to the target device. The figure below shows the physical connection.
**Figure 1** ADC physical connection
![](figures/ADC_physical_connection.png "ADC_physical_connection")
### Constraints
Currently, the ADC module supports only the kernels (LiteOS) of mini and small systems.
The ADC module can read data only in polling mode.
## Usage Guidelines
### When to Use
An ADC is usually used to convert an analog voltage into a digital parameter, for example, it is used with a microphone to collect sound, used with an NTC resistor to measure temperature, or converts the output of analog sensors into digital parameters.
ADC devices are used to convert analog voltage or current into digital parameters. For example, an ADC can be used with an NTC resistor to measure temperature, or can be used to convert the output of an analog sensor into a digital parameter.
### Available APIs
The table below describes the APIs of the ADC module. For more details, see API Reference.
The following table describes the APIs of the ADC module. For more information, see **//drivers/hdf_core/framework/include/platform/adc_if.h**.
**Table 1** APIs of the ADC driver
| API | Description |
| API | Description |
| -------- | ---------------- |
| AdcOpen | Opens an ADC device. |
| AdcClose | Closes an ADC device. |
| AdcRead | Obtains the AD conversion result.|
| DevHandle AdcOpen(uint32_t number) | Opens an ADC device. |
| void AdcClose(DevHandle handle) | Closes an ADC device. |
| int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t \*val) | Obtains the AD conversion result.|
### How to Develop
The figure below shows the general development process.
The following figure illustrates how to use ADC APIs.
**Figure 2** Process of using ADC APIs
**Figure 2** Process of using ADC APIs
![](figures/using-ADC-process.png)
#### Opening an ADC Device
Call **AdcOpen** to open an ADC device.
Call **AdcOpen()** to open an ADC device.
```c
DevHandle AdcOpen(int16_t number);
......@@ -83,12 +74,11 @@ DevHandle AdcOpen(int16_t number);
**Table 2** Description of AdcOpen
| Parameter | Description |
| ---------- | ----------------- |
| number | ADC device number. |
| **Return Value**| **Description** |
| NULL | The operation failed. |
| NULL | The operation fails. |
| Device handle | The operation is successful. The handle of the ADC device opened is returned.|
Example: Open device 1 of the two ADCs (numbered 0 and 1) in the system.
......@@ -99,7 +89,7 @@ DevHandle adcHandle = NULL; /* ADC device handle /
/* Open ADC device 1. */
adcHandle = AdcOpen(1);
if (adcHandle == NULL) {
HDF_LOGE("AdcOpen: failed\n");
HDF_LOGE("AdcOpen: fail\n");
return;
}
```
......@@ -112,7 +102,6 @@ int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t *val);
**Table 3** Description of AdcRead
| Parameter | Description |
| ---------- | -------------- |
| handle | ADC device handle. |
......@@ -120,7 +109,7 @@ int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t *val);
| val | Pointer to the AD conversion result. |
| **Return Value**| **Description**|
| 0 | The operation is successful. |
| Negative value | The operation failed. |
| Negative value | The operation fails. |
Example: Obtain the AD conversion result of channel 1.
......@@ -137,13 +126,12 @@ if (ret != 0) {
#### Closing an ADC Device
Call **AdcClose** to close the ADC device after the ADC communication is complete.
Call **AdcClose()** to close the ADC device after the ADC communication is complete.
```c
void AdcClose(DevHandle handle);
```
**Table 4** Description of AdcClose
| Parameter | Description |
| ------ | ----------- |
| handle | ADC device handle.|
......@@ -158,13 +146,13 @@ AdcClose(adcHandle); /* Close the ADC device. */
### Example
This following example shows how to use ADC APIs to manage an ADC device on a Hi3516D V300 board.
The following example shows how to use ADC APIs to manage an ADC device on a Hi3516D V300 board.
The basic hardware information is as follows:
The hardware information is as follows:
- SoC: hi3516dv300
- The potentiometer is connected to channel 1 of ADC device 0.
- The potentiometer is connected to channel 1 of ADC 0.
Perform continuous read operations on the ADC device to check whether the ADC is functioning.
......@@ -175,16 +163,17 @@ Example:
#include "hdf_log.h" /* Header file for log APIs */
/* Define device 0, channel 1. */
#define ADC_DEVICE_NUM 0
#define ADC_DEVICE_NUM 0
#define ADC_CHANNEL_NUM 1
#define ADC_TEST_NUM 30
/* Main entry of ADC routines. */
static int32_t TestCaseAdc(void)
{
int32_t i;
int32_t ret;
DevHandle adcHandle;
uint32_t readBuf[30] = {0};
DevHandle adcHandle = NULL;
uint32_t readBuf[ADC_TEST_NUM] = {0};
/* Open the ADC device. */
adcHandle = AdcOpen(ADC_DEVICE_NUM);
......@@ -194,10 +183,10 @@ static int32_t TestCaseAdc(void)
}
/* Perform 30 times of AD conversions continuously and read the conversion results. */
for (i = 0; i < 30; i++) {
for (i = 0; i < ADC_TEST_NUM; i++) {
ret = AdcRead(adcHandle, ADC_CHANNEL_NUM, &readBuf[i]);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: Failed to read ADC!:%d", __func__, ret);
HDF_LOGE("%s: ADC read fail!:%d", __func__, ret);
AdcClose(adcHandle);
return -1;
}
......
......@@ -2,18 +2,19 @@
## Overview
### DAC
### Function
A digit-to-analog converter (DAC) is a device that converts a digital signal into an analog signal in electronics.
A digit-to-analog converter (DAC) is a device that converts a digital signal into an analog signal in electronics. DAC devices are used to:
The DAC APIs provide a set of methods for DAC data transfer, including:
- Provide the output channel for the process control computer system and connect to the executor to implement automatic control of the production process.
- Serve as an important module in the analog-to-digital converter using feedback technologies.
The DAC module provides a set of methods for DAC data transfer, including:
- Opening or closing a DAC device
- Setting the target digital-to-analog (DA) value
### Basic Concepts
The DAC module provides the output channel for the process control computer system. It connects to the executor to implement automatic control of the production process. It is also an important module in the analog-to-digital converter using feedback technologies.
- Resolution
The number of binary bits that can be converted by a DAC. A greater number of bits indicates a higher resolution.
......@@ -32,7 +33,7 @@ The DAC module provides the output channel for the process control computer syst
### Working Principles
In the Hardware Driver Foundation (HDF), the DAC module uses the unified service mode for API adaptation. In this mode, a service is used as the DAC manager to handle external access requests in a unified manner. The unified service mode applies when the system has multiple device objects of the same type. If the independent service mode is used in this case, more device nodes need to be configured and more memory resources will be consumed. The figure below shows the unified service mode.
In the Hardware Driver Foundation (HDF), the DAC module uses the unified service mode for API adaptation. In this mode, a service is used as the DAC manager to handle external access requests in a unified manner. The unified service mode applies when the system has multiple device objects of the same type. If the independent service mode is used, more device nodes need to be configured and memory resources will be consumed by services. The following figure illustrates the unified service mode of the DAC module.
The DAC module is divided into the following layers:
......@@ -40,9 +41,7 @@ The DAC module is divided into the following layers:
- Core layer: provides the capabilities of binding, initializing, and releasing devices.
- Adaptation layer: implements driver-specific functions.
>![](../public_sys-resources/icon-note.gif) **NOTE**
>
> The core layer can call the functions of the interface layer and uses a 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
......@@ -50,7 +49,7 @@ The DAC module is divided into the following layers:
### Constraints
Currently, the DAC module supports only the kernels (LiteOS) of mini and small systems.
The DAC module supports only the kernel (LiteOS-A) for mini and small systems.
## Usage Guidelines
......@@ -60,11 +59,11 @@ The DAC module converts digital signals into analog signals in the form of curre
### Available APIs
The table below describes the APIs of the DAC module. For more details, see API Reference.
The following table describes the APIs of the DAC module. For more information about the APIs, see **//drivers/hdf_core/framework/include/platform/dac_if.h**.
**Table 1** DAC driver APIs
| API | Description |
| API | Description |
| ------------------------------------------------------------------ | ------------ |
| DevHandle DacOpen(uint32_t number) | Opens a DAC device. |
| void DacClose(DevHandle handle) | Closes a DAC device. |
......@@ -72,12 +71,11 @@ The table below describes the APIs of the DAC module. For more details, see API
### How to Develop
The figure below shows the general development process.
The following figure illustrates how to use DAC APIs.
**Figure 2** Process of using DAC APIs
![](figures/using-DAC-process.png)
![Process of using a DAC](figures/using-DAC-process.png "Process of using a DAC")
#### Opening a DAC Device
......@@ -93,13 +91,13 @@ DevHandle DacOpen(uint32_t number);
| --------- | ---------------- |
| number | DAC device number. |
| **Return Value**| **Description** |
| NULL | The operation failed. |
| NULL | The operation fails. |
| Device handle | The operation is successful. The handle of the DAC device opened is returned.|
Example: Open device 1 of the two DAC devices (numbered 0 and 1) in the system.
Open device 1 of the two DAC devices (numbered 0 and 1) in the system.
```c++
DevHandle dacHandle = NULL; /* DAC device handle /
DevHandle dacHandle = NULL; // DAC device handle.
/* Open DAC device 1. */
dacHandle = DacOpen(1);
......@@ -109,7 +107,7 @@ if (dacHandle == NULL) {
}
```
#### Setting a Target DA Value
#### Setting a DA Value
```c++
int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val);
......@@ -124,16 +122,16 @@ int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val);
| val | DA value to set. |
| **Return Value**| **Description**|
| 0 | The operation is successful. |
| Negative value | The operation failed. |
| Negative value | The operation fails. |
```c++
/* Write the target DA value through the DAC_CHANNEL_NUM channel. */
ret = DacWrite(dacHandle, DAC_CHANNEL_NUM, val);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: tp DAC write reg fail!:%d", __func__, ret);
DacClose(dacHandle);
return -1;
}
ret = DacWrite(dacHandle, DAC_CHANNEL_NUM, val);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: tp DAC write reg fail!:%d", __func__, ret);
DacClose(dacHandle);
return -1;
}
```
#### Closing a DAC Device
......@@ -168,8 +166,8 @@ The procedure is as follows:
You can obtain the operation result by printing the log information based on the **val**.
```c++
#include "dac_if.h" /* Header file for DAC APIs */
#include "hdf_log.h" /* Header file for log APIs */
#include "dac_if.h" /* Header file for DAC APIs. */
#include "hdf_log.h" /* Header file for log APIs. */
/* Define device 0, channel 1. */
#define DAC_DEVICE_NUM 0
......
......@@ -8,7 +8,7 @@ Improved Inter-Integrated Circuit (I3C) is a simple and cost-efficient two-wire
I3C is a two-wire bidirectional serial bus, optimized for multiple sensor target devices and controlled by only one I3C controller at a time. It is backward compatible with Inter-Integrated circuit (I2C) target devices, but features higher speed and lower power consumption. Moreover, I3C supports in-band interrupts (IBIs), hot-joins of target devices, and controller switchover. The IBIs over the serial bus eliminates the need for an extra interrupt line to complete interrupts in I2C. I2C devices, I3C target devices, and the I3C secondary controller can co-exist on the same I3C bus.
The I3C driver APIs provide a set of common functions for I3C transfer, including:
The I3C module provides a set of common APIs for I3C transfer, including:
- Opening and closing an I3C controller
- Obtaining and setting I3C controller parameters
- Performing custom I3C message transfer by using a message array
......@@ -17,17 +17,14 @@ The I3C driver APIs provide a set of common functions for I3C transfer, includin
### Basic Concepts
- IBI
When there is no start signal on the serial clock (SCL) line, the I3C target device can pull down the serial data (SDA) line to make the controller send an SCL start signal, which initiates an IBI request. If multiple target devices send interrupt requests at the same time, the I3C controller arbitrates the requests based on the target device addresses. The request with a lower address is responded first.
- Dynamic Address Assignment (DAA)
The I3C controller can dynamically allocate addresses to target devices to avoid address conflicts. Before addresses are allocated, each I3C device connected to a I3C bus must be uniquely identified in either of the following ways:
- The device has an I2C compliant static address that can be used by the host.
- The device has a 48-bit temporary ID.
The host must use a 48-bit temporary ID unless the device has a static IP address.
1) The device has an I2C compliant static address that can be used by the host.
2) The device has a 48-bit temporary ID. The host must use a 48-bit temporary ID unless the device has a static IP address.
- Common Command Code (CCC)
......@@ -43,49 +40,54 @@ The I3C driver APIs provide a set of common functions for I3C transfer, includin
### Working Principles
In the Hardware Driver Foundation (HDF), the I3C module uses the unified service mode for API adaptation. In this mode, a service is used as the I3C manager to handle external access requests in a unified manner. The unified service mode applies when the system has multiple device objects of the same type, for example, when there are more than 10 I3C controllers. If the independent service mode is used in this case, more device nodes need to be configured and more memory resources will be consumed.
In the Hardware Driver Foundation (HDF), the I3C module uses the unified service mode for API adaptation. In this mode, a service is used as the I3C manager to handle external access requests in a unified manner. The unified service mode applies when the system has multiple device objects of the same type, for example, when there are more than 10 I3C controllers. If the independent service mode is used in this case, more device nodes need to be configured and more memory resources will be consumed.
Multiple devices, such as I2C target device, I3C target device, and I3C secondary controller, can be connected to an I3C bus. However, the I3C bus must have only one controller.
Compared with I2C, I3C features higher speed and lower power consumption, supports IBIs, hot-joins of target devices, and controller switchover. I3C is also backward compatible with I2C target devices. Multiple devices, such as I2C target device, I3C target device, and I3C secondary controller, can be connected to an I3C bus. However, the I3C bus must have only one controller.
**Figure 1** I3C physical connection
**Figure 1** I3C physical connection
![](figures/I3C_physical_connection.png "I3C_physical_connection")
### Constraints
Currently, the I3C module supports only the kernels (LiteOS) of mini and small systems.
The I3C module supports only the kernel (LiteOS-A) for mini and small systems and cannot be used in user mode.
## Usage Guidelines
### When to Use
I3C can connect to one or more I3C or I2C target devices. It is used to:
- Communicate with sensors, such as gyroscopes, barometers, and image sensors that support the I3C protocol.
- Communicate with devices with other ports (such as UART serial ports) through software or hardware protocols.
### Available APIs
**Table 1** I3C driver APIs
The following table describes the APIs provided by the I3C module. For more information about the APIs, see **//drivers/hdf_core/framework/include/platform/i3c_if.h**.
**Table 1** I3C driver APIs
| API | Description |
| API | Description |
| ------------- | ----------------- |
| I3cOpen | Opens an I3C controller. |
| I3cClose | Closes an I3C controller. |
| I3cTransfer | Performs custom transfer. |
| I3cSetConfig | Sets the I3C controller. |
| I3cGetConfig | Obtains the I3C controller configuration. |
| I3cRequestIbi | Requests an IBI. |
| I3cFreeIbi | Releases an IBI. |
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
| DevHandle I3cOpen(int16_t number) | Opens an I3C controller. |
| void I3cClose(DevHandle handle) | Closes an I3C controller. |
| int32_t I3cTransfer(DevHandle handle, struct I3cMsg \*msg, int16_t count, enum TransMode mode) | Performs custom transfer. |
| int32_t I3cSetConfig(DevHandle handle, struct I3cConfig \*config) | Sets the I3C controller. |
| int32_t I3cGetConfig(DevHandle handle, struct I3cConfig \*config) | Obtains I3C controller configuration.|
| int32_t I3cRequestIbi(DevHandle handle, uint16_t addr, I3cIbiFunc func, uint32_t payload) | Requests an IBI. |
| int32_t I3cFreeIbi(DevHandle handle, uint16_t addr) | Releases an IBI. |
>![](../public_sys-resources/icon-note.gif) **NOTE**
>
>All APIs described in this document can be called only in kernel mode.
### How to Develop
The figure below illustrates the use of I3C driver APIs.
The following figure illustrates how to use the I3C APIs.
**Figure 2** Process of using I3C driver APIs
**Figure 2** Process of using I3C driver APIs
![](figures/I3C_usage_flowchart.png "I3C_usage_flowchart")
![](figures/using-I3C-process.png)
#### Opening an I3C Controller
......@@ -98,10 +100,10 @@ DevHandle I3cOpen(int16_t number);
| Name | Description |
| ---------- | ------------------- |
| number | I3C controller number. |
| number | I3C controller number. |
| **Return Value**| **Description** |
| NULL | The operation failed. |
| Controller handle| The operation is successful. The handle of the I3C controller opened is returned. |
| NULL | The operation fails. |
| Controller handle| The operation is successful. The handle of the I3C controller opened is returned.|
Example: Open I3C controller 1 of the eight I3C controllers numbered from 0 to 7 in the system.
......@@ -116,64 +118,13 @@ if (i3cHandle == NULL) {
}
```
#### Performing I3C Communication
Call **I3cTransfer()** to transfer messages.
```c
int32_t I3cTransfer(DevHandle handle, struct I3cMsg *msgs, int16_t count, enum TransMode mode);
```
**Table 3** Description of I3cTransfer
| Name | Description |
| ---------- | -------------------------------------------- |
| handle | I3C controller handle. |
| msgs | Pointer to the message array of the data to transfer. |
| count | Length of the message array. |
| mode | Transmission mode. The value **0** indicates I2C mode, **1** indicates I3C mode, and **2** indicates CCC transmission. |
| **Return Value**| **Description** |
| Positive integer | The operation is successful. The number of message structures that are successfully transmitted is returned. |
| Negative value | The operation failed. |
The I3C messages are of the I3cMsg type. Each message structure indicates a read or write operation. A message array can be used to perform multiple read or write operations.
```c
int32_t ret;
uint8_t wbuff[2] = { 0x12, 0x13 };
uint8_t rbuff[2] = { 0 };
struct I3cMsg msgs[2]; /* Custom message array for transfer. */
msgs[0].buf = wbuff; /* Data to write. */
msgs[0].len = 2; /* Length of the data to write. */
msgs[0].addr = 0x3F; /* Address of the device to which the data is written. */
msgs[0].flags = 0; /* Transfer flag. A write operation is performed by default. */
msgs[1].buf = rbuff; /* Data to read. */
msgs[1].len = 2; /* Length of the data to read. */
msgs[1].addr = 0x3F; /* Address of the device from which the data is read. */
msgs[1].flags = I3C_FLAG_READ /* I3C_FLAG_READ is set. */
/* Transfer two messages in I2C mode. */
ret = I3cTransfer(i3cHandle, msgs, 2, I2C_MODE);
if (ret != 2) {
HDF_LOGE("I3cTransfer: failed, ret %d\n", ret);
return;
}
```
>![](./public_sys-resources/icon-caution.gif) **Caution**<br>
>- The device address in the **I3cMsg** structure does not contain the read/write flag bit. The read/write information is passed by the read/write control bit in the member variable **flags**.
>- The **I3cTransfer()** function does not limit the number of message structures or the length of data in each message structure. The I3C controller determines these two limits.
>- Using **I3cTransfer()** may cause the system to sleep. Do not call it in the interrupt context.
#### Obtaining the I3C Controller Configuration
Call **I3cGetConfig()** to obtain the configuration of an I3C controller.
```c
int32_t I3cGetConfig(DevHandle handle, struct I3cConfig *config);
```
**Table 4** Description of I3cGetConfig
**Table 3** Description of I3cGetConfig
| Name | Description |
| ---------- | -------------- |
......@@ -181,7 +132,7 @@ int32_t I3cGetConfig(DevHandle handle, struct I3cConfig *config);
| config | Pointer to the I3C controller configuration. |
| **Return Value**| **Description**|
| 0 | The operation is successful. |
| Negative value | The operation failed. |
| Negative value | The operation fails. |
The following is an example of obtaining the I3C controller configuration:
......@@ -197,14 +148,11 @@ if (ret != HDF_SUCCESS) {
#### Setting an I3C Controller
Call **I3cSetConfig()** to set an I3C controller.
```c
int32_t I3cSetConfig(DevHandle handle, struct I3cConfig *config);
```
**Table 5** Description of I3cSetConfig
**Table 4** Description of I3cSetConfig
| Name | Description |
| ---------- | -------------- |
......@@ -212,7 +160,7 @@ int32_t I3cSetConfig(DevHandle handle, struct I3cConfig *config);
| config | Pointer to the I3C controller configuration. |
| **Return Value**| **Description**|
| 0 | The operation is successful. |
| Negative value | The operation failed. |
| Negative value | The operation fails. |
The following is an example of setting an I3C controller:
......@@ -228,9 +176,54 @@ if (ret != HDF_SUCCESS) {
}
```
#### Requesting an IBI
#### Performing I3C Communication
Call **I3cTransfer()** to transfer messages.
```c
int32_t I3cTransfer(DevHandle handle, struct I3cMsg *msgs, int16_t count, enum TransMode mode);
```
**Table 5** Description of I3cTransfer
| Name | Description |
| ---------- | -------------------------------------------- |
| handle | I3C controller handle. |
| msgs | Pointer to the message array of the data to transfer. |
| count | Length of the message array. |
| mode | Transmission mode. The value **0** indicates I2C mode, **1** indicates I3C mode, and **2** indicates CCC transmission.|
| **Return Value**| **Description** |
| Positive integer | The operation is successful. The number of message structures that are successfully transmitted is returned. |
| Negative value | The operation fails. |
The I3C messages are of the I3cMsg type. Each message structure indicates a read or write operation. A message array can be used to perform multiple read or write operations.
```c
int32_t ret;
uint8_t wbuff[2] = { 0x12, 0x13 };
uint8_t rbuff[2] = { 0 };
struct I3cMsg msgs[2]; /* Custom message array for transfer. */
msgs[0].buf = wbuff; /* Data to write. */
msgs[0].len = 2; /* Length of the data to write. */
msgs[0].addr = 0x3F; /* Address of the device to which the data is written. */
msgs[0].flags = 0; /* Transfer flag. A write operation is performed by default. */
msgs[1].buf = rbuff; /* Data to read. */
msgs[1].len = 2; /* Length of the data to read. */
msgs[1].addr = 0x3F; /* Address of the device from which the data is read. */
msgs[1].flags = I3C_FLAG_READ /* I3C_FLAG_READ is set. */
/* Transfer two messages in I2C mode. */
ret = I3cTransfer(i3cHandle, msgs, 2, I2C_MODE);
if (ret != 2) {
HDF_LOGE("I3cTransfer: failed, ret %d\n", ret);
return;
}
```
>![](./public_sys-resources/icon-caution.gif) **Caution**<br>
>- The device address in the **I3cMsg** structure does not contain the read/write flag bit. The read/write information is passed by the read/write control bit in **flags**.
>- The I3C controller determines the maximum number of messages to transfer at a time and the maximum length of each message.
>- Using **I3cTransfer()** may cause the system to sleep. Do not call it in the interrupt context.
Call **I3cRequestIbi()** to request an IBI.
#### Requesting an IBI
```c
int32_t I3cRequestIbi(DevHandle handle, uint16_t addr, I3cIbiFunc func, uint32_t payload);
......@@ -238,7 +231,6 @@ int32_t I3cRequestIbi(DevHandle handle, uint16_t addr, I3cIbiFunc func, uint32_t
**Table 6** Description of I3cRequestIbi
| Name | Description |
| ---------- | -------------- |
| handle | I3C controller handle. |
......@@ -247,7 +239,7 @@ int32_t I3cRequestIbi(DevHandle handle, uint16_t addr, I3cIbiFunc func, uint32_t
| payload | IBI payload. |
| **Return Value**| **Description**|
| 0 | The operation is successful. |
| Negative value | The operation failed. |
| Negative value | The operation fails. |
The following is an example:
......@@ -287,22 +279,19 @@ int32_t I3cTestRequestIbi(void)
#### Releasing an IBI
Call **I3cFreeIbi()** to release an IBI.
```c
int32_t I3cFreeIbi(DevHandle handle, uint16_t addr);
```
**Table 7** Description of I3cFreeIbi
| Name | Description |
| ---------- | -------------- |
| handle | I3C controller handle. |
| addr | I3C device address. |
| **Return Value**| **Description**|
| 0 | The operation is successful. |
| Negative value | The operation failed. |
| Negative value | The operation fails. |
The following is an example:
......@@ -319,7 +308,6 @@ void I3cClose(DevHandle handle);
**Table 8** Description of I3cClose
| Name | Description |
| ---------- | -------------- |
| handle | I3C controller handle. |
......@@ -330,17 +318,15 @@ The following is an example:
I3cClose(i3cHandle); /* Close the I3C controller. */
```
## Development Example
This following example shows how to use I3C APIs to manage an I3C device on a Hi3516D V300 development board.
## Example
Because the Hi3516D V300 SoC has no I3C controller, this example describes how to perform simple transfer operations on a virtual driver on a Hi3516D V300. The basic information is as follows:
The following example presents how to use I3C APIs to manage an I3C device on a Hi3516D V300 development board. <br>The basic hardware information is as follows:
- SoC: Hi3516D V300
- Virtual: The I3C address is 0x3f, and the register bit width is 1 byte.
- Virtual I3C device: The I3C address is 0x3f, and the register bit width is 1 byte.
- The virtual I3C devices are connected to virtual I3C controllers 18 and 19.
- The virtual I3C device is connected to I3C controllers 18 and 19.
Perform simple I3C transfer to test whether the I3C channels are normal.
......@@ -349,7 +335,7 @@ The sample code is as follows:
```c
#include "i3c_if.h" /* Header file for I3C standard APIs */
#include "hdf_log.h" /* Header file for log APIs */
##include "osal_io.h" /* Header file for I/O read and write APIs */
##include "osal_io.h" /* Header file for I/O read and write APIs */
#include "osal_time.h" /* Header file for delay and sleep APIs */
/* Define a device structure to hold information. */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册