1.struct file_operations character Device file interface
1: staticint mpu_open (structstruct file *file)
2: {
3: return 0;
4: }
5:
6:
7:
8: staticint mpu_close (structstruct file *file)
9: {
Ten: return 0;
One : }
:
:
A : staticlongstructintlong Arg)
: {
+ : return 0;
: }
:
: static ssize_t mpu_read (structchar __user *buffer, size_t size, loff_t *off)
: {
: return 0;
: }
At :
: static ssize_t mpu_write (structconstchar __ User *buffer, size_t size, loff_t *off)
: {
: return 0;
: }
Structure
1: struct file_operations mpu_ops = {
2: . Owner = This_module,
3: . Open = Mpu_open,
4: . unlocked_ioctl = Mpu_ioctl,
5:
6: . Read = Mpu_read,
7: . Write = Mpu_write,
8: };
2. Registering the character device framework with the kernel
1: //register character device according to device number and device name
2: "Dt-mpu", &mpu_ops);
3: if (Ret < 0) {
4: PRINTK ("Unable to register character device%d!\n", 253);
5: return ret;
6: }
3. Register a class under/sys/class
1: "Dt-mpu"
2: if (!mcls) {
3: printk ("class_create dt-mpu failure...\n");
4: goto un_register;
5: }
4. Create a Dt-mpu device file in the/dev/directory
//Create a device node with the node named Device_name "Dt-mpu"); if (!dev) { PRINTK ("device_create dt-mpu failure...\n"); goto des_class; }
Create a character device-driven process in the dev directory