📄 wdbvisiondrv.c
字号:
EXIT_CRITSECT (pFd->rxCrSection); return (bytesRead); } } else if (pFd->opMode == VISION_PISR_MODE) { return (ERROR); } else { return(ERROR); } return (bytesRead); }/***************************************************************************** visionDriverWrite - write to vision driver** This routine write to the low level driver.** RETURNS: The number of bytes written, or ERROR/errno ** NOTE: some redundancy in various mode sections.*/int visionDriverWrite ( VDRIV_DEV *pDev, /* file descriptor of file to close */ char *pBuffer, /* buffer to be written */ int nbytes /* number of bytes to write from buffer */ ) { volatile VDRIV_DEV *pFd = pDev; VDR_ULONG nToWrite; int bytesAdded; VDR_ULONG ioStatus; VDR_ULONG writeStatus; VDR_ULONG curLoc; /* Insure driver has been previously opened */ if (pFd->state != VISION_STATE_OPEN) { return (ERROR); } /* Insure proper read/write mode */ if (pFd->rdWrMode == O_RDONLY) { return (ERROR); } /* Normal/Loopback Mode ? */ if (pFd->loopMode == VISION_LPBK_MODE) { ENTER_CRITSECT (pFd->loopCrSection); bytesAdded = visionAddToQueue(&pFd->loopQueue ,pBuffer ,nbytes); EXIT_CRITSECT (pFd->loopCrSection); if (bytesAdded != nbytes) { return (ERROR); } } /* * Polled verses Pseudo-Interrupt, Blocking verses Non-Blocking, * and Buffered verses Non-Buffered are handled slightly different. * (see Application Note, Mode Matrix for details). */ if (pFd->opMode == VISION_POLL_MODE) { if (pFd->blockMode == VISION_BLOCKED_MODE) { /* This mode has to be VISION_NONBUFFERED_MODE */ nToWrite = nbytes; curLoc = 0; while (nToWrite > 0) { /* * If emulator is not busy, place buffer in tx descriptor * otherwise wait for emulator to come ready. */ ioStatus = pFd->inter.writeStatusFunc (pFd->inter.privateData, &writeStatus); if (ioStatus == VDR_SUCCESS) { if (writeStatus == VDR_WRITE_COMPLETE) { if (nToWrite < VISION_PKT_MTU) { ioStatus = pFd->inter.writeFunc (pFd->inter.privateData, pBuffer, nToWrite); if (ioStatus == VDR_FAILURE) { return (ERROR); } nToWrite = 0; } else { ioStatus = pFd->inter.writeFunc (pFd->inter.privateData, &pBuffer[curLoc], nToWrite); if (ioStatus == VDR_FAILURE) { return (ERROR); } nToWrite -= VISION_PKT_MTU; curLoc += VISION_PKT_MTU; } } else /* Emulator busy reading buffer */ { DELAY_TASK (pFd->pollDelay); } } else { return (ERROR); } } /* Before returning, insure emulator has retrieved the buffer */ writeStatus = VDR_WRITE_PENDING; while (writeStatus == VDR_WRITE_PENDING) { DELAY_TASK (pFd->pollDelay); ioStatus = pFd->inter.writeStatusFunc (pFd->inter.privateData, &writeStatus); if (ioStatus == VDR_FAILURE) { return (ERROR); } } return (nbytes); } else /* VISION_POLL_MODE & VISION_NONBLOCKED_MODE */ { if (pFd->bufferMode == VISION_NONBUFFERED_MODE) { /* NonBlocking Poll Mode cannot handle > MTU blocks */ if (nbytes > VISION_PKT_MTU) { return (ERROR); } /* * Request that the lowlevel I/O subsystem transmit the * data across the communications media. */ ioStatus = pFd->inter.writeStatusFunc (pFd->inter.privateData, &writeStatus); if (ioStatus == VDR_SUCCESS) { if (writeStatus == VDR_WRITE_COMPLETE) { ioStatus = pFd->inter.writeFunc (pFd->inter.privateData, pBuffer, nbytes); if (ioStatus == VDR_FAILURE) { return (ERROR); } return (nbytes); } else /* Emulator busy reading buffer */ { return(ERROR); } } else { return (ERROR); } } else /* POLL_MODE, NONBLOCKING_MODE, BUFFERED */ { /* * This is a possible mode, but not a practical mode. The * buffered mode was intended to be used with a pTask running. */ return (ERROR); } } } else if (pFd->opMode == VISION_PINTR_MODE) { if (pFd->blockMode == VISION_BLOCKED_MODE) { /* * Since this mode is Blocking, there is no reason to * buffer the transmit packet -- it can be sent out * directly in MTU size chunks (identical to POLL, * BLOCKING,NONBUFFERED). In this mode, the term BUFFERED * refers to the receiver. * * Note: the pTask will still monitor the tx queue, but * since this write routine never writes anything * to it, it is affectively disabled. */ nToWrite = nbytes; curLoc = 0; while (nToWrite > 0) { /* * If emulator is not busy, place buffer in tx descriptor * otherwise wait for emulator to come ready. */ ioStatus = pFd->inter.writeStatusFunc (pFd->inter.privateData, &writeStatus); if (ioStatus == VDR_SUCCESS) { if (writeStatus == VDR_WRITE_COMPLETE) { if (nToWrite < VISION_PKT_MTU) { ioStatus = pFd->inter.writeFunc (pFd->inter.privateData, pBuffer, nToWrite); if (ioStatus == VDR_FAILURE) { return (ERROR); } nToWrite = 0; } else { ioStatus = pFd->inter.writeFunc (pFd->inter.privateData, &pBuffer[curLoc], nToWrite); if (ioStatus == VDR_FAILURE) { return (ERROR); } nToWrite -= VISION_PKT_MTU; curLoc += VISION_PKT_MTU; } } else /* Emulator busy reading buffer */ { DELAY_TASK (pFd->pollDelay); } } else { return (ERROR); } } /* Before returning, insure emulator has retrieved the buffer */ writeStatus = VDR_WRITE_PENDING; while (writeStatus == VDR_WRITE_PENDING) { DELAY_TASK (pFd->pollDelay); ioStatus = pFd->inter.writeStatusFunc (pFd->inter.privateData, &writeStatus); if (ioStatus == VDR_FAILURE) { return (ERROR); } } return (nbytes); } else /* VISION_PINTR_MODE & VISION_NONBLOCKED_MODE */ { /* (This mode has to be VISION_BUFFERED_MODE) */ /* * Queue up transmit buffer for background pTask to * send it -- don't block. */ ENTER_CRITSECT (pFd->txCrSection); bytesAdded = visionAddToQueue (&pFd->txQueue , pBuffer, nbytes); EXIT_CRITSECT (pFd->txCrSection); return (bytesAdded); } } else if (pFd->opMode == VISION_PISR_MODE) { return (ERROR); } else { return (ERROR); } return (nbytes); }/***************************************************************************** visionDriverIoctl - do device specific control function** This routine do device specific control functions as listed below:** VISION_POLL_MODE - switch to Polling Mode* VISION_PINTR_MODE - switch to Pseudo Interrupt Mode* VISION_BLOCKED_MODE - switch to blocking mode* VISION_NONBLOCKED_MODE - switch to non-blocking mode* VISION_BUFFERED_MODE - switch to buffered mode* VISION_NONBUFFERED_MODE - switch to non-buffered mode* VISION_RX_QUEUE_SIZE - Set the size of the RX queue.* This will remove any characters in the RX queue.* VISION_TX_QUEUE_SIZE - Set the size of the TX queue.* This will remove any characters in the TX queue.** RETURNS: OK, or ERROR if seeking passed the end of memory.*/int visionDriverIoctl ( VDRIV_DEV *pDev, /* descriptor to control */ int function, /* function code */ int arg /* some argument */ ) { int status = OK; volatile VDRIV_DEV *pFd = pDev; switch (function) { case VISION_PINTR_MODE: case VISION_PISR_MODE: case VISION_BLOCKED_MODE: case VISION_NONBLOCKED_MODE: case VISION_BUFFERED_MODE: case VISION_NONBUFFERED_MODE: { /* * For now, do not allow dynamic mode switching * of these individual items. */ status = ERROR; break; } case VISION_POLL_MODE | VISION_NONBLOCKED_MODE | VISION_NONBUFFERED_MODE: { /* * This is a special major mode switch. This is used when the TM * Driver is configured as a WDB Agent Driver. This mode switch is * called when specifying 'System-Level' debug mode. Since the * user will probably reissue a 'Task-Level' debug mode' command, * don't back completely out of the existing settings -- just * tidy up and make safe (i.e. don't free malloc'ed memory, etc). */ /* Suspend tTmdDrv polling task */ if (taskSuspend (pFd->pollTaskId) == ERROR) { return (ERROR); } /* flush the Tx/Rx buffer queues */ ENTER_CRITSECT ( pFd->txCrSection); visionFlushQueue (&pFd->txQueue); EXIT_CRITSECT ( pFd->txCrSection); ENTER_CRITSECT ( pFd->rxCrSection); visionFlushQueue (&pFd->rxQueue); EXIT_CRITSECT ( pFd->rxCrSection); ENTER_CRITSECT ( pFd->loopCrSection); visionFlushQueue (&pFd->loopQueue); EXIT_CRITSECT ( pFd->loopCrSection); /* Specify polling, non-buffered, non-blocking mode */ pFd->opMode = VISION_POLL_MODE; pFd->blockMode = VISION_NONBLOCKED_MODE; pFd->bufferMode = VISION_NONBUFFERED_MODE; break; } case VISION_PINTR_MODE | VISION_BLOCKED_MODE | VISION_BUFFERED_MODE: { /* * This is a special major mode switch, it is used when the * vision Driver is configured as a WDB Agent Driver. This * mode switch is called when specifying 'Task-Level * Debugging Mode'. Since the user may reissue a * 'System-Level Debug Mode' cmnd, don't back completely * out of the existing settings -- just tidy up and make * safe (i.e. don't free malloc'ed memory, remove tasks, etc). */ /* Restart the tVisionDrv polling task */ if ( taskRestart (pFd->pollTaskId) == ERROR) { return (ERROR); } /* Specify polling, non-buffered, non-blocking mode */ pFd->opMode = VISION_PINTR_MODE; pFd->blockMode = VISION_BLOCKED_MODE; pFd->bufferMode = VISION_BUFFERED_MODE; break; } case VISION_PTASK_PRIORITY: { if ((arg < VISION_MIN_PTASK_PRIOR) || (arg > VISION_MAX_PTASK_PRIOR)) { status = ERROR; } else { status = taskPrioritySet (pFd->pollTaskId , arg); } break; } case VISION_PTASK_DELAY: { if ((arg < 0) || (arg > VISION_MAX_PTASK_DELAY)) { status = ERROR; } else { pFd->pollDelay = arg; } break; } case VISION_LPBK_MODE: { pFd->loopMode = VISION_LPBK_MODE; break; } case VISION_NORMAL_MODE: { pFd->loopMode = VISION_NORMAL_MODE; break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -