相信很多人都看过以下这段代码:
/* includes */
#include "vxWorks.h"
#include "intLib.h"
#include "taskLib.h"
#include "sysLib.h"
#include "logLib.h"
/* function prototypes */
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 IVEC_TO_INUM(intVec) ((int) (intVec))
#define INUM_TO_IVEC(intNum) ((VOIDFUNCPTR *) (intNum))
void interruptGenerator(void) /* task to generate the SIGINT signal */
{
int i, j, taskId;
STATUS taskAlive;
if ((taskId = taskSpawn("interruptCatcher", PRIORITY, 0x100, 20000, (FUNCPTR)
interruptCatcher, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) == ERROR)
logMsg("taskSpawn interruptCatcher failed\n", 0, 0, 0, 0, 0, 0);
for (i = 0; i < ITER1; i++)
{
taskDelay(1); /* suspend interruptGenerator */
/* check to see if interruptCatcher task is alive! */
if ((taskAlive = taskIdVerify(taskId)) == OK)
{
logMsg("++++++++++++++++++++++++++Interrupt generated\n", 0, 0, 0, 0, 0,
0);
/* generate hardware interrupt 2 */
if ((sysBusIntGen(INTERRUPT_NUM, INTERRUPT_LEVEL)) == ERROR)
logMsg("Interrupt not generated\n", 0, 0, 0, 0, 0, 0);
}
else
/* interruptCatcher is dead */
{
logMsg("interruptCatcher is dead\n", 0,0,0,0,0,0);
break;
}
}
logMsg("\n***************interruptGenerator Exited***************\n\n\n\n", 0,
0, 0, 0, 0, 0);
}
void interruptCatcher(void) /* task to handle the interrupt */
{
int i, j;
STATUS connected;
/* connect the interrupt vector, INTERRUPT_LEVEL, to a specific interrupt
handler routine ,interruptHandler, and pass an argument, i */
if ((connected = intConnect(INUM_TO_IVEC(INTERRUPT_LEVEL), (VOIDFUNCPTR)
interruptHandler, i)) == ERROR)
logMsg("intConnect failed\n", 0, 0, 0, 0, 0, 0);
for (i = 0; i < ITER1; i++)
{
taskDelay(1);
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);
}
void interruptHandler(int arg) /* signal handler code */
{
int i;
logMsg("-------------------------------interrupt caught\n", 0, 0, 0, 0, 0, 0);
for (i = 0; i < 5; i++)
logMsg("interrupt processing\n", 0, 0, 0, 0, 0, 0);
}
程序是在simnt上跑的。当调用sysBusIntGen产生中断时会出错,无法激活ISR,问题出在哪儿呢,望高手指点,谢谢!