Although Linux drives deal directly with hardware, it is not the Linux driver that writes data directly to the hardware's memory, but interacts with the native I/O. The so-called I/O memory is a mapping in memory that is connected to the host through various interfaces.
The Linux kernel provides multiple functions that interact with I/O memory. Each hardware connected to Linux has a map header address in I/O memory.
To create an LED-driven device file:
First step: Initialize the Cdev with the Cdev_init function
Step Two: Specify the device number
Step three: Use the Cdev_init function to add a character device to the character device array in the kernel
Fourth step: Create a struct class using the Class_create macro
Fifth step: Create a device file using the Device_create function
Uninstalling a Linux-powered device file is a bit simpler and requires a call to the Device_destroy Class_destroy Unregister_chrdev_region method.
LED drivers have two ways of interacting with device files: writing string data directly and I/O control commands. Writing data directly to a device file can be done using the command line, or through the write function.
NDK Program tests and executable program tests are similar. But the NDK Library can be called by Java programs, and the most straightforward way to test Linux drivers on an Android system is to use the NDK.
A complete Linux driver consists mainly of internal processing and interaction with hardware. The internal processing mainly refers to the Linux driver loading, unloading, device file-related motion processing and business logic.
Seventh chapter I/O