简单的android驱动-helloworld

2018-11-30  本文已影响24人  Havoc_Zhang

简单的android驱动--helloworld

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h> 
#include <linux/delay.h>

static int __init hello_init(void)
{
    int i;
    for(i=0;i<=10;i++)
    {
    printk(KERN_ALERT"~~~~~~~~~~~~~~~~~~~~~~~~Hello world~~~~~~~~~~~~~~~~~~~~~~~~ %d\n",i);
    mdelay(1000);
    }
return 0;
}

static void __exit hello_exit(void)
{
    printk("Exit Hello world\n");
}

subsys_initcall(hello_init);
module_exit(hello_exit);

MODULE_AUTHOR("HraychQJ");
MODULE_DESCRIPTION("hello world");
MODULE_LICENSE("GPL");

这段代码实现的功能是,在启动时连续打印10条helloworld

config HELLO
    tristate "Hello world"
    default n

Makefile

# LED Core
obj-y       += hello.o

Kconfig source "drivers/hello/Kconfig" Makefile obj-y += hello/

如果烧写完成后发现并没有开机打印helloworld,检查hello文件夹下是否生成了.o文件,没有生成的话说明没有编译进内核。

另附 如何查看串口打印log

windows下使用putty可查看板子的log信息。

上一篇 下一篇

猜你喜欢

热点阅读