QT210 驱动 流水灯

来源:互联网 发布:js 三个等号 编辑:程序博客网 时间:2024/04/29 20:57

QT210 有4个led,例程创建一个work,实现每秒钟流水灯的运转

#include <linux/device.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/fs.h>#include <linux/init.h>#include <linux/delay.h>#include <asm/uaccess.h>#include <asm/irq.h>#include <asm/io.h>#include <linux/workqueue.h>static struct delayed_work my_work;//static int watercount=0;volatile unsigned long *gph0con = NULL;volatile unsigned long *gph0dat = NULL;static void waterfun(void){static int watercount=0;*gph0dat = 0x1 << ((watercount++)%4);//流水灯//printk("waterfun:watercount:%d\n",watercount);schedule_delayed_work(&my_work,msecs_to_jiffies(1000));}static int __init waterinit(void){int ret;gph0con = (volatile unsigned long *)ioremap(0xE0200c00, 16);gph0dat = gph0con + 1;*gph0con |=0x1111 ;*gph0con &=~0xf;INIT_DELAYED_WORK(&my_work,waterfun);ret = schedule_delayed_work(&my_work,msecs_to_jiffies(1000));printk("water init:ret:%d\n",ret);return 0;}static void __exit waterexit(void){cancel_delayed_work(&my_work);//destroy_wor(my_work);//_work(&my_work);iounmap(gph0con);}module_init(waterinit);module_exit(waterexit);MODULE_LICENSE("GPL");


原创粉丝点击