The Linux driver interacts directly with the hardware, but not the Linux driver writes the data directly to the memory in the hardware, but interacts with the native I/O memory. Every hardware that connects to Linux has a map header address in I/O memory. This hardware is detected by any modern operating system host when it is plugged into the hardware, but the hardware is detected only to indicate I/O memory is established in the kernel space, the program that wants user space can access the hardware, and the driver that can interact with I/O memory must also be installed.
Readers can create a device file based on the following steps:
(1) Initialize the Cdev with the Cdev_init function;
(2) Specify the device number, can be specified directly in the code can also be dynamically assigned;
(3) Use the Cdev_add function to add the character device to the character device array in the kernel;
(4) Create struct class with Class_create macro;
(5) Create a device file using the Device_create function;
Uninstalling a Linux-powered device file is a bit simpler, and you need to call the Device_destroy,class_destroy and Unregister_chrdev_region methods in turn.
You must know how to set the register before controlling the led to light off. The ARM processor has multiple registers, and by setting the register value, you can set the status of the LED PIN, open or disable the pull-up circuit, and control the LED's light off. Wherein the LED has two pins, the control led needs three registers to complete, each register can use 4 bytes, using the low 16 bits of the Gpmcon register to set the LED two port properties to output. The low 4-bit control using the Gpmdat register controls 4 LEDs, and the low 8 bits of the GPMPUD register open the pull-up circuit for 4 LEDs respectively.
Android Deep Explore seventh chapter