開發板:龍芯1B
PC:Ubuntu 13.10
本程序利用紅外線接收器觸發中斷信號,然後打印信息,紅外線接收器通過gpio控制
/*************************************************************************
> File Name: redlight_irq.c
> Author: kid
> Mail: [email protected]
> 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");