This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F28377D:USB (串行模式)通信、如何直接传输写入缓冲区的数据。

Guru**** 2482225 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1449168/tms320f28377d-usb-serial-mode-communication-how-to-directly-transmit-the-data-of-write-buffer

器件型号:TMS320F28377D

工具与软件:

在本例中、按照中所示

uint32_t
RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,
          void *pvMsgData)
{
    uint32_t ui32Count;

    //
    // Which event are we being sent?
    //
    switch(ui32Event)
    {
        //
        // A new packet has been received.
        //
        case USB_EVENT_RX_AVAILABLE:
        {
            //
            // Feed some characters into the SCI TX FIFO and enable the
            // interrupt so we are told when there is more space.
            //
            int i;
            uint8_t tmpData;
            uint16_t flagSTX = 0;

            uint32_t ui32Count,ui32Read, dataSize;
            uint8_t ui8Char;

            dataSize = USBBufferDataAvailable((tUSBBuffer*)&g_sRxBuffer);

            //for(i = 0; i < 20; i++ )
            while(dataSize)
            {
                ui32Read = USBBufferRead((tUSBBuffer *)&g_sRxBuffer, &tmpData, 1);
                rxData[usbRxCnt] = tmpData;
                if(ui32Read)
                {
                    if(usbRxCnt == 0 || usbRxCnt == 1) {
                        if (usbRxCnt == 0 && rxData[usbRxCnt] == STX) {
                            usbRxCnt++;
                            flagSTX = 1;
                        } else if (flagSTX == 1 && rxData[usbRxCnt] == STX) {
                            usbRxCnt++;
                        }
                    } else {
                        usbRxCnt++;
                    }

                    if(usbRxCnt >= 4)
                    {
                        usbRxSize = ((rxData[2] + (rxData[3] << 8)) * 4) + 10;
                        if((usbRxCnt == usbRxSize) && ( rxData[usbRxSize-2] == ETX && rxData[usbRxSize-1] == ETX ) ) {
                            Parcing_UsbData(rxData, usbRxSize);
                            usbRxCnt = 0;
                            flagSTX = 0;
                        }
                    }
                    g_ui32SCIRxCount++;
                }
                else
                {
                    break;
                }
            }
            break;
        }

        //
        // We are being asked how much unprocessed data we have still to
        // process. We return 0 if the SCI is currently idle or 1 if it is
        // in the process of transmitting something. The actual number of
        // bytes in the SCI FIFO is not important here, merely whether or
        // not everything previously sent to us has been transmitted.
        //
        case USB_EVENT_DATA_REMAINING:
        {
            //
            // Get the number of bytes in the buffer and add 1 if some data
            // still has to clear the transmitter.
            //
            //ui32Count = SCI_isTransmitterBusy(SCIA_BASE) ? 1 : 0;
            //return(ui32Count);
        }

        //
        // We are being asked to provide a buffer into which the next packet
        // can be read. We do not support this mode of receiving data so let
        // the driver know by returning 0. The CDC driver should not be sending
        // this message but this is included just for illustration and
        // completeness.
        //
        case USB_EVENT_REQUEST_BUFFER:
        {
            return(0);
        }

        //
        // We don't expect to receive any other events.  Ignore any that show
        // up in a release build or hang in a debug build.
        //
        default:
#ifdef DEBUG
            while(1);
#else
            break;
#endif
    }

    return(0);
}

Parcing_UsbData(rxData, usbRxSize)
{
    if(rxData[3] == 0x01)
    {
        txData[0] = 0x7E;
        txData[1] = 0x7E;
        .....
        txData[14] = 0x81;
        txData[15] = 0x81;
        
        int i;
        for(i = 0; i < 16; i++)
        {
            while(USBBufferSpaceAvailable((tUSBBuffer *)&g_sTxBuffer) == 0) {}
            USBBufferWrite((tUSBBuffer *)&g_sTxBuffer, &txData[i], 1);
        }
    }
}

在 PC 中、我将数据传输到电路板、然后电路板正确地重新传输数据。

然后,使用 Parcing_usbData (),电路板传输返回数据。

USBWriteBuffer 函数将数据压入环形缓冲区。 缓冲区数据。

在 PC 中、为了接收来自电路板的数据、它必须连续发送两次。

1)为什么不立即在 USBBufferWrite()中传输数据?

2) 2)如何立即传输数据?