开发板:龙芯1B
PC:Ubuntu 13.10
本程序利用红外线接收器触发中断信号,然后打印信息,红外线接收器通过gpio控制
/*************************************************************************
> File Name: redlight_irq.c
> Author: kid
> Mail: 280197326@qq.com
> Created Time: 2014年03月04日 星期二 16时07分55秒
************************************************************************/
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/init.h>
#define SET_GPIO (*(volatile unsigned *)0xbfd010C4)
#define SET_IN (*(volatile unsigned *)0xbfd010D4)
#define SET_RED (*(volatile unsigned *)0xbfd010F4)
int *j = (int*)125;
int i = 0;
static irqreturn_t redlight (int k, void *p)
{
printk(KERN_ALERT "%d.receive redlight!\n",i);
i++;
return (IRQ_HANDLED);
}
static int __init redlight_init(void)
{
int result;
SET_GPIO = SET_GPIO | 0x20000000;
SET_IN = SET_IN | 0x20000000;
SET_RED = SET_RED | 0x20000000;
result = request_irq(125, redlight, IRQF_SHARED|IRQ_TYPE_LEVEL_LOW, "redlight", j); //请求中断,IRQ_TYPE_LEVEL_LOW为低电平有效
if( result!=0 ){
printk(KERN_WARNING "result=%d\nrequest_irq is fail\n",result);
}
enable_irq(125);
return 0;
}
static void __exit redlight_exit(void)
{
free_irq(125, j); //释放内存
printk(KERN_ALERT "quit!\n");
}
module_init(redlight_init);
module_exit(redlight_exit);
MODULE_LICENSE("GPL");