未验证 提交 2b70f792 编写于 作者: O openharmony_ci 提交者: Gitee

!4012 【OpenHarmony开源贡献者计划2022】pin, regulator英文相关格式及表达问题

Merge pull request !4012 from king_he/dirver-2a
......@@ -5,12 +5,12 @@
### Pin<a name="section2"></a>
- The pin, also called pin controller, manages pin resources of system on a chip (SoC) vendors and provides the pin multiplexing function.
- The pin module defines a set of common methods for managing pins, including:
The pin module, also called pin controller, manages pin resources of system on a chip (SoC) vendors and provides the pin multiplexing function.
The module defines a set of common methods for managing pins, including:
- Obtaining or releasing the pin description handle: The kernel compares the pin name passed in with the pin names of each controller in the linked list. If a match is found, a pin description handle is obtained. After the operation on the pin is complete, the pin description handle will be released.
- Setting or obtaining the pull type of a pin: The pull type can be pull-up, pull-down, or floating.
- Setting or obtaining the pull strength of a pin: You can set the pull strength as required.
- Setting or obtaining the functions of a pin to implement pin multiplexing
- Setting or obtaining the pull type of a pin: The pull type can be pull-up, pull-down, or floating.
- Setting or obtaining the pull strength of a pin: You can set the pull strength as required.
- Setting or obtaining the functions of a pin to implement pin multiplexing
### Basic Concepts<a name="section3"></a>
Pin, as a software concept, provides APIs for uniformly managing the pins from different SoC vendors, providing the pin multiplexing function, and configuring the electrical features of pins.
......@@ -52,7 +52,7 @@ The table below describes the APIs of the pin module. For more details, see API
**Table 1** Pin driver APIs
<a name="table1"></a>
| **API** | **Description** |
| **API** | **Description** |
| ------------------------------------------------------------ | ---------------- |
| DevHandle PinGet(const char *pinName); | Obtains the pin description handle.|
| void PinPut(DevHandle handle); | Releases the pin description handle.|
......@@ -88,7 +88,7 @@ DevHandle PinGet(const char *pinName);
| Parameter | Description |
| ---------- | ----------------------- |
| pinName | Pointer to the pin name. |
| **Return Value**| **Description** |
| **Return Value**| **Description** |
| NULL | Failed to obtain the pin description handle.|
| handle | Pin description handle obtained. |
......@@ -120,7 +120,7 @@ int32_t PinSetPull(DevHandle handle, enum PinPullType pullType);
| ---------- | ----------------------- |
| handle | Pin description handle. |
| pullType | Pull type to set. |
| **Return Value**| **Description** |
| **Return Value**| **Description** |
| 0 | The operation is successful.|
| Negative value | The operation fails.|
......@@ -154,7 +154,7 @@ int32_t PinGetPull(DevHandle handle, enum PinPullType *pullType);
| ---------- | ------------------------- |
| handle | Pin description handle. |
| pullType | Pointer to the pull type obtained.|
| **Return Value**| **Description** |
| **Return Value**| **Description** |
| 0 | The operation is successful. |
| Negative value | The operation fails. |
......@@ -187,7 +187,7 @@ int32_t PinSetStrength(DevHandle handle, uint32_t strength);
| ---------- | ----------------------- |
| handle | Pin description handle. |
| strength | Pull strength to set. |
| **Return Value**| **Description** |
| **Return Value**| **Description** |
| 0 | The operation is successful.|
| Negative value | The operation fails.|
......@@ -221,7 +221,7 @@ int32_t PinGetStrength(DevHandle handle, uint32_t *strength);
| ---------- | ------------------------- |
| handle | Pin description handle. |
| strength | Pointer to the pull strength obtained.|
| **Return Value**| **Description** |
| **Return Value**| **Description** |
| 0 | The operation is successful. |
| Negative value | The operation fails. |
......@@ -256,7 +256,7 @@ int32_t PinSetFunc(DevHandle handle, const char *funcName);
| ---------- | ------------------- |
| handle | Pin description handle. |
| funcName | Pointer to the pin function to set. |
| **Return Value**| **Description** |
| **Return Value**| **Description** |
| 0 | The operation is successful.|
| Negative value | The operation fails.|
......@@ -289,7 +289,7 @@ int32_t PinGetFunc(DevHandle handle, const char **funcName);
| ---------- | --------------------- |
| handle | Pin description handle. |
| funcName | Pointer to the function name obtained.|
| **Return Value**| **Description** |
| **Return Value**| **Description** |
| 0 | The operation is successful. |
| Negative value | The operation fails. |
......@@ -406,4 +406,4 @@ ERR:
/* Release the pin description handle. */
PinPut(handle);
return ret;
}
}
\ No newline at end of file
......@@ -19,7 +19,7 @@ struct PwmMethod {
};
```
**Table 1** Callbacks for the members in the PwmMethod structure
**Table 1** Callbacks for the members in the PwmMethod structure
<a name="table11173154124311"></a>
<table><thead align="left"><tr id="row2173441164311"><th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.1"><p id="p17174144144310"><a name="p17174144144310"></a><a name="p17174144144310"></a>Callback</p>
......@@ -68,33 +68,30 @@ struct PwmMethod {
The PWM module adaptation involves the following steps:
1. Instantiate the driver entry.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
2. Configure attribute files.
- Add the **deviceNode** information to the **device\_info.hcs** file.
- \(Optional\) Add the **pwm\_config.hcs** file.
- Add the **deviceNode** information to the **device\_info.hcs** file.
- \(Optional\) Add the **pwm\_config.hcs** file.
3. Instantiate the PWM controller object.
- Initialize **PwmDev**.
- Instantiate **PwmMethod** in the **PwmDev** object.
- Initialize **PwmDev**.
- Instantiate **PwmMethod** in the **PwmDev** object.
>![](../public_sys-resources/icon-note.gif) **NOTE**
For details, see [Available APIs](#available-apis).
>For details, see [Available APIs](#available-apis).
4. Debug the driver.
- \(Optional\) For new drivers, verify the basic functions, such as the PWM control status and response to interrupts.
4. \(Optional\) Debug the driver.
For new drivers, verify the basic functions, such as the PWM control status and response to interrupts.
## Development Example<a name="section1883877829164144"></a>
The following uses **pwm\_hi35xx.c** as an example to present the contents that need to be provided by the vendor to implement device functions.
The following uses **pwm\_hi35xx.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. 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, 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 exits.
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 exits.
- PWM driver entry reference
......@@ -110,8 +107,8 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
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 corresponding device attributes to the **pwm\_config** file.
- **device\_info.hcs** configuration reference
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 corresponding device attributes to the **pwm\_config** file.
- **device\_info.hcs** configuration reference
```
root {
......@@ -143,7 +140,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
}
```
- **pwm\_config.hcs** configuration reference
- **pwm\_config.hcs** configuration reference
```
root {
......@@ -168,10 +165,10 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
}
```
3. Initialize the **PwmDev** object at the core layer, including initializing the vendor custom structure \(transferring parameters and data\), instantiating **PwmMethod** \(used to call underlying functions of the driver\) in **PwmDev**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\).
3. Initialize the **PwmDev** object at the core layer, including initializing the vendor custom structure \(transferring parameters and data\), instantiating **PwmMethod** \(used to call underlying functions of the driver\) in **PwmDev**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\).
- Custom structure reference
To the driver, the custom structure carries parameters and data. The values in the **pwm\_config.hcs** file are read by HDF, and the structure members are initialized through **DeviceResourceIface**. Some important values, such as the device number, are also passed to the objects at the core layer.
To the driver, the custom structure carries parameters and data. The values in the **pwm\_config.hcs** file are read by HDF, and the structure members are initialized through **DeviceResourceIface**. Some important values, such as the device number, are also passed to the objects at the core layer.
```
struct HiPwm {
......@@ -208,7 +205,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
};
```
- Instantiate the callback function structure **PwmMethod** in **PwmDev**. Other members are initialized by using the **Init** function.
- Instantiate the callback function structure **PwmMethod** in **PwmDev**. Other members are initialized by using the **Init** function.
```
// Example in pwm_hi35xx.c: fill the hook function
......@@ -221,11 +218,11 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
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.\)
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.\)
<a name="table1057438215164144"></a>
<table><thead align="left"><tr id="row31521027164144"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="entry1990732428164144p0"><a name="entry1990732428164144p0"></a><a name="entry1990732428164144p0"></a>Status (Value)</p>
......@@ -269,7 +266,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
Function description:
Initializes the custom structure object and **PwmDev**, and calls the **PwmDeviceAdd** function at the core layer.
Initializes the custom structure object and **PwmDev**, and calls the **PwmDeviceAdd** function at the core layer.
```
// The bind function is empty. It can be combined with the init function or implement related operations based on the vendor's requirements.
......@@ -320,7 +317,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
......@@ -328,7 +325,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
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.
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.
```
static void HdfPwmRelease(struct HdfDeviceObject *obj)
......@@ -340,7 +337,4 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
PwmDeviceRemove(obj, &(hp->dev));// (Mandatory) Call the core layer functions to release PwmDev devices and services. A forced conversion from HiPwm to PwmDev is involved in the process.
HiPwmRemove(hp); //Release HiPwm.
}
```
```
\ No newline at end of file
......@@ -266,13 +266,13 @@ The regulator module adaptation procedure is as follows:
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration.
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** (The following table lists some states. For more details, see **HDF\_STATUS** in **/drivers/framework/include/utils/hdf\_base.h**.)
**Table 2** HDF\_STATUS
**Table 2** HDF\_STATUS
| State | Description |
| ---------------------- | -------------- |
......@@ -319,11 +319,11 @@ The regulator module adaptation procedure is as follows:
}
```
- **Release** function
- **Release** function
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration.
Return value:
......@@ -341,8 +341,6 @@ The regulator module adaptation procedure is as follows:
}
```
4. Debug the driver.
4. (Optional) Debug the driver.
(Optional) Verify the basic functions of the new driver, for example, whether the test cases are successful after the driver is loaded.
Verify the basic functions of the new driver, for example, whether the test cases are successful after the driver is loaded.
\ No newline at end of file
......@@ -6,7 +6,7 @@ The real-time clock \(RTC\) driver provides precise real time for the operating
## Available APIs<a name="section20331159102519"></a>
**Table 1** APIs provided by the RTC driver
**Table 1** APIs provided by the RTC driver
<a name="table1731550155318"></a>
<table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" valign="top" width="21.902190219021904%" id="mcps1.2.4.1.1"><p id="p641050105320"><a name="p641050105320"></a><a name="p641050105320"></a><strong id="b17744818255"><a name="b17744818255"></a><a name="b17744818255"></a>Capability</strong></p>
......@@ -95,7 +95,7 @@ The real-time clock \(RTC\) driver provides precise real time for the operating
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>All functions provided in this document can be called only in kernel mode.
## Usage Guidelines<a name="section20636145604113"></a>
......@@ -106,19 +106,19 @@ During the OS startup, the HDF loads the RTC driver based on the configuration f
[Figure 1](#fig1610020107333) illustrates the process of using an RTC device.
**Figure 1** Process of using an RTC device<a name="fig1610020107333"></a>
**Figure 1** Process of using an RTC device<a name="fig1610020107333"></a>
![](figures/process-of-using-an-rtc-device.png "process-of-using-an-rtc-device")
### Creating an RTC Device Handle<a name="section1131212144310"></a>
After the RTC driver is loaded, you can use the API provided by the HDF and call APIs of the RTC driver.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>Currently, only one RTC device is supported in the OS.
DevHandle RtcOpen\(void\);
**Table 2** Description of RtcOpen
**Table 2** Description of RtcOpen
<a name="table1380712985611"></a>
<table><tbody><tr id="row580722985616"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1280722911565"><a name="p1280722911565"></a><a name="p1280722911565"></a><strong id="b748651620573"><a name="b748651620573"></a><a name="b748651620573"></a>Parameter</strong></p>
......@@ -165,7 +165,7 @@ You can call the following function to release the RTC device handle, thereby re
void RtcClose\(DevHandle handle\);
**Table 3** Description of RtcClose
**Table 3** Description of RtcClose
<a name="table37525421510"></a>
<table><tbody><tr id="row10752134216114"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1075217421019"><a name="p1075217421019"></a><a name="p1075217421019"></a><strong id="b229461765710"><a name="b229461765710"></a><a name="b229461765710"></a>Parameter</strong></p>
......@@ -188,11 +188,11 @@ RtcClose(handle);
### Registering RtcAlarmCallback<a name="section14839440184320"></a>
After the OS is started, call the following function to register **RtcAlarmCallback**, which will be invoked when an alarm is generated at the specified time:
After the OS is started, call the following function to register **RtcAlarmCallback**, which will be invoked when an alarm is generated at the specified time:
int32\_t RtcRegisterAlarmCallback\(DevHandle handle, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb\);
**Table 4** Description of RtcRegisterAlarmCallback
**Table 4** Description of RtcRegisterAlarmCallback
<a name="table7603619123820"></a>
<table><thead align="left"><tr id="row1060351914386"><th class="cellrowborder" valign="top" width="21.36%" id="mcps1.2.3.1.1"><p id="p14603181917382"><a name="p14603181917382"></a><a name="p14603181917382"></a><strong id="b4295161718571"><a name="b4295161718571"></a><a name="b4295161718571"></a>Parameter</strong></p>
......@@ -234,7 +234,7 @@ int32\_t RtcRegisterAlarmCallback\(DevHandle handle, enum RtcAlarmIndex alarmInd
</tbody>
</table>
The following is an example of registering **RtcAlarmCallback** for processing alarm **RTC\_ALARM\_INDEX\_A**:
The following is an example of registering **RtcAlarmCallback** for processing alarm **RTC\_ALARM\_INDEX\_A**:
```
/* Register an RTC alarm callback. */
......@@ -265,7 +265,7 @@ Call the following function to read time information from the RTC driver, includ
int32\_t RtcReadTime\(DevHandle handle, struct RtcTime \*time\);
**Table 5** Description of RtcReadTime
**Table 5** Description of RtcReadTime
<a name="table1018490043"></a>
<table><tbody><tr id="row31848013417"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b10296717125710"><a name="b10296717125710"></a><a name="b10296717125710"></a>Parameter</strong></p>
......@@ -318,7 +318,7 @@ Call the following function to set the RTC time:
int32\_t RtcWriteTime\(DevHandle handle, struct RtcTime \*time\);
**Table 6** Description of RtcWriteTime
**Table 6** Description of RtcWriteTime
<a name="table223910318361"></a>
<table><tbody><tr id="row924033173613"><td class="cellrowborder" valign="top" width="21.54%"><p id="p16240143143611"><a name="p16240143143611"></a><a name="p16240143143611"></a><strong id="b17297111720576"><a name="b17297111720576"></a><a name="b17297111720576"></a>Parameter</strong></p>
......@@ -354,8 +354,8 @@ int32\_t RtcWriteTime\(DevHandle handle, struct RtcTime \*time\);
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
```
int32_t ret;
......@@ -382,7 +382,7 @@ Call the following function to read the alarm time:
int32\_t RtcReadAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime \*time\);
**Table 7** Description of RtcReadAlarm
**Table 7** Description of RtcReadAlarm
<a name="table11342203111420"></a>
<table><tbody><tr id="row133429310140"><td class="cellrowborder" valign="top" width="21.54%"><p id="p9886411201416"><a name="p9886411201416"></a><a name="p9886411201416"></a><strong id="b152971517185720"><a name="b152971517185720"></a><a name="b152971517185720"></a>Parameter</strong></p>
......@@ -440,7 +440,7 @@ Call the following function to set the RTC alarm time based on the alarm index:
int32\_t RtcWriteAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime \*time\);
**Table 8** Description of RtcWriteAlarm
**Table 8** Description of RtcWriteAlarm
<a name="table107922162179"></a>
<table><tbody><tr id="row14793316131710"><td class="cellrowborder" valign="top" width="21.62%"><p id="p1891718412183"><a name="p1891718412183"></a><a name="p1891718412183"></a><strong id="b029811725716"><a name="b029811725716"></a><a name="b029811725716"></a>Parameter</strong></p>
......@@ -481,8 +481,8 @@ int32\_t RtcWriteAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
```
int32_t ret;
......@@ -505,11 +505,11 @@ if (ret != 0) {
- Enabling or disabling alarm interrupts
Before performing alarm operations, use the following function to enable alarm interrupts, so that **RtcAlarmCallback** will be called when the alarm is not generated upon a timeout:
Before performing alarm operations, use the following function to enable alarm interrupts, so that **RtcAlarmCallback** will be called when the alarm is not generated upon a timeout:
int32\_t RtcAlarmInterruptEnable\(DevHandle handle, enum RtcAlarmIndex alarmIndex, uint8\_t enable\);
**Table 9** Description of RtcAlarmInterruptEnable
**Table 9** Description of RtcAlarmInterruptEnable
<a name="table1934615314159"></a>
<table><tbody><tr id="row5346853171519"><td class="cellrowborder" valign="top" width="21.36%"><p id="p143464533153"><a name="p143464533153"></a><a name="p143464533153"></a><strong id="b829913171576"><a name="b829913171576"></a><a name="b829913171576"></a>Parameter</strong></p>
......@@ -566,7 +566,7 @@ Call the following function to read the frequency of the external crystal oscill
int32\_t RtcGetFreq\(DevHandle handle, uint32\_t \*freq\);
**Table 10** Description of RtcGetFreq
**Table 10** Description of RtcGetFreq
<a name="table125881625185"></a>
<table><tbody><tr id="row1458811241816"><td class="cellrowborder" valign="top" width="21.36%"><p id="p658820241813"><a name="p658820241813"></a><a name="p658820241813"></a><strong id="b3300217175712"><a name="b3300217175712"></a><a name="b3300217175712"></a>Parameter</strong></p>
......@@ -619,7 +619,7 @@ Call the following function to set the frequency of the external crystal oscilla
int32\_t RtcSetFreq\(DevHandle handle, uint32\_t freq\);
**Table 11** Description of RtcSetFreq
**Table 11** Description of RtcSetFreq
<a name="table1170124316209"></a>
<table><tbody><tr id="row270119432202"><td class="cellrowborder" valign="top" width="21.36%"><p id="p127011343132010"><a name="p127011343132010"></a><a name="p127011343132010"></a><strong id="b130031711578"><a name="b130031711578"></a><a name="b130031711578"></a>Parameter</strong></p>
......@@ -672,7 +672,7 @@ Call the following function to perform a reset on the RTC driver \(after the res
int32\_t RtcReset\(DevHandle handle\);
**Table 12** Description of RtcReset
**Table 12** Description of RtcReset
<a name="table398973152517"></a>
<table><tbody><tr id="row179899311254"><td class="cellrowborder" valign="top" width="21.36%"><p id="p199899314257"><a name="p199899314257"></a><a name="p199899314257"></a><strong id="b1330101719577"><a name="b1330101719577"></a><a name="b1330101719577"></a>Parameter</strong></p>
......@@ -719,7 +719,7 @@ Call the following function to read the configuration of a custom RTC register b
int32\_t RtcReadReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t \*value\);
**Table 13** Description of RtcReadReg
**Table 13** Description of RtcReadReg
<a name="table1624674153319"></a>
<table><tbody><tr id="row92469423320"><td class="cellrowborder" valign="top" width="21.62%"><p id="p102461548331"><a name="p102461548331"></a><a name="p102461548331"></a><strong id="b73024170576"><a name="b73024170576"></a><a name="b73024170576"></a>Parameter</strong></p>
......@@ -778,7 +778,7 @@ Call the following function to configure a register based on the specified regis
int32\_t RtcWriteReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t value\);
**Table 14** Description of RtcWriteReg
**Table 14** Description of RtcWriteReg
<a name="table1072216482360"></a>
<table><tbody><tr id="row187221648133611"><td class="cellrowborder" valign="top" width="21.62%"><p id="p2722184823617"><a name="p2722184823617"></a><a name="p2722184823617"></a><strong id="b530321795712"><a name="b530321795712"></a><a name="b530321795712"></a>Parameter</strong></p>
......@@ -838,7 +838,7 @@ This section describes the process of using RTC APIs:
1. During the OS startup, the HDF identifies the RTC component in the system.
2. The HDF initializes and creates the RTC device.
3. You can perform operations on the RTC device by calling different APIs.
4. Call the **RtcClose** function to release the device handle and device resources.
4. Call the **RtcClose** function to release the device handle and device resources.
Example:
......@@ -926,5 +926,4 @@ void RtcTestSample(void)
/* Release the RTC device handle. */
RtcClose(handle);
}
```
```
\ No newline at end of file
......@@ -4,7 +4,7 @@
In the Hardware Driver Foundation \(HDF\) framework, the real-time clock \(RTC\) 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.
**Figure 1** Independent service mode<a name="fig6742142611299"></a>
**Figure 1** Independent service mode<a name="fig6742142611299"></a>
![](figures/independent-service-mode.png "independent-service-mode-11")
## Available APIs<a name="section752964871810"></a>
......@@ -27,7 +27,7 @@ struct RtcMethod {
};
```
**Table 1** Callbacks for the members in the RtcMethod structure
**Table 1** Callbacks for the members in the RtcMethod structure
<a name="table12929217311"></a>
<table><thead align="left"><tr id="row293621203111"><th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.1"><p id="p15932212314"><a name="p15932212314"></a><a name="p15932212314"></a>Callback</p>
......@@ -183,33 +183,31 @@ struct RtcMethod {
The RTC module adaptation involves the following steps:
1. Instantiate the driver entry.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
2. Configure attribute files.
- Add the **deviceNode** information to the **device\_info.hcs** file.
- \(Optional\) Add the **rtc\_config.hcs** file.
- Add the **deviceNode** information to the **device\_info.hcs** file.
- \(Optional\) Add the **rtc\_config.hcs** file.
3. Instantiate the RTC controller object.
- Initialize **RtcHost**.
- Instantiate **RtcMethod** in the **RtcHost** object.
>![](../public_sys-resources/icon-note.gif) **NOTE**
>For details, see [Available APIs](#available-apis).
- Initialize **RtcHost**.
- Instantiate **RtcMethod** in the **RtcHost** object.
For details, see [Available APIs](#available-apis).
4. \(Optional\) Debug the driver.
4. Debug the driver.
- \(Optional\) For new drivers, verify the basic functions, such as the RTC control status and response to interrupts.
For new drivers, verify the basic functions, such as the RTC control status and response to interrupts.
## Development Example<a name="section1594883301142407"></a>
The following uses **rtc\_hi35xx.c** as an example to present the contents that need to be provided by the vendor to implement device functions.
The following uses **rtc\_hi35xx.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. 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, 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.
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.
- RTC driver entry reference
......@@ -225,11 +223,11 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
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. 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.
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.
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.
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.
- **device\_info.hcs** configuration reference
- **device\_info.hcs** configuration reference
```
root {
......@@ -250,7 +248,7 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
}
```
- **rtc\_config.hcs** configuration reference
- **rtc\_config.hcs** configuration reference
```
root {
......@@ -274,10 +272,10 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
}
```
3. Initialize the **RtcHost** object at the core layer, including initializing the vendor custom structure \(transferring parameters and data\), instantiating **RtcMethod** \(used to call underlying functions of the driver\) in **RtcHost**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\).
3. Initialize the **RtcHost** object at the core layer, including initializing the vendor custom structure \(transferring parameters and data\), instantiating **RtcMethod** \(used to call underlying functions of the driver\) in **RtcHost**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\).
- Custom structure reference
To the driver, the custom structure carries parameters and data. The values in the **rtc\_config.hcs** file are read by HDF, and the structure members are initialized through **DeviceResourceIface**.
To the driver, the custom structure carries parameters and data. The values in the **rtc\_config.hcs** file are read by HDF, and the structure members are initialized through **DeviceResourceIface**.
```
struct RtcConfigInfo {
......@@ -303,7 +301,7 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
};
```
- Instantiate the callback function structure **RtcMethod** in **RtcHost**. Other members are initialized by using the **Init** function.
- Instantiate the callback function structure **RtcMethod** in **RtcHost**. Other members are initialized by using the **Init** function.
```
// Example in rtc_hi35xx.c: instantiate the hook.
......@@ -326,13 +324,13 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
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.\)
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.\)
**Table 2** Input parameters and return values of the Bind function
**Table 2** Input parameters and return values of the Bind function
<a name="table14285177465"></a>
<table><thead align="left"><tr id="row6280177461"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p528181764613"><a name="p528181764613"></a><a name="p528181764613"></a>Status (Value)</p>
......@@ -376,7 +374,7 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
Function description:
Associates the **HdfDeviceObject** object and **RtcHost**.
Associates the **HdfDeviceObject** object and **RtcHost**.
```
static int32_t HiRtcBind(struct HdfDeviceObject *device)
......@@ -395,7 +393,7 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
......@@ -403,7 +401,7 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
Function description:
Initializes the custom structure object and **RtcHost**.
Initializes the custom structure object and **RtcHost**.
```
static int32_t HiRtcInit(struct HdfDeviceObject *device)
......@@ -437,15 +435,15 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
**Function description**:
**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 **Init** or **Bind** function has the corresponding value assignment operations.
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 **Init** or **Bind** function has the corresponding value assignment operations.
```
static void HiRtcRelease(struct HdfDeviceObject *device)
......@@ -462,7 +460,4 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
}
RtcHostDestroy(host); // Release RtcHost.
}
```
```
\ No newline at end of file
......@@ -2,46 +2,46 @@
## Overview<a name="section193356154511"></a>
- Serial Peripheral Interface \(SPI\) is a serial bus specification used for high-speed, full-duplex, and synchronous communication.
- SPI is developed by Motorola. It is commonly used for communication with flash memory, real-time clocks, sensors, and analog-to-digital \(A/D\) converters.
- SPI works in controller/device mode. Generally, there is one SPI controller that controls one or more SPI devices. They are connected via four wires:
- SCLK: clock signals output from the SPI controller
- MOSI: data output from the SPI controller and input into an SPI device
- MISO: data output from an SPI device and input into the SPI controller
- CS: signals enabled by an SPI device and controlled by the SPI controller
Serial Peripheral Interface \(SPI\) is a serial bus specification used for high-speed, full-duplex, and synchronous communication.
SPI is developed by Motorola. It is commonly used for communication with flash memory, real-time clocks, sensors, and analog-to-digital \(A/D\) converters.
SPI works in controller/device mode. Generally, there is one SPI controller that controls one or more SPI devices. They are connected via four wires:
- SCLK: clock signals output from the SPI controller
- MOSI: data output from the SPI controller and input into an SPI device
- MISO: data output from an SPI device and input into the SPI controller
- CS: signals enabled by an SPI device and controlled by the SPI controller
- [Figure 1](#fig89085710359) shows the connection between one SPI controller and two SPI devices \(device A and device B\). In this figure, device A and device B share three pins \(SCLK, MISO, and MOSI\) of the controller. CS0 of device A and CS1 of device B are connected to CS0 and CS1 of the controller, respectively.
[Figure 1](#fig89085710359) shows the connection between one SPI controller and two SPI devices \(device A and device B\). In this figure, device A and device B share three pins \(SCLK, MISO, and MOSI\) of the controller. CS0 of device A and CS1 of device B are connected to CS0 and CS1 of the controller, respectively.
**Figure 1** SPI controller/device connection<a name="fig89085710359"></a>
**Figure 1** SPI controller/device connection<a name="fig89085710359"></a>
![](figures/spi-controller-device-connection.png "spi-controller-device-connection")
- SPI communication is usually initiated by the SPI controller and is operated as follows:
SPI communication is usually initiated by the SPI controller and is operated as follows:
1. A single SPI device is selected at a time via the CS to communicate with the SPI controller.
2. Clock signals are provided for the selected SPI device via the SCLK.
3. The SPI controller sends data to SPI devices via the MOSI, and receives data from SPI devices via the MISO.
- SPI can work in one of the following four modes, equivalent to one of the four possible states for Clock Polarity \(CPOL\) and Clock Phase \(CPHA\):
- If both CPOL and CPHA are **0**, the clock signal level is low in the idle state and data is sampled on the first clock edge.
- If CPOL is **0** and CPHA is **1**, the clock signal level is low in the idle state and data is sampled on the second clock edge.
- If CPOL is **1** and CPHA is **0**, the clock signal level is high in the idle state and data is sampled on the first clock edge.
- If both CPOL and CPHA are **1**, the clock signal level is high in the idle state and data is sampled on the second clock edge.
- If both CPOL and CPHA are **0**, the clock signal level is low in the idle state and data is sampled on the first clock edge.
- If CPOL is **0** and CPHA is **1**, the clock signal level is low in the idle state and data is sampled on the second clock edge.
- If CPOL is **1** and CPHA is **0**, the clock signal level is high in the idle state and data is sampled on the first clock edge.
- If both CPOL and CPHA are **1**, the clock signal level is high in the idle state and data is sampled on the second clock edge.
- SPI defines a set of common functions for operating an SPI device, including those for:
- Obtaining and releasing the handle of an SPI device.
- Reading or writing data of a specified length from or into an SPI device.
- Customizing data reading or writing via **SpiMsg**.
- Customizing data reading or writing via **SpiMsg**.
- Obtaining and setting SPI device configuration parameters.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>Currently, these functions are only applicable in the communication initiated by the SPI controller.
## Available APIs<a name="section1325964832615"></a>
**Table 1** APIs for the SPI driver
**Table 1** APIs for the SPI driver
<a name="table1731550155318"></a>
<table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" align="left" valign="top" width="20.857914208579142%" id="mcps1.2.4.1.1"><p id="p641050105320"><a name="p641050105320"></a><a name="p641050105320"></a><strong id="b17365506414"><a name="b17365506414"></a><a name="b17365506414"></a>Capability</strong></p>
......@@ -106,16 +106,16 @@
[Figure 2](#fig1586912310348) shows the process of using an SPI device.
**Figure 2** Process of using an SPI device<a name="fig1586912310348"></a>
**Figure 2** Process of using an SPI device<a name="fig1586912310348"></a>
![](figures/process-of-using-an-spi-device.png "process-of-using-an-spi-device")
### Obtaining an SPI Device Handle<a name="section1927265711481"></a>
Before performing SPI communication, obtain an SPI device handle by calling **SpiOpen**. This function returns an SPI device handle with a specified bus number and CS number.
Before performing SPI communication, obtain an SPI device handle by calling **SpiOpen**. This function returns an SPI device handle with a specified bus number and CS number.
DevHandle SpiOpen\(const struct SpiDevInfo \*info\);
**Table 2** Description of SpiOpen
**Table 2** Description of SpiOpen
<a name="table7603619123820"></a>
<table><tbody><tr id="row1060351914386"><td class="cellrowborder" valign="top" width="50%"><p id="p14603181917382"><a name="p14603181917382"></a><a name="p14603181917382"></a><strong id="b139290298482"><a name="b139290298482"></a><a name="b139290298482"></a>Parameter</strong></p>
......@@ -146,7 +146,7 @@ DevHandle SpiOpen\(const struct SpiDevInfo \*info\);
</tbody>
</table>
The following example shows how to obtain an SPI device handle based on the assumption that both the bus number and CS number of the SPI device are **0**.
The following example shows how to obtain an SPI device handle based on the assumption that both the bus number and CS number of the SPI device are **0**.
```
struct SpiDevInfo spiDevinfo; /* SPI device descriptor */
......@@ -168,7 +168,7 @@ After obtaining the SPI device handle, obtain the SPI device configuration param
int32\_t SpiGetCfg\(DevHandle handle, struct SpiCfg \*cfg\);
**Table 3** Description of SpiGetCfg
**Table 3** Description of SpiGetCfg
<a name="table14209152141313"></a>
<table><tbody><tr id="row1420918529133"><td class="cellrowborder" valign="top" width="50%"><p id="p42091852141314"><a name="p42091852141314"></a><a name="p42091852141314"></a><strong id="b6279123012486"><a name="b6279123012486"></a><a name="b6279123012486"></a>Parameter</strong></p>
......@@ -219,7 +219,7 @@ After obtaining the SPI device handle, set SPI device configuration parameters b
int32\_t SpiSetCfg\(DevHandle handle, struct SpiCfg \*cfg\);
**Table 4** Description of SpiSetCfg
**Table 4** Description of SpiSetCfg
<a name="table219052945210"></a>
<table><tbody><tr id="row14191192918522"><td class="cellrowborder" valign="top" width="50%"><p id="p17424155016529"><a name="p17424155016529"></a><a name="p17424155016529"></a><strong id="b11281163011480"><a name="b11281163011480"></a><a name="b11281163011480"></a>Parameter</strong></p>
......@@ -276,7 +276,7 @@ To write data into an SPI device only once, call the following function:
int32\_t SpiWrite\(DevHandle handle, uint8\_t \*buf, uint32\_t len\);
**Table 5** Description of SpiWrite
**Table 5** Description of SpiWrite
<a name="table1018490043"></a>
<table><tbody><tr id="row31848013417"><td class="cellrowborder" valign="top" width="50%"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b42810303484"><a name="b42810303484"></a><a name="b42810303484"></a>Parameter</strong></p>
......@@ -333,7 +333,7 @@ To read data from an SPI device only once, call the following function:
int32\_t SpiRead\(DevHandle handle, uint8\_t \*buf, uint32\_t len\);
**Table 6** Description of SpiRead
**Table 6** Description of SpiRead
<a name="table0265191412124"></a>
<table><tbody><tr id="row42651914141213"><td class="cellrowborder" valign="top" width="50%"><p id="p1483184123"><a name="p1483184123"></a><a name="p1483184123"></a><strong id="b528223019480"><a name="b528223019480"></a><a name="b528223019480"></a>Parameter</strong></p>
......@@ -390,7 +390,7 @@ To launch a custom transfer, call the following function:
int32\_t SpiTransfer\(DevHandle handle, struct SpiMsg \*msgs, uint32\_t count\);
**Table 7** Description of SpiTransfer
**Table 7** Description of SpiTransfer
<a name="table1934414174212"></a>
<table><tbody><tr id="row1134415176216"><td class="cellrowborder" valign="top" width="50%"><p id="p13295152320217"><a name="p13295152320217"></a><a name="p13295152320217"></a><strong id="b1628393012482"><a name="b1628393012482"></a><a name="b1628393012482"></a>Parameter</strong></p>
......@@ -457,7 +457,7 @@ void SpiClose\(DevHandle handle\);
This function will release the resources previously obtained.
**Table 8** Description of SpiClose
**Table 8** Description of SpiClose
<a name="table72517953115"></a>
<table><tbody><tr id="row1525793312"><td class="cellrowborder" valign="top" width="50%"><p id="p115402031153111"><a name="p115402031153111"></a><a name="p115402031153111"></a><strong id="b1728493044820"><a name="b1728493044820"></a><a name="b1728493044820"></a>Parameter</strong></p>
......@@ -545,5 +545,4 @@ err:
/* Destroy the SPI device handle. */
SpiClose(spiHandle);
}
```
```
\ No newline at end of file
......@@ -5,7 +5,7 @@
In the Hardware Driver Foundation \(HDF\), the Serial Peripheral Interface \(SPI\) 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.
**Figure 1** Independent service mode<a name="fig666465313303"></a>
**Figure 1** Independent service mode<a name="fig666465313303"></a>
![](figures/independent-service-mode.png "SPI-independent-service-mode")
## Available APIs<a name="section752964871810"></a>
......@@ -21,7 +21,7 @@ struct SpiCntlrMethod {
int32_t (*Close)(struct SpiCntlr *cntlr);
};
```
**Table 1** Callbacks for the members in the SpiCntlrMethod structure
**Table 1** Callbacks for the members in the SpiCntlrMethod structure
<a name="table7167123615321"></a>
<table><thead align="left"><tr id="row816783615326"><th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.1"><p id="p8167193643218"><a name="p8167193643218"></a><a name="p8167193643218"></a>Callback</p>
......@@ -91,32 +91,30 @@ struct SpiCntlrMethod {
The SPI module adaptation involves the following steps:
1. Instantiate the driver entry.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
2. Configure attribute files.
- Add the **deviceNode** information to the **device\_info.hcs** file.
- \(Optional\) Add the **spi\_config.hcs** file.
- Add the **deviceNode** information to the **device\_info.hcs** file.
- \(Optional\) Add the **spi\_config.hcs** file.
3. Instantiate the SPI controller object.
- Initialize **SpiCntlr**.
- Instantiate **SpiCntlrMethod** in the **SpiCntlr** object.
- Initialize **SpiCntlr**.
- Instantiate **SpiCntlrMethod** in the **SpiCntlr** object.
>![](../public_sys-resources/icon-note.gif) **NOTE**
For details, see [Available APIs](#section752964871810).
>For details, see [Available APIs](#section752964871810).
4. Debug the driver.
- \(Optional\) For new drivers, verify the basic functions, such as the SPI control status and response to interrupts.
4. \(Optional\) Debug the driver.
For new drivers, verify the basic functions, such as the SPI control status and response to interrupts.
## Development Example<a name="section956157227152909"></a>
The following uses **spi\_hi35xx.c** as an example to present the contents that need to be provided by the vendor to implement device functions.
The following uses **spi\_hi35xx.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. 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, 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.
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.
- SPI driver entry reference
......@@ -132,11 +130,11 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
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. 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.
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.
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.
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.
- **device\_info.hcs** configuration reference
- **device\_info.hcs** configuration reference
```
root {
......@@ -169,7 +167,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
}
```
- **spi\_config.hcs** configuration reference
- **spi\_config.hcs** configuration reference
```
root {
......@@ -218,10 +216,10 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
}
```
3. Initialize the **SpiCntlr** object at the core layer, including initializing the vendor custom structure \(transferring parameters and data\), instantiating **SpiCntlrMethod** \(used to call underlying functions of the driver\) in **SpiCntlr**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\).
3. Initialize the **SpiCntlr** object at the core layer, including initializing the vendor custom structure \(transferring parameters and data\), instantiating **SpiCntlrMethod** \(used to call underlying functions of the driver\) in **SpiCntlr**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\).
- Custom structure reference
To the driver, the custom structure carries parameters and data. The values in the **spi\_config.hcs** file are read by HDF, and the structure members are initialized through **DeviceResourceIface**. Some important values, such as the device number and bus number, are also passed to the object at the core layer.
To the driver, the custom structure carries parameters and data. The values in the **spi\_config.hcs** file are read by HDF, and the structure members are initialized through **DeviceResourceIface**. Some important values, such as the device number and bus number, are also passed to the object at the core layer.
```
struct Pl022 {// Corresponds to parameters in .hcs.
......@@ -264,7 +262,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
};
```
- Instantiate the callback function structure **SpiCntlrMethod** in **SpiCntlr**. Other members are initialized by using the **Init** function.
- Instantiate the callback function structure **SpiCntlrMethod** in **SpiCntlr**. Other members are initialized by using the **Init** function.
```
// Example in spi_hi35xx.c: instantiate the hook.
......@@ -281,7 +279,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
......@@ -289,7 +287,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
Function description:
Associates the **SpiCntlr** object with **HdfDeviceObject**.
Associates the **SpiCntlr** object with **HdfDeviceObject**.
```
static int32_t HdfSpiDeviceBind(struct HdfDeviceObject *device)
......@@ -317,13 +315,13 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
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.\)
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.\)
**Table 2** Input parameters and return values of the init function
**Table 2** Input parameters and return values of the init function
<a name="table4311552173914"></a>
<table><thead align="left"><tr id="row8314152103916"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p331413523392"><a name="p331413523392"></a><a name="p331413523392"></a>Status (Value)</p>
......@@ -367,7 +365,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
Function description:
Initializes the custom structure object and **SpiCntlr**.
Initializes the custom structure object and **SpiCntlr**.
```
static int32_t HdfSpiDeviceInit(struct HdfDeviceObject *device)
......@@ -418,7 +416,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
......@@ -426,7 +424,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
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 **Init** function has the corresponding value assignment operations.
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 **Init** function has the corresponding value assignment operations.
```
static void HdfSpiDeviceRelease(struct HdfDeviceObject *device)
......@@ -441,8 +439,4 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
}
SpiCntlrDestroy(cntlr); // Release the Pl022 object.
}
```
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册