QT210 驱动 流水灯

本文介绍了一个基于QT210平台的简单程序实例,该程序通过使用工作队列(workqueue)机制实现了每秒钟一次的流水灯效果。具体而言,通过对GPIO寄存器的操作控制了四个LED的状态变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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");


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值