diff --git a/en/device-dev/driver/Readme-EN.md b/en/device-dev/driver/Readme-EN.md index 5ca9c29d50b6d22048cf73195e43adb9ef3c0406..0f88055fd95e4a2422b349aba144b42eaccf05d8 100644 --- a/en/device-dev/driver/Readme-EN.md +++ b/en/device-dev/driver/Readme-EN.md @@ -1,13 +1,13 @@ # Drivers -- [HDF](driver-hdf.md) +- HDF - [HDF Overview](driver-hdf-overview.md) - [Driver Development](driver-hdf-development.md) - [Driver Service Management](driver-hdf-servicemanage.md) - [Driver Message Mechanism Management](driver-hdf-message-management.md) - [Driver Configuration Management](driver-hdf-manage.md) - [HDF Development Example](driver-hdf-sample.md) -- [Platform Driver Development](driver-develop.md) +- Platform Driver Development - [ADC](driver-platform-adc-develop.md) - [DAC](driver-platform-dac-develop.md) - [GPIO](driver-platform-gpio-develop.md) @@ -25,7 +25,7 @@ - [SPI](driver-platform-spi-develop.md) - [UART](driver-platform-uart-develop.md) - [Watchdog](driver-platform-watchdog-develop.md) -- [Platform Driver Usage](driver-platform.md) +- Platform Driver Usage - [ADC](driver-platform-adc-des.md) - [DAC](driver-platform-dac-des.md) - [GPIO](driver-platform-gpio-des.md) @@ -41,8 +41,8 @@ - [SDIO](driver-platform-sdio-des.md) - [SPI](driver-platform-spi-des.md) - [UART](driver-platform-uart-des.md) - - [Watchdog](driver-platform-watchdog-des.md) -- [Peripheral Driver Usage](driver-peripherals.md) + - [Watchdog](driver-platform-watchdog-des.md) +- Peripheral Driver Usage - [LCD](driver-peripherals-lcd-des.md) - [Touchscreen](driver-peripherals-touch-des.md) - [Sensor](driver-peripherals-sensor-des.md) @@ -51,4 +51,4 @@ - [USB](driver-peripherals-usb-des.md) - [Camera](driver-peripherals-camera-des.md) - [Vibrator](driver-peripherals-vibrator-des.md) - - [Light](driver-peripherals-light-des.md) \ No newline at end of file + - [Light](driver-peripherals-light-des.md) diff --git a/en/device-dev/driver/driver-hdf-development.md b/en/device-dev/driver/driver-hdf-development.md index 192e813d41a4733dab2f666fe08e48dc86eca748..47166373579e4a465e2bc0850759a9f104a8f123 100644 --- a/en/device-dev/driver/driver-hdf-development.md +++ b/en/device-dev/driver/driver-hdf-development.md @@ -3,7 +3,9 @@ ## Driver Model -The Hardware Driver Foundation (HDF) is designed based on the component-based driver model. This model allows refined driver management and standardize driver development and deployment. Device drivers of the same type are placed in the same host. You can develop and deploy the drivers separately. One driver can have multiple nodes. The figure below shows the HDF driver model. +The Hardware Driver Foundation (HDF) is designed upon a component-based driver model. This model enables refined driver management and streamlines driver development and deployment. In the HDF, the same type of device drivers are placed in a host. You can develop and deploy the drivers separately. One driver can have multiple nodes. + +The figure below shows the HDF driver model. **Figure 1** HDF driver model @@ -12,74 +14,78 @@ The Hardware Driver Foundation (HDF) is designed based on the component-based dr ## How to Development -The HDF-based driver development involves driver implementation and driver configuration. The development procedure is as follows: +The HDF-based driver development involves driver implementation and configuration. The procedure is as follows: -1. Implement a driver. - To implement a driver, compile driver service code and register a driver entry. +1. Implement a driver.
+ Write the driver code and register the driver entry with the HDF. - - Driver service code - - ``` - #include "hdf_device_desc.h" // Header file that describes the APIs provided by the HDF to the driver. - #include "hdf_log.h" // Header file that describes the log APIs provided by the HDF. - - #define HDF_LOG_TAG "sample_driver" // Tag contained in logs. If no tag is not specified, the default HDF_TAG is used. - - // Service capabilities provided by the driver. Bind the service APIs to the HDF. - int32_t HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) - { - HDF_LOGD("Sample driver bind success"); - return 0; - } - - // Initialize the driver service. - int32_t HdfSampleDriverInit(struct HdfDeviceObject *deviceObject) - { - HDF_LOGD("Sample driver Init success"); - return 0; - } - - // Release the driver resources. - void HdfSampleDriverRelease(struct HdfDeviceObject *deviceObject) - { - HDF_LOGD("Sample driver release success"); - return; - } - ``` + - Writing the driver service code + + The following is an example: + + ``` + #include "hdf_device_desc.h" // Header file that defines the driver development APIs provided by the HDF. + #include "hdf_log.h" // Header file that defines the log APIs provided by the HDF. + + #define HDF_LOG_TAG "sample_driver" // Tag contained in logs. If no tag is not specified, the default HDF_TAG is used. + + // Bind the service interface provided by the driver to the HDF. + int32_t HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) + { + HDF_LOGD("Sample driver bind success"); + return 0; + } + + // Initialize the driver service. + int32_t HdfSampleDriverInit(struct HdfDeviceObject *deviceObject) + { + HDF_LOGD("Sample driver Init success"); + return 0; + } + + // Release the driver resources. + void HdfSampleDriverRelease(struct HdfDeviceObject *deviceObject) + { + HDF_LOGD("Sample driver release success"); + return; + } + ``` + - Registering the driver entry with the HDF - - ``` - // Define a driver entry object. It must be a global variable of the HdfDriverEntry type (defined in hdf_device_desc.h). - struct HdfDriverEntry g_sampleDriverEntry = { - .moduleVersion = 1, - .moduleName = "sample_driver", - .Bind = HdfSampleDriverBind, - .Init = HdfSampleDriverInit, - .Release = HdfSampleDriverRelease, - }; - - // Call HDF_INIT to register the driver entry with the HDF. When loading the driver, the HDF calls the Bind() function first and then the Init() function. If the Init() function fails to be called, the HDF will call Release() to release the driver resources and exit the driver model. - HDF_INIT(g_sampleDriverEntry); - ``` - -2. Build the driver. - - LiteOS + + + ``` + // Define a driver entry object. It must be a global variable of the HdfDriverEntry type (defined in hdf_device_desc.h). + struct HdfDriverEntry g_sampleDriverEntry = { + .moduleVersion = 1, + .moduleName = "sample_driver", + .Bind = HdfSampleDriverBind, + .Init = HdfSampleDriverInit, + .Release = HdfSampleDriverRelease, + }; + + // Call HDF_INIT to register the driver entry with the HDF. When loading the driver, the HDF calls the Bind() function and then the Init() function. If the Init() function fails to be called, the HDF will call Release() to release driver resources and exit the driver model. + HDF_INIT(g_sampleDriverEntry); + ``` + +2. Build the driver.
+ - LiteOS
Modify **makefile** and **BUILD.gn**. - - makefile: + - **makefile**:
Use the **makefile** template provided by the HDF to compile the driver code. ``` include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk # Import the content predefined by the HDF. This operation is mandatory. MODULE_NAME := # File to be generated. - LOCAL_INCLUDE: = # Header file directory of the driver. + LOCAL_INCLUDE: = # Directory of the driver header files. LOCAL_SRCS : = # Source code file of the driver. LOCAL_CFLAGS : = # Custom compilation options. include $(HDF_DRIVER) # Import the makefile template to complete the compilation. ``` - Add the path of the generated file to **hdf_lite.mk** in the **drivers/adapter/khdf/liteos** directory to link the file to the kernel image. The following is an example: + Add the path of the generated file to **hdf_lite.mk** in the **drivers/adapter/khdf/liteos** directory to link the file to the kernel image. ``` @@ -87,7 +93,7 @@ The HDF-based driver development involves driver implementation and driver confi LIB_SUBDIRS += # Directory in which the driver code makefile is located. ``` - - **BUILD.gn**: + - **BUILD.gn**:
Add **BUILD.gn**. The content of **BUILD.gn** is as follows: @@ -98,18 +104,18 @@ The HDF-based driver development involves driver implementation and driver confi module_name = "xxx" hdf_driver(module_name) { sources = [ - "xxx/xxx/xxx.c", # Source code file of the driver + "xxx/xxx/xxx.c", # Source code to compile. ] - public_configs = [ ":public" ] # Configuration applied to dependencies + public_configs = [ ":public" ] # Head file configuration of the dependencies. } - config("public") {# Configuration of the dependencies + config("public") {# Define the head file configuration of the dependencies. include_dirs = [ - "xxx/xxx/xxx", # Directory of the dependency header file. + "xxx/xxx/xxx", # Directory of the dependency header files. ] } ``` - Add the directory where the **BUILD.gn** file of the driver is located to **/drivers/adapter/khdf/liteos/BUILD.gn**. + Add the **BUILD.gn** directory to **/drivers/adapter/khdf/liteos/BUILD.gn**. ``` @@ -120,7 +126,7 @@ The HDF-based driver development involves driver implementation and driver confi ] } ``` - - Linux + - Linux
To define the driver control macro, add the **Kconfig** file to the driver directory **xxx** and add the path of the **Kconfig** file to **drivers/adapter/khdf/linux/Kconfig**. @@ -142,25 +148,25 @@ The HDF-based driver development involves driver implementation and driver confi obj-y += xxx.o ``` -3. Configure the driver. - HDF Configuration Source (HCS) is the source code that describes the configuration of the HDF. For details about the HCS, see [Driver Configuration Management](../driver/driver-hdf-manage.md). +3. Configure the driver.
+ The HDF Configuration Source (HCS) contains the source code of HDF configuration. For details about the HCS, see [Configuration Management](../driver/driver-hdf-manage.md). The driver configuration consists of the driver device description defined by the HDF and the private driver configuration. - - (Mandatory) Driver device description - The information required for the HDF to load drivers comes from the driver device description defined by the HDF. Therefore, the device description must be added to the configuration file **device_info.hcs** defined by the HDF for drivers developed based on the HDF. The following is an example: + - (Mandatory) Setting the driver device description
+ The HDF loads a driver based on the driver device description defined by the HDF. Therefore, the driver device description must be added to the **device_info.hcs** file defined by the HDF. The following is an example: ``` root { device_info { match_attr = "hdf_manager"; - template host { // Host template. If the node (for example, sample_host) uses the default values in the template, the values of the node fields can be omitted. + template host { // Host template. If a node (for example, sample_host) uses the default values in this template, the node fields can be omitted. hostName = ""; priority = 100; - uid = ""; // User ID (UID) of the user-mode process. By default, it is left empty, that is, set to the value defined for hostName, which indicates a common user. - gid = ""; // Group ID (GID) of the user-mode process. By default, it is left empty, that is, set to the value defined for hostName, which indicates a common user group. - caps = [""]]; // Linux capabilities of the user-mode process. It is left empty by default. Set this parameter based on service requirements. + uid = ""; // User ID (UID) of a user-mode process. It is left empty by default. If you do not set the value, this parameter will be set to the value of hostName, which indicates a common user. + gid = ""; // Group ID (GID) of a user-mode process. It is left empty by default. If you do not set the value, this parameter will be set to the value of hostName, which indicates a common user group. + caps = [""]]; // Linux capabilities of a user-mode process. It is left empty by default. Set this parameter based on service requirements. template device { template deviceNode { policy = 0; @@ -174,16 +180,16 @@ The HDF-based driver development involves driver implementation and driver confi } } sample_host :: host{ - hostName = "host0"; // Host name. The host node is used to store a type of drivers. - priority = 100; // Host startup priority (0-200). A larger value indicates a lower priority. The default value 100 is recommended. If the priorities are the same, the host loading sequence is random. + hostName = "host0"; // Host name. The host node is used as a container to hold a type of drivers. + priority = 100; // Host startup priority (0-200). A smaller value indicates a higher priority. The default value 100 is recommended. The hosts with the same priority start based on the time when the priority was configured. The host configured first starts first. caps = ["DAC_OVERRIDE", "DAC_READ_SEARCH"]; // Linux capabilities of the user-mode process. device_sample :: device { // Sample device node. device0 :: deviceNode { // DeviceNode of the sample driver. - policy = 1; // Driver service release policy. For details, see the Driver Service Management. - priority = 100; // Driver startup priority (0-200). A larger value indicates a lower priority. The default value 100 is recommended. If the priorities are the same, the host loading sequence is random. - preload = 0; // On-demand loading of the driver. For details, see "NOTE" at the end of this section. + policy = 1; // Policy for publishing the driver service. For details, see Driver Service Management. + priority = 100; // Driver startup priority (0-200). A smaller value indicates a higher priority. The default value 100 is recommended. The drivers with the same priority start based on the time when the priority was configured. The driver configured first starts first. + preload = 0; // The loading mode of the driver is on-demand loading. For details, see "NOTE" at the end of this document. permission = 0664; // Permission for the driver to create a device node. - moduleName = "sample_driver"; // Driver name. The value of this field must be the same as that of moduleName in the HdfDriverEntry structure. + moduleName = "sample_driver"; // Driver name. The value must be the same as that of moduleName in the HdfDriverEntry structure. serviceName = "sample_service"; // Name of the service published by the driver. The service name must be unique. deviceMatchAttr = "sample_config"; // Keyword for matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver. } @@ -192,32 +198,36 @@ The HDF-based driver development involves driver implementation and driver confi } } ``` - > ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**
+ ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**
- - **uid**, **gid**, and **caps** are startup configuration for user-mode drivers and do not need to be configured for kernel-mode drivers. + - **uid**, **gid**, and **caps** are startup parameters for user-mode drivers only. - According to the principle of least privilege for processes, **uid** and **gid** do not need to be configured for service modules. In the preceding example, **uid** and **gid** are left empty (granted with the common user rights) for sample_host. - - If you need to set **uid** and **gid** to **system** or **root** due to service requirements, contact security experts for review. - - The process UID is configured in **base/startup/init_lite/services/etc/passwd**, and the process GID is configured in **base/startup/init_lite/services/etc/group**. For details, see [Adding a System Service User Group]( https://gitee.com/openharmony/startup_init_lite/wikis). - - If CAP_DAC_OVERRIDE needs to be configured for a service module, set **caps = ["DAC_OVERRIDE"]** instead of **caps = ["CAP_DAC_OVERRIDE"]**. + - If you need to set **uid** and **gid** to **system** or **root** due to service requirements, contact security experts for review. + - The process UIDs are configured in **base/startup/init_lite/services/etc/passwd**, and the process GIDs are configured in **base/startup/init_lite/services/etc/group**. For details, see [Adding a System Service User Group]( https://gitee.com/openharmony/startup_init_lite/wikis). + - If CAP_DAC_OVERRIDE needs to be configured for a service module, enter **caps = ["DAC_OVERRIDE"]** instead of **caps = ["CAP_DAC_OVERRIDE"]**. - - (Optional) Private configuration information of the driver - If the driver has private configuration, you can add a driver configuration file to set default driver configuration. When loading the driver, the HDF obtains and saves the corresponding configuration in **property** of **HdfDeviceObject**, and passes the configuration to the driver through **Bind()** and **Init()** (see step 1). The following is an example of the driver configuration: + - (Optional) Setting driver private information
+ If the driver has private configuration, add a driver configuration file to set default driver configuration. When loading the driver, the HDF obtains and saves the driver private information in **property** of **HdfDeviceObject**, and passes the information to the driver using **Bind()** and **Init()** (see step 1). + The following is an example of the driver private configuration: + ``` root { SampleDriverConfig { sample_version = 1; sample_bus = "I2C_0"; - match_attr = "sample_config"; // The value of this field must be the same as that of deviceMatchAttr in device_info.hcs. + match_attr = "sample_config"; // The value must be the same as that of deviceMatchAttr in device_info.hcs. } } ``` - - After the configuration, add the configuration file to the board-level configuration entry file **hdf.hcs**. (You can use DevEco to perform on-click configuration. For details, see the description about the driver development suite.) The following is an example: + After the configuration, add the configuration file to the board-level configuration entry file **hdf.hcs**. (You can use DevEco to perform one-click configuration. For details, see the description about the driver development suite.) + + The following is an example: + ``` #include "device_info/device_info.hcs" @@ -225,7 +235,7 @@ The HDF-based driver development involves driver implementation and driver confi ``` -> ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**
+> ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**
> Drivers can be loaded on demand or in sequence. > > - On-demand loading @@ -239,11 +249,11 @@ The HDF-based driver development involves driver implementation and driver confi > } DevicePreload; > ``` > -> If **preload** in the configuration file is set to **0** (**DEVICE_PRELOAD_ENABLE**), the driver is loaded by default during the system boot process. +> If **preload** in the configuration file is set to **0 (DEVICE_PRELOAD_ENABLE)**, the driver is loaded by default during the system boot process. > -> If **preload** is set to **1** (**DEVICE\_PRELOAD\_ENABLE\_STEP2**), the driver is loaded after a quick start is complete if the system supports quick start. If the system does not support quick start, the value **1** has the same meaning as **DEVICE\_PRELOAD\_ENABLE**. +> If **preload** is set to **1 (DEVICE_PRELOAD_ENABLE_STEP2)**, the driver is loaded after a quick start is complete. If the system does not support quick start, the value **1** has the same meaning as **DEVICE_PRELOAD_ENABLE**. > -> If **preload** is set to **2** (**DEVICE\_PRELOAD\_DISABLE**), the driver is dynamically loaded instead of being loaded during the system boot process. When a user-mode process requests the driver service (for details, see [Driver Message Mechanism Management](driver-hdf-message-management.md)), the HDF attempts to dynamically load the driver if the driver service does not exist. +> If **preload** is set to **2 (DEVICE_PRELOAD_DISABLE)** , the driver is dynamically loaded instead of being loaded during the system boot process. When a user-mode process requests the driver service, the HDF attempts to dynamically load the driver if the driver service does not exist. For more details, see [Driver Message Mechanism Management](driver-hdf-message-management.md). > -> - Sequential loading (drivers must be loaded by default) -> In the configuration file, the **priority** field \(value range: 0 to 200\) indicates the priority of the host and driver. For drivers in different hosts, a smaller host priority value indicates a higher driver loading priority; for drivers in the same host, a smaller driver priority value indicates a higher driver loading priority. +> - Sequential loading (**preload** set to **0 (DEVICE_PRELOAD_ENABLE)**)
+> In the configuration file, the **priority** fields (value range: 0 to 200) determines the loading sequence of a host and a driver. For drivers in different hosts, a smaller host priority value indicates a higher driver loading priority; for drivers in the same host, a smaller driver priority value indicates a higher driver loading priority. diff --git a/en/device-dev/driver/driver-hdf-manage.md b/en/device-dev/driver/driver-hdf-manage.md index 7acd765714a62973371c584a6f3e8c4708a1f9d6..e8aa65985913cec33e7538d820aa687bd3d30199 100644 --- a/en/device-dev/driver/driver-hdf-manage.md +++ b/en/device-dev/driver/driver-hdf-manage.md @@ -1,107 +1,72 @@ -# Driver Configuration Management - -## HDF Configuration Overview - -HCS is the source code that describes the configuration of the HDF using key-value pairs. It decouples the configuration code from driver code, thereby facilitating configuration management. - -HDF Configuration Generator \(HC-GEN\) is a tool for converting a configuration file into a file that can be read by the target software. - -- In a low-performance system on a chip \(SoC\), this tool can convert a configuration file into the source code or macro definitions of the configuration tree so that the driver can obtain the configuration by calling the C library code or macro-based APIs. -- In a high-performance SoC, this tool can convert an HCS configuration file into the HDF Configuration Binary \(HCB\) file, allowing the driver to obtain the configuration through the APIs provided by the HDF. - -The following figure shows the typical application scenario of the HCB mode. - -**Figure 1** Configuration process -![](figures/configuration-process.png "configuration-process") - -The HCS is compiled using the HC-GEN tool to generate an HCB file. The HCS Parser module in the HDF recreates a configuration tree using the HCB file. Then, the HDF driver modules obtain the configurations using the API provided by the HCS Paser. - -## Configuration Syntax - -The HCS syntax is described as follows: - -### Keywords - -The keywords listed in the following table below are reserved for HCS configuration files. - -**Table 1** Reserved keywords for HCS configuration files - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Keywords

-

Description

-

Remarks

-

root

-

Configures the root node.

-

-

-

include

-

References other HCS configuration files.

-

-

-

delete

-

Deletes a node or an attribute.

-

This keyword applies only to the configuration tree imported using the include keyword.

-

template

-

Defines a template node.

-

-

-

match_attr

-

Marks the node attribute for matching.

-

During configuration parsing, the keyword value can be used to find the corresponding node.

-
- -### Basic Structures - -The HCS configuration file consists of configurations of attributes and nodes. - -**Attributes** - -An attribute, as the minimum configuration unit, is an independent configuration item. Its syntax is as follows: +# Configuration Management -``` - attribute_name = value; -``` -- The value of **attribute\_name** is a case-sensitive string of characters starting with a letter and consisting of letters, digits, and underscores \(\_\). +## HDF Configuration Overview + +HDF Configuration Source (HCS) is the source code that describes the HDF configuration in key-value pairs. It decouples the configuration code from driver code, simplifying configuration management. + +HDF Configuration Generator (HC-GEN) is a tool for converting an HDF configuration file into a file that can be read by the software. + +- In a low-performance system on a chip (SoC), this tool converts an HCS configuration file into the source code or macro definitions of the configuration tree. The driver can obtain the configuration by calling the C library code or macro-based APIs. + +- In a high-performance SoC, this tool converts an HCS configuration file into an HDF Configuration Binary (HCB) file. The driver can obtain the configuration by calling the configuration parsing APIs provided by the HDF. + +The figure below illustrates how an HCB file is used. + + **Figure 1** Process of using an HCB file -- Available formats of **value** are as follows: + ![](figures/HCB-using-process.png) - - A binary, octal, decimal, or hexadecimal integer. For details, see [Data Types](#section177001259134). +The HC-GEN converts the HCS into an HCB file. The HCS Parser module in the HDF rebuilds a configuration tree from the HCB file. The HDF driver obtains the configuration through the configuration read API provided by the HCS Parser. - - A character string. The content should be enclosed in double quotation marks \(" "\). - - A node reference +## Configuration Syntax +The following describes the HCS syntax. -- An attribute key-value pair must end with a semicolon \(;\) and belong to a node. +### Keywords -**Nodes** +The table below describes the keywords used in the HCS syntax. + + **Table 1** Keywords used in HCS syntax + +| Keyword| Description| Remarks| +| -------- | -------- | -------- | +| root | Sets the root node.| - | +| include | References other HCS files.| - | +| delete | Deletes a node or an attribute.| Applicable only to the configuration tree referenced by **include**.| +| template | Defines a template node.| - | +| match_attr | Marks the node attribute for matching.| During configuration parsing, the attribute value can be used to locate the corresponding node.| + + +### Basic Structures + +The HCS has two structures: attribute and node. + +**Attribute** + +An attribute is the minimum, independent configuration unit. The syntax is as follows: + + +``` + attribute_name = value; +``` + +- **attribute_name** is a case-sensitive string of letters, digits, and underscores (_) and must start with a letter or underscore (_). + +- The **value** can be in any of the following formats: + + - A binary, octal, decimal, or hexadecimal integer. For details, see the **Data Types** section. + - String quoted by double quotation marks (""). + - Node reference. + +- An attribute key-value pair must end with a semicolon (;) and belong to a node. + +**Node** + +A node is a set of attributes. The syntax is as follows: -A node is a set of attributes. Its syntax is as follows: ``` node_name { @@ -110,39 +75,40 @@ A node is a set of attributes. Its syntax is as follows: } ``` -- The value of **node\_name** is a case-sensitive string of characters starting with a letter and consisting of letters, digits, and underscores \(\_\). +- **node_name** is a case-sensitive string of letters, digits, and underscores (_) and must start with a letter or underscore (_). -- A semicolon \(;\) is not required after the curly brace \(\}\). +- No semicolon (;) is required after the curly brace ({) or (}). -- The reserved keyword **root** is used to declare the root node of a configuration table. +- The keyword **root** is used to declare the root node of a configuration table. Each configuration table must start with the root node. -- The root node must contain a **module** attribute that uses a string to represent the module to which the configuration belongs. +- The root node must contain a **module** attribute. The value is a string indicating the module to which the configuration belongs. -- The **match\_attr** attribute can be added to a node. Its value is a globally unique character string. During configuration parsing, the query interface can be invoked to query the nodes with the attribute based on the attribute value. +- The **match_attr** attribute can be added to a node. Its value is a globally unique string. During configuration parsing, the **match_attr** attribute can be used to quickly locate the node that contains the attribute. -### Data Types + +### Data Types Attributes automatically use built-in data types, including integer, string, array, and boolean. You do not need to explicitly specify the data type for the attribute values. **Integer** -An integer can be binary, octal, decimal, or hexadecimal. The minimum space is automatically allocated to the integer based on the actual data length. - -- Binary: prefixed with 0b, for example, 0b1010 + An integer can be binary, octal, decimal, or hexadecimal. The minimum space is automatically allocated to the integer based on the actual data length. +- Binary: prefixed with **0b**, for example, **0b1010**. -- Octal: prefixed with 0, for example, 0664 -- Decimal: either signed or unsigned, without a prefix, for example, 1024 or +1024. Negative integers can be read only via signed interfaces. +- Octal: prefixed with **0**, for example, **0664**. -- Hexadecimal: prefixed with 0x, for example, 0xff00 and 0xFF +- Decimal: signed or unsigned, without prefix, for example, **1024** or **+1024**. Negative integers can be read only via signed interfaces. +- Hexadecimal: prefixed with **0x**, for example, **0xff00** and **0xFF**. **String** -A string is enclosed by double quotation marks \(" "\). +A string is enclosed in double quotation marks (""). **Array** -The elements in an array can be integers or strings, but cannot be a combination of both. The combination of **uint32\_t** and **uint64\_t** in an integer array will enable up-casting to **uint64**. The following is an example of an integer array and a string array: +An array can hold either integers or strings, but not a mixture of them. The mixed use of **uint32_t** and **uint64_t** in an integer array will cause typecasting to **uint64**. The following is an example of an integer array and a string array: + ``` attr_foo = [0x01, 0x02, 0x03, 0x04]; @@ -151,53 +117,62 @@ attr_bar = ["hello", "world"]; **Boolean** -A Boolean data type has two possible values: **true** and **false**. +Boolean data type is a form of data with only two possible values: **true** and **false**. + -### Pre-Processing +### Preprocessing **include** -The **include** keyword is used to import other HCS files. The syntax is as follows: +The keyword **include** is used to import other HCS files. The syntax is as follows: + ``` #include "foo.hcs" #include "../bar.hcs" ``` -- The file names must be enclosed by double quotation marks \(" "\). Files in different directories can be referenced using relative paths. The file included must be a valid HCS file. -- In the scenario that multiple HCS files are imported using **include**, if the same nodes exist, the latter node will override the former one, and other nodes are listed in sequence. +- The file name must be enclosed in double quotation marks (""). If the file to be included is in a different directory with the target file, use a relative path. The included file must be a valid HCS file. + +- If multiple HCS files included contain the same nodes, the same nodes will be overridden and other nodes are listed in sequence. -### Comments -Comments can be formatted as follows: +### Comments -- Single-line comment +The following two comment formats are supported: - ``` - // comment - ``` +- Single-line comment -- Multi-line comment + + ``` + // comment + ``` - ``` - /* - comment - */ - ``` +- Multi-line comment - >![](../public_sys-resources/icon-note.gif) **NOTE:** - >Multi-line comments cannot be nested. + + ``` + /* + comment + */ + ``` + > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+ > Multi-line comments cannot be nested. -### Reference Modifications -You can use the following syntax to modify the content of any other node: +### Reference Modification + +You can reference the content of a node to modify the content of another node. The syntax is as follows: + ``` node :& source_node ``` -This syntax indicates that the node value is a modification of the source\_node value. Example: +In this statement, the content of **node** is referenced to modify the content of **source_node**. + +Example: ``` root { @@ -220,7 +195,8 @@ root { } ``` -The following configuration tree is generated: +The configuration tree generated is as follows: + ``` root { @@ -236,20 +212,26 @@ root { } ``` -In the preceding example, the **foo.foo\_** node changes the value of the referenced **bar.attr** to "**foo**", and the **foo.foo1** node changes the value of the referenced **foo.foo2.attr** to **0x2**. In the generated configuration tree, **foo.foo\_** and **foo.foo1** are not displayed, but their configuration modifications are presented by their referenced nodes. +In this example, the value of **bar.attr** is changed to **foo** by referencing **foo.foo_**, and the value of **foo.foo2.attr** is changed to **0x2** by referencing **foo.foo1**. The **foo.foo_** and **foo.foo1** nodes are used to modify the content of the target nodes, and do not exist in the configuration tree generated. -- A node of the same level can be referenced simply using the node name. A node of a different level must be referenced by the absolute path, and node names are separated using a period \(.\). **root** indicates the root node. The path format is the node path sequence starting with root. For example, **root.foo.bar** is a valid absolute path. -- If multiple modifications are made to the same attribute, only one uncertain modification can take effect, and a warning will be displayed. +- A node of the same level can be referenced simply using the node name. To reference a node of a different level, use the absolute path starting with **root**, and separate the node names using a period (.). **root** indicates the root node. For example, **root.foo.bar**. -### Node Replication +- If multiple modifications are made to the same attribute, only one modification takes effect and a warning will be displayed for you to confirm the result. + + +### Node Replication + +You can replicate a node to define a node with similar content. The syntax is as follows: -The content of a node can be replicated to another node to define the node with similar content. The syntax is as follows: ``` node : source_node ``` -The preceding statement indicates that the attributes of **source\_node** are replicated to **node**. Example: +This statement replicates the attributes of the **source_node** node to define **node**. + +Example: + ``` root { @@ -263,7 +245,8 @@ root { } ``` -The following configuration tree is generated: +The configuration tree generated is as follows: + ``` root { @@ -278,13 +261,17 @@ root { } ``` -In the preceding example, the **bar** node configuration includes both the **attr\_0** and **attr\_1** values. The modification to **attr\_0** in the **bar** node does not affect the **foo** node. +In this example, the **bar** node contains **attr_0** and **attr_1** attributes, and the modification of the **attr_0** attribute in the **bar** node does not affect the **foo** node. + +You do not need to specify the path of the **foo** node if the **foo** node and the **bar** node are of the same level. Otherwise, specify the absolute path of **foo**. For details, see [Reference Modification](referencemodification). + -The path of the **foo** node is not required if the **foo** node and the **bar** node are of the same level. Otherwise, the absolute path must be used. For details, see [Reference Modifications](#section193708571145). +### Delete -### Delete +You can use the keyword **delete** to delete unnecessary nodes or attributes from the base configuration tree imported by using the **include** keyword. The following example includes the configuration in **sample2.hcs** to **sample1.hcs** and deletes the **attribute2** attribute and the **foo_2** node. + +Example: -You can use the keyword **delete** to delete unnecessary nodes or attributes in the base configuration tree imported by the **include** keyword. In the following example, **sample1.hcs** imports the configuration of **sample2.hcs** using **include**, and deletes the **attribute2** attribute and the **foo\_2** node using the **delete** keyword. ``` // sample2.hcs @@ -305,7 +292,8 @@ root { } ``` -The following configuration tree is generated: +The configuration tree generated is as follows: + ``` root { @@ -313,18 +301,23 @@ root { } ``` ->![](../public_sys-resources/icon-note.gif) **NOTE:** ->The **delete** keyword cannot be used in the same HCS file. It is recommended that you delete unnecessary attributes directly from the configuration source code. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> 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. + + +### Attribute Reference -### Attribute References +You can associate an attribute and a node so that the node can be quickly located when the attribute is read during configuration parsing. The syntax is as follows: -To quickly locate the associated node during configuration parsing, you can use the node as the value of the attribute and read the attribute to find the corresponding node. The syntax is as follows: ``` attribute = &node; ``` -This syntax indicates that the **attribute** value is a reference to **node**. During code parsing, you can quickly locate the node using this attribute. Example: +In this statement, the value of **attribute** is a referenced to the node. During code parsing, you can quickly locate the node based on this **attribute**. + +Example: + ``` node1 { @@ -334,8 +327,10 @@ node2 { attr_1 = &root.node1; } ``` + Or + ``` node2 { node1 { @@ -345,11 +340,15 @@ node2 { } ``` -### Template -The **template** keyword is used to generate nodes with strictly consistent syntax, thereby facilitating the traverse and management of nodes of the same type. +### Template + +The template is used to generate nodes with consistent syntax, thereby facilitating the traverse and management of nodes of the same type. + +If a node is defined using the keyword **template**, its child nodes inherit from the node configuration through the double colon operator (::). The child nodes can modify but cannot add or delete attributes in **template**. The attributes not defined in the child nodes will use the attributes defined in **template** as the default values. + +Example: -If a node is defined using the keyword **template**, its child nodes inherit the node configuration through the double colon operator \(::\). The child nodes can modify but cannot add or delete attributes in **template**. The attributes not defined in the child nodes will use the attributes defined in **template** as the default values. Example: ``` root { @@ -368,7 +367,8 @@ root { } ``` -The following configuration tree is generated: +The configuration tree generated is as follows: + ``` root { @@ -384,15 +384,18 @@ root { } ``` -In the preceding example, the **bar** and **bar\_1** nodes inherit the **foo** node. The structures of the generated configuration tree nodes are the same as that of the **foo** node, but the attribute values are different. +In this example, the **bar** and **bar_1** nodes inherit from the **foo** node. The structure of the generated configuration tree is the same as that of the **foo** node, except that the attribute values are different. -## Configuration Generation -The HC-GEN tool is used to generate configurations. It checks the HCS configuration syntax and converts HCS source files into HCB files. +## **Configuration Generation** -### Introduction to hc-gen +The HC-GEN tool checks the HCS configuration syntax and converts HCS source files into HCB files. + + +### HC-GEN + +HC-GEN options: -Parameter description: ``` Usage: hc-gen [Options] [File] @@ -410,7 +413,8 @@ options: -h show this help message ``` -Generate a **.c** or **.h** configuration file. +Generate a .c or .h configuration file. + ``` hc-gen -o [OutputCFileName] -t [SourceHcsFileName] @@ -418,19 +422,21 @@ hc-gen -o [OutputCFileName] -t [SourceHcsFileName] Generate an HCB file. + ``` hc-gen -o [OutputHcbFileName] -b [SourceHcsFileName] ``` Generate a macro definition file. + ``` hc-gen -o [OutputMacroFileName] -m [SourceHcsFileName] ``` -Compile an **HCB** file to an **HCS** file: +Decompile an HCB file to an HCS file. + ``` hc-gen -o [OutputHcsFileName] -d [SourceHcbFileName] ``` - diff --git a/en/device-dev/driver/driver-platform-i3c-des.md b/en/device-dev/driver/driver-platform-i3c-des.md index 555bc6eaebf26723f4481f129ccecd37fc696589..487947c2728ac31ba41f1fb078ea30870cf5eaed 100644 --- a/en/device-dev/driver/driver-platform-i3c-des.md +++ b/en/device-dev/driver/driver-platform-i3c-des.md @@ -17,7 +17,7 @@ The I3C APIs provide a set of common functions for I3C transfer, including: - Requesting and releasing an IBI [Figure 1](#fig1) shows the I3C physical connection. -**Figure 1** I3C physical connection +**Figure 1** I3C physical connection
![](figures/I3C_physical_connection.png "I3C_physical_connection") ## Available APIs @@ -81,7 +81,7 @@ The I3C APIs provide a set of common functions for I3C transfer, including: ->![](../public_sys-resources/icon-note.gif) **NOTE** +>![](../public_sys-resources/icon-note.gif) **NOTE**
> >All functions described in this document can be called only in the kernel space. @@ -91,7 +91,7 @@ The I3C APIs provide a set of common functions for I3C transfer, including: [Figure 2](#fig2) shows how I3C works. -**Figure 2** How I3C works +**Figure 2** How I3C works
![](figures/I3C_usage_flowchart.png "I3C_usage_flowchart") ### Opening an I3C Controller diff --git a/en/device-dev/driver/figures/configuration-process.png b/en/device-dev/driver/figures/HCB-using-process.png similarity index 100% rename from en/device-dev/driver/figures/configuration-process.png rename to en/device-dev/driver/figures/HCB-using-process.png