Changeset 4236 in vbox
- Timestamp:
- Aug 20, 2007 8:56:32 AM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 23734
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/log.h
r4071 r4236 135 135 /** Host Parallel Driver group */ 136 136 LOG_GROUP_DRV_HOST_PARALLEL, 137 /** Host Serial Driver Group */ 138 LOG_GROUP_DRV_HOST_SERIAL, 137 139 /** The internal networking transport driver group. */ 138 140 LOG_GROUP_DRV_INTNET, … … 324 326 "DRV_HOST_HDD", \ 325 327 "DRV_HOST_PARALLEL", \ 328 "DRV_HOST_SERIAL", \ 326 329 "DRV_INTNET", \ 327 330 "DRV_ISCSI", \ -
trunk/src/VBox/Devices/Makefile.kmk
r4144 r4236 442 442 Drivers_SOURCES.win = \ 443 443 Network/DrvTAPWin32.cpp \ 444 Audio/dsoundaudio.c 444 Audio/dsoundaudio.c \ 445 Serial/DrvHostSerial.cpp 445 446 446 447 -
trunk/src/VBox/Devices/Serial/DrvHostSerial.cpp
r4148 r4236 28 28 * Header Files * 29 29 *******************************************************************************/ 30 #define LOG_GROUP LOG_GROUP_DRV_ CHAR30 #define LOG_GROUP LOG_GROUP_DRV_HOST_SERIAL 31 31 #include <VBox/pdm.h> 32 32 #include <VBox/err.h> … … 37 37 #include <iprt/stream.h> 38 38 #include <iprt/semaphore.h> 39 #include <iprt/file.h> 40 #include <iprt/alloc.h> 39 41 40 42 #ifdef RT_OS_LINUX 41 #include <termios.h> 42 #include <sys/types.h> 43 #include <fcntl.h> 44 #include <string.h> 45 #include <unistd.h> 43 # include <termios.h> 44 # include <sys/types.h> 45 # include <fcntl.h> 46 # include <string.h> 47 # include <unistd.h> 48 #elif defined(RT_OS_WINDOWS) 49 # include <windows.h> 46 50 #endif 47 51 … … 80 84 char *pszDevicePath; 81 85 /** the device handle */ 82 intDeviceFile;86 RTFILE DeviceFile; 83 87 84 88 /** Internal send FIFO queue */ … … 150 154 { 151 155 PDRVHOSTSERIAL pData = PDMICHAR_2_DRVHOSTSERIAL(pInterface); 152 struct termios termiosSetup; 156 #ifdef RT_OS_LINUX 157 struct termios *termiosSetup; 153 158 int baud_rate; 159 #elif defined(RT_OS_WINDOWS) 160 LPDCB comSetup; 161 #endif 154 162 155 163 LogFlow(("%s: Bps=%u chParity=%c cDataBits=%u cStopBits=%u\n", __FUNCTION__, Bps, chParity, cDataBits, cStopBits)); 156 157 memset(&termiosSetup, 0, sizeof(termiosSetup)); 158 164 165 #ifdef RT_OS_LINUX 166 termiosSetup = (struct termios *)RTMemTmpAllocZ(sizeof(struct termios)); 167 159 168 /* Enable receiver */ 160 termiosSetup .c_cflag |= (CLOCAL | CREAD);169 termiosSetup->c_cflag |= (CLOCAL | CREAD); 161 170 162 171 switch (Bps) { … … 234 243 switch (cDataBits) { 235 244 case 5: 236 termiosSetup .c_cflag |= CS5;245 termiosSetup->c_cflag |= CS5; 237 246 break; 238 247 case 6: 239 termiosSetup .c_cflag |= CS6;248 termiosSetup->c_cflag |= CS6; 240 249 break; 241 250 case 7: 242 termiosSetup .c_cflag |= CS7;251 termiosSetup->c_cflag |= CS7; 243 252 break; 244 253 case 8: 245 termiosSetup .c_cflag |= CS8;254 termiosSetup->c_cflag |= CS8; 246 255 break; 247 256 default: … … 260 269 261 270 tcsetattr(pData->DeviceFile, TCSANOW, &termiosSetup); 271 RTMemFree(termiosSetup); 272 #elif defined(RT_OS_WINDOWS) 273 comSetup = (LPDCB)RTMemTmpAllocZ(sizeof(DCB)); 274 275 comSetup->DCBlength = sizeof(DCB); 276 277 switch (Bps) { 278 case 110: 279 comSetup->BaudRate = CBR_110; 280 break; 281 case 300: 282 comSetup->BaudRate = CBR_300; 283 break; 284 case 600: 285 comSetup->BaudRate = CBR_600; 286 break; 287 case 1200: 288 comSetup->BaudRate = CBR_1200; 289 break; 290 case 2400: 291 comSetup->BaudRate = CBR_2400; 292 break; 293 case 4800: 294 comSetup->BaudRate = CBR_4800; 295 break; 296 case 9600: 297 comSetup->BaudRate = CBR_9600; 298 break; 299 case 14400: 300 comSetup->BaudRate = CBR_14400; 301 break; 302 case 19200: 303 comSetup->BaudRate = CBR_19200; 304 break; 305 case 38400: 306 comSetup->BaudRate = CBR_38400; 307 break; 308 case 57600: 309 comSetup->BaudRate = CBR_57600; 310 break; 311 case 115200: 312 comSetup->BaudRate = CBR_115200; 313 break; 314 default: 315 comSetup->BaudRate = CBR_9600; 316 } 317 318 comSetup->fBinary = TRUE; 319 comSetup->fOutxCtsFlow = FALSE; 320 comSetup->fOutxDsrFlow = FALSE; 321 comSetup->fDtrControl = DTR_CONTROL_DISABLE; 322 comSetup->fDsrSensitivity = FALSE; 323 comSetup->fTXContinueOnXoff = TRUE; 324 comSetup->fOutX = FALSE; 325 comSetup->fInX = FALSE; 326 comSetup->fErrorChar = FALSE; 327 comSetup->fNull = FALSE; 328 comSetup->fRtsControl = RTS_CONTROL_DISABLE; 329 comSetup->fAbortOnError = FALSE; 330 comSetup->wReserved = 0; 331 comSetup->XonLim = 5; 332 comSetup->XoffLim = 5; 333 comSetup->ByteSize = cDataBits; 334 335 switch (chParity) { 336 case 'E': 337 comSetup->Parity = EVENPARITY; 338 break; 339 case 'O': 340 comSetup->Parity = ODDPARITY; 341 break; 342 case 'N': 343 comSetup->Parity = NOPARITY; 344 break; 345 default: 346 break; 347 } 348 349 switch (cStopBits) { 350 case 1: 351 comSetup->StopBits = ONESTOPBIT; 352 break; 353 case 2: 354 comSetup->StopBits = TWOSTOPBITS; 355 break; 356 default: 357 break; 358 } 359 360 comSetup->XonChar = 0; 361 comSetup->XoffChar = 0; 362 comSetup->ErrorChar = 0; 363 comSetup->EofChar = 0; 364 comSetup->EvtChar = 0; 365 366 SetCommState((HANDLE)pData->DeviceFile, comSetup); 367 RTMemFree(comSetup); 368 #endif /* RT_OS_WINDOWS */ 262 369 263 370 return VINF_SUCCESS; … … 292 399 size_t cbProcessed = 1; 293 400 294 rc = write(pData->DeviceFile, &pData->aSendQueue[pData->iSendQueueTail], cbProcessed);295 if ( rc > 0)401 rc = RTFileWrite(pData->DeviceFile, &pData->aSendQueue[pData->iSendQueueTail], cbProcessed, NULL); 402 if (VBOX_SUCCESS(rc)) 296 403 { 297 404 Assert(cbProcessed); … … 299 406 pData->iSendQueueTail &= CHAR_MAX_SEND_QUEUE_MASK; 300 407 } 301 else if ( rc < 0)408 else if (VBOX_FAILURE(rc)) 302 409 { 303 410 LogFlow(("Write failed with %Vrc; skipping\n", rc)); … … 329 436 PDRVHOSTSERIAL pData = (PDRVHOSTSERIAL)pvUser; 330 437 char aBuffer[256], *pBuffer; 331 size_t cbRemaining, cbProcessed ;438 size_t cbRemaining, cbProcessed, cbRead; 332 439 int rc; 333 440 … … 338 445 if (!cbRemaining) 339 446 { 340 /* Get block of data from s tream driver. */447 /* Get block of data from serial device. */ 341 448 cbRemaining = sizeof(aBuffer); 342 rc = read(pData->DeviceFile, aBuffer, cbRemaining);343 if ( rc < 0)449 rc = RTFileRead(pData->DeviceFile, aBuffer, cbRemaining, &cbRead); 450 if (VBOX_FAILURE(rc)) 344 451 { 345 452 LogFlow(("Read failed with %Vrc\n", rc)); 346 453 break; 347 454 } else { 348 cbRemaining = rc;455 cbRemaining = cbRead; 349 456 } 350 457 pBuffer = aBuffer; … … 426 533 * Open the device 427 534 */ 428 pData->DeviceFile = open(pData->pszDevicePath, O_RDWR | O_NONBLOCK); 429 if (pData->DeviceFile < 0) { 430 431 } 535 rc = RTFileOpen(&pData->DeviceFile, pData->pszDevicePath, RTFILE_O_OPEN | RTFILE_O_READWRITE); 536 537 if (VBOX_FAILURE(rc)) { 538 pData->DeviceFile = NIL_RTFILE; 539 AssertMsgFailed(("Could not open host device %s, rc=%Vrc\n", pData->pszDevicePath, rc)); 540 switch (rc) { 541 case VERR_ACCESS_DENIED: 542 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, 543 #ifdef RT_OS_LINUX 544 N_("Cannot open host device '%s' for read/write access. Check the permissions " 545 "of that device ('/bin/ls -l %s'): Most probably you need to be member " 546 "of the device group. Make sure that you logout/login after changing " 547 "the group settings of the current user"), 548 #else 549 N_("Cannot open host device '%s' for read/write access. Check the permissions " 550 "of that device"), 551 #endif 552 pData->pszDevicePath, pData->pszDevicePath); 553 default: 554 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, 555 N_("Failed to open host device '%s'"), 556 pData->pszDevicePath); 557 } 558 } 559 560 /* Set to non blocking I/O */ 561 #ifdef RT_OS_LINUX 562 fcntl(pData->DeviceFile, F_SETFL, O_NONBLOCK); 563 #elif defined(RT_OS_WINDOWS) 564 /* Set the COMMTIMEOUTS to get non blocking I/O */ 565 COMMTIMEOUTS comTimeout; 566 567 comTimeout.ReadIntervalTimeout = MAXDWORD; 568 comTimeout.ReadTotalTimeoutMultiplier = 0; 569 comTimeout.ReadTotalTimeoutConstant = 0; 570 comTimeout.WriteTotalTimeoutMultiplier = 0; 571 comTimeout.WriteTotalTimeoutConstant = 0; 572 573 SetCommTimeouts((HANDLE)pData->DeviceFile, &comTimeout); 574 #endif 432 575 433 576 /* … … 436 579 pData->pDrvCharPort = (PPDMICHARPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_CHAR_PORT); 437 580 if (!pData->pDrvCharPort) 438 return PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE, RT_SRC_POS, N_(" Char#%d has no char port interface above"), pDrvIns->iInstance);581 return PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE, RT_SRC_POS, N_("HostSerial#%d has no char port interface above"), pDrvIns->iInstance); 439 582 440 583 rc = RTThreadCreate(&pData->ReceiveThread, drvHostSerialReceiveLoop, (void *)pData, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "Char Receive"); 441 584 if (VBOX_FAILURE(rc)) 442 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_(" Char#%d cannot create receive thread"), pDrvIns->iInstance);585 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostSerial#%d cannot create receive thread"), pDrvIns->iInstance); 443 586 444 587 rc = RTSemEventCreate(&pData->SendSem); 445 588 AssertRC(rc); 446 589 447 rc = RTThreadCreate(&pData->SendThread, drvHostSerialSendLoop, (void *)pData, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, " CharSend");590 rc = RTThreadCreate(&pData->SendThread, drvHostSerialSendLoop, (void *)pData, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "Serial Send"); 448 591 if (VBOX_FAILURE(rc)) 449 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_(" Char#%d cannot create send thread"), pDrvIns->iInstance);450 451 452 PDMDrvHlpSTAMRegisterF(pDrvIns, &pData->StatBytesWritten, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, "Nr of bytes written", "/Devices/ Char%d/Written", pDrvIns->iInstance);453 PDMDrvHlpSTAMRegisterF(pDrvIns, &pData->StatBytesRead, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, "Nr of bytes read", "/Devices/ Char%d/Read", pDrvIns->iInstance);592 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostSerial#%d cannot create send thread"), pDrvIns->iInstance); 593 594 595 PDMDrvHlpSTAMRegisterF(pDrvIns, &pData->StatBytesWritten, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, "Nr of bytes written", "/Devices/HostSerial%d/Written", pDrvIns->iInstance); 596 PDMDrvHlpSTAMRegisterF(pDrvIns, &pData->StatBytesRead, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, "Nr of bytes read", "/Devices/HostSerial%d/Read", pDrvIns->iInstance); 454 597 455 598 return VINF_SUCCESS; … … 476 619 RTThreadWait(pData->ReceiveThread, 1000, NULL); 477 620 if (pData->ReceiveThread != NIL_RTTHREAD) 478 LogRel((" Char%d: receive thread did not terminate\n", pDrvIns->iInstance));621 LogRel(("HostSerial%d: receive thread did not terminate\n", pDrvIns->iInstance)); 479 622 } 480 623 … … 490 633 RTThreadWait(pData->SendThread, 1000, NULL); 491 634 if (pData->SendThread != NIL_RTTHREAD) 492 LogRel((" Char%d: send thread did not terminate\n", pDrvIns->iInstance));635 LogRel(("HostSerial%d: send thread did not terminate\n", pDrvIns->iInstance)); 493 636 } 494 637 }
Note:
See TracChangeset
for help on using the changeset viewer.