TQ2440 time0定时器控制led0闪烁驱动(OK).doc

上传人:hs****ma 文档编号:544324469 上传时间:2022-12-11 格式:DOC 页数:5 大小:46.51KB
返回 下载 相关 举报
TQ2440 time0定时器控制led0闪烁驱动(OK).doc_第1页
第1页 / 共5页
TQ2440 time0定时器控制led0闪烁驱动(OK).doc_第2页
第2页 / 共5页
TQ2440 time0定时器控制led0闪烁驱动(OK).doc_第3页
第3页 / 共5页
TQ2440 time0定时器控制led0闪烁驱动(OK).doc_第4页
第4页 / 共5页
TQ2440 time0定时器控制led0闪烁驱动(OK).doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《TQ2440 time0定时器控制led0闪烁驱动(OK).doc》由会员分享,可在线阅读,更多相关《TQ2440 time0定时器控制led0闪烁驱动(OK).doc(5页珍藏版)》请在金锄头文库上搜索。

1、TQ2440 time0定时器控制led0闪烁驱动mytimer.c/*基于tq2440开发板,内核2.6.30功能能实现定时器0 的中断函数。定时器的中断让led 闪烁2012年7月15日13:14:02*/#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #inclu

2、de #include #include #include #include #include #include #include #include volatile unsigned long *gpbcon = NULL;volatile unsigned long *gpbdat = NULL;volatile unsigned long *tcfg0 = NULL;/用来设置预分频volatile unsigned long *tcfg1 = NULL;/用来设置分频volatile unsigned long *tcon = NULL;/定时器控制器volatile unsigned

3、 long *tcntb0 = NULL;/计数缓冲寄存器volatile unsigned long *tcmpb0 = NULL;/比较缓冲寄存器volatile unsigned long *tcnto0 = NULL;/计数观察寄存器volatile unsigned long *gpfcon = NULL;volatile unsigned long *gpfdat = NULL;volatile unsigned long *srcpnd = NULL;volatile unsigned long *intmask = NULL;volatile unsigned long *in

4、tpnd = NULL;volatile unsigned long *intoffset = NULL;static irqreturn_t irq_interrupt(int irq, int dev_id)/*gpbcon &= (3 0 * 2);/*gpbcon |= (2 0 * 2);/设置b0 为 tout0static unsigned int irq_count;irq_count+;printk(in irq_interrupt %dn, irq_count);if(irq_count % 2)*gpbdat &= (1 5);else*gpbdat |= (1 5);r

5、eturn IRQ_RETVAL(IRQ_HANDLED);ssize_t drive_open (struct inode *inode, struct file *file)*gpbcon &= (0x3 (5 * 2) | (0x3 (6 * 2) | (0x3 (7 * 2) | (0x3 (8 * 2);/清零*gpbcon |= (0x1 (5 * 2) | (0x1 (6 * 2) | (0x1 (7 * 2) | (0x1 (8 * 2);/设置成输出request_irq(IRQ_TIMER0, irq_interrupt, IRQ_TYPE_EDGE_FALLING, TI

6、ME0, NULL);printk(-drive open ok-n);return 0;ssize_t drive_release (struct inode *inode, struct file *file)free_irq(IRQ_TIMER0, NULL);printk(-drive close ok-n);return 0;ssize_t drive_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)struct clk *clk_p; unsigned int pc

7、lk;unsigned int tcnt;printk(-drive ioctl ok-n);/定时器时钟频率=pclk /( 预分频器的值+1) / 分频器/62.5k*tcfg0 &= 0xff; /定时器0预分配清零*tcfg0 |= (50 - 1); /预分频 50*tcfg1 &= 0xf; /定时器0 mux 输入分频清零*tcfg1 |= 3; /mux 分频 16clk_p = clk_get(NULL, pclk);pclk = clk_get_rate(clk_p);tcnt = (pclk/50/16)/10;printk(pclk = %dn,pclk);printk

8、(tcnt = %dn,tcnt);*tcntb0 &= 0x0000; /16位寄存器*tcmpb0 &= 0x0000;*tcntb0 |= 1000;*tcmpb0 |= 500;printk(tcntb0 = %dn, *tcntb0);printk(tcmpb0 = %dn, *tcmpb0); *tcon &= 0x1f; /清零/printk(tcon=%dn, *tcon);msleep(10);/第一次必须手动更新*tcon |= 0xb; /关闭死区、自动重载、关反相器、手动更新TCNTB0&TCMPB0、启动定时器0/1011/printk(tcon=%dn,*tcon)

9、;msleep(10);*tcon &= 2; /清除定时器0的手动更新位printk(tcfg0 = %dn, *tcfg0);printk(tcfg1 = %dn, *tcfg1);printk(tcntb0 = %dn, *tcntb0);printk(tcmpb0 = %dn, *tcmpb0);printk(tcon = %dn, *tcon); return 0;static struct file_operations drive_ops =.owner = THIS_MODULE,.open = drive_open,.ioctl = drive_ioctl,.release

10、= drive_release,;static struct miscdevice misc = .minor = MISC_DYNAMIC_MINOR,.name = mytimer,.fops = &drive_ops,;static int _init init_drive(void) int ret; ret = misc_register(&misc);gpbcon = (volatile unsigned long *)ioremap(0x56000010,32);gpbdat = (volatile unsigned long *)ioremap(0x56000014, 32);

11、tcfg0 = (volatile unsigned long *)ioremap(0x51000000, 4);tcfg1 = (volatile unsigned long *)ioremap(0x51000004, 4);tcon = (volatile unsigned long *)ioremap(0x51000008, 4);tcntb0 = (volatile unsigned long *)ioremap(0x5100000c, 4);tcmpb0 = (volatile unsigned long *)ioremap(0x51000010, 4);tcnto0 = (vola

12、tile unsigned long *)ioremap(0x51000014, 4);gpfcon = (volatile unsigned long *)ioremap(0x56000050, 4); gpfdat = (volatile unsigned long *)ioremap(0x56000054, 4); srcpnd = (volatile unsigned long *)ioremap(0x4a000000, 4); intmask = (volatile unsigned long *)ioremap(0x4a000008, 4); intpnd = (volatile unsigned long *)ioremap(0x4a000010, 4); intoffset = (volatile unsigned long *)ioremap(0x4a000014, 4);printk(-drive button init ok-n); ret

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号