Seventh chapter LED will blink for me: Control the light-emitting secondary tube-learning notes
1. Realization principle of LED drive
Linux driver and hardware interaction principle: Linux Drive and I/O memory through the IOREAD30 and IOWRITE32 functions, I/O memory and hardware, memory management module is responsible for synchronizing I/O memory and hardware in Germany data.
Explanation: Although the Linux driver deals directly with hardware, it is not the Linux driver that writes data directly to the memory in the hardware but interacts with the native i/0 memory, which is located in the kernel space. The so-called 1/0 memory is through a variety of interfaces (PCI, USB, Bluetooth, Ethernet port, etc.) connected to the host (PC, mobile phone) hardware (network card, sound card, camera, etc.) in the host memory mapping. For example, a driver running on Ubuntu Linux only needs to access I/O memory in a host running Ubuntu Linux, and then the Linux kernel interacts with the data hardware in I/O memory. The Linux kernel provides several functions that interact with 1/0 of memory, such as Ioread16 ioread32 Iowrite16 iowrite32, and so on. The memory management module of the Linux kernel is responsible for synchronizing the data in i/0 storage and hardware. Every hardware that connects to Linux has a map header address in I/O memory. You need to specify these first addresses when reading I/O memory using functions such as IOREAD32. The LEDs on the Development Board also have their mapping first address.
2. Write LED Driver
1. Create LED-driven device files
Use the Cdev_init function to initialize the Cdev; Specify the device number, the device number of the Linux device file is the primary device number and the secondary device number, the first 12 main device number, and the last 20 bits represent the secondary device number. Device number designation method: directly in code (hard coded), dynamically allocated, multiple Linux device files can have the same master device number. However, the main device number and the secondary device number of the two devices will not be the same. Use the Cdev_add function to add a character device to an array of German character devices in the kernel. Use the Class_create macro to create a struct class. Create a device file using the Device_create function
2. Uninstalling the LED-driven device files
Call three methods in turn:
Void Device_destroy (struct class *class,dev_t devt)
Void Class_destroy (struct class *cls)
Void unregister_chrdev_region (dev_t from,unsigned count)
3. Setting the register and initializing the LED driver
4. Control LED
Control LEDs via string, control LEDs via I/o command
Module parameters for 5.LED drives
If you have more than one module parameter in your Linux driver, you need to enclose these parameters in single or double quotation marks.
The LED driver can be controlled in the following two ways: The LED is controlled by a string, and the LED is controlled by a command. After the LED lamp code is written, then the LED light test. You can also use the Java Test LED light driver. After the test is complete, the LED light can be transplanted.
Seven, LED will blink for me: control of light-emitting secondary tube-learning notes