1: driver module loading and unloading of
1.1: module_init (xxx_init); // registration module loading functions, drivers are loaded through insmod or modprobe command time, xxx_init this function is called.
例如: insmod chrdevtest.ko; modprobe chrdevtest.ko
1.2: module_exit (xxx_exit); // registration module unload function, load the driver when, xxx_init this function is called by rmmod or modprobe -r command.
例如: rmmod chrdevtest.ko; modprobe -r chrdevtest.ko
2: Character device registration and cancellation
2.1:static inline int register_chrdev(unsigned int major, const char*name,const struct file_operations*fops);
Parameter No. 1 master device; device name parameter 2; 3 operating parameters of a set of functions; in general called xxx_init
2.2:static inline void unregister_chrdev(unsigned int major, const char*name);
No. 1 is the primary device parameters; 2 parameters for the device name; in general call xxx_exit
3: The specific operation function for device
3.1: depends on the specific implementation
4: device number assigned
4.1: device number (that is, unsigned int type) divided into the main device number (12 bits), minor (No. 20)
4.2: static assignment: when enrolling the device, specify the major device number; call unregister_chrdev cancellation of this device number and the device when you log off equipment
4.3: Dynamic allocation: Before registering the device, call
alloc_chrdev_region, the system will assign a device number was not used; called when the logout device
unregister_chrdev_region recovery device number
5: Create a device node files
5.1:
Driver loaded successfully need to create a device node file a corresponding application in the / dev directory is used to perform operations on specific devices by operating the device node files
For example:
the mknod / dev / C 200 is 0 chrdevtest