through the study of this chapter, I learned to LED the driving process of the lamp, Inux Drive Send Data Control LED the light is off.
Drive Control LED Lights We need to create LED device files for drives :
First step: Use Cdev-init Initialization of functions Cdev ;
The second step: Specify the device number;
Step three: Use Cdev-add function to add a character device to a character device array in the kernel;
Fourth step: Use class-create ; macro Creation struct class ;
Fifth step: Use Device creat function to create a device file;
Uninstall LED drive device files are required to be called in turn 1 , device-destory 2 , class-destory , and 3 , unregistor-chrder-region (dev__t from,.unsigned count)
First, LED the implementation principle of the drive
Software-driven hardware: 1 , Linux Drive and I/O Memory through Ioread30 and the iowrite32 function to interact; 2 , I/O memory and hardware, memory management module is responsible for synchronization I/O the data in the memory and hardware.
Ii. Preparation of LED Driver Program
which 1 indicates open, 0 indicates off when the string length is insufficient 4 one, back with 0 Padded
1. Create the LED device driver file
( 1 ) using Cdev_init function Initialization Device Cdev
( 2 ) Specify the device number
Linux The device number of the device file is divided into the main device number and the secondary device number, before A bit master device number, rear - bit represents the secondary device number.
Device number Designation Method: Specify (hard code) directly in the code, dynamically assign
multiple Linux a device file can have the same main device number. However, the main device number and the secondary device number for two devices cannot be the same.
( 3 ) using Cdev_add function adds a character device to the kernel in a German character device array
( 4 ) using class_create Macro Creation struct class
( 5 ) using device_create function to create a device file
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
( 1 ) through string control LED Light
( 2 ) by I/O Command Control LED Light
5.LED module parameter setting of the driver
if Linux There are multiple module parameters in the drive, which need to be enclosed in single or double quotation marks.
third, testing led Drive
1. General Procedures for writing test I/O control commands
2. test LED driver with NDK
3. use Java code to test The success of LED drivers
cat/proc/devices ( get master device and its main device number )
5 , specify Word_count_read and the Word_count_write these two callback functions
The most common way to interact is to read and write device files.
6. Implementation Methods
number of words used int type variable storage, Mem the length of the array is 10000 , and the last character is " / , so the maximum length of the string with statistics is 999
7. compiling, installing, and uninstalling Linux Drivers
Iii. Testing with multiple methods Linux Drive
1. testing Linux drivers with Ubuntu Linux
2. test via native (Native)C program on Android emulator Linux Drivers
3. testing Linux drivers with the Android NDK
4. use Java code to directly manipulate device files to test Linux Drivers
5. using the s3c6410 Development Board side-Test Linux driver
6. Test The driver compilation by the Linux kernel
Iv. Use of Eclipse Development and testing Linux Driver Program
1. developing Linux drivers in Eclipse
( 1 ) Establish C Engineering
( 2 ) Establish C Source code file links
( 3 ) Settings include Path
( 4 ) Compile Linux Drive
2. testing Linux drivers in Eclipse
( 1 ) Import test-word_count.c
( 2 ) Settings include Path
( 3 ) Establish Target
( 4 ) Build Engineering
( 5 ) run the test program
Seventh chapter, LED will blink for me: Control Light Emitting diode