我想通过中断接收数据,一台机器是windows一台是qnx。在windows运行一个串口调试程序,在qnx运行我写的程序,但是只要windows那边一发送,qnx就死机!而且什么也接不到!实在想不明白,请指点迷津呀!很急的!下面是我的程序:
#include
#define BUFFLEN 1024
void InitCOM();
void OpenPort();
void ClosePort();
unsigned char read_char();
const struct sigevent *asyncint (void *arg, int id);
unsigned char Buffer[BUFFLEN];
int buffin=0;
int buffout=0;
main()
{
unsigned char unChar;
short bExit_Flag=0;
OpenPort();
do
{
if(tcischars(1)>0)
{
unChar=getchar();
switch (unChar)
{
case 0x1B:
bExit_Flag = 1;
break;
//You may want to handle other keys here
}
}
unChar = read_char();
if (unChar != 0xff)
{
fprintf(stdout,"%c",unChar);
}
} while (!bExit_Flag);
ClosePort();
}
void OpenPort()
{
unsigned char ucTemp;
InitCOM();
InterruptDisable();
in8(0x3f8);
in8(0x3fe);
in8(0x3fb);
in8(0x3fa);
out8(0x3fc,0x08|0x0b);
out8(0x3f9,0x01);
ucTemp=in16(0x21)&0xef;
out8(0x21,ucTemp);
InterruptAttach(4,asyncint,NULL, 0, 0);
InterruptEnable();
}
const struct sigevent *asyncint (void *arg, int id)
{
Buffer[buffin++] =in8(0x3f8);
if (buffin >= BUFFLEN)
buffin=0;
out8(0x20,0x20);
}
void ClosePort(void)
{
InterruptDisable();
out8(0x3f9,0x00);
out8(0x3fc,0x00);
out8(0x21,in8(0x21)&0x10);
InterruptEnable();
}
void InitCOM()
{
ThreadCtl (_NTO_TCTL_IO, NULL);
out8(0x3fb,0x80);
out8(0x3f8,0x0C);
out8(0x3f9,0x00);
out8(0x3fb,0x03);
out8(0x3fc,0x08|0x0b);
out8(0x3f9,0x01);
}
unsigned char read_char()
{
unsigned unch;
if(buffout != buffin)
{
unch = Buffer[buffout];
buffout++;
if(buffout >= BUFFLEN)
buffout=0;
return(unch);
}
else
return(0xff);
}