//***************************************************************************** // //! Reads a block of data from a USB receive buffer into storage supplied by //! the caller. //! //! \param psBuffer is the pointer to the buffer instance from which data is //! to be read. //! \param pucData points to a buffer into which the received data will be //! written. //! \param ulLength is the size of the buffer pointed to by pucData. //! //! This function reads up to ulLength bytes of data received from the USB //! host into the supplied application buffer. If the receive buffer //! contains fewer than \e ulLength bytes of data, the data that is present //! will be copied and the return code will indicate the actual number of bytes //! copied to \e pucData. //! //! \return Returns the number of bytes of data read. // //***************************************************************************** unsigned long USBBufferRead(const tUSBBuffer *psBuffer, unsigned char *pucData, unsigned long ulLength) { tUSBBufferVars *psVars; unsigned long ulAvail, ulRead; // // Check parameter validity. // ASSERT(psBuffer && pucData && ulLength); // // Get our workspace variables. // psVars = psBuffer->pvWorkspace; // // How much data is in the buffer? // ulAvail = USBRingBufUsed(&psVars->sRingBuf); // // Determine how many bytes we can actually read. // ulRead = (ulAvail < ulLength) ? ulAvail : ulLength; // // Read the data from the buffer assuming there is some to read. // if(ulRead) { USBRingBufRead(&psVars->sRingBuf, pucData, ulRead); } // // Tell the caller how many bytes we wrote to their buffer. // return(ulRead); }
//***************************************************************************** // //! Reads a block of data from a USB receive buffer into storage supplied by //! the caller. //! //! \param psBuffer is the pointer to the buffer instance from which data is //! to be read. //! \param pui8Data points to a buffer into which the received data will be //! written. //! \param ui32Length is the size of the buffer pointed to by pui8Data. //! //! This function reads up to \e ui32Length bytes of data received from the USB //! host into the supplied application buffer. If the receive buffer //! contains fewer than \e ui32Length bytes of data, the data that is present //! will be copied and the return code will indicate the actual number of bytes //! copied to \e pui8Data. //! //! \return Returns the number of bytes of data read. // //***************************************************************************** uint32_t USBBufferRead(const tUSBBuffer *psBuffer, uint8_t *pui8Data, uint32_t ui32Length) { uint32_t ui32Avail, ui32Read; tUSBBufferVars *psPrivate; // // Check parameter validity. // ASSERT(psBuffer && pui8Data && ui32Length); // // Create a writable pointer to the private data. // psPrivate = &((tUSBBuffer *)psBuffer)->sPrivateData; // // How much data is in the buffer? // ui32Avail = USBRingBufUsed(&psPrivate->sRingBuf); // // Determine how many bytes we can actually read. // ui32Read = (ui32Avail < ui32Length) ? ui32Avail : ui32Length; // // Read the data from the buffer assuming there is some to read. // if(ui32Read) { USBRingBufRead(&psPrivate->sRingBuf, pui8Data, ui32Read); } // // Tell the caller how many bytes we wrote to their buffer. // return(ui32Read); }