我的目标机是pentium3,从串口设备(接COM1)读数据,使用串口调试精灵每秒钟发一次数,我想通过中断方式读取数据,每来一个数据我就中断一次。用了二进制信号量来同步中断和接受任务,中断服务程序中只有semGive(semRecv ),在tyRecv( )里面用semTake(semRecv )。问题是中断服务程序执行了,在接收任务中的信号量获取不成功。程序如下:
/*includes*/ #include "vxworks.h" #include "ioLib.h" #include "stdio.h" #include "selectLib.h" #include "errnoLib.h" #include "intLib.h" #include "taskLib.h" #include "logLib.h" #include "string.h" #include "arch/i86/ivI86.h" #include "semLib.h" /*function status*/ void interruptHandler(); int tyRecv(int,SEM_ID);
/* globals */ #define INT_NUM_IRQ0 0x20 #define COM1_INT_LVL 0x04 #define INT_NUM_COM1 (INT_NUM_IRQ0 + COM1_INT_LVL) #define RECV_PRIORITY 200 #define STACK_SIZE 1024*40 #define BUF_SIZE 1024 SEM_ID semRecv; /*main function*/ int gpsmain( ) { int taskId; STATUS connected; /*open COM1*/ int SerialDevFd=open("/tyCo/0",O_RDWR,0); if(ERROR==SerialDevFd) { logMsg("open_com1:Unable to open/tyCo/0",0,0,0,0,0,0); return 0; }
if(ERROR==ioctl(SerialDevFd,FIOSETOPTIONS,OPT_RAW)) { logMsg("can not set tty options!\n",0,0,0,0,0,0); return 0; }
/*Set baudrate*/ if(ERROR==ioctl(SerialDevFd,FIOBAUDRATE,38400)) { logMsg("can not set BAUDRATE!\n",0,0,0,0,0,0); return 0; } /*flush the buffer*/ if(ERROR==ioctl(SerialDevFd,FIOFLUSH,0)) { logMsg("can not flush the buffer!\n",0,0,0,0,0,0); return 0; } semRecv=semBCreate(SEM_Q_FIFO,SEM_EMPTY);
intConnect(INUM_TO_IVEC(INT_NUM_COM1),(VOIDFUNCPTR)interruptHandler,semRecv); sysIntEnablePIC(COM1_INT_LVL);
/*Start receiving task*/ if((taskId=taskSpawn("recv",RECV_PRIORITY,0,STACK_SIZE,(FUNCPTR)tyRecv,SerialDevFd,0,0,0,0,0,0,0,0,0))==ERROR) logMsg("taskSpawn tyRecv failed!",0,0,0,0,0,0); }
/*receive data routine*/ int tyRecv(int SerialDevFd,SEM_ID semRecv) { int length=0; char rece_buf[BUF_SIZE]; char destin_buff[BUF_SIZE]; for(length=0;length<1024;length++) { if(semTake(semRecv,WAIT_FOREVER)==ERROR) { logMsg("sem take failed\n",0,0,0,0,0,0); return; }
if (NULL!=read(SerialDevFd,rece_buf,1)) printf("%s",rece_buf); if (length==1023) { bcopyBytes(rece_buf,destin_buff,BUF_SIZE); length=0; }
/*taskDelay(WAIT_FOREVER);*/ } return; }
/*interrupt service routine*/ void interruptHandler( ) { int level=intLock(); /*logMsg("acknowledging interrupt!\n",0,0,0,0,0,0);*/ if(semGive(semRecv)==OK) {logMsg("give Recv sem OK!",0,0,0,0,0,0); return ; } intUnlock(level); }
向各位高手请教!小弟不胜感激