//***************************************************************************** // //! This function is used to send chars to Bulk Out Pipe //! //! \param *pcData is pointer to data //! \param Size is number of bytes //! //! //! \return None. // //***************************************************************************** void USBHCDCSendString(unsigned char *pucData) { int Size = 0, Page = 0; while(pucData[Size] != 0) { Size ++; if(Size % 64) { // // Send out full pipe // USBHCDPipeWrite(g_USBHCDCDevice.ui32BulkOutPipe,&pucData[Page], Size); // // Increment Page // Page++; } } // // If anything left, send out // if(Size) USBHCDCWrite(0, pucData, Size); //USBHCDPipeWrite(g_USBHCDCDevice.ulBulkOutPipe,&pucData[Page], Size); }
int ANDROID_write(t_AndroidInstance handle, const void * const buff/*in*/, int len) { t_USBHANDROIDInstance *pANDROIDDevice; t_u32 ulBytes; // Get a pointer to the device instance data from the handle. pANDROIDDevice = (t_USBHANDROIDInstance *)handle; if(pANDROIDDevice != NULL) { ulBytes = USBHCDPipeWrite(pANDROIDDevice->ulBulkOutPipe, (unsigned char*)buff, len); }else { /* Error invalid handle */ ulBytes = 0; } return ulBytes; }
//***************************************************************************** // //! This function sends out data to connected CDC device. //! //! \param ulInstance is the device instance //! \param pucData is the pointer to data buffer to be sent out //! \param ulSize is the size of data to be sent out in bytes //! //! \return This function will return number of data in bytes scheduled to //! sent out. // //***************************************************************************** int32_t USBHCDCWrite(tUSBHCDCInstance *psCDCInstance, unsigned char *pucData, int32_t ulSize) { //System_printf("USBHCDCWrite: Start\n"); //System_flush(); // // If there is no device present then return an error. // if(psCDCInstance->psDevice == 0) { return(0); } // // Send data through OUT pipe (MAY NEED TO LOOK AT psCDCInstance) // return (USBHCDPipeWrite(psCDCInstance->ui32BulkOutPipe, pucData, ulSize)); //return (USBHCDPipeWrite(2, pucData, ulSize)); }
//***************************************************************************** // //! This function is used to send chars to Bulk Out Pipe //! //! \param *pcData is pointer to data //! \param Size is number of bytes //! //! //! \return None. // //***************************************************************************** void USBHCDCSendChars(unsigned char *pucData, uint32_t ulSize) { USBHCDPipeWrite(g_USBHCDCDevice.ui32BulkOutPipe, pucData, ulSize); }
//***************************************************************************** // //! This function is used to issue SCSI commands via USB. //! //! \param ulInPipe is the USB IN pipe to use for this command. //! \param ulOutPipe is the USB OUT pipe to use for this command. //! \param pSCSICmd is the SCSI command structure to send. //! \param pucData is pointer to the command data to be sent. //! \param pulSize is the number of bytes is the number of bytes expected or //! sent by the command. //! //! This internal function is used to handle SCSI commands sent by other //! functions. It serves as a layer between the SCSI command and the USB //! interface being used to send the command. The \e pSCSI parameter contains //! the SCSI command to send. For commands that expect data back, the //! \e pucData is the buffer to store the data into and \e pulSize is used to //! store the amount of data to request as well as used to indicate how many //! bytes were filled into the \e pucData buffer on return. For commands that //! are sending data, \e pucData is the data to be sent and \e pulSize is the //! number of bytes to send. //! //! \return This function returns the SCSI status from the command. The value //! will be either \b SCSI_CMD_STATUS_PASS or \b SCSI_CMD_STATUS_FAIL. // //***************************************************************************** static unsigned long USBHSCSISendCommand(unsigned long ulInPipe, unsigned long ulOutPipe, tMSCCBW *pSCSICmd, unsigned char *pucData, unsigned long *pulSize) { tMSCCSW CmdStatus; unsigned long ulBytes; // // Initialize the command status. // CmdStatus.dCSWSignature = 0; CmdStatus.dCSWTag = 0; CmdStatus.bCSWStatus = SCSI_CMD_STATUS_FAIL; // // Set the CBW signature and tag. // pSCSICmd->dCBWSignature = CBW_SIGNATURE; pSCSICmd->dCBWTag = CBW_TAG_VALUE; // // Set the size of the data to be returned by the device. // pSCSICmd->dCBWDataTransferLength = *pulSize; // // Send the command. // ulBytes = USBHCDPipeWrite(ulOutPipe, (unsigned char*)pSCSICmd, sizeof(tMSCCBW)); // // If no bytes went out then the command failed. // if(ulBytes == 0) { return(SCSI_CMD_STATUS_FAIL); } // // Only request data if there is data to request. // if(pSCSICmd->dCBWDataTransferLength != 0) { // // See if this is a read or a write. // if(pSCSICmd->bmCBWFlags & CBWFLAGS_DIR_IN) { // // Read the data back. // *pulSize = USBHCDPipeRead(ulInPipe, pucData, *pulSize); } else { // // Write the data out. // *pulSize = USBHCDPipeWrite(ulOutPipe, pucData, *pulSize); } } // // Get the status of the command. // ulBytes = USBHCDPipeRead(ulInPipe, (unsigned char *)&CmdStatus, sizeof(tMSCCSW)); // // If the status was invalid or did not have the correct signature then // indicate a failure. // if((ulBytes == 0) || (CmdStatus.dCSWSignature != CSW_SIGNATURE) || (CmdStatus.dCSWTag != CBW_TAG_VALUE)) { return(SCSI_CMD_STATUS_FAIL); } // // Return the status. // return((unsigned long)CmdStatus.bCSWStatus); }
//***************************************************************************** // //! This function is used to issue SCSI commands via USB. //! //! \param ui32InPipe is the USB IN pipe to use for this command. //! \param ui32OutPipe is the USB OUT pipe to use for this command. //! \param psSCSICmd is the SCSI command structure to send. //! \param pui8Data is pointer to the command data to be sent. //! \param pui32Size is the number of bytes is the number of bytes expected or //! sent by the command. //! //! This internal function is used to handle SCSI commands sent by other //! functions. It serves as a layer between the SCSI command and the USB //! interface being used to send the command. The \e pSCSI parameter contains //! the SCSI command to send. For commands that expect data back, the //! \e pui8Data is the buffer to store the data into and \e pui32Size is used //! to store the amount of data to request as well as used to indicate how many //! bytes were filled into the \e pui8Data buffer on return. For commands that //! are sending data, \e pui8Data is the data to be sent and \e pui32Size is //! the number of bytes to send. //! //! \return This function returns the SCSI status from the command. The value //! will be either \b SCSI_CMD_STATUS_PASS or \b SCSI_CMD_STATUS_FAIL. // //***************************************************************************** static uint32_t USBHSCSISendCommand(uint32_t ui32InPipe, uint32_t ui32OutPipe, tMSCCBW *psSCSICmd, uint8_t *pui8Data, uint32_t *pui32Size) { tMSCCSW sCmdStatus; uint32_t ui32Bytes; // // Initialize the command status. // writeusb32_t(&(sCmdStatus.dCSWSignature), 0); writeusb32_t(&(sCmdStatus.dCSWTag), 0); sCmdStatus.bCSWStatus = SCSI_CMD_STATUS_FAIL; // // Set the CBW signature and tag. // writeusb32_t(&(psSCSICmd->dCBWSignature), CBW_SIGNATURE); writeusb32_t(&(psSCSICmd->dCBWTag), CBW_TAG_VALUE); // // Set the size of the data to be returned by the device. // writeusb32_t(&(psSCSICmd->dCBWDataTransferLength), *pui32Size); // // Send the command. // ui32Bytes = USBHCDPipeWrite(ui32OutPipe, (uint8_t*)psSCSICmd, sizeof(tMSCCBW)); // // If no bytes went out then the command failed. // if(ui32Bytes == 0) { return(SCSI_CMD_STATUS_FAIL); } // // Only request data if there is data to request. // if(readusb32_t(&(psSCSICmd->dCBWDataTransferLength)) != 0) { // // See if this is a read or a write. // if(psSCSICmd->bmCBWFlags & CBWFLAGS_DIR_IN) { // // Read the data back. // *pui32Size = USBHCDPipeRead(ui32InPipe, pui8Data, *pui32Size); } else { // // Write the data out. // *pui32Size = USBHCDPipeWrite(ui32OutPipe, pui8Data, *pui32Size); } } // // Get the status of the command. // ui32Bytes = USBHCDPipeRead(ui32InPipe, (uint8_t *)&sCmdStatus, sizeof(tMSCCSW)); // // If the status was invalid or did not have the correct signature then // indicate a failure. // if((ui32Bytes == 0) || (readusb32_t(&(sCmdStatus.dCSWSignature)) != CSW_SIGNATURE) || (readusb32_t(&(sCmdStatus.dCSWTag)) != CBW_TAG_VALUE)) { return(SCSI_CMD_STATUS_FAIL); } // // Return the status. // return((uint32_t)sCmdStatus.bCSWStatus); }