📄 moxa.c
字号:
* 9. MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); * * 10. MoxaPortLineCtrl(int port, int dtrState, int rtsState); * * 11. MoxaPortFlowCtrl(int port, int rts, int cts, int rx, int tx,int xany); * * 12. MoxaPortLineStatus(int port); * * 13. MoxaPortDCDChange(int port); * * 14. MoxaPortDCDON(int port); * * 15. MoxaPortFlushData(int port, int mode); * * 16. MoxaPortWriteData(int port, unsigned char * buffer, int length); * * 17. MoxaPortReadData(int port, unsigned char * buffer, int length); * * 18. MoxaPortTxBufSize(int port); * * 19. MoxaPortRxBufSize(int port); * * 20. MoxaPortTxQueue(int port); * * 21. MoxaPortTxFree(int port); * * 22. MoxaPortRxQueue(int port); * * 23. MoxaPortRxFree(int port); * * 24. MoxaPortTxDisable(int port); * * 25. MoxaPortTxEnable(int port); * * 26. MoxaPortGetBrkCnt(int port); * * 27. MoxaPortResetBrkCnt(int port); * * 28. MoxaPortSetXonXoff(int port, int xonValue, int xoffValue); * * 29. MoxaPortIsTxHold(int port); * * 30. MoxaPortSendBreak(int port, int ticks); * *****************************************************************************//* * Moxa Port Number Description: * * MOXA serial driver supports up to 4 MOXA-C218/C320 boards. And, * the port number using in MOXA driver functions will be 0 to 31 for * first MOXA board, 32 to 63 for second, 64 to 95 for third and 96 * to 127 for fourth. For example, if you setup three MOXA boards, * first board is C218, second board is C320-16 and third board is * C320-32. The port number of first board (C218 - 8 ports) is from * 0 to 7. The port number of second board (C320 - 16 ports) is form * 32 to 47. The port number of third board (C320 - 32 ports) is from * 64 to 95. And those port numbers form 8 to 31, 48 to 63 and 96 to * 127 will be invalid. * * * Moxa Functions Description: * * Function 1: Driver initialization routine, this routine must be * called when initialized driver. * Syntax: * void MoxaDriverInit(); * * * Function 2: Moxa driver private IOCTL command processing. * Syntax: * int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port); * * unsigned int cmd : IOCTL command * unsigned long arg : IOCTL argument * int port : port number (0 - 127) * * return: 0 (OK) * -EINVAL * -ENOIOCTLCMD * * * Function 3: Moxa driver polling process routine. * Syntax: * int MoxaDriverPoll(void); * * return: 0 ; polling O.K. * -1 : no any Moxa card. * * * Function 4: Get the ports of this card. * Syntax: * int MoxaPortsOfCard(int cardno); * * int cardno : card number (0 - 3) * * return: 0 : this card is invalid * 8/16/24/32 * * * Function 5: Check this port is valid or invalid * Syntax: * int MoxaPortIsValid(int port); * int port : port number (0 - 127, ref port description) * * return: 0 : this port is invalid * 1 : this port is valid * * * Function 6: Enable this port to start Tx/Rx data. * Syntax: * void MoxaPortEnable(int port); * int port : port number (0 - 127) * * * Function 7: Disable this port * Syntax: * void MoxaPortDisable(int port); * int port : port number (0 - 127) * * * Function 8: Get the maximun available baud rate of this port. * Syntax: * long MoxaPortGetMaxBaud(int port); * int port : port number (0 - 127) * * return: 0 : this port is invalid * 38400/57600/115200 bps * * * Function 9: Get the current baud rate of this port. * Syntax: * long MoxaPortGetCurBaud(int port); * int port : port number (0 - 127) * * return: 0 : this port is invalid * 50 - 115200 bps * * * Function 10: Setting baud rate of this port. * Syntax: * long MoxaPortSetBaud(int port, long baud); * int port : port number (0 - 127) * long baud : baud rate (50 - 115200) * * return: 0 : this port is invalid or baud < 50 * 50 - 115200 : the real baud rate set to the port, if * the argument baud is large than maximun * available baud rate, the real setting * baud rate will be the maximun baud rate. * * * Function 11: Setting the data-bits/stop-bits/parity of this port * Syntax: * int MoxaPortSetMode(int port, int databits, int stopbits, int parity); * int port : port number (0 - 127) * int databits : data bits (8/7/6/5) * int stopbits : stop bits (2/1/0, 0 show 1.5 stop bits) int parity : parity (0:None,1:Odd,2:Even,3:Mark,4:Space) * * return: -1 : invalid parameter * 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 & PAR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -