Linux内核驱动程序

Linux内核驱动程序,linux,drivers,embedded,Linux,Drivers,Embedded,我正在学习如何为连接到USB1串行总线的卡开发一个简单的驱动程序。 我想知道内核如何理解我的设备需要映射为/dev/ebbchar。如何更改为/dev/ebbGV?如果我连接了另一个设备,为什么我不查看/dev/ebbchar,而是查看/dev/tty0? 谢谢 简而言之,内核如何理解连接到USB1的板是ebbchar或其他设备 我的驱动程序的初始化函数是: static int __init ebbchar_init(void){ printk(KERN_INFO "EBBChar: I

我正在学习如何为连接到USB1串行总线的卡开发一个简单的驱动程序。 我想知道内核如何理解我的设备需要映射为/dev/ebbchar。如何更改为/dev/ebbGV?如果我连接了另一个设备,为什么我不查看/dev/ebbchar,而是查看/dev/tty0? 谢谢 简而言之,内核如何理解连接到USB1的板是ebbchar或其他设备

我的驱动程序的初始化函数是:

static int __init ebbchar_init(void){
   printk(KERN_INFO "EBBChar: Initializing the EBBChar LKM\n");

   // Try to dynamically allocate a major number for the device -- more difficult but worth it
   majorNumber = register_chrdev(0, ebbchar, &fops);
   if (majorNumber<0){
      printk(KERN_ALERT "EBBChar failed to register a major number\n");
      return majorNumber;
   }
   printk(KERN_INFO "EBBChar: registered correctly with major number %d\n", majorNumber);

   // Register the device class
   ebbcharClass = class_create(THIS_MODULE, ebb);
   if (IS_ERR(ebbcharClass)){                // Check for error and clean up if there is
      unregister_chrdev(majorNumber, ebbchar);
      printk(KERN_ALERT "Failed to register device class\n");
      return PTR_ERR(ebbcharClass);          // Correct way to return an error on a pointer
   }
   printk(KERN_INFO "EBBChar: device class registered correctly\n");

   // Register the device driver
   ebbcharDevice = device_create(ebbcharClass, NULL, MKDEV(majorNumber, 0), NULL, DEVICE_NAME);
   if (IS_ERR(ebbcharDevice)){               // Clean up if there is an error
      class_destroy(ebbcharClass);           // Repeated code but the alternative is goto statements
      unregister_chrdev(majorNumber, ebbchar);
      printk(KERN_ALERT "Failed to create the device\n");
      return PTR_ERR(ebbcharDevice);
   }
   printk(KERN_INFO "EBBChar: device class created correctly\n"); // Made it! device was initialized
   return 0;
}
static int\uuu init ebbchar\u init(void){
printk(KERN_INFO“EBBChar:初始化EBBChar LKM\n”);
//尝试为设备动态分配一个主要号码——虽然更难,但值得
majorNumber=寄存器chrdev(0、ebbchar和fops);

如果(majorNumberWell,首先,卡在
DEVICE\u create()中的
DEVICE\u NAME
是什么
call?take file是。但是内核如何理解插入usb的设备是我这个驱动程序的设备呢?或者否?在你试图解决内核编程问题之前,我建议你从用户角度来阅读一些东西是如何工作的。这应该是有用的背景知识。