Be doubly-certain that the incomming CDC class driver's endpoint/pipe is flushed...
[pub/USBasp.git] / Demos / Host / LowLevel / MassStorageHost / Lib / MassStoreCommands.h
index 8f3e8a1..30b74a2 100644 (file)
@@ -1,21 +1,21 @@
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting\r
-  documentation, and that the name of the author not be used in\r
-  advertising or publicity pertaining to distribution of the\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, distribute, and sell this \r
+  software and its documentation for any purpose is hereby granted\r
+  without fee, provided that the above copyright notice appear in \r
+  all copies and that both that the copyright notice and this\r
+  permission notice and warranty disclaimer appear in supporting \r
+  documentation, and that the name of the author not be used in \r
+  advertising or publicity pertaining to distribution of the \r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
                #include "MassStorageHost.h"\r
                #include "SCSI_Codes.h"\r
 \r
-               #include <LUFA/Drivers/USB/USB.h>                    // USB Functionality\r
+               #include <LUFA/Drivers/USB/USB.h>\r
 \r
        /* Macros: */\r
                /** Class specific request to reset the Mass Storage interface of the attached device */\r
-               #define REQ_MassStorageReset             0xFF\r
+               #define REQ_MassStorageReset                0xFF\r
 \r
                /** Class specific request to retrieve the maximum Logical Unit Number (LUN) index of the attached device */\r
-               #define REQ_GetMaxLUN                    0xFE\r
+               #define REQ_GetMaxLUN                       0xFE\r
 \r
                /** Command Block Wrapper signature byte, for verification of valid CBW blocks */\r
-               #define CBW_SIGNATURE                    0x43425355UL\r
+               #define CBW_SIGNATURE                       0x43425355UL\r
 \r
                /** Command Static Wrapper signature byte, for verification of valid CSW blocks */\r
-               #define CSW_SIGNATURE                    0x53425355UL\r
+               #define CSW_SIGNATURE                       0x53425355UL\r
                \r
                /** Data direction mask for the Flags field of a CBW, indicating Host-to-Device transfer direction */\r
-               #define COMMAND_DIRECTION_DATA_OUT       (0 << 7)\r
+               #define COMMAND_DIRECTION_DATA_OUT          (0 << 7)\r
 \r
                /** Data direction mask for the Flags field of a CBW, indicating Device-to-Host transfer direction */\r
-               #define COMMAND_DIRECTION_DATA_IN        (1 << 7)\r
+               #define COMMAND_DIRECTION_DATA_IN           (1 << 7)\r
                \r
                /** Timeout period between the issuing of a CBW to a device, and the reception of the first packet */\r
-               #define COMMAND_DATA_TIMEOUT_MS          2000\r
+               #define COMMAND_DATA_TIMEOUT_MS             10000\r
 \r
                /** Pipe number of the Mass Storage data IN pipe */\r
-               #define MASS_STORE_DATA_IN_PIPE          1\r
+               #define MASS_STORE_DATA_IN_PIPE             1\r
 \r
                /** Pipe number of the Mass Storage data OUT pipe */\r
-               #define MASS_STORE_DATA_OUT_PIPE         2\r
+               #define MASS_STORE_DATA_OUT_PIPE            2\r
+               \r
+               /** Additional error code for Mass Storage functions when a device returns a logical command failure */\r
+               #define MASS_STORE_SCSI_COMMAND_FAILED      0xC0\r
 \r
        /* Type defines: */\r
                /** Type define for a Mass Storage class Command Block Wrapper, used to wrap SCSI\r
                 */\r
                typedef struct\r
                {\r
-                       struct\r
-                       {\r
-                               uint32_t Signature; /**< Command block signature, always equal to CBW_SIGNATURE */\r
-                               uint32_t Tag; /**< Current CBW tag, to positively associate a CBW with a CSW */\r
-                               uint32_t DataTransferLength; /**< Length of data to transfer, following the CBW */\r
-                               uint8_t  Flags; /**< Block flags, equal to one of the COMMAND_DIRECTION_DATA_* macros */\r
-                               uint8_t  LUN; /**< Logical Unit Number the CBW is addressed to in the device */\r
-                               uint8_t  SCSICommandLength; /**< Length of the SCSI command in the CBW */\r
-                       } Header;\r
-                       \r
-                       uint8_t SCSICommandData[16]; /**< SCSI command to issue to the device */\r
+                       uint32_t Signature; /**< Command block signature, always equal to CBW_SIGNATURE */\r
+                       uint32_t Tag; /**< Current CBW tag, to positively associate a CBW with a CSW (filled automatically) */\r
+                       uint32_t DataTransferLength; /**< Length of data to transfer, following the CBW */\r
+                       uint8_t  Flags; /**< Block flags, equal to one of the COMMAND_DIRECTION_DATA_* macros */\r
+                       uint8_t  LUN; /**< Logical Unit Number the CBW is addressed to in the device */\r
+                       uint8_t  SCSICommandLength; /**< Length of the SCSI command in the CBW */\r
+                       uint8_t  SCSICommandData[16]; /**< SCSI command to issue to the device */\r
                } CommandBlockWrapper_t;\r
                \r
                /** Type define for a Mass Storage class Command Status Wrapper, used to wrap SCSI\r
                 */\r
                typedef struct\r
                {\r
-                       uint8_t       ReponseCode;\r
+                       uint8_t       ResponseCode;\r
 \r
                        uint8_t       SegmentNumber;\r
                        \r
                        Command_Fail = 1, /**< Command failed to complete successfully */\r
                        Phase_Error  = 2 /**< Phase error while processing the issued command */\r
                };\r
-               \r
-       /* External Variables: */\r
-               extern CommandStatusWrapper_t SCSICommandStatus;\r
-               \r
+       \r
        /* Function Prototypes: */\r
                #if defined(INCLUDE_FROM_MASSSTORE_COMMANDS_C)\r
-                       static uint8_t MassStore_SendCommand(void);\r
+                       static uint8_t MassStore_SendCommand(CommandBlockWrapper_t* SCSICommandBlock, void* BufferPtr);\r
                        static uint8_t MassStore_WaitForDataReceived(void);\r
-                       static uint8_t MassStore_SendReceiveData(void* BufferPtr) ATTR_NON_NULL_PTR_ARG(1);\r
-                       static uint8_t MassStore_GetReturnedStatus(void);\r
+                       static uint8_t MassStore_SendReceiveData(CommandBlockWrapper_t* SCSICommandBlock, void* BufferPtr) ATTR_NON_NULL_PTR_ARG(1);\r
+                       static uint8_t MassStore_GetReturnedStatus(CommandStatusWrapper_t* SCSICommandStatus) ATTR_NON_NULL_PTR_ARG(1);\r
                #endif\r
                \r
                uint8_t MassStore_MassStorageReset(void);\r
                uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex);\r
-               uint8_t MassStore_RequestSense(const uint8_t LUNIndex, const SCSI_Request_Sense_Response_t* const SensePtr)\r
+               uint8_t MassStore_RequestSense(const uint8_t LUNIndex, SCSI_Request_Sense_Response_t* const SensePtr)\r
                                               ATTR_NON_NULL_PTR_ARG(2);\r
-               uint8_t MassStore_Inquiry(const uint8_t LUNIndex, const SCSI_Inquiry_Response_t* const InquiryPtr)\r
+               uint8_t MassStore_Inquiry(const uint8_t LUNIndex, SCSI_Inquiry_Response_t* const InquiryPtr)\r
                                               ATTR_NON_NULL_PTR_ARG(2);\r
                uint8_t MassStore_ReadDeviceBlock(const uint8_t LUNIndex, const uint32_t BlockAddress,\r
                                                  const uint8_t Blocks, const uint16_t BlockSize, void* BufferPtr) ATTR_NON_NULL_PTR_ARG(5);\r