在学习 C 语言或者其他语言的时候,我们通常是打印一句“helloworld”来开启编程世界的大门。学习驱动程序编程亦可以如此,使用 helloworld 作为我们的第一个驱动程序。 接下来开始编写第一个驱动程序—helloworld。 本小节来编写一个最简单的驱动——helloworld 驱动。helloworld.c 如下(图 3-1)所示代码: 1 #include 2 #include 3 4 static int __init helloworld_init(void) //驱动入口函数 5 { 6 printk(KERN_EMERG "helloworld_init\r\n");//注意:内核打印用 printk 而不是 printf 7 return 0; 8 } 9 10 static void __exit helloworld_exit(void) //驱动出口函数 11 { 12 printk(KERN_EMERG "helloworld_exit\r\n"); 13 } 14 15 module_init(helloworld_init); //注册入口函数 16 module_exit(helloworld_exit); //注册出口函数 17 MODULE_LICENSE("GPL v2"); //同意 GPL 开源协议 18 MODULE_AUTHOR("topeet"); //作者信息 看似非常简单的 helloworld 驱动代码,却五脏俱全。一个简单的 helloworld 驱动包含驱动的基本框架。 |
807 浏览 0 评论
迅为RK3568开发板helloworld 驱动实验-驱动编写
564 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡-platform总线驱动简单示例
795 浏览 0 评论
智能配电新纪元:基于飞凌嵌入式T536核心板的DTU解决方案
1033 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡-Linux系统中的中断之按键中断驱动
1685 浏览 0 评论