The seventh chapter outlines another driver: LED light control
1. Create an LED-driven device file:
1th Step: Initialize the Cdev with the Cdev_init function;
2nd step: Specify the number of the device, divided into two specified methods
3rd Step: Use the Cdev_add function to add the character device to the character device array in the kernel;
4th Step: Use Class_create macro to create struct class;
5th step: Create a device file using the Device_create function.
2. Uninstalling the LED-driven device files
Key code:
void Device_destory (Sruct class *class,dev_t devt)
void Clss_dsetroy (struct class *class)
void Unregister_chrdex_region (dev_t from,unsigned count)
1. The control led,led driver can control the LEDs in two ways, string and I/O commands.
LEDs have two pins: GPB0 and GPB1. One of the pins is connected to the ARM processor's GPI0 port, and the other pin is connected to the power supply via a current-limiting resistor. The control LEDs need to be completed by 3 registers, Gpmcon, Gpmdat, Gpmpud, respectively. Each register can use 4 bytes. Use the low 16 bits of the Gpmcon register to set the LED two port property to OUTPT. The low 4-bit control using the Gpmdat register controls the light and off of 4 LEDs.
Working with hardware, you need to write the program to I/O memory, and I/O memory is responsible for interacting with each of the host's hardware. In LED drivers, direct write string data and I/O control commands can be used to interact with device files.
"Android" Deep Exploration of the seventh chapter experience