Linux Learning: Character device framework

Source: Internet
Author: User

I. system functional Framework :

U-boot: Boot kernel

Linux kernel: Launching apps

Application: Open,read,write are implemented through the C library, and the assembly is equivalent to Swi Val, which throws interrupts, invoking different handler functions (VFS) in an abnormal interrupt through the system call interface.

Two. character device driver frame :

1. Write driver: Open, read, write functions such as the implementation of:

static int Led_drv_open (struct inode *inode, struct file *file) {
PRINTK ("led_drv_open\n");
return 0;

}

static int led_drv_write (struct file *file, const char __user *buf, size_t count, loff_t* PPOs) {
PRINTK ("led_drv_write\n");
return 0;
}

2. Registration drive:

① Construction File_operations Structure:
static struct File_operation Led_drv_fops = {
. Owner = This_module,
. open = Led_drv_open,
. write = Led_drv_write,
}

② Registration Drive:
Entry function: int led_drv_init (void) {
Register_chrdev (Major, "Led_drv", &led_drv_fops); Registers the character device, major-the main device number mior-the second device number, the app calls the specific driver according to the device type and the main device number.
return 0;
}
Modifier entry function: Module_init (led_drv_init);
    
Exit Function: void Led_drv_exit (void) {
Unregister_chrdev (Major, "led_drv");
}
Modifier Exit Function: Module_exit (led_drv_exit);

Makefile:

kern_dir=/work/system/linux-2.6.22.6//locally compiled Linux source directory
All
Make-c $ (kern_dir) m= ' pwd ' modules
Clean
Make-c $ (kern_dir) m= ' pwd ' modules clean
RM-RF Modules.order
Obj-m + = LED_DRV.O

  


        

Linux Learning: Character device framework

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.