moxa.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 2,401 行 · 第 1/5 页
C
2,401 行
* 0 : setting O.K. * * * Function 12: Configure the port. * Syntax: * int MoxaPortSetTermio(int port, struct termios *termio); * int port : port number (0 - 127) * struct termios * termio : termio structure pointer * * return: -1 : this port is invalid or termio == NULL * 0 : setting O.K. * * * Function 13: Get the DTR/RTS state of this port. * Syntax: * int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); * int port : port number (0 - 127) * int * dtrState : pointer to INT to receive the current DTR * state. (if NULL, this function will not * write to this address) * int * rtsState : pointer to INT to receive the current RTS * state. (if NULL, this function will not * write to this address) * * return: -1 : this port is invalid * 0 : O.K. * * * Function 14: Setting the DTR/RTS output state of this port. * Syntax: * void MoxaPortLineCtrl(int port, int dtrState, int rtsState); * int port : port number (0 - 127) * int dtrState : DTR output state (0: off, 1: on) * int rtsState : RTS output state (0: off, 1: on) * * * Function 15: Setting the flow control of this port. * Syntax: * void MoxaPortFlowCtrl(int port, int rtsFlow, int ctsFlow, int rxFlow, * int txFlow,int xany); * int port : port number (0 - 127) * int rtsFlow : H/W RTS flow control (0: no, 1: yes) * int ctsFlow : H/W CTS flow control (0: no, 1: yes) * int rxFlow : S/W Rx XON/XOFF flow control (0: no, 1: yes) * int txFlow : S/W Tx XON/XOFF flow control (0: no, 1: yes) * int xany : S/W XANY flow control (0: no, 1: yes) * * * Function 16: Get ths line status of this port * Syntax: * int MoxaPortLineStatus(int port); * int port : port number (0 - 127) * * return: Bit 0 - CTS state (0: off, 1: on) * Bit 1 - DSR state (0: off, 1: on) * Bit 2 - DCD state (0: off, 1: on) * * * Function 17: Check the DCD state has changed since the last read * of this function. * Syntax: * int MoxaPortDCDChange(int port); * int port : port number (0 - 127) * * return: 0 : no changed * 1 : DCD has changed * * * Function 18: Check ths current DCD state is ON or not. * Syntax: * int MoxaPortDCDON(int port); * int port : port number (0 - 127) * * return: 0 : DCD off * 1 : DCD on * * * Function 19: Flush the Rx/Tx buffer data of this port. * Syntax: * void MoxaPortFlushData(int port, int mode); * int port : port number (0 - 127) * int mode * 0 : flush the Rx buffer * 1 : flush the Tx buffer * 2 : flush the Rx and Tx buffer * * * Function 20: Write data. * Syntax: * int MoxaPortWriteData(int port, unsigned char * buffer, int length); * int port : port number (0 - 127) * unsigned char * buffer : pointer to write data buffer. * int length : write data length * * return: 0 - length : real write data length * * * Function 21: Read data. * Syntax: * int MoxaPortReadData(int port, unsigned char * buffer, int length); * int port : port number (0 - 127) * unsigned char * buffer : pointer to read data buffer. * int length : read data buffer length * * return: 0 - length : real read data length * * * Function 22: Get the Tx buffer size of this port * Syntax: * int MoxaPortTxBufSize(int port); * int port : port number (0 - 127) * * return: .. : Tx buffer size * * * Function 23: Get the Rx buffer size of this port * Syntax: * int MoxaPortRxBufSize(int port); * int port : port number (0 - 127) * * return: .. : Rx buffer size * * * Function 24: Get the Tx buffer current queued data bytes * Syntax: * int MoxaPortTxQueue(int port); * int port : port number (0 - 127) * * return: .. : Tx buffer current queued data bytes * * * Function 25: Get the Tx buffer current free space * Syntax: * int MoxaPortTxFree(int port); * int port : port number (0 - 127) * * return: .. : Tx buffer current free space * * * Function 26: Get the Rx buffer current queued data bytes * Syntax: * int MoxaPortRxQueue(int port); * int port : port number (0 - 127) * * return: .. : Rx buffer current queued data bytes * * * Function 27: Get the Rx buffer current free space * Syntax: * int MoxaPortRxFree(int port); * int port : port number (0 - 127) * * return: .. : Rx buffer current free space * * * Function 28: Disable port data transmission. * Syntax: * void MoxaPortTxDisable(int port); * int port : port number (0 - 127) * * * Function 29: Enable port data transmission. * Syntax: * void MoxaPortTxEnable(int port); * int port : port number (0 - 127) * * * Function 30: Get the received BREAK signal count. * Syntax: * int MoxaPortGetBrkCnt(int port); * int port : port number (0 - 127) * * return: 0 - .. : BREAK signal count * * * Function 31: Get the received BREAK signal count and reset it. * Syntax: * int MoxaPortResetBrkCnt(int port); * int port : port number (0 - 127) * * return: 0 - .. : BREAK signal count * * * Function 32: Set the S/W flow control new XON/XOFF value, default * XON is 0x11 & XOFF is 0x13. * Syntax: * void MoxaPortSetXonXoff(int port, int xonValue, int xoffValue); * int port : port number (0 - 127) * int xonValue : new XON value (0 - 255) * int xoffValue : new XOFF value (0 - 255) * * * Function 33: Check this port's transmission is hold by remote site * because the flow control. * Syntax: * int MoxaPortIsTxHold(int port); * int port : port number (0 - 127) * * return: 0 : normal * 1 : hold by remote site * * * Function 34: Send out a BREAK signal. * Syntax: * void MoxaPortSendBreak(int port, int ms100); * int port : port number (0 - 127) * int ms100 : break signal time interval. * unit: 100 mini-second. if ms100 == 0, it will * send out a about 250 ms BREAK signal. * */int MoxaPortIsValid(int port){ if (moxaCard == 0) return (0); if (moxaChkPort[port] == 0) return (0); return (1);}void MoxaPortEnable(int port){ unsigned long ofsAddr; int MoxaPortLineStatus(int); short lowwater = 512; ofsAddr = moxaTableAddr[port]; writew(lowwater, ofsAddr + Low_water); moxaBreakCnt[port] = 0; if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { moxafunc(ofsAddr, FC_SetBreakIrq, 0); } else { writew(readw(ofsAddr + HostStat) | WakeupBreak, ofsAddr + HostStat); } moxafunc(ofsAddr, FC_SetLineIrq, Magic_code); moxafunc(ofsAddr, FC_FlushQueue, 2); moxafunc(ofsAddr, FC_EnableCH, Magic_code); MoxaPortLineStatus(port);}void MoxaPortDisable(int port){ unsigned long ofsAddr; ofsAddr = moxaTableAddr[port]; moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */ moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code); writew(0, ofsAddr + HostStat); moxafunc(ofsAddr, FC_DisableCH, Magic_code);}long MoxaPortGetMaxBaud(int port){ if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) return (460800L); else return (921600L);}long MoxaPortSetBaud(int port, long baud){ unsigned long ofsAddr; long max, clock; unsigned int val; if ((baud < 50L) || ((max = MoxaPortGetMaxBaud(port)) == 0)) return (0); ofsAddr = moxaTableAddr[port]; if (baud > max) baud = max; if (max == 38400L) clock = 614400L; /* for 9.8304 Mhz : max. 38400 bps */ else if (max == 57600L) clock = 691200L; /* for 11.0592 Mhz : max. 57600 bps */ else clock = 921600L; /* for 14.7456 Mhz : max. 115200 bps */ val = clock / baud; moxafunc(ofsAddr, FC_SetBaud, val); baud = clock / val; moxaCurBaud[port] = baud; return (baud);}int MoxaPortSetTermio(int port, struct termios *termio){ unsigned long ofsAddr; tcflag_t cflag; long baud; tcflag_t mode = 0; if (moxaChkPort[port] == 0 || termio == 0) return (-1); ofsAddr = moxaTableAddr[port]; cflag = termio->c_cflag; /* termio->c_cflag */ mode = termio->c_cflag & CSIZE; if (mode == CS5) mode = MX_CS5; else if (mode == CS6) mode = MX_CS6; else if (mode == CS7) mode = MX_CS7; else if (mode == CS8) mode = MX_CS8; if (termio->c_cflag & CSTOPB) { if (mode == MX_CS5) mode |= MX_STOP15; else mode |= MX_STOP2; } else mode |= MX_STOP1; if (termio->c_cflag & PARENB) { if (termio->c_cflag & PARODD) mode |= MX_PARODD; else mode |= MX_PAREVEN; } else mode |= MX_PARNONE; moxafunc(ofsAddr, FC_SetDataMode, (ushort) mode); cflag &= (CBAUD | CBAUDEX);#ifndef B921600#define B921600 (B460800+1)#endif switch (cflag) { case B921600: baud = 921600L; break; case B460800: baud = 460800L; break; case B230400: baud = 230400L; break; case B115200: baud = 115200L; break; case B57600: baud = 57600L; break; case B38400: baud = 38400L; break; case B19200: baud = 19200L; break; case B9600: baud = 9600L; break; case B4800: baud = 4800L; break; case B2400: baud = 2400L; break; case B1800: baud = 1800L; break; case B1200: baud = 1200L; break; case B600: baud = 600L; break; case B300: baud = 300L; break; case B200: baud = 200L; break; case B150: baud = 150L; break; case B134: baud = 134L; break; case B110: baud = 110L; break; case B75: baud = 75L; break; case B50: baud = 50L; break; default: baud = 0; } if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { if (baud == 921600L) return (-1); } MoxaPortSetBaud(port, baud); if (termio->c_iflag & (IXON | IXOFF | IXANY)) { writeb(termio->c_cc[VSTART], ofsAddr + FuncArg); writeb(termio->c_cc[VSTOP], ofsAddr + FuncArg1); writeb(FC_SetXonXoff, ofsAddr + FuncCode); wait_finish(ofsAddr); } return (0);}int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState){ if (!MoxaPortIsValid(port)) return (-1); if (dtrState) { if (moxaLineCtrl[port] & DTR_ON) *dtrState = 1; else *dtrState = 0; } if (rtsState) { if (moxaLineCtrl[port] & RTS_ON) *rtsState = 1; else *rtsState = 0; } return (0);}void MoxaPortLineCtrl(int port, int dtr, int rts){ unsigned long ofsAddr; int mode; ofsAddr = moxaTableAddr[port]; mode = 0; if (dtr) mode |= DTR_ON; if (rts) mode |= RTS_ON; moxaLineCtrl[port] = mode; moxafunc(ofsAddr, FC_LineControl, mode);}void MoxaPortFlowCtrl(int port, int rts, int cts, int txflow, int rxflow, int txany){ unsigned long ofsAddr; int mode; ofsAddr = moxaTableAddr[port]; mode = 0; if (rts) mode |= RTS_FlowCtl; if (cts) mode |= CTS_FlowCtl; if (txflow) mode |= Tx_FlowCtl; if (rxflow) mode |= Rx_FlowCtl; if (txany) mode |= IXM_IXANY; moxafunc(ofsAddr, FC_SetFlowCtl, mode);}int MoxaPortLineStatus(int port){ unsigned long ofsAddr; int val; ofsAddr = moxaTableAddr[port]; if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || (moxa_boards[port / MAX_PORTS_PER_BOARD].bo
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?