串口有意思的问题

我使用了一个PC104多串口扩展板,这些串口共用一个IRQ,为了保证串口读写,我没有采用8250驱动,而是直接对串口地址操作。在一个IRQ到来的时候首先通过串口中断寄存器判断是谁的中断,然后关闭其他中断,在此中断结束后恢复。
现在的问题是第一次运行正常,而再次运行需要重新关闭整个系统电源然后重启,否则只能从串口向外写数据,不能读数据。我怀疑是某些寄存器在程序结束的时候没有清空,因为我用的是直接对串口地址操作,不知道还需要清空哪些寄存器,谢谢

8250的几个寄存器,包括与中断相关的8259寄存器都要清一下

我现在用的串口板和网卡共享一个中断,第一次运行收发正常,再运行就不行了,网卡也不能用了,好像中断不能用了,不知道怎么回事,望那个大侠指点一二,代码明天贴上来。

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <hw/inout.h>
#include <stdarg.h>
#include <sys/neutrino.h>

#define TXR 0
#define RXR 0
#define IER 1
#define IIR 2
#define LCR 3
#define MCR 4
#define LSR 5
#define MSR 6
#define DLL 0
#define DLH 1

#define RCVRDY 0x01
#define XMTRDY 0x20
#define XMTRSR 0x40

void INIT_COM(void);
unsigned short COMBASE1,COMBASE2,COMBASE3,COMBASE4;

void WR_TO_COM(unsigned short WCOMBASE,unsigned char data2);
void RD_TO_COM(unsigned short RCOMBASE);
const sigevent *isr_handler (void *, int);
struct sigevent event;
int intid;
int IRQ=5;



int main( void )
{

COMBASE1=0x9000;
COMBASE2=0x9008;
COMBASE3=0x9010;
COMBASE4=0x9018;
INIT_COM();
SIGEV_INTR_INIT(&event);


ThreadCtl (_NTO_TCTL_IO, NULL);

intid=InterruptAttach (IRQ, isr_handler, NULL, 0, 0);
printf(“the intid is %d\n”,intid);
while(1)
{

WR_TO_COM(COMBASE1,0x11);
WR_TO_COM(COMBASE2,0x22);
WR_TO_COM(COMBASE3,0x33);
WR_TO_COM(COMBASE4,0x55);
printf(“write success!\n”);
InterruptWait (NULL, NULL);
unsigned char flag;
flag=in8(COMBASE1+0x62);
printf("%x\n",flag);
if(flag&0x0f!=0)
{
RD_TO_COM(COMBASE1);
RD_TO_COM(COMBASE2);
RD_TO_COM(COMBASE3);
RD_TO_COM(COMBASE4);
}

InterruptUnmask(IRQ, intid );


delay(1000);
}
int aa=InterruptDetach( intid );
printf(“InterruptDetach %d\n”,aa);
printf( “This is end\n” );
return EXIT_SUCCESS;
}

void INIT_COM(void)
{
ThreadCtl(_NTO_TCTL_IO, 0) ;

//COM1
out8(COMBASE1+3,0x80);//DLAB=1
out8(COMBASE1+1,0x00);
out8(COMBASE1+0,0x0c);//0c:9600;06:19200
out8(COMBASE1+3,0x03);//8,N,1
out8(COMBASE1+4, 0x0b);
out8(COMBASE1+1, 0x01);
in8(COMBASE1);
in8(COMBASE1+5);
in8(COMBASE1+6);
in8(COMBASE1+6);

//COM2:
out8(COMBASE2+3,0x80);//DLAB=1
out8(COMBASE2+1,0x00);
out8(COMBASE2+0,0x0c);//0c:9600;06:19200
out8(COMBASE2+3,0x03);//8,N,1
out8(COMBASE2+4, 0x0b);
out8(COMBASE2+1, 0x01);
in8(COMBASE2);
in8(COMBASE2+5);
in8(COMBASE2+6);
in8(COMBASE2+6);

//COM2:
out8(COMBASE3+3,0x80);//DLAB=1
out8(COMBASE3+1,0x00);
out8(COMBASE3+0,0x0c);//0c:9600;06:19200
out8(COMBASE3+3,0x03);//8,N,1
out8(COMBASE3+4, 0x0b);
out8(COMBASE3+1, 0x01);
in8(COMBASE3);
in8(COMBASE3+5);
in8(COMBASE3+6);
in8(COMBASE3+6);

//COM2:
out8(COMBASE4+3,0x80);//DLAB=1
out8(COMBASE4+1,0x00);
out8(COMBASE4+0,0x0c);//0c:9600;06:19200
out8(COMBASE4+3,0x03);//8,N,1
out8(COMBASE4+4, 0x0b);
out8(COMBASE4+1, 0x01);
in8(COMBASE4);
in8(COMBASE4+5);
in8(COMBASE4+6);
in8(COMBASE4+6);

}




void RD_TO_COM(unsigned short RCOMBASE)
{
unsigned char data1;
static unsigned char i=0;
data1=in8(RCOMBASE+LSR);

if(( data1& RCVRDY)==RCVRDY)
{
data1=in8(RCOMBASE+RXR);

printf("%x %x\n",RCOMBASE,data1);

}
}
void WR_TO_COM(unsigned short WCOMBASE,unsigned char data2)
{
unsigned char i=0;

while((in8(WCOMBASE+LSR) & XMTRSR)==0){}
out8(WCOMBASE,data2);

}
const struct sigevent * isr_handler (void *arg, int id)
{
InterruptMask(IRQ,intid );
return (&event);
}

上面就是我的串口通讯的代码,每次退出后就会造成网卡不能用,且串口也不能用了.望那位大侠指点迷津.