| setCntlrCfg | **cntlr**: structure pointer to the MIPI DSI controller.| –| HDF_STATUS| Sets controller parameters.|
| setCntlrCfg | **cntlr**: structure pointer to the MIPI DSI controller.| –| HDF_STATUS| Sets controller parameters.|
| setCmd | **cntlr**: structure pointer to the MIPI DSI controller.<br>cmd: structure pointer to the commands to send.| –| HDF_STATUS| Sends commands to a display device.|
| setCmd | **cntlr**: structure pointer to the MIPI DSI controller.<br>**cmd**: structure pointer to the commands to send. | –| HDF_STATUS| Sends commands to a display device.|
| getCmd | **cntlr**: structure pointer to the MIPI DSI controller.<br>**cmd**: pointer to the command description structure.<br>**readLen**: length of the data to read.| **out**: structure pointer to the data obtained.| HDF_STATUS| Reads data by sending commands.|
| getCmd | **cntlr**: structure pointer to the MIPI DSI controller.<br>**cmd**: pointer to the command description structure.<br>**readLen**: length of the data to read.| **out**: structure pointer to the data obtained.| HDF_STATUS| Reads data by sending commands.|
| toHs | **cntlr**: structure pointer to the MIPI DSI controller.| –| HDF_STATUS| Sets the high speed (HS) mode.|
| toHs | **cntlr**: structure pointer to the MIPI DSI controller.| –| HDF_STATUS| Sets the high speed (HS) mode.|
| toLp | **cntlr**: structure pointer to the MIPI DSI controller.| –| HDF_STATUS| Sets the low power (LP) mode.|
| toLp | **cntlr**: structure pointer to the MIPI DSI controller.| –| HDF_STATUS| Sets the low power (LP) mode.|
## How to Develop
## How to Develop
The MIPI DSI module adaptation involves the following steps:
The MIPI DSI module adaptation involves the following steps:
1. Instantiate the driver entry.
1. Configure attribute files.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF_INIT** to register the **HdfDriverEntry** instance with the HDF.
2. Configure attribute files.
- Add the **deviceNode** description to the **device_info.hcs** file.
- Add the **deviceNode** description to the **device_info.hcs** file.
- (Optional) Add the **mipidsi_config.hcs** file.
- (Optional) Add the **mipidsi_config.hcs** file.
2. Instantiate the driver entry.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF_INIT** to register the **HdfDriverEntry** instance with the HDF.
3. Instantiate the MIPI DSI controller object.
3. Instantiate the MIPI DSI controller object.
- Initialize **MipiDsiCntlr**.
- Initialize **MipiDsiCntlr**.
- Instantiate **MipiDsiCntlrMethod** in the **MipiDsiCntlr** object.
- Instantiate **MipiDsiCntlrMethod** in the **MipiDsiCntlr** object.
...
@@ -59,6 +59,7 @@ The MIPI DSI module adaptation involves the following steps:
...
@@ -59,6 +59,7 @@ The MIPI DSI module adaptation involves the following steps:
> For details about the functions in **MipiDsiCntlrMethod**, see [Available APIs](#available-apis).
> For details about the functions in **MipiDsiCntlrMethod**, see [Available APIs](#available-apis).
4. Debug the driver.
4. Debug the driver.
(Optional) For new drivers, verify basic functions, for example, check the information returned after the driver is attached and whether data is successfully transmitted.
(Optional) For new drivers, verify basic functions, for example, check the information returned after the driver is attached and whether data is successfully transmitted.
...
@@ -66,12 +67,14 @@ The MIPI DSI module adaptation involves the following steps:
...
@@ -66,12 +67,14 @@ The MIPI DSI module adaptation involves the following steps:
The following uses **mipi_tx_hi35xx.c** as an example to present the contents that need to be provided by the vendor to implement device functions.
The following uses **mipi_tx_hi35xx.c** as an example to present the contents that need to be provided by the vendor to implement device functions.
1. Configure the device attributes in **xx_config.hcs** and add the **deviceNode** information to the **device_info.hcs** file. <br>The device attribute values are closely related to the default values or value range of the **MipiDsiCntlr** members at the core layer. The **deviceNode** information is related to the driver entry registration.
1. Configure the device attributes in **xx_config.hcs** and add the **deviceNode** information to the **device_info.hcs** file.
The device attribute values are closely related to the default values or value range of the **MipiDsiCntlr** members at the core layer. The **deviceNode** information is related to the driver entry registration.
In this example, no additional attribute needs to be configured for the MIPI DSI controller. If required, add the **deviceMatchAttr** information to **deviceNode** in the **device_info** file and add the **mipidsi_config** file.
In this example, no additional attribute needs to be configured for the MIPI DSI controller. If required, add the **deviceMatchAttr** information to **deviceNode** in the **device_info** file and add the **mipidsi_config** file.
**device_info.hcs** configuration example:
**device_info.hcs** configuration example:
```
```
root {
root {
device_info {
device_info {
...
@@ -84,7 +87,7 @@ The following uses **mipi_tx_hi35xx.c** as an example to present the contents th
...
@@ -84,7 +87,7 @@ The following uses **mipi_tx_hi35xx.c** as an example to present the contents th
policy = 0;
policy = 0;
priority = 150;
priority = 150;
permission = 0644;
permission = 0644;
moduleName = "HDF_MIPI_TX"; // (Mandatory) Driver name, which must be the same as moduleName in the driver entry.
moduleName = "HDF_MIPI_TX"; // (Mandatory) Driver name, which must be the same as moduleName in the driver entry.
serviceName = "HDF_MIPI_TX"; // (Mandatory) Unique name of the service published by the driver.
serviceName = "HDF_MIPI_TX"; // (Mandatory) Unique name of the service published by the driver.
}
}
}
}
...
@@ -93,148 +96,158 @@ The following uses **mipi_tx_hi35xx.c** as an example to present the contents th
...
@@ -93,148 +96,158 @@ The following uses **mipi_tx_hi35xx.c** as an example to present the contents th
}
}
```
```
2. Instantiate the driver entry.<br/>The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. The function pointer members in the **HdfDriverEntry** structure are filled by the vendors' operation functions. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
2. Instantiate the driver entry.
The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. The function pointer members in the **HdfDriverEntry** structure are filled by the vendors' operation functions. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
- MIPI DSI driver entry example
MIPI DSI driver entry example:
```
```
struct HdfDriverEntry g_mipiTxDriverEntry = {
struct HdfDriverEntry g_mipiTxDriverEntry = {
.moduleVersion = 1,
.moduleVersion = 1,
.Init = Hi35xxMipiTxInit, // See the Init function.
.Init = Hi35xxMipiTxInit, // See the Init function.
.Release = Hi35xxMipiTxRelease, // See the Release function.
.Release = Hi35xxMipiTxRelease, // See the Release function.
.moduleName = "HDF_MIPI_TX", // (Mandatory) The value must be the same as that in the device_info.hcs file.
.moduleName = "HDF_MIPI_TX", // (Mandatory) The value must be the same as that in the device_info.hcs file.
};
};
HDF_INIT(g_mipiTxDriverEntry); // Call HDF_INIT to register the driver entry with the HDF.
HDF_INIT(g_mipiTxDriverEntry); // Call HDF_INIT to register the driver entry with the HDF.
```
```
3. Initialize the **MipiDsiCntlr** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init** and **Release**) to instantiate **MipiDsiCntlrMethod** in **MipiDsiCntlr** (so that the underlying driver functions can be called).
3. Initialize the **MipiDsiCntlr** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init** and **Release**) to instantiate **MipiDsiCntlrMethod** in **MipiDsiCntlr** (so that the underlying driver functions can be called).
- Defining a custom structure
- Defining a custom structure
To the driver, the custom structure holds parameters and data. Generally, the values in the **config** file are used to initialize the structure members. However, in this example, the MIPI DSI has no device attribute file. Therefore, the basic member structure is similar to that of **MipiDsiCntlr**.
To the driver, the custom structure holds parameters and data. Generally, the values in the **config** file are used to initialize the structure members. However, in this example, the MIPI DSI has no device attribute file. Therefore, the basic member structure is similar to that of **MipiDsiCntlr**.
```
typedef struct {
unsigned int devno; // Device number
short laneId[LANE_MAX_NUM]; // Lane ID
OutPutModeTag outputMode; // Output mode, which can be CSI mode, DSI Video mode, or DSI Command mode.
VideoModeTag videoMode; // Synchronization mode of the display device
OutputFormatTag outputFormat; // Format of the output DSI image, which can be RGB or YUV.
SyncInfoTag syncInfo; // Settings related to timing
unsigned int phyDataRate; // Data rate, in Mbit/s
unsigned int pixelClk; // Clock, in kHz
} ComboDevCfgTag;
// MipiDsiCntlr is the controller structure at the core layer. The Init function assigns values to the members of MipiDsiCntlr.
struct MipiDsiCntlr {
struct IDeviceIoService service;
struct HdfDeviceObject *device;
unsigned int devNo; // Device number
struct MipiCfg cfg;
struct MipiDsiCntlrMethod *ops;
struct OsalMutex lock;
void *priv;
};
```
```
typedef struct {
unsigned int devno; // Device number
short laneId[LANE_MAX_NUM]; // Lane ID
OutPutModeTag outputMode; // Output mode, which can be CSI mode, DSI Video mode, or DSI Command mode.
VideoModeTag videoMode; // Synchronization mode of the display device
OutputFormatTag outputFormat; // Format of the output DSI image, which can be RGB or YUV.
SyncInfoTag syncInfo; // Settings related to timing
unsigned int phyDataRate; // Data rate, in Mbit/s
unsigned int pixelClk; // Clock, in kHz
} ComboDevCfgTag;
// MipiDsiCntlr is the controller structure at the core layer. The Init function assigns values to the members of MipiDsiCntlr.
struct MipiDsiCntlr {
struct IDeviceIoService service;
struct HdfDeviceObject *device;
unsigned int devNo; // Device number
struct MipiCfg cfg;
struct MipiDsiCntlrMethod *ops;
struct OsalMutex lock;
void *priv;
};
```
- Instantiating **MipiDsiCntlrMethod** in **MipiDsiCntlr** (other members are initialized by **Init**)
- Instantiating **MipiDsiCntlrMethod** in **MipiDsiCntlr** (other members are initialized by **Init**)
```
```
static struct MipiDsiCntlrMethod g_method = {
static struct MipiDsiCntlrMethod g_method = {
.setCntlrCfg = Hi35xxSetCntlrCfg,
.setCntlrCfg = Hi35xxSetCntlrCfg,
.setCmd = Hi35xxSetCmd,
.setCmd = Hi35xxSetCmd,
.getCmd = Hi35xxGetCmd,
.getCmd = Hi35xxGetCmd,
.toHs = Hi35xxToHs,
.toHs = Hi35xxToHs,
.toLp = Hi35xxToLp,
.toLp = Hi35xxToLp,
};
};
```
```
-**Init** function
-**Init** function
**Input parameter**:
**Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**Return value**:
**Return value**:
HDF_STATUS<br>The table below lists some status. For more information, see HDF_STATUS in the /drivers/framework/include/utils/hdf_base.h file.
**HDF_STATUS**
The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
| Status| Description|
| -------- | -------- |
| HDF_ERR_INVALID_OBJECT | Invalid object.|
| HDF_ERR_MALLOC_FAIL | Failed to allocate memory.|
g_mipiTx.priv = NULL; // g_mipiTx is a global variable defined.
// static struct MipiDsiCntlr g_mipiTx {
// .devNo=0
//};
g_mipiTx.ops = &g_method; // Attach the MipiDsiCntlrMethod instance.
ret = MipiDsiRegisterCntlr(&g_mipiTx, device);// (Mandatory) Call the function at the core layer and g_mipiTx to initialize global variables at the core layer.
...
return MipiTxDrvInit(0); // (Mandatory) Device initialization customized by the vendor.
g_mipiTx.priv = NULL; // g_mipiTx is a global variable defined.
// static struct MipiDsiCntlr g_mipiTx {
// .devNo=0
//};
g_mipiTx.ops = &g_method;// Attach the MipiDsiCntlrMethod instance.
ret = MipiDsiRegisterCntlr(&g_mipiTx, device);// (Mandatory) Call the function at the core layer and g_mipiTx to initialize global variables at the core layer.
...
return MipiTxDrvInit(0); // (Mandatory) Device initialization customized by the vendor.
cntlr->device = device; // Prerequisites for conversion between HdfDeviceObject and MipiDsiHandle.
device->service = &(cntlr->service); // Prerequisites for conversion between HdfDeviceObject and MipiDsiHandle.
cntlr->priv = NULL;
...
return HDF_SUCCESS;
}
...
return HDF_FAILURE;
}
```
-**Release** function
-**Release** function
**Input parameter**:
**Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**Return value**:
**Return value**:
No value is returned.
No value is returned.
**Function description**:
**Function description**:
Releases the memory and deletes the controller. This function assigns values to the **Release** API in the driver entry structure. When the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. All forced conversion operations for obtaining the corresponding object can be successful only when the **Init** function has the corresponding value assignment operations.
Releases the memory and deletes the controller. This function assigns values to the **Release** API in the driver entry structure. When the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
> All forced conversion operations for obtaining the corresponding object can be successful only when the **Init** function has the corresponding value assignment operations.
| doRequest | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**cmd**: structure pointer to the command to execute.| HDF_STATUS| Processes the request.|
| doRequest | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**cmd**: structure pointer to the command to execute.| HDF_STATUS| Processes the request.|
| setClock | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**clock**: clock frequency to set.| HDF_STATUS| Sets the clock frequency.|
| setClock | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**clock**: clock frequency to set.| HDF_STATUS| Sets the clock frequency.|
| setPowerMode | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**mode**: power consumption mode, which is an enumerated value.| HDF_STATUS| Sets the power consumption mode.|
| setPowerMode | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**mode**: power consumption mode, which is an enumerated value.| HDF_STATUS| Sets the power consumption mode.|
| setBusWidth | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**width**: bus width, which is an enumerated value.| HDF_STATUS| Sets the bus width.|
| setBusWidth | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**width**: bus width, which is an enumerated value.| HDF_STATUS| Sets the bus width.|
| setBusTiming | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**timing**: bus timing, which is an enumerated value.| HDF_STATUS| Sets the bus timing.|
| setBusTiming | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**timing**: bus timing, which is an enumerated value.| HDF_STATUS| Sets the bus timing.|
| setSdioIrq | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**enable**: whether to enable Secure Digital Input Output (SDIO) interrupts.| HDF_STATUS| Enables or disables SDIO interrupts.|
| setSdioIrq | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**enable**: whether to enable Secure Digital Input Output (SDIO) interrupts.| HDF_STATUS| Enables or disables SDIO interrupts.|
| hardwareReset | **cntlr**: structure pointer to the MMC controller at the core layer.| HDF_STATUS| Resets hardware.|
| hardwareReset | **cntlr**: structure pointer to the MMC controller at the core layer.| HDF_STATUS| Resets hardware.|
| systemInit | **cntlr**: structure pointer to the MMC controller at the core layer.| HDF_STATUS| Performs system initialization.|
| systemInit | **cntlr**: structure pointer to the MMC controller at the core layer.| HDF_STATUS| Performs system initialization.|
| setEnhanceSrobe | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**enable**: whether to enable the enhanced strobe feature.| HDF_STATUS| Sets the enhanced strobe feature.|
| setEnhanceSrobe | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**enable**: whether to enable the enhanced strobe feature.| HDF_STATUS| Sets the enhanced strobe feature.|
| switchVoltage | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**volt**: voltage to set, which can be 3.3 V, 1.8 V, or 1.2 V.| HDF_STATUS| Sets the voltage.|
| switchVoltage | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**volt**: voltage to set, which can be 3.3 V, 1.8 V, or 1.2 V.| HDF_STATUS| Sets the voltage.|
| devReadOnly | **cntlr**: structure pointer to the MMC controller at the core layer.| Boolean value| Checks whether the device is read-only.|
| devReadOnly | **cntlr**: structure pointer to the MMC controller at the core layer.| Boolean value| Checks whether the device is read-only.|
| cardPluged | **cntlr**: structure pointer to the MMC controller at the core layer.| Boolean value| Checks whether the device is removed.|
| cardPluged | **cntlr**: structure pointer to the MMC controller at the core layer.| Boolean value| Checks whether the device is removed.|
| devBusy | **cntlr**: structure pointer to the MMC controller at the core layer.| Boolean value| Checks whether the device is being used.|
| devBusy | **cntlr**: structure pointer to the MMC controller at the core layer.| Boolean value| Checks whether the device is being used.|
| tune | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**cmdCode**: command code of the uint32_t type.| HDF_STATUS| Tunes the oscillator circuit frequency.|
| tune | **cntlr**: structure pointer to the MMC controller at the core layer.<br>**cmdCode**: command code of the uint32_t type.| HDF_STATUS| Tunes the oscillator circuit frequency.|
| rescanSdioDev | **cntlr**: structure pointer to the MMC controller at the core layer.| HDF_STATUS| Scans and adds an SDIO device.|
| rescanSdioDev | **cntlr**: structure pointer to the MMC controller at the core layer.| HDF_STATUS| Scans and adds an SDIO device.|
## How to Develop
## How to Develop
...
@@ -75,6 +75,7 @@ The MMC module adaptation involves the following steps:
...
@@ -75,6 +75,7 @@ The MMC module adaptation involves the following steps:
> For details about the functions in **MmcCntlrOps**, see [Available APIs](#available-apis).
> For details about the functions in **MmcCntlrOps**, see [Available APIs](#available-apis).
4. Debug the driver.
4. Debug the driver.
(Optional) For new drivers, verify the basic functions, for example, check the information returned after the **MmcCntlrOps** instance is attached and whether the device starts successfully.
(Optional) For new drivers, verify the basic functions, for example, check the information returned after the **MmcCntlrOps** instance is attached and whether the device starts successfully.
...
@@ -82,12 +83,14 @@ The MMC module adaptation involves the following steps:
...
@@ -82,12 +83,14 @@ The MMC module adaptation involves the following steps:
The following uses **himci.c** as an example to present the information required for implementing device functions.
The following uses **himci.c** as an example to present the information required for implementing device functions.
1. Instantiate the driver entry.<br/>The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
1. Instantiate the driver entry.
The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
MMC driver entry example:
MMC driver entry example:
```
```
struct HdfDriverEntry g_mmcDriverEntry = {
struct HdfDriverEntry g_mmcDriverEntry = {
.moduleVersion = 1,
.moduleVersion = 1,
...
@@ -99,13 +102,15 @@ The following uses **himci.c** as an example to present the information required
...
@@ -99,13 +102,15 @@ The following uses **himci.c** as an example to present the information required
HDF_INIT(g_mmcDriverEntry); // Call HDF_INIT to register the driver entry with the HDF.
HDF_INIT(g_mmcDriverEntry); // Call HDF_INIT to register the driver entry with the HDF.
```
```
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **mmc_config.hcs** file.
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **mmc_config.hcs** file.
The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **MmcCntlr** members at the core layer. If there are multiple devices, you need to add the **deviceNode** information to the **device_info** file and add the device attributes to the **mmc_config** file for each device.
The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **MmcCntlr** members at the core layer.
If there are multiple devices, you need to add the **deviceNode** information to the **device_info** file and add the device attributes to the **mmc_config** file for each device.
-**device_info.hcs** configuration example
-**device_info.hcs** configuration example
```
```
root {
root {
device_info {
device_info {
...
@@ -118,7 +123,7 @@ The following uses **himci.c** as an example to present the information required
...
@@ -118,7 +123,7 @@ The following uses **himci.c** as an example to present the information required
policy = 2;
policy = 2;
priority = 10;
priority = 10;
permission = 0644;
permission = 0644;
moduleName = "hi3516_mmc_driver"; // (Mandatory) Driver name, which must be the same as moduleName in the driver entry.
moduleName = "hi3516_mmc_driver"; // (Mandatory) Driver name, which must be the same as moduleName in the driver entry.
serviceName = "HDF_PLATFORM_MMC_0"; // (Mandatory) Unique name of the service published by the driver.
serviceName = "HDF_PLATFORM_MMC_0"; // (Mandatory) Unique name of the service published by the driver.
deviceMatchAttr = "hi3516_mmc_emmc";// (Mandatory) Private data of the controller. The value must be the same as the controller information in mmc_config.hcs.
deviceMatchAttr = "hi3516_mmc_emmc";// (Mandatory) Private data of the controller. The value must be the same as the controller information in mmc_config.hcs.
}
}
...
@@ -146,12 +151,12 @@ The following uses **himci.c** as an example to present the information required
...
@@ -146,12 +151,12 @@ The following uses **himci.c** as an example to present the information required
-**mmc_config.hcs** configuration example
-**mmc_config.hcs** configuration example
```
```
root {
root {
platform {
platform {
mmc_config {
mmc_config {
template mmc_controller { // Template configuration. In the template, you can configure the common parameters shared by device nodes.
template mmc_controller { // Template configuration. In the template, you can configure the common parameters shared by device nodes.
match_attr = "";
match_attr = "";
voltDef = 0; // 3.3V
voltDef = 0; // 3.3V
freqMin = 50000; // (Mandatory) Minimum frequency
freqMin = 50000; // (Mandatory) Minimum frequency
...
@@ -165,7 +170,7 @@ The following uses **himci.c** as an example to present the information required
...
@@ -165,7 +170,7 @@ The following uses **himci.c** as an example to present the information required
hostId = 0; // (Mandatory) Host ID
hostId = 0; // (Mandatory) Host ID
regBasePhy = 0x10020000;// (Mandatory) Physical base address of the register
regBasePhy = 0x10020000;// (Mandatory) Physical base address of the register
irqNum = 63; // (Mandatory) Interrupt number
irqNum = 63; // (Mandatory) Interrupt number
devType = 2; // (Mandatory) Device type, which can be eMMC, SD, SDIO, or COMBO
devType = 2; // (Mandatory) Device type, which can be eMMC, SD, SDIO, or COMBO.
caps = 0x0001e045; // (Mandatory) Attribute register. For details, see MmcCaps in mmc_caps.h.
caps = 0x0001e045; // (Mandatory) Attribute register. For details, see MmcCaps in mmc_caps.h.
}
}
controller_0x10100000 :: mmc_controller {
controller_0x10100000 :: mmc_controller {
...
@@ -199,11 +204,12 @@ The following uses **himci.c** as an example to present the information required
...
@@ -199,11 +204,12 @@ The following uses **himci.c** as an example to present the information required
```
```
3. Initialize the **MmcCntlr** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **MmcCntlrOps** in **MmcCntlr** (so that the underlying driver functions can be called).
3. Initialize the **MmcCntlr** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **MmcCntlrOps** in **MmcCntlr** (so that the underlying driver functions can be called).
- Defining a custom structure
- Defining a custom structure
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **mmc_config.hcs** file to initialize the members in the custom structure and passes important parameters to the **MmcCntlr** object at the core layer.
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **mmc_config.hcs** file to initialize the members in the custom structure and passes important parameters to the **MmcCntlr** object at the core layer.
@@ -225,7 +231,7 @@ The following uses **himci.c** as an example to present the information required
...
@@ -225,7 +231,7 @@ The following uses **himci.c** as an example to present the information required
bool waitForEvent;
bool waitForEvent;
HIMCI_EVENT himciEvent;
HIMCI_EVENT himciEvent;
};
};
// MmcCntlr is the core layer controller structure. The bind function assigns values to the members of MmcCntlr.
// MmcCntlr is the core layer controller structure. The Bind function assigns values to the members of MmcCntlr.
struct MmcCntlr {
struct MmcCntlr {
struct IDeviceIoService service;
struct IDeviceIoService service;
struct HdfDeviceObject *hdfDevObj;
struct HdfDeviceObject *hdfDevObj;
...
@@ -256,7 +262,7 @@ The following uses **himci.c** as an example to present the information required
...
@@ -256,7 +262,7 @@ The following uses **himci.c** as an example to present the information required
- Instantiating **MmcCntlrOps** in **MmcCntlr** (other members are initialized by **Bind**)
- Instantiating **MmcCntlrOps** in **MmcCntlr** (other members are initialized by **Bind**)
```
```
static struct MmcCntlrOps g_himciHostOps = {
static struct MmcCntlrOps g_himciHostOps = {
.request = HimciDoRequest,
.request = HimciDoRequest,
...
@@ -284,22 +290,22 @@ The following uses **himci.c** as an example to present the information required
...
@@ -284,22 +290,22 @@ The following uses **himci.c** as an example to present the information required
**Return value**:
**Return value**:
HDF_STATUS<br/>The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
**HDF_STATUS**<br/>The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
| HDF_ERR_MALLOC_FAIL | Failed to allocate memory.|
| HDF_ERR_MALLOC_FAIL | Failed to allocate memory.|
| HDF_ERR_INVALID_PARAM | Invalid parameter.|
| HDF_ERR_INVALID_PARAM | Invalid parameter.|
| HDF_ERR_IO | I/O error.|
| HDF_ERR_IO | I/O error.|
| HDF_SUCCESS | Initialization successful.|
| HDF_SUCCESS | Initialization successful.|
| HDF_FAILURE | Initialization failed.|
| HDF_FAILURE | Initialization failed.|
**Function description**:
**Function description**:
Initializes the custom structure **HimciHost** object and **MmcCntlr**, and calls the **MmcCntlrAdd** function at the core layer. **MmcCntlr**, **HimciHost**, and **HdfDeviceObject** assign values with each other so that other functions can be converted successfully.
Initializes the custom structure **HimciHost** object and **MmcCntlr**, and calls the **MmcCntlrAdd** function at the core layer. **MmcCntlr**, **HimciHost**, and **HdfDeviceObject** assign values with each other so that other functions can be converted successfully.
@@ -374,16 +380,19 @@ The following uses **himci.c** as an example to present the information required
...
@@ -374,16 +380,19 @@ The following uses **himci.c** as an example to present the information required
**Function description**:
**Function description**:
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. All forced conversion operations for obtaining the corresponding object can be successful only when the **Init** function has the value assignment operations.
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
> All forced conversion operations for obtaining the corresponding object can be successful only when **Init()** has the corresponding value assignment operations.
cntlr = (struct MmcCntlr *)obj->service;// Forcibly convert HdfDeviceObject to MmcCntlr by using service. For details about the value assignment, see the Bind function.
cntlr = (struct MmcCntlr *)obj->service;// Forcibly convert HdfDeviceObject to MmcCntlr by using service. For details about the value assignment, see the Bind function.
...
...
HimciDeleteHost((struct HimciHost *)cntlr->priv);// Customized memory release function. A forced conversion from MmcCntlr to HimciHost is involved in the process.
HimciDeleteHost((struct HimciHost *)cntlr->priv);// Customized memory release function. A forced conversion from MmcCntlr to HimciHost is involved in the process.
@@ -20,10 +20,9 @@ Pin, as a software concept, provides APIs for uniformly managing the pins from d
...
@@ -20,10 +20,9 @@ Pin, as a software concept, provides APIs for uniformly managing the pins from d
### Working Principles
### Working Principles
In the HDF, the pin module does not support the user mode and therefore does not need to publish services. It uses the service-free mode in interface adaptation. The service-free mode applies to the devices that do not provide user-mode APIs or the OS that does not distinguish the user mode and the kernel mode. The **DevHandle**, a void pointer, directly points to the kernel mode address of the device object.
In the HDF, the pin module does not support the user mode and therefore does not need to publish services. The pin module uses the service-free mode (as shown in Figure 1) in interface adaptation. The service-free mode applies to the devices that do not provide user-mode APIs or the OS that does not distinguish the user mode and the kernel mode. The **DevHandle**, a void pointer, directly points to the kernel mode address of the device object.
The pin module is divided into the following layers:
The pin module is divided into the following layers:
- Interface layer: provides APIs for obtaining a pin, setting or obtaining the pull type, pull strength, and functions of a pin, and releasing a pin.
- Interface layer: provides APIs for obtaining a pin, setting or obtaining the pull type, pull strength, and functions of a pin, and releasing a pin.
- Core layer: provides the capabilities of matching pin resources and adding, removing, and managing pin controllers. The core layer interacts with the adaptation layer by using hooks.
- Core layer: provides the capabilities of matching pin resources and adding, removing, and managing pin controllers. The core layer interacts with the adaptation layer by using hooks.
- Adaptation layer: instantiates hooks to implement specific functions.
- Adaptation layer: instantiates hooks to implement specific functions.
...
@@ -44,8 +43,7 @@ The pin module is used to manage pin resources. When the devices from SoC vendor
...
@@ -44,8 +43,7 @@ The pin module is used to manage pin resources. When the devices from SoC vendor
### Available APIs
### Available APIs
The **PinCntlrMethod** APIs are used to call the functions of the pin driver.
The **PinCntlrMethod** structure defines callbacks to be invoked to call the functions of the pin driver.
**PinCntlrMethod** definition:
```c
```c
structPinCntlrMethod{
structPinCntlrMethod{
...
@@ -58,7 +56,7 @@ struct PinCntlrMethod {
...
@@ -58,7 +56,7 @@ struct PinCntlrMethod {
};
};
```
```
**Table 1**APIs for the members in the PinCntlrMethod structure
**Table 1**Callbacks in the PinCntlrMethod structure
The pin module adaptation procedure is as follows:
The pin module adaptation procedure is as follows:
- Instantiate the driver entry.
1. Instantiate the driver entry.
- Configure attribute files.
2. Configure attribute files.
- Instantiate the core layer APIs.
3. Instantiate the core layer APIs.
- Debug the driver.
4. Debug the driver.
### Development Example
1. Instantiate the driver entry.
1. Instantiate the driver entry.
- Instantiate the **HdfDriverEntry** structure.
- Instantiate the **HdfDriverEntry** structure.
Instantiate the driver entry. The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**.
Instantiate the driver entry. The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**.
- Call **HDF_INIT** to register the **HdfDriverEntry** instance with the HDF.
- Call **HDF_INIT** to register the **HdfDriverEntry** instance with the HDF.
Generally, the HDF calls the **Init()** function to load the driver. If **Init()** fails to be called, the HDF calls **Release()** to release driver resources and exit.
Generally, the HDF calls the **Init** function to load the driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
@@ -92,13 +94,15 @@ The pin module adaptation procedure is as follows:
...
@@ -92,13 +94,15 @@ The pin module adaptation procedure is as follows:
.Bind = Hi35xxPinBind,
.Bind = Hi35xxPinBind,
.Init = Hi35xxPinInit,
.Init = Hi35xxPinInit,
.Release = Hi35xxPinRelease,
.Release = Hi35xxPinRelease,
.moduleName = "hi35xx_pin_driver",// (Mandatory) The value must be the same as that of moduleName in the .hcs file.
.moduleName = "hi35xx_pin_driver",// (Mandatory) The value must be the same as that of moduleName in the .hcs file.
};
};
HDF_INIT(g_hi35xxPinDriverEntry);// Call HDF_INIT to register the driver entry with the HDF.
HDF_INIT(g_hi35xxPinDriverEntry);// Call HDF_INIT to register the driver entry with the HDF.
```
```
2. Configure attribute files.
2. Configure attribute files.
- Add the device node description to the **vendor/hisilicon/hispark_taurus/hdf_config/device_info/device_info.hcs** file.
- Add the device node description to the **vendor/hisilicon/hispark_taurus/hdf_config/device_info/device_info.hcs** file.
```c
```c
root {
root {
device_info {
device_info {
...
@@ -106,8 +110,8 @@ The pin module adaptation procedure is as follows:
...
@@ -106,8 +110,8 @@ The pin module adaptation procedure is as follows:
hostName = "platform_host";
hostName = "platform_host";
priority = 50;
priority = 50;
device_pin :: device {
device_pin :: device {
device0::deviceNode{// Set an HDF device node for each pin controller.
device0:: deviceNode { // Set an HDF device node for each pin controller.
policy=0;// 2: visible in user mode; 1: visible in kernel mode; 0: no service required.
policy = 0; // Policy for publishing services.
priority = 10; // Driver startup priority.
priority = 10; // Driver startup priority.
permission = 0644; // Permission to create device nodes for the driver.
permission = 0644; // Permission to create device nodes for the driver.
/* (Mandatory) Driver name, which must be the same as the moduleName in the driver entry. */
/* (Mandatory) Driver name, which must be the same as the moduleName in the driver entry. */
...
@@ -122,13 +126,14 @@ The pin module adaptation procedure is as follows:
...
@@ -122,13 +126,14 @@ The pin module adaptation procedure is as follows:
moduleName = "hi35xx_pin_driver";
moduleName = "hi35xx_pin_driver";
deviceMatchAttr = "hisilicon_hi35xx_pin_1";
deviceMatchAttr = "hisilicon_hi35xx_pin_1";
}
}
......
...
}
}
}
}
}
}
}
}
```
```
- Add the **pin_config.hcs** file.
- Add the **pin_config.hcs** file.
Configure the device attributes in the **device/soc/hisilicon/hi3516dv300/sdk_liteos/hdf_config/pin/pin_config.hcs** file. The parameters are set as follows:
Configure the device attributes in the **device/soc/hisilicon/hi3516dv300/sdk_liteos/hdf_config/pin/pin_config.hcs** file. The parameters are set as follows:
```c
```c
root {
root {
...
@@ -137,12 +142,12 @@ The pin module adaptation procedure is as follows:
...
@@ -137,12 +142,12 @@ The pin module adaptation procedure is as follows:
template pin_controller { // (Mandatory) Template configuration. In the template, you can configure the common parameters shared by device nodes.
template pin_controller { // (Mandatory) Template configuration. In the template, you can configure the common parameters shared by device nodes.
number = 0; // (Mandatory) Controller ID.
number = 0; // (Mandatory) Controller ID.
regStartBasePhy = 0; // (Mandatory) Start physical base address of the register.
regStartBasePhy = 0; // (Mandatory) Start physical base address of the register.
regSize=0;// (Mandatory) Register bit width.
regSize = 0; // (Mandatory) Register bit width.
PinCount = 0; // (Mandatory) Number of pins.
PinCount = 0; // (Mandatory) Number of pins.
match_attr = "";
match_attr = "";
template pin_desc {
template pin_desc {
pinName = ""; // (Mandatory) Name of the pin.
pinName = ""; // (Mandatory) Name of the pin.
init=0;// (Mandatory) Default value of the register.
init = 0; // (Mandatory) Default value of the register.
F0 = ""; // (Mandatory) Function 0.
F0 = ""; // (Mandatory) Function 0.
F1 = ""; // Function 1.
F1 = ""; // Function 1.
F2 = ""; // Function 2.
F2 = ""; // Function 2.
...
@@ -164,16 +169,18 @@ The pin module adaptation procedure is as follows:
...
@@ -164,16 +169,18 @@ The pin module adaptation procedure is as follows:
F1 = "SFC_CLK";
F1 = "SFC_CLK";
F2 = "SFC_BOOT_MODE";
F2 = "SFC_BOOT_MODE";
}
}
......// Correspond to the pins of the pin controller. Add pins according to actual situation.
... // Correspond to the pins of the pin controller. Add pins according to actual situation.
}
}
...// Each pin controller corresponds to a controller node. If there are multiple pin controllers, add the corresponding controller nodes one by one.
...// Each pin controller corresponds to a controller node. If there are multiple pin controllers, add the corresponding controller nodes one by one.
}
}
}
}
}
}
```
```
3. Instantiate the pin controller object.
3. Instantiate the pin controller object.
- Initialize the **PinCntlr** object.
- Initialize the **PinCntlr** object.
Call **Hi35xxPinCntlrInit** to initialize the **PinCntlr** members.
Call **Hi35xxPinCntlrInit** to initialize the **PinCntlr** members.
```c
```c
...
@@ -209,14 +216,14 @@ The pin module adaptation procedure is as follows:
...
@@ -209,14 +216,14 @@ The pin module adaptation procedure is as follows:
uint32_t pinCount;
uint32_t pinCount;
};
};
// PinCntlr is the controller structure at the core layer. Its members are assigned with values by using the Init() function.
// PinCntlr is the controller structure at the core layer. The Init function assigns values to PinCntlr.
struct PinCntlr {
struct PinCntlr {
struct IDeviceIoService service;
struct IDeviceIoService service;
struct HdfDeviceObject *device;
struct HdfDeviceObject *device;
struct PinCntlrMethod *method;
struct PinCntlrMethod *method;
struct DListHead node; // Node in the linked list.
struct DListHead node; // Node in the linked list.
OsalSpinlock spin; // Spinlock.
OsalSpinlock spin; // Spinlock.
uint16_t number; // ID of the pin controller.
uint16_t number; // ID of the pin controller.
uint16_t pinCount; // Number of pins.
uint16_t pinCount; // Number of pins.
struct PinDesc *pins;
struct PinDesc *pins;
void *priv; // Private data.
void *priv; // Private data.
...
@@ -268,29 +275,31 @@ The pin module adaptation procedure is as follows:
...
@@ -268,29 +275,31 @@ The pin module adaptation procedure is as follows:
}
}
```
```
- Instantiate the callback structure **PinCntlrMethod** in **PinCntlr**. Other members are initialized by using the **Init()** function.
- Instantiate the callback structure **PinCntlrMethod** in **PinCntlr**. Other members are initialized by using the **Init** function.
```c
```c
// The members of the PinCntlrMethod structure are all callbacks. Vendors need to implement the corresponding functions according to Table 1.
// The members of the PinCntlrMethod structure are all callbacks. Vendors need to implement the corresponding functions according to Table 1.
static struct PinCntlrMethod g_method = {
static struct PinCntlrMethod g_method = {
.SetPinPull = Hi35xxPinSetPull, // Set the pull type.
.SetPinPull = Hi35xxPinSetPull, // Set the pull type.
.GetPinPull = Hi35xxPinGetPull, // Obtains the pull type.
.GetPinPull = Hi35xxPinGetPull, // Obtain the pull type.
.SetPinStrength = Hi35xxPinSetStrength, // Set the pull strength.
.SetPinStrength = Hi35xxPinSetStrength, // Set the pull strength.
.GetPinStrength = Hi35xxPinGetStrength, // Obtains the pull strength.
.GetPinStrength = Hi35xxPinGetStrength, // Obtain the pull strength.
.SetPinFunc = Hi35xxPinSetFunc, // Set the pin functions.
.SetPinFunc = Hi35xxPinSetFunc, // Set the pin functions.
.GetPinFunc = Hi35xxPinGetFunc, // Obtain the pin functions.
.GetPinFunc = Hi35xxPinGetFunc, // Obtain the pin functions.
};
};
```
```
-**Init()** function
-**Init** function
**Input parameter**:
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
Return value:
**Return value**:
**HDF\_STATUS** (The following table lists some states. For more details, see **HDF\_STATUS** in **/drivers/framework/include/utils/hdf\_base.h**.)
**HDF\_STATUS** <br>The table below describes some status. For more details, see **HDF\_STATUS** in **/drivers/framework/include/utils/hdf\_base.h**.
@@ -375,19 +385,19 @@ The pin module adaptation procedure is as follows:
...
@@ -375,19 +385,19 @@ The pin module adaptation procedure is as follows:
}
}
```
```
-**Release()** function
-**Release** function
Input parameters:
**Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
Return value:
**Return value**:
–
No value is returned.
Function description:
**Function description**:
Releases memory and deletes the controller. This function assigns a value to the **Release** API in the driver entry structure. If the HDF fails to call the **Init()** function to initialize the driver, the **Release()** function can be called to release driver resources.
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, **Release** can be called to release driver resources.
@@ -426,4 +436,5 @@ The pin module adaptation procedure is as follows:
...
@@ -426,4 +436,5 @@ The pin module adaptation procedure is as follows:
}
}
```
```
4. Debug the driver.
4. Debug the driver.
(Optional) Verify basic functionalities of new drivers. For example, verify the information returned when the driver is loaded and whether data is successfully transmitted.
(Optional) Verify basic functionalities of new drivers. For example, verify the information returned when the driver is loaded and whether data is successfully transmitted.
| setConfig | -**pwm**: structure pointer to the PWM controller at the core layer.<br>-**config**: structure pointer to the attributes to set.| HDF_STATUS| Sets attributes.|
| setConfig | **pwm**: structure pointer to the PWM controller at the core layer.<br>**config**: structure pointer to the attributes to set.| HDF_STATUS| Sets attributes.|
| open | **pwm**: structure pointer to the PWM controller at the core layer.| HDF_STATUS| Opens a device.|
| open | **pwm**: structure pointer to the PWM controller at the core layer.| HDF_STATUS| Opens a device.|
| close | **pwm**: structure pointer to the PWM controller at the core layer.| HDF_STATUS| Closes a device.|
| close | **pwm**: structure pointer to the PWM controller at the core layer.| HDF_STATUS| Closes a device.|
## How to Develop
## How to Develop
...
@@ -51,6 +51,7 @@ The PWM module adaptation involves the following steps:
...
@@ -51,6 +51,7 @@ The PWM module adaptation involves the following steps:
> For details about the functions in **PwmMethod**, see [Available APIs](#available-apis).
> For details about the functions in **PwmMethod**, see [Available APIs](#available-apis).
4. Debug the driver.
4. Debug the driver.
(Optional) For new drivers, verify the basic functions, such as the PWM status control and response to interrupts.
(Optional) For new drivers, verify the basic functions, such as the PWM status control and response to interrupts.
...
@@ -58,12 +59,16 @@ The PWM module adaptation involves the following steps:
...
@@ -58,12 +59,16 @@ The PWM module adaptation involves the following steps:
The following uses **pwm_hi35xx.c** as an example to present the information required for implementing device functions.
The following uses **pwm_hi35xx.c** as an example to present the information required for implementing device functions.
1. Instantiate the driver entry.<br/>The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
1. Instantiate the driver entry.
The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**.
In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
PWM driver entry example:
PWM driver entry example:
```
```
struct HdfDriverEntry g_hdfPwm = {
struct HdfDriverEntry g_hdfPwm = {
.moduleVersion = 1,
.moduleVersion = 1,
...
@@ -76,23 +81,26 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
...
@@ -76,23 +81,26 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
HDF_INIT(g_hdfPwm);
HDF_INIT(g_hdfPwm);
```
```
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **pwm_config.hcs** file. The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **PwmDev** members at the core layer. If there are multiple devices, you need to add the **deviceNode** information to the **device_info** file and add the device attributes to the **pwm_config** file for each device.
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **pwm_config.hcs** file.
The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **PwmDev** members at the core layer. If there are multiple devices, you need to add the **deviceNode** information to the **device_info** file and add the device attributes to the **pwm_config** file for each device.
-**device_info.hcs** configuration example
-**device_info.hcs** configuration example
```
```
root {
root {
device_info {
device_info {
platform :: host {
platform :: host {
hostName = "platform_host";
hostName = "platform_host";
priority = 50;
priority = 50;
device_pwm :: device {// Configure an HDF device node for each PWM controller.
device_pwm :: device {// Configure an HDF device node for each PWM controller.
device0 :: deviceNode {
device0 :: deviceNode {
policy = 1; // Publish kernel-mode services.
policy = 1; // Publish services for kernel-mode processes.
priority = 80; // Driver startup priority
priority = 80; // Driver startup priority.
permission = 0644; // Permission to create device nodes for the driver.
permission = 0644; // Permission for the driver to create a device node.
moduleName = "HDF_PLATFORM_PWM"; // (Mandatory) Driver name, which must be the same as moduleName in the driver entry.
moduleName = "HDF_PLATFORM_PWM"; // (Mandatory) Driver name, which must be the same as moduleName in the driver entry.
serviceName = "HDF_PLATFORM_PWM_0"; // (Mandatory) Unique name of the service published by the driver.
serviceName = "HDF_PLATFORM_PWM_0"; // (Mandatory) Unique name of the service published by the driver.
deviceMatchAttr = "hisilicon_hi35xx_pwm_0";// (Mandatory) Used to configure the private data of the controller.
deviceMatchAttr = "hisilicon_hi35xx_pwm_0";// (Mandatory) Used to configure the private data of the controller.
// The value must be the same as the controller information in pwm_config.hcs.
// The value must be the same as the controller information in pwm_config.hcs.
}
}
...
@@ -111,7 +119,7 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
...
@@ -111,7 +119,7 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
```
```
-**pwm_config.hcs** configuration example
-**pwm_config.hcs** configuration example
```
```
root {
root {
platform {
platform {
...
@@ -135,12 +143,13 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
...
@@ -135,12 +143,13 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
}
}
```
```
3. Initialize the **PwmDev** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **PwmMethod** in **PwmDev** (so that the underlying driver functions can be called).
3. Initialize the **wmDev** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **PwmMethod** in **PwmDev** (so that the underlying driver functions can be called).
- Defining a custom structure
- Defining a custom structure
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **pwm_config.hcs** file to initialize the members in the custom structure and passes important parameters, such as the device number, to the **GpioCntlr** object at the core layer.
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **pwm_config.hcs** file to initialize the members in the custom structure and passes important parameters, such as the device number, to the object at the core layer.
@@ -154,14 +163,14 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
...
@@ -154,14 +163,14 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
struct IDeviceIoService service;
struct IDeviceIoService service;
struct HdfDeviceObject *device;
struct HdfDeviceObject *device;
struct PwmConfig cfg; // Attribute structure. For details, see the description of PwmConfig.
struct PwmConfig cfg; // Attribute structure. For details, see the description of PwmConfig.
struct PwmMethod *method; // Hook function template
struct PwmMethod *method; // Hook function template
bool busy;
bool busy;
uint32_t num; // Device number
uint32_t num; // Device number
OsalSpinlock lock;
OsalSpinlock lock;
void *priv; // Private data. Generally, the start address of the custom structure is stored to facilitate invoking of the structure.
void *priv; // Private data. Generally, the start address of the custom structure is stored to facilitate invoking of the structure.
};
};
struct PwmConfig {
struct PwmConfig {
uint32_t duty // Time that a signal is in the ON state, in ns.
uint32_t duty // Time that a signal is in the ON state, in ns.
uint32_t period; // Time for a signal to complete an on-and-off cycle, in ns.
uint32_t period; // Time for a signal to complete an on-and-off cycle, in ns.
uint32_t number; // Number of square waves to generate.
uint32_t number; // Number of square waves to generate.
uint8_t polarity; // Polarity
uint8_t polarity; // Polarity
...
@@ -178,7 +187,7 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
...
@@ -178,7 +187,7 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
- Instantiating **PwmMethod** in **PwmDev** (other members are initialized by **Init**)
- Instantiating **PwmMethod** in **PwmDev** (other members are initialized by **Init**)
```
```
// The following uses pwm_hi35xx.c as an example. Fill the hook function.
// The following uses pwm_hi35xx.c as an example. Fill the hook function.
struct PwmMethod g_pwmOps = {
struct PwmMethod g_pwmOps = {
...
@@ -193,24 +202,24 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
...
@@ -193,24 +202,24 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
**Return value**:
**Return value**:
HDF_STATUS<br>The table below lists some status. For more information, see HDF_STATUS in the /drivers/framework/include/utils/hdf_base.h file.
**HDF_STATUS**<br/>The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
if (PwmDeviceAdd(obj, &(hp->dev)) ) != HDF_SUCCESS) {// (Important) Call the core layer function to initialize hp->dev devices and services.
if (PwmDeviceAdd(obj, &(hp->dev)) ) != HDF_SUCCESS) { // Call the core layer function to initialize devices and services.
OsalIoUnmap((void *)hp->base);
OsalIoUnmap((void *)hp->base);
return HDF_FAILURE;
return HDF_FAILURE;
}
}
...
@@ -267,7 +276,7 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
...
@@ -267,7 +276,7 @@ The following uses **pwm_hi35xx.c** as an example to present the information req
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
@@ -16,7 +16,7 @@ The regulator module is divided into the following layers:
...
@@ -16,7 +16,7 @@ The regulator module is divided into the following layers:
- Core layer: provides the capabilities of binding, initializing, and releasing devices.
- Core layer: provides the capabilities of binding, initializing, and releasing devices.
- Adaptation layer: implements other functions.
- Adaptation layer: implements other functions.
NOTE<br/>The core layer can call the APIs of the interface layer and uses hooks to call APIs of the adaptation layer. In this way, the adaptation layer can indirectly call the APIs of the interface layer, but the interface layer cannot call the APIs of the adaptation layer.
**NOTE**<br/>The core layer can call the APIs of the interface layer and uses hooks to call APIs of the adaptation layer. In this way, the adaptation layer can indirectly call the APIs of the interface layer, but the interface layer cannot call the APIs of the adaptation layer.
**Figure 1** Unified service mode
**Figure 1** Unified service mode
...
@@ -28,12 +28,13 @@ The regulator module is divided into the following layers:
...
@@ -28,12 +28,13 @@ The regulator module is divided into the following layers:
Currently, the regulator module supports only the kernels (LiteOS) of mini and small systems.
Currently, the regulator module supports only the kernels (LiteOS) of mini and small systems.
## Development Guidelines
### When to Use
### When to Use
The regulator module controls the voltage and current supplies of some devices in the system.
The regulator module controls the voltage and current supplies of some devices in the system.
## Available APIs
### Available APIs
The functions in **RegulatorMethod** are used to call the corresponding regulator driver functions:
The functions in **RegulatorMethod** are used to call the corresponding regulator driver functions:
...
@@ -72,8 +73,7 @@ struct RegulatorMethod {
...
@@ -72,8 +73,7 @@ struct RegulatorMethod {
| getCurrent | **node**: structure pointer to the regulator node at the core layer.<br>**regCurrent**: pointer to the output current, which is of the uint32_t type.| HDF_STATUS| Obtains the current. |
| getCurrent | **node**: structure pointer to the regulator node at the core layer.<br>**regCurrent**: pointer to the output current, which is of the uint32_t type.| HDF_STATUS| Obtains the current. |
| getStatus | **node**: structure pointer to the regulator node at the core layer.<br>**status**: pointer to the output status, which is of the uint32_t type.| HDF_STATUS| Obtains the device status. |
| getStatus | **node**: structure pointer to the regulator node at the core layer.<br>**status**: pointer to the output status, which is of the uint32_t type.| HDF_STATUS| Obtains the device status. |
### How to Develop
## How to Develop
The regulator module adaptation procedure is as follows:
The regulator module adaptation procedure is as follows:
...
@@ -86,9 +86,11 @@ The regulator module adaptation procedure is as follows:
...
@@ -86,9 +86,11 @@ The regulator module adaptation procedure is as follows:
1. Instantiate the driver entry.
1. Instantiate the driver entry.
The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**.
In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
Generally, the HDF calls the **Init()** function to load the driver. If **Init()** fails to be called, the HDF calls **Release** to release driver resources and exit.
Generally, the HDF calls the **Init** function to load the driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
```
```
struct HdfDriverEntry g_regulatorDriverEntry = {
struct HdfDriverEntry g_regulatorDriverEntry = {
...
@@ -116,7 +118,7 @@ The regulator module adaptation procedure is as follows:
...
@@ -116,7 +118,7 @@ The regulator module adaptation procedure is as follows:
Configure regulator controller information from the second node. This node specifies a type of regulator controllers rather than a specific regulator controller. In this example, there is only one regulator device. If there are multiple regulator devices, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **regulator\_config** file.
Configure regulator controller information from the second node. This node specifies a type of regulator controllers rather than a specific regulator controller. In this example, there is only one regulator device. If there are multiple regulator devices, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **regulator\_config** file.
...
@@ -131,7 +133,7 @@ The regulator module adaptation procedure is as follows:
...
@@ -131,7 +133,7 @@ The regulator module adaptation procedure is as follows:
device_regulator :: device {
device_regulator :: device {
device0:: deviceNode { // Set an HDF device node for each regulator controller.
device0:: deviceNode { // Set an HDF device node for each regulator controller.
policy = 1; // Policy for the driver to publish services.
policy = 1; // Policy for the driver to publish services.
priority = 50; // Driver startup priority.
priority = 50; // Driver startup priority.
permission = 0644; // Permission to create device nodes for the driver.
permission = 0644; // Permission to create device nodes for the driver.
/* (Mandatory) Driver name, which must be the same as the moduleName in the driver entry. */
/* (Mandatory) Driver name, which must be the same as the moduleName in the driver entry. */
moduleName = "HDF_PLATFORM_REGULATOR_MANAGER";
moduleName = "HDF_PLATFORM_REGULATOR_MANAGER";
...
@@ -198,7 +200,7 @@ The regulator module adaptation procedure is as follows:
...
@@ -198,7 +200,7 @@ The regulator module adaptation procedure is as follows:
}
}
```
```
3. Instantiate the APIs of the core layer.
3. Instantiate the core layer APIs.
Initialize the **RegulatorNode** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **RegulatorMethod** in **RegulatorNode** (so that the underlying driver functions can be called).
Initialize the **RegulatorNode** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **RegulatorMethod** in **RegulatorNode** (so that the underlying driver functions can be called).
...
@@ -206,8 +208,6 @@ The regulator module adaptation procedure is as follows:
...
@@ -206,8 +208,6 @@ The regulator module adaptation procedure is as follows:
The **RegulatorNode** structure holds parameters and data for the driver. The HDF obtains the values in **regulator_config.hcs** using **DeviceResourceIface**.
The **RegulatorNode** structure holds parameters and data for the driver. The HDF obtains the values in **regulator_config.hcs** using **DeviceResourceIface**.
```
```
// RegulatorNode is the core layer controller structure. The Init function assigns values to the members of RegulatorNode.
// RegulatorNode is the core layer controller structure. The Init function assigns values to the members of RegulatorNode.
struct RegulatorNode {
struct RegulatorNode {
...
@@ -219,17 +219,17 @@ The regulator module adaptation procedure is as follows:
...
@@ -219,17 +219,17 @@ The regulator module adaptation procedure is as follows:
| HDF_ERR_MALLOC_FAIL | Failed to allocate memory. |
| HDF_ERR_INVALID_PARAM | Invalid parameter. |
| HDF_ERR_IO | I/O error. |
| HDF_SUCCESS | Initialization successful. |
| HDF_FAILURE | Initialization failed. |
Function description:
Initializes the custom structure and **RegulatorNode** members, and adds the regulator controller by calling the **RegulatorNodeAdd** function at the core layer.
| HDF_ERR_MALLOC_FAIL | Failed to allocate memory. |
| HDF_ERR_INVALID_PARAM | Invalid parameter. |
| HDF_ERR_IO | I/O error. |
| HDF_SUCCESS | Initialization successful. |
| HDF_FAILURE | Initialization failed. |
**Function description**:
Initializes the custom structure and **RegulatorNode** members, and adds the regulator controller by calling the **RegulatorNodeAdd** function at the core layer.
regNode = (struct RegulatorNode *)OsalMemCalloc(sizeof(*regNode));// Load the .hcs file.
...
ret = VirtualRegulatorReadHcs(regNode, node); // Read .hcs information.
...
regNode->priv = (void *)node; ; // Instantiate the node.
regNode->ops = &g_method; // Instantiate OPS.
ret = RegulatorNodeAdd(regNode); // Add the node.
...
}
```
-**Release** function
-**Release** function
Input parameter:
**Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
Return value:
**Return value**:
No value is return.
No value is returned.
Function description:
**Function description**:
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
| ReadTime | **host**: structure pointer to the RTC controller at the core layer.| **time**: structure pointer to the time read.| HDF_STATUS| Reads the RTC time.|
| ReadTime | **host**: structure pointer to the RTC controller at the core layer.| **time**: structure pointer to the time read.| HDF_STATUS| Reads the RTC time.|
| WriteTime | **host**: structure pointer to the RTC controller at the core layer.<br>**time**: structure pointer to the time to write.| –| HDF_STATUS| Writes the RTC time (including the year, month, day, day of week, hour, minute, second, and millisecond).|
| WriteTime | **host**: structure pointer to the RTC controller at the core layer.<br>**time**: structure pointer to the time to write.| –| HDF_STATUS| Writes the RTC time (including the year, month, day, day of week, hour, minute, second, and millisecond).|
| ReadAlarm | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.| **time**: structure pointer to the time read.| HDF_STATUS| Reads the RTC alarm time.|
| ReadAlarm | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.| **time**: structure pointer to the time read.| HDF_STATUS| Reads the RTC alarm time.|
| WriteAlarm | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.<br>**time**: structure pointer to the time to write.| –| HDF_STATUS| Writes the RTC alarm time.|
| WriteAlarm | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.<br>**time**: structure pointer to the time to write.| –| HDF_STATUS| Writes the RTC alarm time.|
| RegisterAlarmCallback | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.<br>**cb**: pointer to the callback to register.| –| HDF_STATUS| Registers a callback to be invoked when an alarm is not generated at the specified time.|
| RegisterAlarmCallback | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.<br>**cb**: pointer to the callback to register.| –| HDF_STATUS| Registers a callback to be invoked when an alarm is not generated at the specified time.|
| AlarmInterruptEnable | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.<br>**enable**: whether to enable interrupts for an RTC alarm. | –| HDF_STATUS| Enables or disables interrupts for an RTC alarm.|
| AlarmInterruptEnable | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.<br>**enable**: whether to enable interrupts for an RTC alarm. | –| HDF_STATUS| Enables or disables interrupts for an RTC alarm.|
| GetFreq | **host**: structure pointer to the RTC controller at the core layer.| **freq**: pointer to the frequency obtained, which is of the uint32_t type.| HDF_STATUS| Obtains the frequency of the external crystal oscillator connected to the RTC driver.|
| GetFreq | **host**: structure pointer to the RTC controller at the core layer.| **freq**: pointer to the frequency obtained, which is of the uint32_t type.| HDF_STATUS| Obtains the frequency of the external crystal oscillator connected to the RTC driver.|
| SetFreq | **host**: structure pointer to the RTC controller at the core layer.<br>**freq**: frequency to set, which is of the uint32_t type.| –| HDF_STATUS| Sets the frequency of the external crystal oscillator connected to the RTC driver.|
| SetFreq | **host**: structure pointer to the RTC controller at the core layer.<br>**freq**: frequency to set, which is of the uint32_t type.| –| HDF_STATUS| Sets the frequency of the external crystal oscillator connected to the RTC driver.|
| Reset | **host**: structure pointer to the RTC controller at the core layer.| –| HDF_STATUS| Resets the RTC.|
| Reset | **host**: structure pointer to the RTC controller at the core layer.| –| HDF_STATUS| Resets the RTC.|
| ReadReg | **host**: structure pointer to the RTC controller at the core layer.<br>**usrDefIndex**: index of a custom register.| **value**: pointer to the register value obtained, which is of the uint8_t type.| HDF_STATUS| Reads a custom RTC register. A register index corresponds to one byte of the register value.|
| ReadReg | **host**: structure pointer to the RTC controller at the core layer.<br>**usrDefIndex**: index of a custom register.| **value**: pointer to the register value obtained, which is of the uint8_t type.| HDF_STATUS| Reads a custom RTC register. A register index corresponds to one byte of the register value.|
| WriteReg | **host**: structure pointer to the RTC controller at the core layer.<br>**usrDefIndex**: index of a custom register.<br>**value**: register value to write, which is of the uint8_t type.| –| HDF_STATUS| Writes a custom RTC register. A register index corresponds to one byte of the register value.|
| WriteReg | **host**: structure pointer to the RTC controller at the core layer.<br>**usrDefIndex**: index of a custom register.<br>**value**: register value to write, which is of the uint8_t type.| –| HDF_STATUS| Writes a custom RTC register. A register index corresponds to one byte of the register value.|
## How to Develop
## How to Develop
...
@@ -67,6 +67,7 @@ The RTC module adaptation involves the following steps:
...
@@ -67,6 +67,7 @@ The RTC module adaptation involves the following steps:
> For details about the functions in **RtcMethod**, see [Available APIs](#available-apis).
> For details about the functions in **RtcMethod**, see [Available APIs](#available-apis).
4. Debug the driver.
4. Debug the driver.
(Optional) For new drivers, verify the basic functions, such as the RTC status control and response to interrupts.
(Optional) For new drivers, verify the basic functions, such as the RTC status control and response to interrupts.
...
@@ -74,31 +75,37 @@ The RTC module adaptation involves the following steps:
...
@@ -74,31 +75,37 @@ The RTC module adaptation involves the following steps:
The following uses **rtc_hi35xx.c** as an example to present the information required for implementing device functions.
The following uses **rtc_hi35xx.c** as an example to present the information required for implementing device functions.
1. Instantiate the driver entry.<br/>The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. In the HDF framework, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
1. Instantiate the driver entry.
The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**.
In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
RTC driver entry example:
RTC driver entry example:
```
```
struct HdfDriverEntry g_rtcDriverEntry = {
struct HdfDriverEntry g_rtcDriverEntry = {
.moduleVersion = 1,
.moduleVersion = 1,
.Bind = HiRtcBind, // See the Bind function.
.Bind = HiRtcBind, // See the Bind function.
.Init = HiRtcInit, // See the Init function.
.Init = HiRtcInit, // See the Init function.
.Release = HiRtcRelease, //See the Release function.
.Release = HiRtcRelease, //See the Release function.
.moduleName = "HDF_PLATFORM_RTC", // (Mandatory) The value must be the same as that in the .hcs file.
.moduleName = "HDF_PLATFORM_RTC", // (Mandatory) The value must be the same as that in the .hcs file.
};
};
// Call HDF_INIT to register the driver entry with the HDF.
// Call HDF_INIT to register the driver entry with the HDF.
HDF_INIT(g_rtcDriverEntry);
HDF_INIT(g_rtcDriverEntry);
```
```
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **rtc_config.hcs** file.
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **rtc_config.hcs** file.
The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **RtcHost** members at the core layer.
The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **RtcHost** members at the core layer.
In this example, there is only one RTC controller. If there are multiple RTC controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **rtc_config** file for each controller.
In this example, there is only one RTC controller. If there are multiple RTC controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **rtc_config** file for each controller.
-**device_info.hcs** configuration example
-**device_info.hcs** configuration example
```
```
root {
root {
device_info {
device_info {
...
@@ -107,9 +114,9 @@ The following uses **rtc_hi35xx.c** as an example to present the information req
...
@@ -107,9 +114,9 @@ The following uses **rtc_hi35xx.c** as an example to present the information req
device0 :: deviceNode {
device0 :: deviceNode {
policy = 1; // The driver publishes services for kernel-mode processes only.
policy = 1; // The driver publishes services for kernel-mode processes only.
priority = 30; // A smaller value indicates a higher priority.
priority = 30; // A smaller value indicates a higher priority.
permission = 0644; // Permission for the driver to create a device node
permission = 0644; // Permission for the driver to create a device node
moduleName = "HDF_PLATFORM_RTC"; // (Mandatory) Driver name, which must be the same as moduleName in the driver entry.
moduleName = "HDF_PLATFORM_RTC"; // (Mandatory) Driver name, which must be the same as moduleName in the driver entry.
serviceName = "HDF_PLATFORM_RTC"; // (Mandatory) Unique name of the service published by the driver.
serviceName = "HDF_PLATFORM_RTC"; // (Mandatory) Unique name of the service published by the driver.
deviceMatchAttr = "hisilicon_hi35xx_rtc";// The value must be the same as that of match_attr in the .hcs file.
deviceMatchAttr = "hisilicon_hi35xx_rtc";// The value must be the same as that of match_attr in the .hcs file.
}
}
}
}
...
@@ -120,7 +127,7 @@ The following uses **rtc_hi35xx.c** as an example to present the information req
...
@@ -120,7 +127,7 @@ The following uses **rtc_hi35xx.c** as an example to present the information req
-**rtc_config.hcs** configuration example
-**rtc_config.hcs** configuration example
```
```
root {
root {
platform {
platform {
...
@@ -143,25 +150,25 @@ The following uses **rtc_hi35xx.c** as an example to present the information req
...
@@ -143,25 +150,25 @@ The following uses **rtc_hi35xx.c** as an example to present the information req
}
}
```
```
3. Initialize the **RtcHost** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init** and **Release**) to instantiate **RtcMethod** in **RtcHost** (so that the underlying driver functions can be called).
3. Initialize the **RtcHost** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **RtcMethod** in **RtcHost** (so that the underlying driver functions can be called).
- Defining a custom structure
- Defining a custom structure
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **rtc_config.hcs** file to initialize the members in the custom structure.
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **rtc_config.hcs** file to initialize the members in the custom structure.
```
```
struct RtcConfigInfo {
struct RtcConfigInfo {
uint32_t spiBaseAddr; // Used for address mapping.
uint32_t spiBaseAddr; // Used for address mapping.
volatile void *remapBaseAddr; // Used for address mapping.
volatile void *remapBaseAddr; // Used for address mapping.
uint16_t regAddrLength; // Used for address mapping.
uint16_t regAddrLength; // Used for address mapping.
uint8_t supportAnaCtrl; // Whether ANACTRL is supported.
uint8_t supportAnaCtrl; // Whether ANACTRL is supported.
uint8_t supportLock; // Whether lock is supported.
uint8_t supportLock; // Whether lock is supported.
uint8_t irq; // Interrupt number.
uint8_t irq; // Interrupt number.
uint8_t alarmIndex; // RTC alarm index.
uint8_t alarmIndex; // RTC alarm index.
uint8_t anaCtrlAddr; // ANACTRL address.
uint8_t anaCtrlAddr; // ANACTRL address.
struct RtcLockAddr lockAddr; // Lock address.
struct RtcLockAddr lockAddr; // Lock address.
RtcAlarmCallback cb; // Callback.
RtcAlarmCallback cb; // Callback.
struct OsalMutex mutex; // Mutex.
struct OsalMutex mutex; // Mutex.
};
};
// RtcHost is the controller structure at the core layer. The Init function assigns values to the members of RtcHost.
// RtcHost is the controller structure at the core layer. The Init function assigns values to the members of RtcHost.
...
@@ -172,125 +179,130 @@ The following uses **rtc_hi35xx.c** as an example to present the information req
...
@@ -172,125 +179,130 @@ The following uses **rtc_hi35xx.c** as an example to present the information req
void *data;
void *data;
};
};
```
```
- Instantiating **RtcMethod** in **RtcHost** (other members are initialized by **Init**)
- Instantiating **RtcMethod** in **RtcHost** (other members are initialized by **Init**)
```
```
// Example in rtc_hi35xx.c: instantiate the hook.
// Example in rtc_hi35xx.c: instantiate the hook.
static struct RtcMethod g_method = {
static struct RtcMethod g_method = {
.ReadTime = HiRtcReadTime,
.ReadTime = HiRtcReadTime,
.WriteTime = HiRtcWriteTime,
.WriteTime = HiRtcWriteTime,
.ReadAlarm = HiReadAlarm,
.ReadAlarm = HiReadAlarm,
.WriteAlarm = HiWriteAlarm,
.WriteAlarm = HiWriteAlarm,
.RegisterAlarmCallback = HiRegisterAlarmCallback,
.RegisterAlarmCallback = HiRegisterAlarmCallback,
.AlarmInterruptEnable = HiAlarmInterruptEnable,
.AlarmInterruptEnable = HiAlarmInterruptEnable,
.GetFreq = HiGetFreq,
.GetFreq = HiGetFreq,
.SetFreq = HiSetFreq,
.SetFreq = HiSetFreq,
.Reset = HiReset,
.Reset = HiReset,
.ReadReg = HiReadReg,
.ReadReg = HiReadReg,
.WriteReg = HiWriteReg,
.WriteReg = HiWriteReg,
};
};
```
```
-**Bind** function
-**Bind** function
Input parameter:
**Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
Return value:
**Return value**:
HDF_STATUS<br/>The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
**HDF_STATUS**
**Table 2** HDF_STATUS
The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
host = RtcHostFromDevice(device);// Forcibly convert HdfDeviceObject to RtcHost.
rtcInfo = OsalMemCalloc(sizeof(*rtcInfo));
...
// HiRtcConfigData reads attributes from the device configuration tree and fills the values in supportAnaCtrl, supportLock, spiBaseAddr, regAddrLength, and irq in rtcInfo.
// Provide parameters for HiRtcSwInit and HiRtcSwInit. When HiRtcSwInit and HiRtcSwInit fail to be executed internally, Release() can be called to release memory.
if (HiRtcConfigData(rtcInfo, device->property) != 0) {
...
}
if (HiRtcSwInit(rtcInfo)! = 0) {// Address mapping and interrupt registration.
...
}
if (HiRtcHwInit(rtcInfo)! = 0) {// Initialize ANACTRL and lockAddr.
...
...
device->service = &host->service; // Prerequisite for conversion between HdfDeviceObject and RtcHost.
// It helps implement a global host by calling RtcHostFromDevice.
return HDF_SUCCESS;
}
}
```
host->method = &g_method; // Attach the RtcMethod instance.
host->data = rtcInfo; // Prerequisites for conversion between RtcConfigInfo and RtcHost.
-**Init** function
HDF_LOGI("Hdf dev service:%s init success!", HdfDeviceGetServiceName(device));
return HDF_SUCCESS;
**Input parameter**:
}
```
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**Return value**:
**HDF_STATUS**
**Function description**:
Initializes the custom structure object and **RtcHost**.
host = RtcHostFromDevice(device);// Forcibly convert HdfDeviceObject to RtcHost.
rtcInfo = OsalMemCalloc(sizeof(*rtcInfo));
...
// HiRtcConfigData reads attributes from the device configuration tree and fills in supportAnaCtrl, supportLock, spiBaseAddr, regAddrLength and irq of RTCInfo.
// Provide parameters for HiRtcSwInit and HiRtcSwInit. When HiRtcSwInit and HiRtcSwInit fail to be executed internally, Release() can be called to release memory.
if (HiRtcConfigData(rtcInfo, device->property) != 0) {
...
}
if (HiRtcSwInit(rtcInfo)! = 0) {// Address mapping and interrupt registration.
...
}
if (HiRtcHwInit(rtcInfo)! = 0) {// Initialize ANACTRL and lockAddr.
...
}
host->method = &g_method; // Attach the RtcMethod instance.
host->data = rtcInfo; // Prerequisites for conversion between RtcConfigInfo and RtcHost.
HDF_LOGI("Hdf dev service:%s init success!", HdfDeviceGetServiceName(device));
return HDF_SUCCESS;
}
```
-**Release** function
-**Release** function
Input parameter:
**Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
Return value:
**Return value**:
No value is returned.
No value is returned.
Function description:
**Function description**:
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. All forced conversion operations for obtaining the corresponding object can be successful only when the **Init** or **Bind** function has the corresponding value assignment operations.
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
> All forced conversion operations for obtaining the corresponding object can be successful only when the **Init** or **Bind** function has the corresponding value assignment operations.
A Secure Digital Input Output \(SDIO\) card is an extension of the SD specification to cover I/O functions. SD and SDIO cards are called multimedia cards \(MMCs\). In the Hardware Driver Foundation \(HDF\) framework, the SDIO module uses the independent service mode for API adaptation. In this mode, each device independently publishes a device service to handle external access requests. After receiving an access request from an API, the device manager extracts the parameters in the request to call the internal method of the target device. In the independent service mode, the service management capabilities of the HDFDeviceManager can be directly used. However, you need to configure a device node for each device, which increases the memory usage.
A Secure Digital Input Output (SDIO) card is an extension of the SD specification to cover I/O functions. SD and SDIO cards are called multimedia cards (MMCs). In the Hardware Driver Foundation (HDF), the SDIO module uses the independent service mode for API adaptation. In this mode, each device independently publishes a service to process external access requests. When receiving an access request, the HDF DeviceManager extracts parameters from the request to call the internal APIs of the target device. In the independent service mode, the HDF DeviceManager provides service management capabilities. However, you need to configure a node for each device, which increases memory usage.
**Figure 1** Independent service mode<aname="fig124181331222"></a>
| incrAddrReadBytes | **dev**: structure pointer to the SDIO device controller.<br>**addr**: SDIO address, which is of the uint32_t type.<br>**size**: size of the data to read, which is of the uint32_t type.| **data**: pointer to the output value, which is of the uint8_t type.| HDF_STATUS| Incrementally reads data of a given length from the specified SDIO address.|
| incrAddrWriteBytes | **dev**: structure pointer to the SDIO device controller.<br>**data**: pointer to the input value, which is of the uint8_t type.<br>**addr**: SDIO address, which is of the uint32_t type.<br>**size**: size of the data to write, which is of the uint32_t type.| –| HDF_STATUS| Incrementally writes data of a given length to the specified SDIO address.|
</th>
| fixedAddrReadBytes | **dev**: structure pointer to the SDIO device controller.<br>**addr**: SDIO address, which is of the uint32_t type.<br>**size**: size of the data to read, which is of the uint32_t type.<br>**scatterLen**: data length, which is of the uint32_t type.| **data**: pointer to the output value, which is of the uint8_t type.| HDF_STATUS| Reads data of a given length from a fixed SDIO address.|
| fixedAddrWriteBytes | **dev**: structure pointer to the SDIO device controller.<br>**data**: pointer to the input value, which is of the uint8_t type.<br>**addr**: SDIO address, which is of the uint32_t type.<br>**size**: size of the data to write, which is of the uint32_t type.<br>**scatterLen**: data length, which is of the uint32_t type.| –| HDF_STATUS| Writes data of a given length to the fixed SDIO address.|
</th>
| func0ReadBytes | **dev**: structure pointer to the SDIO device controller.<br>**addr**: SDIO address, which is of the uint32_t type.<br>**size**: size of the data to read, which is of the uint32_t type.| **data**: pointer to the output value, which is of the uint8_t type.| HDF_STATUS| Reads data of a given length from the address space of SDIO function 0.|
| func0WriteBytes | **dev**: structure pointer to the SDIO device controller.<br>**data**: pointer to the input value, which is of the uint8_t type.<br>**addr**: SDIO address, which is of the uint32_t type.<br>**size**: size of the data to write, which is of the uint32_t type.| –| HDF_STATUS| Writes data of a given length to the address space of SDIO function 0.|
</th>
| setBlockSize | **dev**: structure pointer to the SDIO device controller.<br>**blockSize**: block size, which is of the uint32_t type.| –| HDF_STATUS| Sets the block size.|
| getCommonInfo | **dev**: structure pointer to the SDIO device controller. <br>**infoType**: info type, which is of the uint32_t type.| **info**: structure pointer to the output **SdioFuncInfo**.| HDF_STATUS| Obtains **CommonInfo**. For details, see the **NOTE** below this table.|
</th>
| setCommonInfo | **dev**: structure pointer to the SDIO device controller.<br>**info**: union pointer to the input **SdioFuncInfo**.<br>**infoType**: info type, which is of the uint32_t type.| –| HDF_STATUS| Sets **CommonInfo**. For details, see the **NOTE** below this table.|
</tr>
| flushData | **dev**: structure pointer to the SDIO device controller.| –| HDF_STATUS| Called to flush data when the SDIO device needs to be re-initialized or an error occurs.|
</thead>
| enableFunc | **dev**: structure pointer to the SDIO device controller.| –| HDF_STATUS| Enables an SDIO device.|
| disableFunc | **dev**: structure pointer to the SDIO device controller.| –| HDF_STATUS| Disables an SDIO device.|
</td>
| claimIrq | **dev**: structure pointer to the SDIO device controller.<br>**irqHandler**: void function pointer to the interrupt request (IRQ) handler.| –| HDF_STATUS| Claims an SDIO IRQ.|
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p13126132382019"><aname="p13126132382019"></a><aname="p13126132382019"></a><strongid="b5125152392019"><aname="b5125152392019"></a><aname="b5125152392019"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
| releaseIrq | **dev**: structure pointer to the SDIO device controller.| –| HDF_STATUS| Releases an SDIO IRQ.|
<pid="p539123116208"><aname="p539123116208"></a><aname="p539123116208"></a><strongid="b239531132010"><aname="b239531132010"></a><aname="b239531132010"></a>addr</strong>: SDIO address, which is of the uint32_t type.</p>
| findFunc | **dev**: structure pointer to the SDIO device controller.<br>**configData**: structure pointer to the key SDIO function information.| –| HDF_STATUS| Obtains the matching funcNum.|
<pid="p177857442043"><aname="p177857442043"></a><aname="p177857442043"></a><strongid="b10613113712815"><aname="b10613113712815"></a><aname="b10613113712815"></a>size</strong>: size of the data to read, which is of the uint32_t type.</p>
| claimHost | **dev**: structure pointer to the SDIO device controller.| –| HDF_STATUS| Claims a host exclusively.|
</td>
| releaseHost | **dev**: structure pointer to the SDIO device controller.| –| HDF_STATUS| Releases the exclusively claimed host.|
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.3 "><pid="p207851447410"><aname="p207851447410"></a><aname="p207851447410"></a><strongid="b77141033182915"><aname="b77141033182915"></a><aname="b77141033182915"></a>data</strong>: pointer to the output value, which is of the uint8_t type.</p>
> CommonInfo includes the following information:<br>- **maxBlockNum**: specifies the maximum number of blocks in a request. <br>- **maxBlockSize**: specifies the maximum number of bytes in a block. <br>- **maxRequestSize**: specifies the maximum number of bytes in a request. <br>- **enTimeout**: specifies the maximum timeout period, in milliseconds. <br>- **funcNum**: specifies the function number, which ranges from 1 to 7. <br>- **irqCap**: specifies the IRQ capabilities. <br>- **(void \*)data**
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p37855441645"><aname="p37855441645"></a><aname="p37855441645"></a>Incrementally reads data of a given length from the specified SDIO address.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p13541153612013"><aname="p13541153612013"></a><aname="p13541153612013"></a><strongid="b6541103617209"><aname="b6541103617209"></a><aname="b6541103617209"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<pid="p1455963952010"><aname="p1455963952010"></a><aname="p1455963952010"></a><strongid="b165592039142016"><aname="b165592039142016"></a><aname="b165592039142016"></a>data</strong>: pointer to the input value, which is of the uint8_t type.</p>
<pid="p7565542172010"><aname="p7565542172010"></a><aname="p7565542172010"></a><strongid="b0565342182016"><aname="b0565342182016"></a><aname="b0565342182016"></a>addr</strong>: SDIO address, which is of the uint32_t type.</p>
<pid="p078554411417"><aname="p078554411417"></a><aname="p078554411417"></a><strongid="b1773173211314"><aname="b1773173211314"></a><aname="b1773173211314"></a>size</strong>: size of the data to write, which is of the uint32_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p67851444445"><aname="p67851444445"></a><aname="p67851444445"></a>Incrementally writes data of a given length to the specified SDIO address.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p35454464204"><aname="p35454464204"></a><aname="p35454464204"></a><strongid="b3545746122016"><aname="b3545746122016"></a><aname="b3545746122016"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<pid="p98261449132010"><aname="p98261449132010"></a><aname="p98261449132010"></a><strongid="b182684922010"><aname="b182684922010"></a><aname="b182684922010"></a>addr</strong>: SDIO address, which is of the uint32_t type.</p>
<pid="p4926105372014"><aname="p4926105372014"></a><aname="p4926105372014"></a><strongid="b10926175314206"><aname="b10926175314206"></a><aname="b10926175314206"></a>size</strong>: size of the data to read, which is of the uint32_t type.</p>
<pid="p15786144419415"><aname="p15786144419415"></a><aname="p15786144419415"></a><strongid="b17163219183711"><aname="b17163219183711"></a><aname="b17163219183711"></a>scatterLen</strong>: data length, which is of the uint32_t type.</p>
</td>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.3 "><pid="p9786124418414"><aname="p9786124418414"></a><aname="p9786124418414"></a><strongid="b14137104917373"><aname="b14137104917373"></a><aname="b14137104917373"></a>data</strong>: pointer to the output value, which is of the uint8_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p107861744143"><aname="p107861744143"></a><aname="p107861744143"></a>Reads data of a given length from a fixed SDIO address.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p1080445917207"><aname="p1080445917207"></a><aname="p1080445917207"></a><strongid="b380445918202"><aname="b380445918202"></a><aname="b380445918202"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<pid="p0833423219"><aname="p0833423219"></a><aname="p0833423219"></a><strongid="b1583316216211"><aname="b1583316216211"></a><aname="b1583316216211"></a>data</strong>: pointer to the input value, which is of the uint8_t type.</p>
<pid="p6700146102112"><aname="p6700146102112"></a><aname="p6700146102112"></a><strongid="b117001967218"><aname="b117001967218"></a><aname="b117001967218"></a>addr</strong>: SDIO address, which is of the uint32_t type.</p>
<pid="p1068901013214"><aname="p1068901013214"></a><aname="p1068901013214"></a><strongid="b368914103212"><aname="b368914103212"></a><aname="b368914103212"></a>size</strong>: size of the data to write, which is of the uint32_t type.</p>
<pid="p77861444341"><aname="p77861444341"></a><aname="p77861444341"></a><strongid="b1654516614113"><aname="b1654516614113"></a><aname="b1654516614113"></a>scatterLen</strong>: data length, which is of the uint32_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p1478615441948"><aname="p1478615441948"></a><aname="p1478615441948"></a>Writes data of a given length to the fixed SDIO address.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p97041515162116"><aname="p97041515162116"></a><aname="p97041515162116"></a><strongid="b470412150211"><aname="b470412150211"></a><aname="b470412150211"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<pid="p1029871817216"><aname="p1029871817216"></a><aname="p1029871817216"></a><strongid="b17298191818216"><aname="b17298191818216"></a><aname="b17298191818216"></a>addr</strong>: SDIO address, which is of the uint32_t type.</p>
<pid="p4786244541"><aname="p4786244541"></a><aname="p4786244541"></a><strongid="b207721914423"><aname="b207721914423"></a><aname="b207721914423"></a>size</strong>: size of the data to read, which is of the uint32_t type.</p>
</td>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.3 "><pid="p37868445420"><aname="p37868445420"></a><aname="p37868445420"></a><strongid="b8335193874220"><aname="b8335193874220"></a><aname="b8335193874220"></a>data</strong>: pointer to the output value, which is of the uint8_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p107877441146"><aname="p107877441146"></a><aname="p107877441146"></a>Reads data of a given length from the address space of SDIO function 0.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p11251122313211"><aname="p11251122313211"></a><aname="p11251122313211"></a><strongid="b625117238213"><aname="b625117238213"></a><aname="b625117238213"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<pid="p172811926172111"><aname="p172811926172111"></a><aname="p172811926172111"></a><strongid="b528102618213"><aname="b528102618213"></a><aname="b528102618213"></a>data</strong>: pointer to the input value, which is of the uint8_t type.</p>
<pid="p17651829162116"><aname="p17651829162116"></a><aname="p17651829162116"></a><strongid="b1465142962118"><aname="b1465142962118"></a><aname="b1465142962118"></a>addr</strong>: SDIO address, which is of the uint32_t type.</p>
<pid="p67871544242"><aname="p67871544242"></a><aname="p67871544242"></a><strongid="b394817346436"><aname="b394817346436"></a><aname="b394817346436"></a>size</strong>: size of the data to write, which is of the uint32_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p57876441415"><aname="p57876441415"></a><aname="p57876441415"></a>Writes data of a given length to the address space of SDIO function 0.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p16155033152118"><aname="p16155033152118"></a><aname="p16155033152118"></a><strongid="b71556330213"><aname="b71556330213"></a><aname="b71556330213"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<pid="p187872445410"><aname="p187872445410"></a><aname="p187872445410"></a><strongid="b12844183820441"><aname="b12844183820441"></a><aname="b12844183820441"></a>blockSize</strong>: block size, which is of the uint32_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p378710441647"><aname="p378710441647"></a><aname="p378710441647"></a>Sets the block size.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p114691537132117"><aname="p114691537132117"></a><aname="p114691537132117"></a><strongid="b6469143713211"><aname="b6469143713211"></a><aname="b6469143713211"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<pid="p1078820442419"><aname="p1078820442419"></a><aname="p1078820442419"></a><strongid="b12145522184712"><aname="b12145522184712"></a><aname="b12145522184712"></a>infoType</strong>: info type, which is of the uint32_t type.</p>
</td>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.3 "><pid="p678814411418"><aname="p678814411418"></a><aname="p678814411418"></a><strongid="b83512634819"><aname="b83512634819"></a><aname="b83512634819"></a>info</strong>: structure pointer to the output <strongid="b59131139164813"><aname="b59131139164813"></a><aname="b59131139164813"></a>SdioFuncInfo</strong>.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p7788444140"><aname="p7788444140"></a><aname="p7788444140"></a>Obtains <strongid="b176819272491"><aname="b176819272491"></a><aname="b176819272491"></a>CommonInfo</strong>. For details, see the <strongid="b1127411492595"><aname="b1127411492595"></a><aname="b1127411492595"></a>NOTE</strong> below this table.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p10540104472112"><aname="p10540104472112"></a><aname="p10540104472112"></a><strongid="b1954014420218"><aname="b1954014420218"></a><aname="b1954014420218"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<pid="p9107164817213"><aname="p9107164817213"></a><aname="p9107164817213"></a><strongid="b410734816213"><aname="b410734816213"></a><aname="b410734816213"></a>info</strong>: union pointer to the input <strongid="b610774812211"><aname="b610774812211"></a><aname="b610774812211"></a>SdioFuncInfo</strong>.</p>
<pid="p2078815442417"><aname="p2078815442417"></a><aname="p2078815442417"></a><strongid="b138611646185019"><aname="b138611646185019"></a><aname="b138611646185019"></a>infoType</strong>: info type, which is of the uint32_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p1278814415412"><aname="p1278814415412"></a><aname="p1278814415412"></a>Sets <strongid="b840010395517"><aname="b840010395517"></a><aname="b840010395517"></a>CommonInfo</strong>. For details, see the <strongid="b44901724012"><aname="b44901724012"></a><aname="b44901724012"></a>NOTE</strong> below this table.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p67888441442"><aname="p67888441442"></a><aname="p67888441442"></a><strongid="b4882145105215"><aname="b4882145105215"></a><aname="b4882145105215"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p578912441445"><aname="p578912441445"></a><aname="p578912441445"></a>Calls the function when the SDIO device needs to be re-initialized or an error occurs.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p12789144418412"><aname="p12789144418412"></a><aname="p12789144418412"></a><strongid="b1029151718538"><aname="b1029151718538"></a><aname="b1029151718538"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p127891445415"><aname="p127891445415"></a><aname="p127891445415"></a>Enables the SDIO device.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p1978911449418"><aname="p1978911449418"></a><aname="p1978911449418"></a><strongid="b529982985311"><aname="b529982985311"></a><aname="b529982985311"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p1479019449414"><aname="p1479019449414"></a><aname="p1479019449414"></a>Disables the SDIO device.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p1867751642210"><aname="p1867751642210"></a><aname="p1867751642210"></a><strongid="b12677816192216"><aname="b12677816192216"></a><aname="b12677816192216"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<pid="p1279018442419"><aname="p1279018442419"></a><aname="p1279018442419"></a><strongid="b471593695213"><aname="b471593695213"></a><aname="b471593695213"></a>irqHandler</strong>: void function pointer to the IRQ handler.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p6790124418410"><aname="p6790124418410"></a><aname="p6790124418410"></a>Claims an SDIO IRQ.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p27902441414"><aname="p27902441414"></a><aname="p27902441414"></a><strongid="b143101291537"><aname="b143101291537"></a><aname="b143101291537"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p77901544440"><aname="p77901544440"></a><aname="p77901544440"></a>Releases an SDIO IRQ.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p181282417222"><aname="p181282417222"></a><aname="p181282417222"></a><strongid="b81210244229"><aname="b81210244229"></a><aname="b81210244229"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<pid="p5791184417414"><aname="p5791184417414"></a><aname="p5791184417414"></a><strongid="b34537192557"><aname="b34537192557"></a><aname="b34537192557"></a>configData</strong>: structure pointer to the key SDIO function information.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p779119441549"><aname="p779119441549"></a><aname="p779119441549"></a>Obtains the matching funcNum.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p179116441547"><aname="p179116441547"></a><aname="p179116441547"></a><strongid="b931692913535"><aname="b931692913535"></a><aname="b931692913535"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="p5791134412417"><aname="p5791134412417"></a><aname="p5791134412417"></a>Claims a host exclusively.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p67916449413"><aname="p67916449413"></a><aname="p67916449413"></a><strongid="b1632011295536"><aname="b1632011295536"></a><aname="b1632011295536"></a>dev</strong>: structure pointer to the SDIO device controller.</p>
> For details about the functions in **SdioDeviceOps**, see [Available APIs](#available-apis).
>For details, see [Available APIs](#available-apis).
4. Debug the driver.
4. Debug the driver.
(Optional) For new drivers, verify the basic functions, such as the SDIO control status and response to interrupts.
-\(Optional\) For new drivers, verify the basic functions, such as the SDIO control status and response to interrupts.
## Development Example
## Development Example<a name="section2112250242150053"></a>
The following uses **sdio_adapter.c** as an example to present the information required for implementing device functions.
The following uses **sdio\_adapter.c** as an example to present the contents that need to be provided by the vendor to implement device functions.
1. Instantiate the driver entry.
1. Instantiate the driver entry. The driver entry must be a global variable of the **HdfDriverEntry** type \(defined in **hdf\_device\_desc.h**\), and the value of **moduleName** must be the same as that in **device\_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**.
Generally, HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, HDF calls **Release** to release driver resources and exit.
In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
- SDIO driver entry reference
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
```
struct HdfDriverEntry g_sdioDriverEntry = {
SDIO driver entry example:
.moduleVersion = 1,
.Bind = Hi35xxLinuxSdioBind, // See the Bind function.
```
.Init = Hi35xxLinuxSdioInit, // See the Init function.
struct HdfDriverEntry g_sdioDriverEntry = {
.Release = Hi35xxLinuxSdioRelease// See the Release function.
.moduleVersion = 1,
.moduleName = "HDF_PLATFORM_SDIO",// (Mandatory) The value must be the same as that of moduleName in the **.hcs** file.
.Bind = Hi35xxLinuxSdioBind, // See the Bind function.
};
.Init = Hi35xxLinuxSdioInit, // See the Init function.
// Call HDF_INIT to register the driver entry with the HDF.
.Release = Hi35xxLinuxSdioRelease, // See the Release function.
HDF_INIT(g_sdioDriverEntry);
.moduleName = "HDF_PLATFORM_SDIO",// (Mandatory) The value must be the same as that of moduleName in the .hcs file.
```
};
// Call HDF_INIT to register the driver entry with the HDF.
2. Add the **deviceNode** information to the **device\_info.hcs** file and configure the device attributes in the **sdio\_config.hcs** file. The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **SdioDevice** members at the core layer.
HDF_INIT(g_sdioDriverEntry);
```
In this example, there is only one SDIO controller. If there are multiple SDIO controllers, you need to add the **deviceNode** information to the **device\_info** file and add the corresponding device attributes to the **sdio\_config** file.
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **sdio_config.hcs** file.
- **device\_info.hcs** configuration reference
The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **SdioDevice** members at the core layer.
```
root {
In this example, there is only one SDIO controller. If there are multiple SDIO controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **sdio_config** file for each controller.
device_info {
match_attr = "hdf_manager";
-**device_info.hcs** configuration example:
platform :: host {
hostName = "platform_host";
priority = 50;
```
device_sdio :: device {
root {
device0 :: deviceNode {
device_info {
policy = 1;
match_attr = "hdf_manager";
priority = 70;
platform :: host {
permission = 0644;
hostName = "platform_host";
moduleName = "HDF_PLATFORM_SDIO"; // (Mandatory) Driver name, which must be the same as the moduleName in the driver entry.
priority = 50;
serviceName = "HDF_PLATFORM_MMC_2"; // (Mandatory) Unique name of the service published by the driver
device_sdio :: device {
deviceMatchAttr = "hisilicon_hi35xx_sdio_0";// (Mandatory) Used to configure the private data of the controller. The value must be the same as the controller in sdio_config.hcs.
device0 :: deviceNode {
}
policy = 1;
}
priority = 70;
}
permission = 0644;
}
moduleName = "HDF_PLATFORM_SDIO"; // (Mandatory) Driver name, which must be the same as moduleName in the driver entry.
}
serviceName = "HDF_PLATFORM_MMC_2"; // (Mandatory) Unique name of the service published by the driver.
```
deviceMatchAttr = "hisilicon_hi35xx_sdio_0";// (Mandatory) Private data of the controller. The value must be the same as the controller information in sdio_config.hcs.
}
- **sdio\_config.hcs** configuration reference
}
}
```
}
root {
}
platform {
```
sdio_config {
template sdio_controller {
-**sdio_config.hcs** configuration example:
match_attr = "";
hostId = 2; // (Mandatory) Set the value to 2. For details, see mmc_config.hcs.
devType = 2; // (Mandatory) Set the value to 2. For details, see mmc_config.hcs.
```
}
root {
controller_0x2dd1 :: sdio_controller {
platform {
match_attr = "hisilicon_hi35xx_sdio_0";// (Mandatory) The value must be the same as that of deviceMatchAttr in device_info.hcs.
sdio_config {
}
template sdio_controller {
}
match_attr = "";
}
hostId = 2; // (Mandatory) The value must be 2. For details, see mmc_config.hcs.
```
devType = 2; // (Mandatory) The value must be 2. For details, see mmc_config.hcs.
}
3. Initialize the **SdioDevice** object at the core layer, including initializing the vendor custom structure \(transferring parameters and data\), instantiating **SdioDeviceOps**\(used to call underlying functions of the driver\) in **SdioDevice**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\).
controller_0x2dd1 :: sdio_controller {
match_attr = "hisilicon_hi35xx_sdio_0";// (Mandatory) The value must be the same as that of deviceMatchAttr in device_info.hcs.
- Custom structure reference
}
}
To the driver, the custom structure carries parameters and data. The values in the **sdio\_config.hcs** file are read by HDF, and the structure members are initialized through **DeviceResourceIface**. Some important values are also passed to the objects at the core layer.
}
```
```
typedef struct {
3. Initialize the **SdioDevice** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **SdioDeviceOps** in **SdioDevice** (so that the underlying driver functions can be called).
uint32_t maxBlockNum; // Maximum number of blocks in a request.
uint32_t maxBlockSize; // Maximum number of bytes in a block. The value range is 1 to 2048.
- Defining a custom structure
uint32_t maxRequestSize; // Maximum number of bytes in a request. The value range is 1 to 2048.
uint32_t enTimeout; // Maximum timeout period in milliseconds. The value cannot exceed one second.
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **sdio_config.hcs** file to initialize the members in the custom structure and passes important parameters to the object at the core layer.
uint32_t funcNum; // Function number, which ranges from 1 to 7.
uint32_t irqCap; // IRQ capabilities.
void *data; // Private data.
```
} SdioFuncInfo;
typedef struct {
uint32_t maxBlockNum; // Maximum number of blocks in a request.
// SdioDevice is the core layer controller structure. Its members are assigned with values by using the Bind function.
uint32_t maxBlockSize; // Maximum number of bytes in a block. The value range is 1 to 2048.
struct SdioDevice {
uint32_t maxRequestSize; // Maximum number of bytes in a request. The value range is 1 to 2048.
struct SdDevice sd;
uint32_t enTimeout; // Maximum timeout period in milliseconds. The value cannot exceed one second.
struct SdioDeviceOps *sdioOps;
uint32_t funcNum; // Function number, which ranges from 1 to 7.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the **.hcs** configuration file information.
.claimHost = Hi35xxLinuxSdioClaimHost,
.releaseHost = Hi35xxLinuxSdioReleaseHost,
Return values:
};
```
HDF\_STATUS \(The following table lists some status. For details about other status, see **HDF\_STATUS** in the **//drivers/framework/include/utils/hdf\_base.h** file.\)
-**Bind** function
**Table 2** Input parameters and return values of the Bind function
Initializes the custom structure object and **SdioCntlr**, calls the **SdioCntlrAdd** function at the core layer, and performs other initialization operations customized by the vendor.
cntlr->hdfDevObj = obj; // (Mandatory) Prerequisites for conversion between HdfDeviceObject and MmcCntlr.
</td>
obj->service = &cntlr->service; // (Mandatory) Prerequisites for conversion between HdfDeviceObject and MmcCntlr.
</tr>
ret = Hi35xxLinuxSdioCntlrParse(cntlr, obj); // (Mandatory) Initialize index and devType of cntlr. If the initialization fails, execute goto _ERR.
</tbody>
...
</table>
ret = MmcCntlrAdd(cntlr); // (Mandatory) Call the function in mmc_core.c. If the operation fails, execute goto _ERR.
...
Function description:
ret = MmcCntlrAllocDev(cntlr, (enum MmcDevType)cntlr->devType); // (Mandatory) Call the function in mmc_core.c. If the operation fails, execute goto _ERR.
...
Initializes the custom structure object and **SdioCntlr**, calls the **SdioCntlrAdd** function at the core layer, and performs other initialization operations customized by the vendor.
MmcDeviceAddOps(cntlr->curDev, &g_sdioDeviceOps); // (Mandatory) Call the function in mmc_core.c to hook the related functions.
cntlr->hdfDevObj = obj; // (Mandatory) Enable conversion between HdfDeviceObject and MmcCntlr.
-**Init** function
obj->service = &cntlr->service; // (Mandatory) Enable conversion between HdfDeviceObject and MmcCntlr.
ret = Hi35xxLinuxSdioCntlrParse(cntlr, obj);// (Mandatory) Initialize the index and devType of cntlr. If the initialization fails, execute goto _ERR.
**Input parameter**:
...
ret = MmcCntlrAdd(cntlr); // (Mandatory) Call the mmc_core.c function at the core layer. If the function fails to be called, execute goto _ERR.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
...
ret = MmcCntlrAllocDev(cntlr, (enum MmcDevType)cntlr->devType);// (Mandatory) Call the mmc_core.c function at the core layer. If the function fails to be called, execute goto _ERR.
**Return value**:
...
**HDF_STATUS**
MmcDeviceAddOps(cntlr->curDev, &g_sdioDeviceOps);// (Mandatory) Call the function of mmc_core.c at the core layer to instantiate the hook.
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
{
(void)obj;// No operation. The vendor can add operations as required.
> All forced conversion operations for obtaining the corresponding object can be successful only when the **Bind** function has the corresponding value assignment operations.
Hi35xxLinuxSdioDeleteCntlr((struct MmcCntlr *)obj->service);// (Mandatory) Custom function for releasing memory. A forced conversion from HdfDeviceObject to MmcCntlr is involved.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the **.hcs** configuration file information.
}
```
Return values:
–
Function description:
Releases the memory and deletes the controller. This function assigns a value to the **Release** API in the driver entry structure. When the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. All forced conversion operations for obtaining the corresponding object can be successful only when the **Bind** function has the corresponding value assignment operations.
Hi35xxLinuxSdioDeleteCntlr((struct MmcCntlr *)obj->service);// (Mandatory) Custom function for releasing memory. A forced conversion from HdfDeviceObject to MmcCntlr is involved.
> For details about the functions in **SpiCntlrMethod**, see [Available APIs](#available-apis).
> For details about the functions in **SpiCntlrMethod**, see [Available APIs](#available-apis).
4. Debug the driver.<br>
4. Debug the driver.
(Optional) For new drivers, verify the basic functions, such as the SPI status control and response to interrupts.
(Optional) For new drivers, verify the basic functions, such as the SPI status control and response to interrupts.
...
@@ -61,10 +62,15 @@ The SPI module adaptation involves the following steps:
...
@@ -61,10 +62,15 @@ The SPI module adaptation involves the following steps:
The following uses **spi_hi35xx.c** as an example to present the information required for implementing device functions.
The following uses **spi_hi35xx.c** as an example to present the information required for implementing device functions.
1. Instantiate the driver entry.<br/>The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. In the HDF framework, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
1. Instantiate the driver entry.
The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**.
In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
SPI driver entry example:
SPI driver entry example:
```
```
struct HdfDriverEntry g_hdfSpiDevice = {
struct HdfDriverEntry g_hdfSpiDevice = {
...
@@ -78,12 +84,12 @@ The following uses **spi_hi35xx.c** as an example to present the information req
...
@@ -78,12 +84,12 @@ The following uses **spi_hi35xx.c** as an example to present the information req
HDF_INIT(g_hdfSpiDevice);
HDF_INIT(g_hdfSpiDevice);
```
```
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **spi_config.hcs** file.
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **spi_config.hcs** file.
The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **SpiCntlr** members at the core layer.
The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **SpiCntlr** members at the core layer.
In this example, there is only one SPI controller. If there are multiple SPI controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **spi_config** file for each controller.
In this example, there is only one SPI controller. If there are multiple SPI controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **spi_config** file for each controller.
-**device_info.hcs** configuration example
-**device_info.hcs** configuration example
...
@@ -124,22 +130,22 @@ The following uses **spi_hi35xx.c** as an example to present the information req
...
@@ -124,22 +130,22 @@ The following uses **spi_hi35xx.c** as an example to present the information req
```
```
root {
root {
platform {
platform {
spi_config {// Configure private data for each SPI controller.
spi_config {// Configure private data for each SPI controller.
template spi_controller { // Template configuration. In the template, you can configure the common parameters shared by device nodes.
template spi_controller { // Template configuration. In the template, you can configure the common parameters shared by device nodes.
serviceName = "";
serviceName = "";
match_attr = "";
match_attr = "";
transferMode = 0; // Data transfer mode. The value **0** indicates interrupt transfer, **1** indicates flow control transfer, and **2** indicates DMA transfer.
transferMode = 0; // Data transfer mode. The value **0** indicates interrupt transfer, **1** indicates flow control transfer, and **2** indicates DMA transfer.
busNum = 0; // Bus number.
busNum = 0; // Bus number.
clkRate = 100000000;
clkRate = 100000000;
bitsPerWord = 8 // Number of bits per word.
bitsPerWord = 8; // Number of bits per word.
mode = 19; // SPI data input/output mode.
mode = 19; // SPI data input/output mode.
maxSpeedHz = 0; // Maximum clock frequency.
maxSpeedHz = 0; // Maximum clock frequency.
minSpeedHz = 0; // Minimum clock frequency.
minSpeedHz = 0; // Minimum clock frequency.
speed = 2000000; // Current message transfer speed.
speed = 2000000; // Current message transfer speed.
fifoSize = 256; // FIFO size.
fifoSize = 256; // FIFO size.
numCs = 1; // Chip select (CS) number.
numCs = 1; // Chip select (CS) number.
regBase = 0x120c0000; // Used for address mapping.
regBase = 0x120c0000; // Used for address mapping.
match_attr = "hisilicon_hi35xx_spi_0";// (Mandatory) The value must be the same as that of deviceMatchAttr in device_info.hcs.
match_attr = "hisilicon_hi35xx_spi_0";// (Mandatory) The value must be the same as that of deviceMatchAttr in device_info.hcs.
}
}
controller_0x120c1000 :: spi_controller {
controller_0x120c1000 :: spi_controller {
...
@@ -163,17 +169,18 @@ The following uses **spi_hi35xx.c** as an example to present the information req
...
@@ -163,17 +169,18 @@ The following uses **spi_hi35xx.c** as an example to present the information req
}
}
...
...
//(Optional) Add nodes to the device_info.hcs file as required.
//(Optional) Add nodes to the device_info.hcs file as required.
}
}
}
}
}
}
```
```
3. Initialize the **SpiCntlr** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **SpiCntlrMethod** in **SpiCntlr** (so that the underlying driver functions can be called).
3. Initialize the **SpiCntlr** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init** and **Release**) to instantiate **SpiCntlrMethod** in **SpiCntlr** (so that the underlying driver functions can be called).
- Defining a custom structure
- Defining a custom structure
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **spi_config.hcs** file to initialize the members in the custom structure and passes important parameters, such as the device number and bus number, to the **SpiCntlr** object at the core layer.
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **spi_config.hcs** file to initialize the members in the custom structure and passes important parameters, such as the device number and bus number, to the **SpiCntlr** object at the core layer.
```
```
struct Pl022 {// Corresponds to parameters in .hcs.
struct Pl022 {// Corresponds to parameters in .hcs.
struct SpiCntlr *cntlr;
struct SpiCntlr *cntlr;
...
@@ -231,15 +238,15 @@ The following uses **spi_hi35xx.c** as an example to present the information req
...
@@ -231,15 +238,15 @@ The following uses **spi_hi35xx.c** as an example to present the information req
-**Bind** function
-**Bind** function
Input parameter:
**Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
Return value:
**Return value**:
HDF_STATUS
**HDF_STATUS**
Function description:
**Function description**:
Associates the **SpiCntlr** object with **HdfDeviceObject**.
Associates the **SpiCntlr** object with **HdfDeviceObject**.
...
@@ -253,14 +260,14 @@ The following uses **spi_hi35xx.c** as an example to present the information req
...
@@ -253,14 +260,14 @@ The following uses **spi_hi35xx.c** as an example to present the information req
cntlr->device = device; // Prerequisites for conversion between HdfDeviceObject and SpiCntlr.
cntlr->device = device; // Prerequisites for conversion between HdfDeviceObject and SpiCntlr.
device->service = &(cntlr->service); // Prerequisites for conversion between HdfDeviceObject and SpiCntlr.
device->service = &(cntlr->service); // Prerequisites for conversion between HdfDeviceObject and SpiCntlr.
(void)OsalMutexInit(&cntlr->lock); // Initialize the lock.
(void)OsalMutexInit(&cntlr->lock); // Initialize the lock.
DListHeadInit(&cntlr->list); // Add the corresponding nodes.
DListHeadInit(&cntlr->list); // Add nodes.
cntlr->priv = NULL;
cntlr->priv = NULL;
return cntlr;
return cntlr;
}
}
...
@@ -268,17 +275,15 @@ The following uses **spi_hi35xx.c** as an example to present the information req
...
@@ -268,17 +275,15 @@ The following uses **spi_hi35xx.c** as an example to present the information req
-**Init** function
-**Init** function
Input parameter:
**Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
Return value:
**Return value**:
HDF_STATUS
**HDF_STATUS**<br/>The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
The table below lists some status. For more information, see **HDF_STATUS** in the /drivers/framework/include/utils/hdf_base.h file.
**Table 2** Description of HDF_STATUS
**Table 2** HDF_STATUS
| Status| Description|
| Status| Description|
| -------- | -------- |
| -------- | -------- |
...
@@ -289,10 +294,10 @@ The following uses **spi_hi35xx.c** as an example to present the information req
...
@@ -289,10 +294,10 @@ The following uses **spi_hi35xx.c** as an example to present the information req
| HDF_SUCCESS | Initialization successful.|
| HDF_SUCCESS | Initialization successful.|
| HDF_FAILURE | Initialization failed.|
| HDF_FAILURE | Initialization failed.|
Function description:
**Function description**:
Initializes the custom structure object and **SpiCntlr**.
Initializes the custom structure object and **SpiCntlr**.
@@ -300,10 +305,10 @@ The following uses **spi_hi35xx.c** as an example to present the information req
...
@@ -300,10 +305,10 @@ The following uses **spi_hi35xx.c** as an example to present the information req
int32_t ret;
int32_t ret;
struct SpiCntlr *cntlr = NULL;
struct SpiCntlr *cntlr = NULL;
...
...
cntlr = SpiCntlrFromDevice(device); // Use service to forcibly convert HdfDeviceObject to SpiCntlr. For details about the value assignment, see the Bind function.
cntlr = SpiCntlrFromDevice(device); // Forcibly convert HdfDeviceObject to SpiCntlr using service. For details about the value assignment, see the Bind function.
@@ -338,20 +343,22 @@ The following uses **spi_hi35xx.c** as an example to present the information req
...
@@ -338,20 +343,22 @@ The following uses **spi_hi35xx.c** as an example to present the information req
return 0;
return 0;
}
}
```
```
-**Release** function
-**Release** function
Input parameter:
**Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
Return value:
**Return value**:
No value is returned.
No value is returned.
Function description:
**Function description**:
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. All forced conversion operations for obtaining the corresponding object can be successful only when the **Init** function has the value assignment operations.
> All forced conversion operations for obtaining the corresponding object can be successful only when **Init()** has the corresponding value assignment operations.
```
```
...
@@ -359,8 +366,8 @@ The following uses **spi_hi35xx.c** as an example to present the information req
...
@@ -359,8 +366,8 @@ The following uses **spi_hi35xx.c** as an example to present the information req
{
{
struct SpiCntlr *cntlr = NULL;
struct SpiCntlr *cntlr = NULL;
...
...
cntlr = SpiCntlrFromDevice(device); // Use service to forcibly convert HdfDeviceObject to SpiCntlr. For details about the value assignment, see the Bind function.
cntlr = SpiCntlrFromDevice(device); // Forced conversion from HdfDeviceObject to SpiCntlr is involved. For details about the value assignment, see the Bind function.
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.
## Overview
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)\).
- TX: TX pin of the transmitting UART. It is connected to the RX pin of the peer UART.
A UART is connected to other modules through two wires (as shown in Figure 1) or four wires (as shown in Figure 2).
- RX: RX pin of the receiving UART. It is connected to the TX pin of the peer UART.
- TX: TX pin of the transmitting UART. It is connected to the RX 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.
- RX: RX pin of the receiving UART. It is connected to the TX pin of the peer UART.
- 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.
- 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.
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.
## Available APIs<a name="section1928742202715"></a>
- The UART interface defines a set of common functions for operating a UART port, including obtaining and releasing device handles, reading and writing data of a specified length, and obtaining and setting the baud rate, as well as the device attributes.
The 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.
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p371073520422"><aname="p371073520422"></a><aname="p371073520422"></a>Releases a specified UART device handle.</p>
</td>
</tr>
### How to Use
<trid="row34145016535"><tdclass="cellrowborder"rowspan="2"valign="top"width="26.619999999999997%"headers="mcps1.2.4.1.1 "><pid="p229610227124"><aname="p229610227124"></a><aname="p229610227124"></a>Reading and writing data</p>
<tdclass="cellrowborder"valign="top"width="42.01%"headers="mcps1.2.4.1.3 "><pid="p16297172213125"><aname="p16297172213125"></a><aname="p16297172213125"></a>Reads data of a specified length from a UART device.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p15297162215122"><aname="p15297162215122"></a><aname="p15297162215122"></a>Writes data of a specified length into a UART device.</p>
</td>
</tr>
<trid="row8687115843715"><tdclass="cellrowborder"rowspan="2"valign="top"width="26.619999999999997%"headers="mcps1.2.4.1.1 "><pid="p196317143813"><aname="p196317143813"></a><aname="p196317143813"></a>Obtaining and setting the baud rate</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p152971322111219"><aname="p152971322111219"></a><aname="p152971322111219"></a>Sets the UART device attributes.</p>
</td>
</tr>
<trid="row14614115403"><tdclass="cellrowborder"valign="top"width="26.619999999999997%"headers="mcps1.2.4.1.1 "><pid="p1746281144010"><aname="p1746281144010"></a><aname="p1746281144010"></a>Setting the transmission mode</p>
### 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.
### Opening a UART Device Handle
DevHandle UartOpen\(uint32\_t port\);
Before performing UART communication, call **UartOpen** to obtain a UART device handle. This function returns the pointer to the UART device handle with the specified port number.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1322217518318"><aname="p1322217518318"></a><aname="p1322217518318"></a>UART port number.</p>
| NULL | The operation failed.|
</td>
| Device handle| The operation is successful. The obtained UART device handle is returned.|
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p5222351203112"><aname="p5222351203112"></a><aname="p5222351203112"></a>Failed to obtain the UART device handle.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p163919537322"><aname="p163919537322"></a><aname="p163919537322"></a>Baud rate of the UART to set.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p14391653193210"><aname="p14391653193210"></a><aname="p14391653193210"></a>Succeeded in setting the UART baud rate.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p639185318322"><aname="p639185318322"></a><aname="p639185318322"></a>Failed to set the UART baud rate.</p>
</td>
</tr>
</tbody>
</table>
The following example shows how to set the UART baud rate to **9600**:
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p93926536328"><aname="p93926536328"></a><aname="p93926536328"></a>Pointer to the UART baud rate.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p8393165383218"><aname="p8393165383218"></a><aname="p8393165383218"></a>Succeeded in obtaining the UART baud rate.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1539325393211"><aname="p1539325393211"></a><aname="p1539325393211"></a>Failed to obtain the UART baud rate.</p>
</td>
</tr>
</tbody>
</table>
The following example shows how to obtain the UART baud rate:
### Obtaining the UART Baud Rate
Call **UartGetBaud()** to obtain the UART baud rate.
<tdclass="cellrowborder"valign="top"width="50.019999999999996%"headers="mcps1.2.3.1.2 "><pid="p5530133314343"><aname="p5530133314343"></a><aname="p5530133314343"></a>Pointer to the UART device attributes to set.</p>
<tdclass="cellrowborder"valign="top"width="50.019999999999996%"headers="mcps1.2.3.1.2 "><pid="p1453023323419"><aname="p1453023323419"></a><aname="p1453023323419"></a>Succeeded in setting the UART device attributes.</p>
<tdclass="cellrowborder"valign="top"width="50.019999999999996%"headers="mcps1.2.3.1.2 "><pid="p1953118334347"><aname="p1953118334347"></a><aname="p1953118334347"></a>Failed to set the UART device attributes.</p>
</td>
</tr>
</tbody>
</table>
The following example shows how to set the UART device attributes:
### Setting UART Device Attributes
Call **UartSetAttribute()** to set UART device attributes.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p14531633133416"><aname="p14531633133416"></a><aname="p14531633133416"></a>Pointer to the UART device attributes.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p5532143319341"><aname="p5532143319341"></a><aname="p5532143319341"></a>Succeeded in obtaining the UART device attributes.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p175321933163410"><aname="p175321933163410"></a><aname="p175321933163410"></a>Failed to obtain the UART device attributes.</p>
</td>
</tr>
</tbody>
</table>
The following example shows how to obtain the UART device attributes:
### Obtaining UART Device Attributes
Call **UartGetAttribute()** to obtain the current UART device attributes.
<tdclass="cellrowborder"valign="top"width="50.019999999999996%"headers="mcps1.2.3.1.2 "><pid="p1219012264318"><aname="p1219012264318"></a><aname="p1219012264318"></a>Succeeded in setting the UART transmission mode.</p>
<tdclass="cellrowborder"valign="top"width="50.019999999999996%"headers="mcps1.2.3.1.2 "><pid="p131906262311"><aname="p131906262311"></a><aname="p131906262311"></a>Failed to set the UART transmission mode.</p>
</td>
</tr>
</tbody>
</table>
The following example shows how to set the transmission mode to **UART\_MODE\_RD\_BLOCK**:
### Setting the UART Transmission Mode
Call **UartSetTransMode()** to set the UART transmission mode.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p17782171120366"><aname="p17782171120366"></a><aname="p17782171120366"></a>Pointer to the data to write.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p17782161110366"><aname="p17782161110366"></a><aname="p17782161110366"></a>Length of the data to write.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p11782191103610"><aname="p11782191103610"></a><aname="p11782191103610"></a>Succeeded in writing data into the UART device.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p9782151110366"><aname="p9782151110366"></a><aname="p9782151110366"></a>Failed to write data into the UART device.</p>
</td>
</tr>
</tbody>
</table>
The following example shows how to write data of a specified length into the UART device:
### Writing Data to a UART Device
Call **UartWrite()** to write data of the specified length to a UART device.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p923417175378"><aname="p923417175378"></a><aname="p923417175378"></a>Pointer to the buffer for receiving the data.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p182341817153717"><aname="p182341817153717"></a><aname="p182341817153717"></a>Length of the data to read.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p7234171783718"><aname="p7234171783718"></a><aname="p7234171783718"></a>Length of the data read from the UART device.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p32349178378"><aname="p32349178378"></a><aname="p32349178378"></a>Failed to read data from the UART device.</p>
</td>
</tr>
</tbody>
</table>
The following example shows how to read data of a specified length from the UART device:
### Reading Data from a UART Device
Call **UartRead()** to read data of the specified length from a UART device.
>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 **0** is returned, no valid data can be read from the UART device. A value greater than **0** indicates the length of the data read from the UART device. The data length must be less than or equal to the value of **size** and cannot exceed the maximum length of the data to read at a time specified by the UART controller in use.
### Destroying the UART Device Handle<a name="section1477410521406"></a>
After the UART communication, destroy the UART device handle by calling the following function:
### Closing a UART Device Handle
void UartClose\(DevHandle handle\);
Call **UartClose()** to close a UART device handle.
This function will release the resources previously obtained.
```
void UartClose(DevHandle handle);
```
**Table 10** Description of UartClose
This function releases the resources requested by **UartOpen**.
The following example shows how to destroy the UART device handle:
| Parameter| Description|
| -------- | -------- |
| handle | UART device handle to close.|
Example: Close a UART device handle.
```
```
UartClose(handle); /* Destroy the UART device handle. */
UartClose(handle); /* Close the UART device handle. */
```
```
## Usage Example<a name="section35404241311"></a>
The following is a usage example of a UART device, including how to obtain the UART device handle, set the baud rate, device attributes, and transmission mode, read data from or write data into the UART device, and then destroy the UART device handle.
## Example
The following example shows how to open a UART device handle, set the baud rate, device attributes, and transmission mode, read data from or write data into the UART device, and then close the UART device handle.
```
```
#include "hdf_log.h"
#include "hdf_log.h"
#include "uart_if.h"
#include "uart_if.h"
...
@@ -608,16 +371,16 @@ void UartTestSample(void)
...
@@ -608,16 +371,16 @@ void UartTestSample(void)
uint8_t wbuff[5] = { 1, 2, 3, 4, 5 };
uint8_t wbuff[5] = { 1, 2, 3, 4, 5 };
uint8_t rbuff[5] = { 0 };
uint8_t rbuff[5] = { 0 };
struct UartAttribute attribute;
struct UartAttribute attribute;
attribute.dataBits = UART_ATTR_DATABIT_7; /* Set the number of data bits to 7. */
attribute.dataBits = UART_ATTR_DATABIT_7; /* Enable 7 bits to be transferred each time. */
attribute.parity = UART_ATTR_PARITY_NONE; /* Set the parity bit to no parity. */
| Init | **host**: structure pointer to the UART controller at the core layer.| –| HDF_STATUS| Initializes a UART device.|
| Init | **host**: structure pointer to the UART controller at the core layer.| –| HDF_STATUS| Initializes a UART device.|
| Deinit | **host**: structure pointer to the UART controller at the core layer.| –| HDF_STATUS| Deinitializes a UART device.|
| Deinit | **host**: structure pointer to the UART controller at the core layer.| –| HDF_STATUS| Deinitializes a UART device.|
| Read | **host**: structure pointer to the UART controller at the core layer.<br>**size**: data size, which is of the uint32_t type.| **data**: pointer to the output data. The value is of the uint8_t type.| HDF_STATUS| Reads data.|
| Read | **host**: structure pointer to the UART controller at the core layer.<br>**size**: data size, which is of the uint32_t type.| **data**: pointer to the data read. The value is of the uint8_t type. | HDF_STATUS| Reads data.|
| Write | **host**: structure pointer to the UART controller at the core layer.<br>**data**: pointer to the input data. The value is of the uint8_t type.<br>**size**: data size, which is of the uint32_t type.| –| HDF_STATUS| Writes data.|
| Write | **host**: structure pointer to the UART controller at the core layer.<br>**data**: pointer to the data to write. The value is of the uint8_t type.<br>**size**: data size, which is of the uint32_t type. | –| HDF_STATUS| Writes data.|
| SetBaud | **host**: structure pointer to the UART controller at the core layer.<br>**baudRate**: pointer to the input baud rate. The value is of the uint32_t type. | –| HDF_STATUS| Sets the baud rate.|
| SetBaud | **host**: structure pointer to the UART controller at the core layer.<br>**baudRate**: pointer to the baud rate to set. The value is of the uint32_t type. | –| HDF_STATUS| Sets the baud rate.|
| GetBaud | **host**: structure pointer to the UART controller at the core layer.| **baudRate**: pointer to the output baud rate. The value is of the uint32_t type.| HDF_STATUS| Obtains the current baud rate.|
| GetBaud | **host**: structure pointer to the UART controller at the core layer.| **baudRate**: pointer to the baud rate obtained. The value is of the uint32_t type. | HDF_STATUS| Obtains the current baud rate.|
| GetAttribute | **host**: structure pointer to the UART controller at the core layer.| **attribute**: structure pointer to the UART attributes. For details, see **UartAttribute** in **uart_if.h**.| HDF_STATUS| Obtains UART attributes.|
| GetAttribute | **host**: structure pointer to the UART controller at the core layer.| **attribute**: structure pointer to the attribute obtained. For details, see **UartAttribute** in **uart_if.h**. | HDF_STATUS| Obtains UART attributes.|
| SetAttribute | **host**: structure pointer to the UART controller at the core layer.<br>**attribute**: structure pointer to the UART attributes to set.| –| HDF_STATUS| Sets UART attributes.|
| SetAttribute | **host**: structure pointer to the UART controller at the core layer.<br>**attribute**: structure pointer to the attribute to set. | –| HDF_STATUS| Sets UART attributes.|
| SetTransMode | **host**: structure pointer to the UART controller at the core layer.<br>**mode**: transfer mode to set. For details, see **UartTransMode** in **uart_if.h**.| –| HDF_STATUS| Sets the UART transfer mode.|
| SetTransMode | **host**: structure pointer to the UART controller at the core layer.<br>**mode**: transfer mode to set. For details, see **UartTransMode** in **uart_if.h**.| –| HDF_STATUS| Sets the UART transfer mode.|
| PollEvent | **host**: structure pointer to the UART controller at the core layer.<br>**filep**: void pointer to a file.<br>**table**: void pointer to poll_table.| –| HDF_STATUS| Polls for pending events.|
| PollEvent | **host**: structure pointer to the UART controller at the core layer.<br>**filep**: void pointer to a file.<br>**table**: void pointer to poll_table.| –| HDF_STATUS| Polls for pending events.|
## How to Develop
## How to Develop
...
@@ -64,7 +64,8 @@ The UART module adaptation involves the following steps:
...
@@ -64,7 +64,8 @@ The UART module adaptation involves the following steps:
> For details about the functions in **UartHostMethod**, see [Available APIs](#available-apis).
> For details about the functions in **UartHostMethod**, see [Available APIs](#available-apis).
4. Debug the driver.<br>
4. Debug the driver.
(Optional) For new drivers, verify the basic functions, such as the UART status control and response to interrupts.
(Optional) For new drivers, verify the basic functions, such as the UART status control and response to interrupts.
...
@@ -72,11 +73,16 @@ The UART module adaptation involves the following steps:
...
@@ -72,11 +73,16 @@ The UART module adaptation involves the following steps:
The following uses **uart_hi35xx.c** as an example to present the information required for implementing device functions.
The following uses **uart_hi35xx.c** as an example to present the information required for implementing device functions.
1. Instantiate the driver entry.<br/>The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
1. Instantiate the driver entry.
The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**.
In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
UART driver entry example:
UART driver entry example:
```
```
struct HdfDriverEntry g_hdfUartDevice = {
struct HdfDriverEntry g_hdfUartDevice = {
.moduleVersion = 1,
.moduleVersion = 1,
...
@@ -89,11 +95,15 @@ The following uses **uart_hi35xx.c** as an example to present the information re
...
@@ -89,11 +95,15 @@ The following uses **uart_hi35xx.c** as an example to present the information re
HDF_INIT(g_hdfUartDevice);
HDF_INIT(g_hdfUartDevice);
```
```
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **uart_config.hcs** file.<br> The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **UartHost** members at the core layer.
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **uart_config.hcs** file.
In this example, there is only one UART controller. If there are multiple UART controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **uart_config** file for each controller.
-**device_info.hcs** configuration example
The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **UartHost** members at the core layer.
In this example, there is only one UART controller. If there are multiple UART controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **uart_config** file for each controller.
-**device_info.hcs** configuration example:
```
```
root {
root {
device_info {
device_info {
...
@@ -103,11 +113,11 @@ The following uses **uart_hi35xx.c** as an example to present the information re
...
@@ -103,11 +113,11 @@ The following uses **uart_hi35xx.c** as an example to present the information re
priority = 50;
priority = 50;
device_uart :: device {
device_uart :: device {
device0 :: deviceNode {
device0 :: deviceNode {
policy = 1; // The driver publishes services only for kernel-mode processes.
policy = 1; // The driver publishes services only for kernel-mode processes.
priority = 40; // Driver startup priority.
priority = 40; // Driver startup priority.
permission = 0644; // Permission for the driver to create a device node.
permission = 0644; // Permission for the driver to create a device node.
moduleName = "HDF_PLATFORM_UART"; // Driver name, which must be the same as moduleName in the HdfDriverEntry structure.
moduleName = "HDF_PLATFORM_UART"; // Driver name, which must be the same as moduleName in the HdfDriverEntry structure.
serviceName = "HDF_PLATFORM_UART_0";// Unique name of the service published by the driver. The name is in the HDF_PLATFORM_UART_X format. X indicates the UART controller number.
serviceName = "HDF_PLATFORM_UART_0";// Unique name of the service published by the driver. The name is in the HDF_PLATFORM_UART_X format. X indicates the UART controller number.
deviceMatchAttr = "hisilicon_hi35xx_uart_0"; // 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.
deviceMatchAttr = "hisilicon_hi35xx_uart_0"; // 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.
}
}
device1 :: deviceNode {
device1 :: deviceNode {
...
@@ -127,20 +137,20 @@ The following uses **uart_hi35xx.c** as an example to present the information re
...
@@ -127,20 +137,20 @@ The following uses **uart_hi35xx.c** as an example to present the information re
-**uart_config.hcs** configuration example
-**uart_config.hcs** configuration example
```
```
root {
root {
platform {
platform {
template uart_controller { // Template configuration. In the template, you can configure the common parameters shared by device nodes.
template uart_controller { // Template configuration. In the template, you can configure the common parameters shared by device nodes.
match_attr = "";
match_attr = "";
num = 0; // (Mandatory) Device number
num = 0; // (Mandatory) Device number.
baudrate = 115200; // (Mandatory) Baud rate. Set the value based on service requirements.
baudrate = 115200; // (Mandatory) Baud rate. Set the value based on service requirements.
fifoRxEn = 1; // (Mandatory) Enable FIFOs to be received.
fifoRxEn = 1; // (Mandatory) Enable FIFOs to be received.
fifoTxEn = 1; // (Mandatory) Enable FIFOs to be transferred.
fifoTxEn = 1; // (Mandatory) Enable FIFOs to be transferred.
flags = 4; // (Mandatory) Flag signal.
flags = 4; // (Mandatory) Flag signal.
regPbase = 0x120a0000; // (Mandatory) Used for address mapping.
regPbase = 0x120a0000; // (Mandatory) Used for address mapping.
interrupt = 38; // (Mandatory) Interrupt number.
interrupt = 38; // (Mandatory) Interrupt number.
iomemCount = 0x48; // (Mandatory) Used for address mapping.
iomemCount = 0x48; // (Mandatory) Used for address mapping.
}
}
controller_0x120a0000 :: uart_controller {
controller_0x120a0000 :: uart_controller {
match_attr = "hisilicon_hi35xx_uart_0";// (Mandatory) The value must be the same as that of deviceMatchAttr of the corresponding device in device_info.hcs.
match_attr = "hisilicon_hi35xx_uart_0";// (Mandatory) The value must be the same as that of deviceMatchAttr of the corresponding device in device_info.hcs.
...
@@ -159,43 +169,44 @@ The following uses **uart_hi35xx.c** as an example to present the information re
...
@@ -159,43 +169,44 @@ The following uses **uart_hi35xx.c** as an example to present the information re
```
```
3. Initialize the **UartHost** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **UartHostMethod** in **UartHost** (so that the underlying driver functions can be called).
3. Initialize the **UartHost** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **UartHostMethod** in **UartHost** (so that the underlying driver functions can be called).
- Defining a custom structure
- Defining a custom structure
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **uart_config.hcs** file to initialize the members in the custom structure and passes important parameters, such as the device number, to the **UartHost** object at the core layer.
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **uart_config.hcs** file to initialize the members in the custom structure and passes important parameters, such as the device number, to the **UartHost** object at the core layer.
```
```
struct UartPl011Port { // Interface structure
struct UartPl011Port { // Interface structure
int32_t enable;
int32_t enable;
unsigned long physBase; // Physical address
unsigned long physBase; // Physical address
uint32_t irqNum; // Interrupt number
uint32_t irqNum; // Interrupt number
uint32_t defaultBaudrate;// Default baud rate
uint32_t defaultBaudrate;// Default baud rate
uint32_t flags; // Flags related to the following three macros.
uint32_t flags; // Flags related to the following three macros
#define PL011_FLG_IRQ_REQUESTED (1 << 0)
#define PL011_FLG_IRQ_REQUESTED (1 << 0)
#define PL011_FLG_DMA_RX_REQUESTED (1 << 1)
#define PL011_FLG_DMA_RX_REQUESTED (1 << 1)
#define PL011_FLG_DMA_TX_REQUESTED (1 << 2)
#define PL011_FLG_DMA_TX_REQUESTED (1 << 2)
struct UartDmaTransfer *rxUdt; // DMA transfer
struct UartDmaTransfer *rxUdt; // DMA transfer
struct UartDriverData *udd; // The data structure is defined as follows:
struct UartDriverData *udd; // The data structure is defined as follows:
};
};
struct UartDriverData { // Structure related to data transfer
struct UartDriverData { // Structure related to data transfer
uint32_t num;
uint32_t num;
uint32_t baudrate; // Baud rate (configurable)
uint32_t baudrate; // Baud rate (configurable)
struct UartAttribute attr; // Attributes, such as the data bit and stop bit, related to data transfer
struct UartAttribute attr; // Attributes, such as the data bit and stop bit, related to data transfer.
wait_queue_head_t wait; // Queuing signal related to conditional variables
wait_queue_head_t wait; // Queuing signal related to conditional variables
int32_t count; // Data count
int32_t count; // Data count
int32_t state; // UART controller state
int32_t state; // UART controller state
#define UART_STATE_NOT_OPENED 0
#define UART_STATE_NOT_OPENED 0
#define UART_STATE_OPENING 1
#define UART_STATE_OPENING 1
#define UART_STATE_USEABLE 2
#define UART_STATE_USEABLE 2
#define UART_STATE_SUSPENDED 3
#define UART_STATE_SUSPENDED 3
uint32_t flags; // Status flags
uint32_t flags; // Status flags
#define UART_FLG_DMA_RX (1 << 0)
#define UART_FLG_DMA_RX (1 << 0)
#define UART_FLG_DMA_TX (1 << 1)
#define UART_FLG_DMA_TX (1 << 1)
#define UART_FLG_RD_BLOCK (1 << 2)
#define UART_FLG_RD_BLOCK (1 << 2)
RecvNotify recv; // Pointer to the function that receives serial port data
RecvNotify recv; // Pointer to the function that receives serial port data.
struct UartOps *ops; // Custom function pointer structure. For details, see device/hisilicon/drivers/uart/uart_pl011.c.
struct UartOps *ops; // Custom function pointer structure. For details, see device/hisilicon/drivers/uart/uart_pl011.c.
void *private; // It stores the pointer to the start address of UartPl011Port for easy invocation.
void *private; // It stores the pointer to the start address of UartPl011Port for easy invocation.
};
};
// UartHost is the controller structure at the core layer. The Init function assigns values to the members of UartHost.
// UartHost is the controller structure at the core layer. The Init function assigns values to the members of UartHost.
...
@@ -205,12 +216,13 @@ The following uses **uart_hi35xx.c** as an example to present the information re
...
@@ -205,12 +216,13 @@ The following uses **uart_hi35xx.c** as an example to present the information re
uint32_t num;
uint32_t num;
OsalAtomic atom;
OsalAtomic atom;
void *priv; // It stores the pointer to the start address of the vendor's custom structure for easy invocation.
void *priv; // It stores the pointer to the start address of the vendor's custom structure for easy invocation.
struct UartHostMethod *method; // Hook at the core layer. You need to implement and instantiate its member functions.
struct UartHostMethod *method; // Hook at the core layer. You need to implement and instantiate its member functions.
};
};
```
```
- Instantiating **UartHostMethod** in **UartHost** (other members are initialized by **Bind**)
- Instantiating **UartHostMethod** in **UartHost** (other members are initialized by **Bind**)
```
```
// Example in uart_hi35xx.c: instantiate the hook.
// Example in uart_hi35xx.c: instantiate the hook.
struct UartHostMethod g_uartHostMethod = {
struct UartHostMethod g_uartHostMethod = {
...
@@ -229,30 +241,30 @@ The following uses **uart_hi35xx.c** as an example to present the information re
...
@@ -229,30 +241,30 @@ The following uses **uart_hi35xx.c** as an example to present the information re
-**Bind** function
-**Bind** function
Input parameter:
**Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
Return value:
**Return value**:
HDF_STATUS<br/>The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
**HDF_STATUS**<br/>The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
@@ -303,7 +315,7 @@ The following uses **uart_hi35xx.c** as an example to present the information re
...
@@ -303,7 +315,7 @@ The following uses **uart_hi35xx.c** as an example to present the information re
...
...
ret = Hi35xxAttach(host, device); // Initialize the UartHost object.
ret = Hi35xxAttach(host, device); // Initialize the UartHost object.
...
...
host->method = &g_uartHostMethod; // Hook the UartHostMethod instance.
host->method = &g_uartHostMethod; // Attach the UartHostMethod instance.
return ret;
return ret;
}
}
// Initialize UartHost.
// Initialize UartHost.
...
@@ -351,30 +363,34 @@ The following uses **uart_hi35xx.c** as an example to present the information re
...
@@ -351,30 +363,34 @@ The following uses **uart_hi35xx.c** as an example to present the information re
```
```
-**Release** function
-**Release** function
Input parameter:
**Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
Return value:
**Return value**:
No value is returned.
No value is returned.
Function description:
**Function description**:
Releases the memory and deletes the controller. This function assigns values to the **Release** API in the driver entry structure. When the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. All forced conversion operations for obtaining the corresponding object can be successful only when **Init()** has the corresponding value assignment operations.
Releases the memory and deletes the controller. This function assigns values to the **Release** API in the driver entry structure. When the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
> All forced conversion operations for obtaining the corresponding object can be successful only when **Init()** has the corresponding value assignment operations.
host = UartHostFromDevice(device);// Forcibly convert HdfDeviceObject to UartHost by using service. For details about the value assignment, see the Bind function.
host = UartHostFromDevice(device);// Forcibly convert HdfDeviceObject to UartHost by using service. For details about the value assignment, see the Bind function.