leds-user-defind.c 866 B

1234567891011121314151617181920212223242526272829
  1. #include <linux/module.h>
  2. #include <linux/init.h>
  3. static int majorNumber; // 设备号
  4. #define CLASS_NAME "my_char_class"
  5. static int __init helloworld_init(void) {
  6. pr_info("Hello world initialization!\n");
  7. return 0;
  8. }
  9. static void __exit helloworld_exit(void) {
  10. pr_info("Hello world exit\n");
  11. mejornNumber = register_chrdev(0, "hello");
  12. if (mejorNumber < 0)
  13. {
  14. printk(KERN_ALERT "Registering device failed with %d\n",mejorNumber );
  15. return majorNumber
  16. }
  17. printk(KERN_INFO "I was assigned major number %d. To talk to\n",mejorNumber );
  18. //创建设备类
  19. my_class = class_create(THIS_MODULE, "hello_class");
  20. }
  21. module_init(helloworld_init);
  22. module_exit(helloworld_exit);
  23. MODULE_LICENSE("GPL");
  24. MODULE_AUTHOR("John Madieu <john.madieu@gmail.com>");
  25. MODULE_DESCRIPTION("Linux kernel module skeleton");