📄 isr_test.c
字号:
/* ISR_test.c */
/*********************************************************************
** 文件描述 :SUMSUNG ARM 4510 EVM板的外中断测试程序,
** 当EINT0 按下时,LED0点亮
** 当EINT1 按下时,LED1点亮
** 当EINT2 按下时,LED2点亮
** 当EINT3 按下时,LED3点亮
** 使 用 :建立downloadable 工程,添加本文件编译生成.o文件下载到目标机中
** 在windSh中敲入IsrTest()回车,按ENIT0按键就会产生中断,并在控制
** 台中显示相应的信息
**********************************************************************/
#include "vxWorks.h"
#include "intLib.h"
#include "taskLib.h"
#include "iv.h"
#include "logLib.h"
/*function prototype*/
void interruptHandler(int);
void interruptCatcher(void);
/*globals */
#define INTERRUPT_NUM 2
#define INTERRUPT_LEVEL 65
#define ITER1 40
#define LONG_TIME 1000000
#define PRIORITY 100
#define ONE_SENCOND 100
/* interrupt intnum */
#define INT_LVL_EXTINT0 0 /* External Interrupt0 */
#define INT_LVL_EXTINT1 1 /* External Interrupt1 */
#define INT_LVL_EXTINT2 2 /* External Interrupt2 */
#define INT_LVL_EXTINT3 3 /* External Interrupt3 */
#define INT_VEC_EXTINT0 IVEC_TO_INUM(INT_LVL_EXTINT0) /* External Interrupt0*/
#define INT_VEC_EXTINT1 IVEC_TO_INUM(INT_LVL_EXTINT1) /* External Interrupt1*/
#define INT_VEC_EXTINT2 IVEC_TO_INUM(INT_LVL_EXTINT2) /* External Interrupt2*/
#define INT_VEC_EXTINT3 IVEC_TO_INUM(INT_LVL_EXTINT3) /* External Interrupt3*/
#define IOPMOD *(unsigned *)(0x3ff5000)
#define IOPCON *(unsigned *)(0x3ff5004)
#define IOPDATA *(unsigned *)(0x3ff5008)
#define INTMODE *(unsigned *)(0x3ff4000) /*set irq=0 firq=1*/
#define INTPEND *(unsigned *)(0x3ff4004) /*0 clear pend */
#define INTMASK *(unsigned *)(0x3ff4008) /*1 disable 0 enable*/
#define INTOFFSET *(unsigned *)(0x3ff4024)
#define INTPENDTST *(unsigned *)(0x3ff402c)
/********************************************************************
** 函数名称 : IsrTest
** 功 能 : 启动中断捕捉任务
** 入 口 : 无
** 出 口 : 无
** 返 回 : 无。
** 被调函数 : taskSpawn
** 调用函数 :
** 版 本 : V1.0
** 创建日期 : 2006.02.10
** 作 者 :zhyg
** 修改纪录 :
*********************************************************************/
void IsrTest(void)
{
int i,j,taskId,priority;
STATUS taskAlive;
IOPMOD|=0x0ff; /*led control reg ,set i/o output mode*/
if((taskId=taskSpawn("interruptCatcher",PRIORITY,0x100,20000,(FUNCPTR)interruptCatcher,0,0,0,0,0,0,0,0,0,0))==ERROR)
logMsg("taskSpawn interCatcher failed\n",0,0,0,0,0,0);
for(i=0;i<ITER1;i++)
{
taskDelay(ONE_SENCOND);
if((taskAlive=taskIdVerify(taskId))==OK)
{
logMsg("++++++++interrupt generated\n",0,0,0,0,0,0);
/*if(sysBusIntGen(INTERRUPT_NUM,INTERRUPT_LEVEL)==ERROR)
logMsg("interrupt not generated\n",0,0,0,0,0,0);*/
}
else
break;
}
logMsg("\n*****************interruptGenerator exited **********\n\n\n\n",0,0,0,0,0,0);
}
/*********************************************************************
** 函数名称 : interruptCatcher
** 功 能 : 中断捕捉任务,中断挂接
** 入 口 : 无
** 出 口 : 无
** 返 回 : 无。
** 被调函数 : intConnect() intEnable()
** 调用函数 :
** 版 本 : V1.0
** 创建日期 : 2006.02.10
** 作 者 : zhyg
** 修改纪录 :
*********************************************************************/
void interruptCatcher(void)
{
int i,j;
STATUS connected;
IOPCON|=0x0b5ad6; /*4个外中断均打开 */
/*INTMODE&=0xfffffff0;
INTMASK&=0xfffffff0;
INTPEND&=0xfffffff0;*/
/* irq0---EINT0*/
/* irq1---EINT1*/
if((connected=intConnect ( ( VOIDFUNCPTR * )INUM_TO_IVEC(INT_LVL_EXTINT0), (VOIDFUNCPTR)interruptHandler, 0) )==ERROR)
logMsg("intConnect failed\n",0,0,0,0,0,0);
/*使能这中断0 */
if(intEnable (INT_LVL_EXTINT0)==ERROR)
logMsg("intEnable fail \n",0,0,0,0,0,0);
if((connected=intConnect ( ( VOIDFUNCPTR * )INUM_TO_IVEC(INT_LVL_EXTINT1), (VOIDFUNCPTR)interruptHandler, 1 ) )==ERROR)
logMsg("intConnect failed\n",0,0,0,0,0,0);
/*使能这中断1 */
if(intEnable (INT_LVL_EXTINT1)==ERROR)
logMsg("intEnable fail \n",0,0,0,0,0,0);
if((connected=intConnect ( ( VOIDFUNCPTR * )INUM_TO_IVEC(INT_LVL_EXTINT2), (VOIDFUNCPTR)interruptHandler, 2) )==ERROR)
logMsg("intConnect failed\n",0,0,0,0,0,0);
/*使能这中断2 */
if(intEnable (INT_LVL_EXTINT2)==ERROR)
logMsg("intEnable fail \n",0,0,0,0,0,0);
if((connected=intConnect ( ( VOIDFUNCPTR * )INUM_TO_IVEC(INT_LVL_EXTINT3), (VOIDFUNCPTR)interruptHandler, 3 ) )==ERROR)
logMsg("intConnect failed\n",0,0,0,0,0,0);
/*使能这中断3 */
if(intEnable (INT_LVL_EXTINT3)==ERROR)
logMsg("intEnable fail \n",0,0,0,0,0,0);
for(i=0;i<ITER1;i++)
{
for(j=0;j<LONG_TIME;j++);
logMsg("Normal processing in interruptCatcher\n",0,0,0,0,0,0);
}
logMsg("\n++++++++++++interruptCatcher exited +++++\n",0,0,0,0,0,0);
}
/*********************************************************************
** 函数名称 : interruptHandler
** 功 能 : 中断服务程序,4个外中断挂接到本服务程序上,通过arg 区分
** 入 口 : int arg 识别外中断的号
** 出 口 : 无
** 返 回 : 无。
** 被调函数 : logMsg();
** 调用函数 :
** 版 本 : V1.0
** 创建日期 : 2006.02.10
** 作 者 : zhyg
** 修改纪录 :
*********************************************************************/
void interruptHandler(int arg)
{
int i;
switch(arg)
{
case 0:
IOPDATA=~(1);
break;
case 1:
IOPDATA=~(1<<1);
break;
case 2:
IOPDATA=~(1<<2);
break;
case 3:
IOPDATA=~(1<<3);
break;
default:
IOPDATA=0xff;
}
logMsg("--------------interrupt caught%d\n",arg,0,0,0,0,0);
for(i=0;i<5;i++)
logMsg("interrupt processing\n",0,0,0,0,0,0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -