Ticket #812: DrvHostSerial.diff
| File DrvHostSerial.diff, 4.7 KB (added by , 16 years ago) |
|---|
-
.cpp
old new 61 61 # ifndef TIOCM_LOOP 62 62 # define TIOCM_LOOP 0x8000 63 63 # endif 64 65 #define LINUX_CMIWAIT_BUG 1 /* 2.6.24 TIOCMIWAIT workaround */66 64 # endif /* linux */ 67 65 68 66 #elif defined(RT_OS_WINDOWS) … … 123 121 RTFILE WakeupPipeR; 124 122 /** The write end of the control pipe */ 125 123 RTFILE WakeupPipeW; 126 # if !defined RT_OS_LINUX || LINUX_CMIWAIT_BUG124 # ifndef RT_OS_LINUX 127 125 /** The current line status. 128 126 * Used by the polling version of drvHostSerialMonitorThread. */ 129 127 int fStatusLines; … … 945 943 { 946 944 PDRVHOSTSERIAL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTSERIAL); 947 945 int rc = VINF_SUCCESS; 948 unsigned const uStatusLinesToCheck = TIOCM_CAR | TIOCM_RNG | TIOCM_DSR | TIOCM_CTS;946 unsigned uStatusLinesToCheck = 0; 949 947 950 if ( PDMTHREADSTATE_INITIALIZING == pThread->enmState) 948 uStatusLinesToCheck = TIOCM_CAR | TIOCM_RNG | TIOCM_LE | TIOCM_CTS; 949 950 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING) 951 951 return VINF_SUCCESS; 952 do 952 953 while (pThread->enmState == PDMTHREADSTATE_RUNNING) 953 954 { 954 955 uint32_t newStatusLine = 0; 955 956 unsigned int statusLines; 956 957 957 if ( 0 > (rc = ioctl( pThis->DeviceFile, TIOCMGET, &statusLines))) 958 # ifdef RT_OS_LINUX 959 /* 960 * Wait for status line change. 961 */ 962 rc = ioctl(pThis->DeviceFile, TIOCMIWAIT, &uStatusLinesToCheck); 963 if (pThread->enmState != PDMTHREADSTATE_RUNNING) 964 break; 965 if (rc < 0) 958 966 { 967 ioctl_error: 959 968 PDMDrvHlpVMSetRuntimeError( pDrvIns, false, "DrvHostSerialFail", 960 969 N_("Ioctl failed for serial host device '%s' (%Rrc). The device will not work properly"), 961 pThis->pszDevicePath, RTErrConvertFromErrno(errno) 962 ); 970 pThis->pszDevicePath, RTErrConvertFromErrno(errno)); 963 971 break; 964 972 } 973 974 rc = ioctl(pThis->DeviceFile, TIOCMGET, &statusLines); 975 if (rc < 0) 976 goto ioctl_error; 977 # else /* !RT_OS_LINUX */ 978 /* 979 * Poll for the status line change. 980 */ 981 rc = ioctl(pThis->DeviceFile, TIOCMGET, &statusLines); 982 if (rc < 0) 983 { 984 PDMDrvHlpVMSetRuntimeError(pDrvIns, false, "DrvHostSerialFail", 985 N_("Ioctl failed for serial host device '%s' (%Rrc). The device will not work properly"), 986 pThis->pszDevicePath, RTErrConvertFromErrno(errno)); 987 break; 988 } 989 if (!((statusLines ^ pThis->fStatusLines) & uStatusLinesToCheck)) 990 { 991 PDMR3ThreadSleep(pThread, 500); /* 0.5 sec */ 992 continue; 993 } 994 pThis->fStatusLines = statusLines; 995 # endif /* !RT_OS_LINUX */ 996 965 997 if ( statusLines & TIOCM_CAR) 966 998 newStatusLine |= PDM_ICHAR_STATUS_LINES_DCD; 967 999 if ( statusLines & TIOCM_RNG) … … 970 1002 newStatusLine |= PDM_ICHAR_STATUS_LINES_DSR; 971 1003 if ( statusLines & TIOCM_CTS) 972 1004 newStatusLine |= PDM_ICHAR_STATUS_LINES_CTS; 973 pThis->pDrvCharPort->pfnNotifyStatusLinesChanged( pThis->pDrvCharPort, newStatusLine); 974 975 if ( PDMTHREADSTATE_RUNNING != pThread->enmState) 976 break; 977 # if defined RT_OS_LINUX && !LINUX_CMIWAIT_BUG 978 /* BUGBUG: In Linux 2.6.24 and earlier the 8250 driver doesn't report modem status 979 * changes unless there has been data I/O. */ 980 981 /* Wait for status line change. */ 982 ioctl( pThis->DeviceFile, TIOCMIWAIT, uStatusLinesToCheck); 983 Log(("HostSerial#%d: MonitorThread modem status changed.\n", pDrvIns->iInstance)); 984 # else 985 /* Poll for status line change. */ 986 if (!((statusLines ^ pThis->fStatusLines) & uStatusLinesToCheck)) 987 PDMR3ThreadSleep( pThread, 500); /* 0.5 sec */ 988 pThis->fStatusLines = statusLines; 989 # endif 1005 rc = pThis->pDrvCharPort->pfnNotifyStatusLinesChanged(pThis->pDrvCharPort, newStatusLine); 990 1006 } 991 while ( PDMTHREADSTATE_RUNNING == pThread->enmState);992 1007 993 return rc;1008 return VINF_SUCCESS; 994 1009 } 995 1010 996 1011 /** … … 1325 1340 1326 1341 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 1327 1342 /* Linux & darwin needs a separate thread which monitors the status lines. */ 1328 # if !defined RT_OS_LINUX || LINUX_CMIWAIT_BUG1343 # ifndef RT_OS_LINUX 1329 1344 ioctl(pThis->DeviceFile, TIOCMGET, &pThis->fStatusLines); 1330 1345 # endif 1331 1346 rc = PDMDrvHlpPDMThreadCreate(pDrvIns, &pThis->pMonitorThread, pThis, drvHostSerialMonitorThread, drvHostSerialWakeupMonitorThread, 0, RTTHREADTYPE_IO, "SerMon");

