- The pin, also called pin controller, manages pin resources of system on a chip (SoC) vendors and provides the pin multiplexing function.
The pin module, also called pin controller, manages pin resources of system on a chip (SoC) vendors and provides the pin multiplexing function.
- The pin module defines a set of common methods for managing pins, including:
The module defines a set of common methods for managing pins, including:
- Obtaining or releasing the pin description handle: The kernel compares the pin name passed in with the pin names of each controller in the linked list. If a match is found, a pin description handle is obtained. After the operation on the pin is complete, the pin description handle will be released.
- Obtaining or releasing the pin description handle: The kernel compares the pin name passed in with the pin names of each controller in the linked list. If a match is found, a pin description handle is obtained. After the operation on the pin is complete, the pin description handle will be released.
- Setting or obtaining the pull type of a pin: The pull type can be pull-up, pull-down, or floating.
- Setting or obtaining the pull type of a pin: The pull type can be pull-up, pull-down, or floating.
- Setting or obtaining the pull strength of a pin: You can set the pull strength as required.
- Setting or obtaining the pull strength of a pin: You can set the pull strength as required.
- Setting or obtaining the functions of a pin to implement pin multiplexing
- Setting or obtaining the functions of a pin to implement pin multiplexing
### Basic Concepts<a name="section3"></a>
### Basic Concepts<a name="section3"></a>
Pin, as a software concept, provides APIs for uniformly managing the pins from different SoC vendors, providing the pin multiplexing function, and configuring the electrical features of pins.
Pin, as a software concept, provides APIs for uniformly managing the pins from different SoC vendors, providing the pin multiplexing function, and configuring the electrical features of pins.
...
@@ -52,7 +52,7 @@ The table below describes the APIs of the pin module. For more details, see API
...
@@ -52,7 +52,7 @@ The table below describes the APIs of the pin module. For more details, see API
For details, see [Available APIs](#available-apis).
>For details, see [Available APIs](#available-apis).
4.\(Optional\) Debug the driver.
For new drivers, verify the basic functions, such as the PWM control status and response to interrupts.
4. Debug the driver.
-\(Optional\) For new drivers, verify the basic functions, such as the PWM control status and response to interrupts.
## Development Example<a name="section1883877829164144"></a>
## 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
- PWM driver entry reference
...
@@ -110,8 +107,8 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
...
@@ -110,8 +107,8 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
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 corresponding device attributes to the **pwm\_config** file.
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
-**device\_info.hcs** configuration reference
```
```
root {
root {
...
@@ -143,7 +140,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
...
@@ -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 {
root {
...
@@ -168,10 +165,10 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
...
@@ -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
- 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 {
struct HiPwm {
...
@@ -208,7 +205,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
...
@@ -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
// 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
...
@@ -221,11 +218,11 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
Input parameters:
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:
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.\)
@@ -269,7 +266,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
...
@@ -269,7 +266,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
Function description:
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.
// 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
...
@@ -320,7 +317,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
Input parameters:
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:
Return values:
...
@@ -328,7 +325,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
...
@@ -328,7 +325,7 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
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.
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.
@@ -340,7 +337,4 @@ The following uses **pwm\_hi35xx.c** as an example to present the contents tha
...
@@ -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.
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.
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:
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
```
```
int32_t ret;
int32_t ret;
...
@@ -382,7 +382,7 @@ Call the following function to read the alarm time:
...
@@ -382,7 +382,7 @@ Call the following function to read the alarm time:
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
```
```
int32_t ret;
int32_t ret;
...
@@ -505,11 +505,11 @@ if (ret != 0) {
...
@@ -505,11 +505,11 @@ if (ret != 0) {
- Enabling or disabling alarm interrupts
- Enabling or disabling alarm interrupts
Before performing alarm operations, use the following function to enable alarm interrupts, so that **RtcAlarmCallback** will be called when the alarm is not generated upon a timeout:
Before performing alarm operations, use the following function to enable alarm interrupts, so that **RtcAlarmCallback** will be called when the alarm is not generated upon a timeout:
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.
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<aname="fig6742142611299"></a>
**Figure 1** Independent service mode<aname="fig6742142611299"></a>
>For details, see [Available APIs](#available-apis).
For details, see [Available APIs](#available-apis).
4.\(Optional\) Debug the driver.
4. Debug the driver.
For new drivers, verify the basic functions, such as the RTC control status and response to interrupts.
-\(Optional\) For new drivers, verify the basic functions, such as the RTC control status and response to interrupts.
## Development Example<a name="section1594883301142407"></a>
## 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
- RTC driver entry reference
...
@@ -225,11 +223,11 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
...
@@ -225,11 +223,11 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
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. 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 {
root {
...
@@ -250,7 +248,7 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
...
@@ -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 {
root {
...
@@ -274,10 +272,10 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
...
@@ -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
- 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 {
struct RtcConfigInfo {
...
@@ -303,7 +301,7 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
...
@@ -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.
// 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
...
@@ -326,13 +324,13 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
Input parameters:
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:
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
@@ -437,15 +435,15 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
...
@@ -437,15 +435,15 @@ The following uses **rtc\_hi35xx.c** as an example to present the contents tha
Input parameters:
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:
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.
-Serial Peripheral Interface \(SPI\) is a serial bus specification used for high-speed, full-duplex, and synchronous communication.
Serial Peripheral Interface \(SPI\) is a serial bus specification used for high-speed, full-duplex, and synchronous communication.
-SPI is developed by Motorola. It is commonly used for communication with flash memory, real-time clocks, sensors, and analog-to-digital \(A/D\) converters.
SPI is developed by Motorola. It is commonly used for communication with flash memory, real-time clocks, sensors, and analog-to-digital \(A/D\) converters.
-SPI works in controller/device mode. Generally, there is one SPI controller that controls one or more SPI devices. They are connected via four wires:
SPI works in controller/device mode. Generally, there is one SPI controller that controls one or more SPI devices. They are connected via four wires:
- SCLK: clock signals output from the SPI controller
- SCLK: clock signals output from the SPI controller
- MOSI: data output from the SPI controller and input into an SPI device
- MOSI: data output from the SPI controller and input into an SPI device
- MISO: data output from an SPI device and input into the SPI controller
- MISO: data output from an SPI device and input into the SPI controller
- CS: signals enabled by an SPI device and controlled by the SPI controller
- CS: signals enabled by an SPI device and controlled by the SPI controller
-[Figure 1](#fig89085710359) shows the connection between one SPI controller and two SPI devices \(device A and device B\). In this figure, device A and device B share three pins \(SCLK, MISO, and MOSI\) of the controller. CS0 of device A and CS1 of device B are connected to CS0 and CS1 of the controller, respectively.
[Figure 1](#fig89085710359) shows the connection between one SPI controller and two SPI devices \(device A and device B\). In this figure, device A and device B share three pins \(SCLK, MISO, and MOSI\) of the controller. CS0 of device A and CS1 of device B are connected to CS0 and CS1 of the controller, respectively.
### Obtaining an SPI Device Handle<a name="section1927265711481"></a>
### Obtaining an SPI Device Handle<a name="section1927265711481"></a>
Before performing SPI communication, obtain an SPI device handle by calling **SpiOpen**. This function returns an SPI device handle with a specified bus number and CS number.
Before performing SPI communication, obtain an SPI device handle by calling **SpiOpen**. This function returns an SPI device handle with a specified bus number and CS number.
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**.
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.
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<aname="fig666465313303"></a>
**Figure 1** Independent service mode<aname="fig666465313303"></a>
For details, see [Available APIs](#section752964871810).
>For details, see [Available APIs](#section752964871810).
4.\(Optional\) Debug the driver.
For new drivers, verify the basic functions, such as the SPI control status and response to interrupts.
4. Debug the driver.
-\(Optional\) For new drivers, verify the basic functions, such as the SPI control status and response to interrupts.
## Development Example<a name="section956157227152909"></a>
## 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
- SPI driver entry reference
...
@@ -132,11 +130,11 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
...
@@ -132,11 +130,11 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
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. 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 {
root {
...
@@ -169,7 +167,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
...
@@ -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 {
root {
...
@@ -218,10 +216,10 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
...
@@ -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
- 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.
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
...
@@ -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.
// 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
...
@@ -281,7 +279,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
Input parameters:
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:
Return values:
...
@@ -289,7 +287,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
...
@@ -289,7 +287,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
Function description:
Function description:
Associates the **SpiCntlr** object with **HdfDeviceObject**.
Associates the **SpiCntlr** object with **HdfDeviceObject**.
@@ -317,13 +315,13 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
...
@@ -317,13 +315,13 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
Input parameters:
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:
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
@@ -418,7 +416,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
...
@@ -418,7 +416,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
Input parameters:
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:
Return values:
...
@@ -426,7 +424,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
...
@@ -426,7 +424,7 @@ The following uses **spi\_hi35xx.c** as an example to present the contents tha
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** 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.