Embedded Linux Driver Development case Flow--led drive __linux

Source: Internet
Author: User

This article is mainly to a simple LED-driven development process, to spy on the Linux driver development.

Basic process:

1. Write driver files xxxx.c

The main purpose of this file is to initialize the device hardware, mainly Xxx_init (), which also includes the registration of the device.

To initialize the file_operations structure, this initialization is the core, in fact, to find the mapping function of Open.write.read function.

The compilation of various mapping functions, such as Xxx_open (), Xxxx_write (), Xxx_read (), etc.

2. After the completion of the driver file, put the file into the "kernel", the path is Linux-2.6.xxx/driver/char (depending on the device type, choose character or block type). This example is clearly a character-type device.

3. Add one line to the/drivers/char/makefile:

Obj-m + = XXXX.O (xxxx is the driver file name in Process 1)

4. Execute the "Make modules" command under the kernel directory to generate Xxx.ko under/drivers/char

5. Download the Xxx.ko to the/LIB/MODULES/2.6.XXX directory of the Development Board equipment.

6. Execute "modprobe xxx" to load the driver module into the Linux kernel of the Development Board. If you want to uninstall the driver module, you can execute the command "Rmmod xxx".

7. Use the command Mknod to create a device file in the Development Board. This is particularly important, which is equivalent to creating a "handle" or "path" for the driver file, so that when the application wants to use the drive, it needs to open the corresponding device with open, and the path in open is the handle.

Command: Mknod name {b | c} Major Minor, where name is the device name, B or C is the device type, Major is the primary device number, and Minor is the secondary device number. For example: Mknod/dev/leds C 231 0

8. At this point, the driver has been developed, if you want to use the driver, you need to develop applications, such as TEST.C, in test mainly to open the corresponding device, and then use the corresponding device.

Command: Open (constchar*pathname,intflags); You can see from the name pathname is the device path, intflags is the open type. Then flow 7, for example: open ("/dev/leds", 0);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.