Added new XCK_RESCUE_CLOCK_ENABLE compile time option to the AVRISP-MKII clone progra...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Host / MassStorage.c
index 97b0aba..ef8053b 100644 (file)
@@ -3,7 +3,7 @@
      Copyright (C) Dean Camera, 2010.
 
   dean [at] fourwalledcubicle [dot] com
      Copyright (C) Dean Camera, 2010.
 
   dean [at] fourwalledcubicle [dot] com
-      www.fourwalledcubicle.com
+           www.lufa-lib.org
 */
 
 /*
 */
 
 /*
@@ -105,14 +105,15 @@ uint8_t MS_Host_ConfigurePipes(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo,
 
 static uint8_t DCOMP_MS_Host_NextMSInterface(void* const CurrentDescriptor)
 {
 
 static uint8_t DCOMP_MS_Host_NextMSInterface(void* const CurrentDescriptor)
 {
-       if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
+       USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
+
+       if (Header->Type == DTYPE_Interface)
        {
        {
-               USB_Descriptor_Interface_t* CurrentInterface = DESCRIPTOR_PCAST(CurrentDescriptor,
-                                                                               USB_Descriptor_Interface_t);
+               USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
 
 
-               if ((CurrentInterface->Class    == MASS_STORE_CLASS)    &&
-                   (CurrentInterface->SubClass == MASS_STORE_SUBCLASS) &&
-                   (CurrentInterface->Protocol == MASS_STORE_PROTOCOL))
+               if ((Interface->Class    == MS_CSCP_MassStorageClass)        &&
+                   (Interface->SubClass == MS_CSCP_SCSITransparentSubclass) &&
+                   (Interface->Protocol == MS_CSCP_BulkOnlyTransportProtocol))
                {
                        return DESCRIPTOR_SEARCH_Found;
                }
                {
                        return DESCRIPTOR_SEARCH_Found;
                }
@@ -123,20 +124,20 @@ static uint8_t DCOMP_MS_Host_NextMSInterface(void* const CurrentDescriptor)
 
 static uint8_t DCOMP_MS_Host_NextMSInterfaceEndpoint(void* const CurrentDescriptor)
 {
 
 static uint8_t DCOMP_MS_Host_NextMSInterfaceEndpoint(void* const CurrentDescriptor)
 {
-       if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)
+       USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
+
+       if (Header->Type == DTYPE_Endpoint)
        {
        {
-               USB_Descriptor_Endpoint_t* CurrentEndpoint = DESCRIPTOR_PCAST(CurrentDescriptor,
-                                                                             USB_Descriptor_Endpoint_t);
+               USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);
 
 
-               uint8_t EndpointType = (CurrentEndpoint->Attributes & EP_TYPE_MASK);
+               uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK);
 
 
-               if ((EndpointType == EP_TYPE_BULK) &&
-                   (!(Pipe_IsEndpointBound(CurrentEndpoint->EndpointAddress))))
+               if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress))))
                {
                        return DESCRIPTOR_SEARCH_Found;
                }
        }
                {
                        return DESCRIPTOR_SEARCH_Found;
                }
        }
-       else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
+       else if (Header->Type == DTYPE_Interface)
        {
                return DESCRIPTOR_SEARCH_Fail;
        }
        {
                return DESCRIPTOR_SEARCH_Fail;
        }
@@ -150,7 +151,7 @@ static uint8_t MS_Host_SendCommand(USB_ClassInfo_MS_Host_t* const MSInterfaceInf
 {
        uint8_t ErrorCode = PIPE_RWSTREAM_NoError;
 
 {
        uint8_t ErrorCode = PIPE_RWSTREAM_NoError;
 
-       SCSICommandBlock->Signature = CBW_SIGNATURE;
+       SCSICommandBlock->Signature = MS_CBW_SIGNATURE;
        SCSICommandBlock->Tag       = ++MSInterfaceInfo->State.TransactionTag;
 
        if (MSInterfaceInfo->State.TransactionTag == 0xFFFFFFFF)
        SCSICommandBlock->Tag       = ++MSInterfaceInfo->State.TransactionTag;
 
        if (MSInterfaceInfo->State.TransactionTag == 0xFFFFFFFF)
@@ -180,7 +181,7 @@ static uint8_t MS_Host_SendCommand(USB_ClassInfo_MS_Host_t* const MSInterfaceInf
 
 static uint8_t MS_Host_WaitForDataReceived(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo)
 {
 
 static uint8_t MS_Host_WaitForDataReceived(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo)
 {
-       uint16_t TimeoutMSRem        = COMMAND_DATA_TIMEOUT_MS;
+       uint16_t TimeoutMSRem        = MS_COMMAND_DATA_TIMEOUT_MS;
        uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber();
 
        Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipeNumber);
        uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber();
 
        Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipeNumber);
@@ -240,7 +241,7 @@ static uint8_t MS_Host_SendReceiveData(USB_ClassInfo_MS_Host_t* const MSInterfac
        uint8_t  ErrorCode = PIPE_RWSTREAM_NoError;
        uint16_t BytesRem  = SCSICommandBlock->DataTransferLength;
 
        uint8_t  ErrorCode = PIPE_RWSTREAM_NoError;
        uint16_t BytesRem  = SCSICommandBlock->DataTransferLength;
 
-       if (SCSICommandBlock->Flags & COMMAND_DIRECTION_DATA_IN)
+       if (SCSICommandBlock->Flags & MS_COMMAND_DIR_DATA_IN)
        {
                if ((ErrorCode = MS_Host_WaitForDataReceived(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError)
                {
        {
                if ((ErrorCode = MS_Host_WaitForDataReceived(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError)
                {
@@ -357,7 +358,7 @@ uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo,
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = sizeof(SCSI_Inquiry_Response_t),
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = sizeof(SCSI_Inquiry_Response_t),
-                       .Flags              = COMMAND_DIRECTION_DATA_IN,
+                       .Flags              = MS_COMMAND_DIR_DATA_IN,
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 6,
                        .SCSICommandData    =
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 6,
                        .SCSICommandData    =
@@ -393,7 +394,7 @@ uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo,
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = 0,
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = 0,
-                       .Flags              = COMMAND_DIRECTION_DATA_IN,
+                       .Flags              = MS_COMMAND_DIR_DATA_IN,
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 6,
                        .SCSICommandData    =
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 6,
                        .SCSICommandData    =
@@ -430,7 +431,7 @@ uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* const MSInterfaceInf
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = sizeof(SCSI_Capacity_t),
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = sizeof(SCSI_Capacity_t),
-                       .Flags              = COMMAND_DIRECTION_DATA_IN,
+                       .Flags              = MS_COMMAND_DIR_DATA_IN,
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 10,
                        .SCSICommandData    =
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 10,
                        .SCSICommandData    =
@@ -474,7 +475,7 @@ uint8_t MS_Host_RequestSense(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo,
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = sizeof(SCSI_Request_Sense_Response_t),
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = sizeof(SCSI_Request_Sense_Response_t),
-                       .Flags              = COMMAND_DIRECTION_DATA_IN,
+                       .Flags              = MS_COMMAND_DIR_DATA_IN,
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 6,
                        .SCSICommandData    =
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 6,
                        .SCSICommandData    =
@@ -511,7 +512,7 @@ uint8_t MS_Host_PreventAllowMediumRemoval(USB_ClassInfo_MS_Host_t* const MSInter
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = 0,
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = 0,
-                       .Flags              = COMMAND_DIRECTION_DATA_OUT,
+                       .Flags              = MS_COMMAND_DIR_DATA_OUT,
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 6,
                        .SCSICommandData    =
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 6,
                        .SCSICommandData    =
@@ -551,7 +552,7 @@ uint8_t MS_Host_ReadDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo,
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = ((uint32_t)Blocks * BlockSize),
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = ((uint32_t)Blocks * BlockSize),
-                       .Flags              = COMMAND_DIRECTION_DATA_IN,
+                       .Flags              = MS_COMMAND_DIR_DATA_IN,
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 10,
                        .SCSICommandData    =
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 10,
                        .SCSICommandData    =
@@ -595,7 +596,7 @@ uint8_t MS_Host_WriteDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = ((uint32_t)Blocks * BlockSize),
        MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
                {
                        .DataTransferLength = ((uint32_t)Blocks * BlockSize),
-                       .Flags              = COMMAND_DIRECTION_DATA_OUT,
+                       .Flags              = MS_COMMAND_DIR_DATA_OUT,
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 10,
                        .SCSICommandData    =
                        .LUN                = LUNIndex,
                        .SCSICommandLength  = 10,
                        .SCSICommandData    =