Example of device driver for LED
The order in which the characters are driven is: the first is to build the kernel module frame, then the character driver, and finally write the open and IOCTL functions to implement the LED light control driver.
The first is the LED.C code:
Implementation of Makefile:
Files generated after make:
Next is our application: led_app.c:
Compile the Build Led_app program:
Put two files: A driver file, a executable program copy to the Development Board.
First execute the driver file: Insmod Led.ko, then cat/proc/devices. View the main device number:
The drive device file is then created according to the device-driven main device number:
Then, as above, we run the program, the parameter is 1, the light is full-lit.
Finally run the above command, the lights are all out.
This is a full-drive hardware operation.
18, the implementation of LED driver program