Endpoint_ResetFIFO() renamed to Endpoint_ResetEndpoint(), to be consistent with the...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / MassStorage.c
index 3ee10d6..a3dcb1c 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2010.
+     Copyright (C) Dean Camera, 2011.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 */
 
 #define  __INCLUDE_FROM_USB_DRIVER
 */
 
 #define  __INCLUDE_FROM_USB_DRIVER
-#include "../../HighLevel/USBMode.h"
+#include "../../Core/USBMode.h"
+
 #if defined(USB_CAN_BE_DEVICE)
 
 #define  __INCLUDE_FROM_MS_DRIVER
 #define  __INCLUDE_FROM_MASSSTORAGE_DEVICE_C
 #include "MassStorage.h"
 
 #if defined(USB_CAN_BE_DEVICE)
 
 #define  __INCLUDE_FROM_MS_DRIVER
 #define  __INCLUDE_FROM_MASSSTORAGE_DEVICE_C
 #include "MassStorage.h"
 
-static volatile bool* CallbackIsResetSource;
-
 void MS_Device_ProcessControlRequest(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
        if (!(Endpoint_IsSETUPReceived()))
 void MS_Device_ProcessControlRequest(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
        if (!(Endpoint_IsSETUPReceived()))
@@ -143,8 +142,8 @@ void MS_Device_USBTask(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 
        if (MSInterfaceInfo->State.IsMassStoreReset)
        {
 
        if (MSInterfaceInfo->State.IsMassStoreReset)
        {
-               Endpoint_ResetFIFO(MSInterfaceInfo->Config.DataOUTEndpointNumber);
-               Endpoint_ResetFIFO(MSInterfaceInfo->Config.DataINEndpointNumber);
+               Endpoint_ResetEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
+               Endpoint_ResetEndpoint(MSInterfaceInfo->Config.DataINEndpointNumber);
 
                Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
                Endpoint_ClearStall();
 
                Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
                Endpoint_ClearStall();
@@ -159,14 +158,17 @@ void MS_Device_USBTask(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 
 static bool MS_Device_ReadInCommandBlock(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
 
 static bool MS_Device_ReadInCommandBlock(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
-       Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
+       uint16_t BytesProcessed;
 
 
-       CallbackIsResetSource = &MSInterfaceInfo->State.IsMassStoreReset;
-       if (Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock,
-                                   (sizeof(MS_CommandBlockWrapper_t) - 16),
-                                   StreamCallback_MS_Device_AbortOnMassStoreReset))
+       Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
+       
+       BytesProcessed = 0;
+       while (Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock,
+                                      (sizeof(MS_CommandBlockWrapper_t) - 16), &BytesProcessed) ==
+                                      ENDPOINT_RWSTREAM_IncompleteTransfer)
        {
        {
-               return false;
+               if (MSInterfaceInfo->State.IsMassStoreReset)
+                 return false;
        }
 
        if ((MSInterfaceInfo->State.CommandBlock.Signature         != MS_CBW_SIGNATURE)                  ||
        }
 
        if ((MSInterfaceInfo->State.CommandBlock.Signature         != MS_CBW_SIGNATURE)                  ||
@@ -182,12 +184,13 @@ static bool MS_Device_ReadInCommandBlock(USB_ClassInfo_MS_Device_t* const MSInte
                return false;
        }
 
                return false;
        }
 
-       CallbackIsResetSource = &MSInterfaceInfo->State.IsMassStoreReset;
-       if (Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock.SCSICommandData,
-                                   MSInterfaceInfo->State.CommandBlock.SCSICommandLength,
-                                   StreamCallback_MS_Device_AbortOnMassStoreReset))
+       BytesProcessed = 0;
+       while (Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock.SCSICommandData,
+                                       MSInterfaceInfo->State.CommandBlock.SCSICommandLength, &BytesProcessed) ==
+                                       ENDPOINT_RWSTREAM_IncompleteTransfer)
        {
        {
-               return false;
+               if (MSInterfaceInfo->State.IsMassStoreReset)
+                 return false;
        }
 
        Endpoint_ClearOUT();
        }
 
        Endpoint_ClearOUT();
@@ -221,27 +224,16 @@ static void MS_Device_ReturnCommandStatus(USB_ClassInfo_MS_Device_t* const MSInt
                  return;
        }
 
                  return;
        }
 
-       CallbackIsResetSource = &MSInterfaceInfo->State.IsMassStoreReset;
-       if (Endpoint_Write_Stream_LE(&MSInterfaceInfo->State.CommandStatus, sizeof(MS_CommandStatusWrapper_t),
-                                    StreamCallback_MS_Device_AbortOnMassStoreReset))
+       uint16_t BytesProcessed = 0;
+       while (Endpoint_Write_Stream_LE(&MSInterfaceInfo->State.CommandStatus,
+                                       sizeof(MS_CommandStatusWrapper_t), &BytesProcessed) ==
+                                       ENDPOINT_RWSTREAM_IncompleteTransfer)
        {
        {
-               return;
+               if (MSInterfaceInfo->State.IsMassStoreReset)
+                 return;
        }
        }
-
+       
        Endpoint_ClearIN();
 }
 
        Endpoint_ClearIN();
 }
 
-static uint8_t StreamCallback_MS_Device_AbortOnMassStoreReset(void)
-{
-       #if !defined(INTERRUPT_CONTROL_ENDPOINT)
-       USB_USBTask();
-       #endif
-
-       if (*CallbackIsResetSource)
-         return STREAMCALLBACK_Abort;
-       else
-         return STREAMCALLBACK_Continue;
-}
-
 #endif
 #endif
-