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