打印
[嵌入式linux]

迅为RK3588开发板helloworld驱动实验

[复制链接]
1316|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
遥寄山川|  楼主 | 2025-5-15 10:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本小节来编写一个最简单的驱动——helloworld 驱动。helloworld.c 如下(图 3-1)所示代码:

1 #include <linux/module.h>
2 #include <linux/kernel.h>
3
4 static int __init helloworld_init(void) //驱动入口函数
5 {
6 printk(KERN_EMERG "helloworld_init\r\n");//注意:内核打印用 printk 而不是 printf
7 return 0;
8 }
9
10static 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 驱动包含驱动的基本框架。我们继续往下看。

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

453

主题

460

帖子

2

粉丝