Added MS_Host_TestUnitReady() and MS_Host_ReadDeviceCapacity() to the host mode Mass Storage Class driver.

pull/1469/head
Dean Camera 15 years ago
parent a765f71727
commit 559ca2ba04

@ -150,11 +150,16 @@ int main(void)
printf("Vendor \"%.8s\", Product \"%.16s\"\r\n", InquiryData.VendorID, InquiryData.ProductID); printf("Vendor \"%.8s\", Product \"%.16s\"\r\n", InquiryData.VendorID, InquiryData.ProductID);
printf("Waiting until ready...\r\n"); printf("Waiting until ready...\r\n");
bool DeviceReady;
do for (;;)
{ {
if (MS_Host_TestUnitReady(&FlashDisk_MS_Interface, 0, &DeviceReady)) uint8_t ErrorCode = MS_Host_TestUnitReady(&FlashDisk_MS_Interface, 0);
if (!(ErrorCode))
break;
/* Check if an error other than a logical command error (device busy) received */
if (ErrorCode != MS_ERROR_LOGICAL_CMD_FAILED)
{ {
printf("Error waiting for device to be ready.\r\n"); printf("Error waiting for device to be ready.\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_ERROR); LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
@ -162,7 +167,6 @@ int main(void)
break; break;
} }
} }
while (!(DeviceReady));
printf("Retrieving Capacity... "); printf("Retrieving Capacity... ");

@ -336,33 +336,146 @@ uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t
} }
}; };
MassStore_SendCommand(MSInterfaceInfo, &SCSICommandBlock); if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock)) != PIPE_RWSTREAM_NoError)
{
Pipe_Freeze();
return ErrorCode;
}
if ((ErrorCode = MassStore_WaitForDataReceived()) != PIPE_RWSTREAM_NoError) if ((ErrorCode = MS_Host_WaitForDataReceived(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError)
{ {
Pipe_Freeze(); Pipe_Freeze();
return ErrorCode; return ErrorCode;
} }
if ((ErrorCode = MassStore_SendReceiveData(MSInterfaceInfo, (uint8_t*)InquiryPtr)) != PIPE_RWSTREAM_NoError) if ((ErrorCode = MS_Host_SendReceiveData(MSInterfaceInfo, &SCSICommandBlock, InquiryData)) != PIPE_RWSTREAM_NoError)
{ {
Pipe_Freeze(); Pipe_Freeze();
return ErrorCode; return ErrorCode;
} }
if ((ErrorCode = MassStore_GetReturnedStatus(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError) MS_CommandStatusWrapper_t SCSICommandStatus;
if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)
{
Pipe_Freeze();
return ErrorCode;
}
if (SCSICommandStatus.Status != SCSI_Command_Pass)
ErrorCode = MS_ERROR_LOGICAL_CMD_FAILED;
return ErrorCode;
}
uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex)
{
if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.Active))
return HOST_SENDCONTROL_DeviceDisconnect;
uint8_t ErrorCode = PIPE_RWSTREAM_NoError;
MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
{
.Signature = CBW_SIGNATURE,
.Tag = MSInterfaceInfo->State.TransactionTag,
.DataTransferLength = 0,
.Flags = COMMAND_DIRECTION_DATA_IN,
.LUN = LUNIndex,
.SCSICommandLength = 6,
.SCSICommandData =
{
SCSI_CMD_TEST_UNIT_READY,
0x00, // Reserved
0x00, // Reserved
0x00, // Reserved
0x00, // Reserved
0x00 // Unused (control)
}
};
if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock)) != PIPE_RWSTREAM_NoError)
{ {
Pipe_Freeze(); Pipe_Freeze();
return ErrorCode; return ErrorCode;
} }
MS_CommandStatusWrapper_t SCSICommandStatus;
if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)
{
Pipe_Freeze();
return ErrorCode; return ErrorCode;
} }
uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, bool* DeviceReady); if (SCSICommandStatus.Status != SCSI_Command_Pass)
ErrorCode = MS_ERROR_LOGICAL_CMD_FAILED;
return ErrorCode;
}
uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,
SCSI_Capacity_t* DeviceCapacity); SCSI_Capacity_t* DeviceCapacity)
{
if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.Active))
return HOST_SENDCONTROL_DeviceDisconnect;
uint8_t ErrorCode = PIPE_RWSTREAM_NoError;
MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
{
.Signature = CBW_SIGNATURE,
.Tag = MSInterfaceInfo->State.TransactionTag,
.DataTransferLength = sizeof(SCSI_Capacity_t),
.Flags = COMMAND_DIRECTION_DATA_IN,
.LUN = LUNIndex,
.SCSICommandLength = 10,
.SCSICommandData =
{
SCSI_CMD_READ_CAPACITY_10,
0x00, // Reserved
0x00, // MSB of Logical block address
0x00,
0x00,
0x00, // LSB of Logical block address
0x00, // Reserved
0x00, // Reserved
0x00, // Partial Medium Indicator
0x00 // Unused (control)
}
};
if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock)) != PIPE_RWSTREAM_NoError)
{
Pipe_Freeze();
return ErrorCode;
}
if ((ErrorCode = MS_Host_WaitForDataReceived(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError)
{
Pipe_Freeze();
return ErrorCode;
}
if ((ErrorCode = MS_Host_SendReceiveData(MSInterfaceInfo, &SCSICommandBlock, DeviceCapacity)) != PIPE_RWSTREAM_NoError)
{
Pipe_Freeze();
return ErrorCode;
}
DeviceCapacity->Blocks = SwapEndian_32(DeviceCapacity->Blocks);
DeviceCapacity->BlockSize = SwapEndian_32(DeviceCapacity->BlockSize);
MS_CommandStatusWrapper_t SCSICommandStatus;
if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)
{
Pipe_Freeze();
return ErrorCode;
}
if (SCSICommandStatus.Status != SCSI_Command_Pass)
ErrorCode = MS_ERROR_LOGICAL_CMD_FAILED;
return ErrorCode;
}
uint8_t MS_Host_RequestSense(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, uint8_t MS_Host_RequestSense(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,
SCSI_Request_Sense_Response_t* SenseData); SCSI_Request_Sense_Response_t* SenseData);

@ -55,6 +55,9 @@
#endif #endif
/* Public Interface - May be used in end-application: */ /* Public Interface - May be used in end-application: */
/* Macros: */
#define MS_ERROR_LOGICAL_CMD_FAILED 0xC0
/* Type Defines: */ /* Type Defines: */
/** Class state structure. An instance of this structure should be made within the user application, /** Class state structure. An instance of this structure should be made within the user application,
* and passed to each of the HID class driver functions as the HIDInterfaceInfo parameter. This * and passed to each of the HID class driver functions as the HIDInterfaceInfo parameter. This
@ -211,11 +214,19 @@
*/ */
uint8_t MS_Host_GetMaxLUN(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t* MaxLUNIndex) ATTR_NON_NULL_PTR_ARG(1, 2); uint8_t MS_Host_GetMaxLUN(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t* MaxLUNIndex) ATTR_NON_NULL_PTR_ARG(1, 2);
/** Retrieves the Mass Storage device's inquiry data for the specified LUN, indicating the device characteristics and
* properties.
*
* \param[in,out] MSInterfaceInfo Pointer to a structure containing a MS Class host configuration and state
* \param[in] LUNIndex LUN index within the device the command is being issued to
* \param[out] InquiryData Location where the read inquiry data should be stored
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum or MS_ERROR_LOGICAL_CMD_FAILED
*/
uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,
SCSI_Inquiry_Response_t* InquiryData) ATTR_NON_NULL_PTR_ARG(1, 3); SCSI_Inquiry_Response_t* InquiryData) ATTR_NON_NULL_PTR_ARG(1, 3);
uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex) ATTR_NON_NULL_PTR_ARG(1);
bool* DeviceReady) ATTR_NON_NULL_PTR_ARG(1, 3);
uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,
SCSI_Capacity_t* DeviceCapacity) ATTR_NON_NULL_PTR_ARG(1, 3); SCSI_Capacity_t* DeviceCapacity) ATTR_NON_NULL_PTR_ARG(1, 3);

Loading…
Cancel
Save