📄 tl16c554_linux.c
字号:
} else{ //set LCR.8BIT,1STOP,ODDPARITY,选择特殊寄存器 *(volatile unsigned char *)(tl0A.LCR) = 0x83|byMode; } //特殊寄存器已打开,设置BPS *(volatile unsigned char *)(tl0A.DLL) = BAUDBASE/nBaud; //高位 *(volatile unsigned char *)(tl0A.DLM) = 0x00; if(byMode&0x80){ *(volatile unsigned char *)(tl0A.LCR) = 0x02|(byMode&0x7f);//7 bit } else{ //set LCR.8BIT,1STOP,ODDPARITY,选择特殊寄存器 *(volatile unsigned char *)(tl0A.LCR) = 0x03|byMode; } //空读一次 byRx = *(volatile unsigned char *)(tl0A.RBR); //读空 i=0; while(1){ //检查接收状态 byRx = *(volatile unsigned char *)(tl0A.LSR); if(byRx&0x01){ byRx = *(volatile unsigned char *)(tl0A.RBR); } else break; //防止死循环 i++; if(i > 4096)//每个UART最多只能缓存16个字节 break; } tl0A.sInited = 1;}void Init_TL0B(int nBaud, unsigned char byMode){ volatile unsigned char byRx; int i; if(0 != tl0B.sInited){ iounmap((void *) (tl0B.pbyBase0)); iounmap((void *) (tl0B.pbyBase1)); } tl0B.pbyBase0 = (unsigned char *)ioremap_nocache(tl0B.nAddress0, 4); tl0B.pbyBase1 = (unsigned char *)ioremap_nocache(tl0B.nAddress1, 4); tl0B.RBR = (int)(tl0B.pbyBase0); tl0B.THR = (int)(tl0B.pbyBase0); tl0B.LSR = (int)(tl0B.pbyBase1+1); tl0B.MSR = (int)(tl0B.pbyBase1+2); tl0B.LCR = (int)(tl0B.pbyBase0+3); tl0B.FCR = (int)(tl0B.pbyBase0+2); tl0B.MCR = (int)(tl0B.pbyBase1); tl0B.DLL = (int)(tl0B.pbyBase0); tl0B.DLM = (int)(tl0B.pbyBase0+1); tl0B.IER = (int)(tl0B.pbyBase0+1); tl0B.SPR = (int)(tl0B.pbyBase1+3); tl0B.IIR = (int)(tl0B.pbyBase0+2); tl0B.sRecvHead = 0; tl0B.sRecvTail = 0; tl0B.sSendHead = 0; tl0B.sSendTail = 0; //IER //接收保持和中断允许 *(volatile unsigned char *)(tl0B.IER) = 0x01;//0x05; //FIFO控制器 //set FCR.FIFO允许,RXD复位,TXD复位,DMAmode=1,触发为14 *(volatile unsigned char *)(tl0B.FCR) = 0xcf; for(i=0; i<100; i++); //set FCR.RXD复位,TXD复位 *(volatile unsigned char *)(tl0B.FCR) = 0xc9; //Modem状态 //set MCR.中断A-D开 *(volatile unsigned char *)(tl0B.MCR) = 0x08; if(byMode&0x80){ *(volatile unsigned char *)(tl0B.LCR) = 0x82|(byMode&0x7f);//7 bit } else{ //set LCR.8BIT,1STOP,ODDPARITY,选择特殊寄存器 *(volatile unsigned char *)(tl0B.LCR) = 0x83|byMode; } //特殊寄存器已打开,设置BPS *(volatile unsigned char *)(tl0B.DLL) = BAUDBASE/nBaud; //高位 *(volatile unsigned char *)(tl0B.DLM) = 0x00; if(byMode&0x80){ *(volatile unsigned char *)(tl0B.LCR) = 0x02|(byMode&0x7f);//7 bit } else{ //set LCR.8BIT,1STOP,ODDPARITY,选择特殊寄存器 *(volatile unsigned char *)(tl0B.LCR) = 0x03|byMode; } //空读一次 byRx = *(volatile unsigned char *)(tl0B.RBR); //读空 i=0; while(1){ //检查接收状态 byRx = *(volatile unsigned char *)(tl0B.LSR); if(byRx&0x01){ byRx = *(volatile unsigned char *)(tl0B.RBR); } else break; //防止死循环 i++; if(i > 4096)//每个UART最多只能缓存16个字节 break; } tl0B.sInited = 1;}void Init_TL0C(int nBaud, unsigned char byMode){ volatile unsigned char byRx; int i; if(0 != tl0C.sInited){ iounmap((void *) (tl0C.pbyBase0)); iounmap((void *) (tl0C.pbyBase1)); } tl0C.pbyBase0 = (unsigned char *)ioremap_nocache(tl0C.nAddress0, 4); tl0C.pbyBase1 = (unsigned char *)ioremap_nocache(tl0C.nAddress1, 4); tl0C.RBR = (int)(tl0C.pbyBase0); tl0C.THR = (int)(tl0C.pbyBase0); tl0C.LSR = (int)(tl0C.pbyBase1+1); tl0C.MSR = (int)(tl0C.pbyBase1+2); tl0C.LCR = (int)(tl0C.pbyBase0+3); tl0C.FCR = (int)(tl0C.pbyBase0+2); tl0C.MCR = (int)(tl0C.pbyBase1); tl0C.DLL = (int)(tl0C.pbyBase0); tl0C.DLM = (int)(tl0C.pbyBase0+1); tl0C.IER = (int)(tl0C.pbyBase0+1); tl0C.SPR = (int)(tl0C.pbyBase1+3); tl0C.IIR = (int)(tl0C.pbyBase0+2); tl0C.sRecvHead = 0; tl0C.sRecvTail = 0; tl0C.sSendHead = 0; tl0C.sSendTail = 0; //IER //接收保持和中断允许 *(volatile unsigned char *)(tl0C.IER) = 0x01;//0x05; //FIFO控制器 //set FCR.FIFO允许,RXD复位,TXD复位,DMAmode=1,触发为14 *(volatile unsigned char *)(tl0C.FCR) = 0xcf; for(i=0; i<100; i++); //set FCR.RXD复位,TXD复位 *(volatile unsigned char *)(tl0C.FCR) = 0xc9; //Modem状态 //set MCR.中断A-D开 *(volatile unsigned char *)(tl0C.MCR) = 0x08; if(byMode&0x80){ *(volatile unsigned char *)(tl0C.LCR) = 0x82|(byMode&0x7f);//7 bit } else{ //set LCR.8BIT,1STOP,ODDPARITY,选择特殊寄存器 *(volatile unsigned char *)(tl0C.LCR) = 0x83|byMode; } //特殊寄存器已打开,设置BPS *(volatile unsigned char *)(tl0C.DLL) = BAUDBASE/nBaud; //高位 *(volatile unsigned char *)(tl0C.DLM) = 0x00; if(byMode&0x80){ *(volatile unsigned char *)(tl0C.LCR) = 0x02|(byMode&0x7f);//7 bit } else{ //set LCR.8BIT,1STOP,ODDPARITY,选择特殊寄存器 *(volatile unsigned char *)(tl0C.LCR) = 0x03|byMode; } //空读一次 byRx = *(volatile unsigned char *)(tl0C.RBR); //读空 i=0; while(1){ //检查接收状态 byRx = *(volatile unsigned char *)(tl0C.LSR); if(byRx&0x01){ byRx = *(volatile unsigned char *)(tl0C.RBR); } else break; //防止死循环 i++; if(i > 4096)//每个UART最多只能缓存16个字节 break; } tl0C.sInited = 1;}void Init_TL0D(int nBaud, unsigned char byMode){ volatile unsigned char byRx; int i; if(0 != tl0D.sInited){ iounmap((void *) (tl0D.pbyBase0)); iounmap((void *) (tl0D.pbyBase1)); } tl0D.pbyBase0 = (unsigned char *)ioremap_nocache(tl0D.nAddress0, 4); tl0D.pbyBase1 = (unsigned char *)ioremap_nocache(tl0D.nAddress1, 4); tl0D.RBR = (int)(tl0D.pbyBase0); tl0D.THR = (int)(tl0D.pbyBase0); tl0D.LSR = (int)(tl0D.pbyBase1+1); tl0D.MSR = (int)(tl0D.pbyBase1+2); tl0D.LCR = (int)(tl0D.pbyBase0+3); tl0D.FCR = (int)(tl0D.pbyBase0+2); tl0D.MCR = (int)(tl0D.pbyBase1); tl0D.DLL = (int)(tl0D.pbyBase0); tl0D.DLM = (int)(tl0D.pbyBase0+1); tl0D.IER = (int)(tl0D.pbyBase0+1); tl0D.SPR = (int)(tl0D.pbyBase1+3); tl0D.IIR = (int)(tl0D.pbyBase0+2); tl0D.sRecvHead = 0; tl0D.sRecvTail = 0; tl0D.sSendHead = 0; tl0D.sSendTail = 0; //IER //接收保持和中断允许 *(volatile unsigned char *)(tl0D.IER) = 0x01;//0x05; //FIFO控制器 //set FCR.FIFO允许,RXD复位,TXD复位,DMAmode=1,触发为14 *(volatile unsigned char *)(tl0D.FCR) = 0xcf; for(i=0; i<100; i++); //set FCR.RXD复位,TXD复位 *(volatile unsigned char *)(tl0D.FCR) = 0xc9; //Modem状态 //set MCR.中断A-D开 *(volatile unsigned char *)(tl0D.MCR) = 0x08; if(byMode&0x80){ *(volatile unsigned char *)(tl0D.LCR) = 0x82|(byMode&0x7f);//7 bit } else{ //set LCR.8BIT,1STOP,ODDPARITY,选择特殊寄存器 *(volatile unsigned char *)(tl0D.LCR) = 0x83|byMode; } //特殊寄存器已打开,设置BPS *(volatile unsigned char *)(tl0D.DLL) = BAUDBASE/nBaud; //高位 *(volatile unsigned char *)(tl0D.DLM) = 0x00; if(byMode&0x80){ *(volatile unsigned char *)(tl0D.LCR) = 0x02|(byMode&0x7f);//7 bit } else{ //set LCR.8BIT,1STOP,ODDPARITY,选择特殊寄存器 *(volatile unsigned char *)(tl0D.LCR) = 0x03|byMode; } //空读一次 byRx = *(volatile unsigned char *)(tl0D.RBR); //读空 i=0; while(1){ //检查接收状态 byRx = *(volatile unsigned char *)(tl0D.LSR); if(byRx&0x01){ byRx = *(volatile unsigned char *)(tl0D.RBR); } else break; //防止死循环 i++; if(i > 4096)//每个UART最多只能缓存16个字节 break; } tl0D.sInited = 1;}//TL16C554的接收unsigned char TL0A_Rxd(void){ volatile unsigned char byRx; volatile unsigned char bySt; int nRxCnt = 0; while(nRxCnt < 512){ bySt = *(volatile unsigned char *)(tl0A.LSR);//检查接收状态 if(bySt&0x01){//数据就绪 byRx = *(volatile unsigned char *)(tl0A.RBR); pushTL0ARX(byRx); } else break; nRxCnt++; } return byRx;}unsigned char TL0B_Rxd(void){ volatile unsigned char byRx; volatile unsigned char bySt; int nRxCnt = 0; while(nRxCnt < 512){ bySt = *(volatile unsigned char *)(tl0B.LSR);//检查接收状态 if(bySt&0x01){//数据就绪 byRx = *(volatile unsigned char *)(tl0B.RBR); pushTL0BRX(byRx); } else break; nRxCnt++; } return byRx;}unsigned char TL0C_Rxd(void){ volatile unsigned char byRx; volatile unsigned char bySt; int nRxCnt = 0; while(nRxCnt < 512){ bySt = *(volatile unsigned char *)(tl0C.LSR);//检查接收状态 if(bySt&0x01){//数据就绪 byRx = *(volatile unsigned char *)(tl0C.RBR); pushTL0CRX(byRx); } else break; nRxCnt++; } return byRx;}unsigned char TL0D_Rxd(void){ volatile unsigned char byRx; volatile unsigned char bySt; int nRxCnt = 0; while(nRxCnt < 512){ bySt = *(volatile unsigned char *)(tl0D.LSR);//检查接收状态 if(bySt&0x01){//数据就绪 byRx = *(volatile unsigned char *)(tl0D.RBR); pushTL0DRX(byRx); } else break; nRxCnt++; } return byRx;}//TL16C554的发送//返回:1,成功// 0,失败int TL0A_Txd(unsigned char byTxd){ unsigned char byRx; int nTxCnt = 0; while(nTxCnt < 512){ byRx = *(volatile unsigned char *)(tl0A.LSR);//检查发送状态 if(byRx&0x20){//发送就绪 *(volatile unsigned char *)(tl0A.THR) = byTxd; return 1; } else{ nTxCnt++; } } return 0;}int TL0B_Txd(unsigned char byTxd){ unsigned char byRx; int nTxCnt = 0; while(nTxCnt < 512){ byRx = *(volatile unsigned char *)(tl0B.LSR);//检查发送状态 if(byRx&0x20){//发送就绪 *(volatile unsigned char *)(tl0B.THR) = byTxd; return 1; } else{ nTxCnt++; } } return 0;}int TL0C_Txd(unsigned char byTxd){ unsigned char byRx; int nTxCnt = 0; while(nTxCnt < 512){ byRx = *(volatile unsigned char *)(tl0C.LSR);//检查发送状态 if(byRx&0x20){//发送就绪 *(volatile unsigned char *)(tl0C.THR) = byTxd; return 1; } else{ nTxCnt++; } } return 0;}int TL0D_Txd(unsigned char byTxd){ unsigned char byRx; int nTxCnt = 0; while(nTxCnt < 512){ byRx = *(volatile unsigned char *)(tl0D.LSR);//检查发送状态 if(byRx&0x20){//发送就绪 *(volatile unsigned char *)(tl0D.THR) = byTxd; return 1; } else{ nTxCnt++; } } return 0;}static void UART0_interrupt(int irq, void *dev_id, struct pt_regs *regs){ long flags; save_flags_cli(flags); TL0A_Rxd(); TL0B_Rxd(); TL0C_Rxd(); TL0D_Rxd(); restore_flags(flags);}/*static void UART1_interrupt(int irq, void *dev_id, struct pt_regs *regs){ long flags; save_flags_cli(flags);// TLUART_Rxd(4);// TLUART_Rxd(5);// TLUART_Rxd(6);// TLUART_Rxd(7);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -