按键中断实例
下面以按键中断为例,简介 SyixOS 下的中断编程。
#define __SYLIXOS_KERNEL
#include <SylixOS.h>
#include <module.h>
#include <linux/compat.h>
#define GPIO_NUM 13
static INT LW_IRQ = 0;
static irqreturn_t __doIsr (PVOID pvArg, ULONG iVector)
{
API_GpioClearIrq(GPIO_NUM); /* 清中断 */
return LW_IRQ_HANDLED;
}
int module_init (void)
{
INT iRet;
iRet = API_GpioRequestOne(GPIO_NUM, LW_GPIOF_IN, "intIn");
/* 下降沿触发中断 */
if (iRet != ERROR_NONE) {
printk("GPIO_NUM Request faile!\n");
}
iRet = API_GpioRequestOne(11, LW_GPIOF_OUT_INIT_LOW, "intIn1");
if (iRet != ERROR_NONE) {
printk("GPIO_11 Request faile!\n");
}
LW_IRQ = API_GpioSetupIrq(GPIO_NUM, LW_FALSE, 0);
API_InterVectorConnect(LW_IRQ,
(PINT_SVR_ROUTINE)__doIsr,
(PVOID)LW_NULL,
"isr");
API_InterVectorEnable(LW_IRQ); /* 中断使能 */
return 0;
}
void module_exit (void)
{
API_GpioFree(GPIO_NUM); /* GPIO管脚释放 */
API_InterVectorDisable(LW_IRQ);
}