您的位置:首页 > 运维架构 > Linux

嵌入式Linux简单字符设备驱动程序---helloworld

2012-11-07 19:51 477 查看
/*
**$ gcc -DMODULE -D__KERNEL__ -I /usr/src/linux-2.4.20/include -c hello.c
**$ insmod hello.o   如果成功加载到内核将在终端上显示:Hello world, Linux Driver!
**$ rmmod hello.o    卸载成功的话将终端显示:             Goodbye, Linux Driver!
*/
#include <linux/module.h>
#include <linux/init.h>/* Tell the kernel I can do what */

static int __init hello_init(void)
{
printk(KERN_ALERT"Hello world, Linux Driver!\n");
return 0;
}

/* Tell the kernel stop me doing */
static void __exit hello_exit(void)
{
printk(KERN_ALERT"Goodbye, Linux Driver!\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("Dual BSD/GPL"); /* All modules need to define the LICENCE */

[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: