X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/34f6e0dd33230441b8a91130467b3164e343853e..1756087c3e1ecd21a594eaf7415c12ba1c852a32:/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c diff --git a/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c b/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c index afeace02f..e2a64da90 100644 --- a/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c +++ b/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c @@ -90,6 +90,7 @@ static uint8_t MassStore_SendCommand(void) /* Send the data in the OUT pipe to the attached device */ Pipe_ClearOUT(); + /* Wait until command has been sent */ while(!(Pipe_IsOUTReady())); /* Freeze pipe after use */ @@ -134,7 +135,7 @@ static uint8_t MassStore_WaitForDataReceived(void) if (Pipe_IsStalled()) { /* Clear the stall condition on the OUT pipe */ - MassStore_ClearPipeStall(MASS_STORE_DATA_OUT_PIPE); + USB_Host_ClearPipeStall(MASS_STORE_DATA_OUT_PIPE); return PIPE_RWSTREAM_PipeStalled; } @@ -147,7 +148,7 @@ static uint8_t MassStore_WaitForDataReceived(void) if (Pipe_IsStalled()) { /* Clear the stall condition on the IN pipe */ - MassStore_ClearPipeStall(MASS_STORE_DATA_IN_PIPE); + USB_Host_ClearPipeStall(MASS_STORE_DATA_IN_PIPE); return PIPE_RWSTREAM_PipeStalled; } @@ -243,29 +244,6 @@ static uint8_t MassStore_GetReturnedStatus(void) return PIPE_RWSTREAM_NoError; } -/** Clears the stall condition in the attached device on the nominated endpoint number. - * - * \param EndpointNum Endpoint number in the attached device whose stall condition is to be cleared - * - * \return A value from the USB_Host_SendControlErrorCodes_t enum - */ -uint8_t MassStore_ClearPipeStall(const uint8_t EndpointNum) -{ - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT), - .bRequest = REQ_ClearFeature, - .wValue = FEATURE_ENDPOINT_HALT, - .wIndex = EndpointNum, - .wLength = 0, - }; - - /* Select the control pipe for the request transfer */ - Pipe_SelectPipe(PIPE_CONTROLPIPE); - - return USB_Host_SendControlRequest(NULL); -} - /** Issues a Mass Storage class specific request to reset the attached device's Mass Storage interface, * readying the device for the next CBW. * @@ -323,6 +301,69 @@ uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex) return ErrorCode; } +/** Issues a SCSI Inquiry command to the attached device, to determine the device's information. This + * gives information on the device's capabilities. + * + * \param LUNIndex Index of the LUN inside the device the command is being addressed to + * \param InquiryPtr Pointer to the inquiry data structure where the inquiry data from the device is to be stored + * + * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum + */ +uint8_t MassStore_Inquiry(const uint8_t LUNIndex, const SCSI_Inquiry_Response_t* const InquiryPtr) +{ + uint8_t ReturnCode = PIPE_RWSTREAM_NoError; + + /* Create a CBW with a SCSI command to issue INQUIRY command */ + SCSICommandBlock = (CommandBlockWrapper_t) + { + .Header = + { + .Signature = CBW_SIGNATURE, + .Tag = MassStore_Tag, + .DataTransferLength = sizeof(SCSI_Inquiry_Response_t), + .Flags = COMMAND_DIRECTION_DATA_IN, + .LUN = LUNIndex, + .SCSICommandLength = 6 + }, + + .SCSICommandData = + { + SCSI_CMD_INQUIRY, + 0x00, // Reserved + 0x00, // Reserved + 0x00, // Reserved + sizeof(SCSI_Inquiry_Response_t), // Allocation Length + 0x00 // Unused (control) + } + }; + + /* Send SCSI command to the attached device */ + MassStore_SendCommand(); + + /* Wait until data received from the device */ + if ((ReturnCode = MassStore_WaitForDataReceived()) != PIPE_RWSTREAM_NoError) + { + Pipe_Freeze(); + return ReturnCode; + } + + /* Read the returned sense data into the buffer */ + if ((ReturnCode = MassStore_SendReceiveData((uint8_t*)InquiryPtr)) != PIPE_RWSTREAM_NoError) + { + Pipe_Freeze(); + return ReturnCode; + } + + /* Read in the returned CSW from the device */ + if ((ReturnCode = MassStore_GetReturnedStatus()) != PIPE_RWSTREAM_NoError) + { + Pipe_Freeze(); + return ReturnCode; + } + + return PIPE_RWSTREAM_NoError; +} + /** Issues a SCSI Request Sense command to the attached device, to determine the current SCSI sense information. This * gives error codes for the last issued SCSI command to the device. *