Break device mode class driver interfaces into seperate config and state structs...
[pub/USBasp.git] / Demos / Device / ClassDriver / MassStorage / Lib / SCSI.c
index d56e343..4e6c050 100644 (file)
@@ -86,12 +86,12 @@ SCSI_Request_Sense_Response_t SenseData =
  *\r
  *  \param MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with\r
  */\r
-bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_t* MSInterfaceInfo)\r
+bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)\r
 {\r
        bool CommandSuccess = false;\r
 \r
        /* Run the appropriate SCSI command hander function based on the passed command */\r
-       switch (MSInterfaceInfo->CommandBlock.SCSICommandData[0])\r
+       switch (MSInterfaceInfo->State.CommandBlock.SCSICommandData[0])\r
        {\r
                case SCSI_CMD_INQUIRY:\r
                        CommandSuccess = SCSI_Command_Inquiry(MSInterfaceInfo);                 \r
@@ -116,7 +116,7 @@ bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_t* MSInterfaceInfo)
                case SCSI_CMD_VERIFY_10:\r
                        /* These commands should just succeed, no handling required */\r
                        CommandSuccess = true;\r
-                       MSInterfaceInfo->CommandBlock.DataTransferLength = 0;\r
+                       MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;\r
                        break;\r
                default:\r
                        /* Update the SENSE key to reflect the invalid command */\r
@@ -146,16 +146,16 @@ bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_t* MSInterfaceInfo)
  *\r
  *  \return Boolean true if the command completed successfully, false otherwise.\r
  */\r
-static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_t* MSInterfaceInfo)\r
+static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)\r
 {\r
-       uint16_t AllocationLength  = (((uint16_t)MSInterfaceInfo->CommandBlock.SCSICommandData[3] << 8) |\r
-                                                MSInterfaceInfo->CommandBlock.SCSICommandData[4]);\r
+       uint16_t AllocationLength  = (((uint16_t)MSInterfaceInfo->State.CommandBlock.SCSICommandData[3] << 8) |\r
+                                                MSInterfaceInfo->State.CommandBlock.SCSICommandData[4]);\r
        uint16_t BytesTransferred  = (AllocationLength < sizeof(InquiryData))? AllocationLength :\r
                                                                               sizeof(InquiryData);\r
 \r
        /* Only the standard INQUIRY data is supported, check if any optional INQUIRY bits set */\r
-       if ((MSInterfaceInfo->CommandBlock.SCSICommandData[1] & ((1 << 0) | (1 << 1))) ||\r
-            MSInterfaceInfo->CommandBlock.SCSICommandData[2])\r
+       if ((MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & ((1 << 0) | (1 << 1))) ||\r
+            MSInterfaceInfo->State.CommandBlock.SCSICommandData[2])\r
        {\r
                /* Optional but unsupported bits set - update the SENSE key and fail the request */\r
                SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,\r
@@ -176,7 +176,7 @@ static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_t* MSInterfaceInfo)
        Endpoint_ClearIN();\r
 \r
        /* Succeed the command and update the bytes transferred counter */\r
-       MSInterfaceInfo->CommandBlock.DataTransferLength -= BytesTransferred;\r
+       MSInterfaceInfo->State.CommandBlock.DataTransferLength -= BytesTransferred;\r
        \r
        return true;\r
 }\r
@@ -188,9 +188,9 @@ static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_t* MSInterfaceInfo)
  *\r
  *  \return Boolean true if the command completed successfully, false otherwise.\r
  */\r
-static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_t* MSInterfaceInfo)\r
+static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)\r
 {\r
-       uint8_t  AllocationLength = MSInterfaceInfo->CommandBlock.SCSICommandData[4];\r
+       uint8_t  AllocationLength = MSInterfaceInfo->State.CommandBlock.SCSICommandData[4];\r
        uint8_t  BytesTransferred = (AllocationLength < sizeof(SenseData))? AllocationLength : sizeof(SenseData);\r
        \r
        uint8_t PadBytes[AllocationLength - BytesTransferred];\r
@@ -200,7 +200,7 @@ static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_t* MSInterfaceInfo)
        Endpoint_ClearIN();\r
 \r
        /* Succeed the command and update the bytes transferred counter */\r
-       MSInterfaceInfo->CommandBlock.DataTransferLength -= BytesTransferred;\r
+       MSInterfaceInfo->State.CommandBlock.DataTransferLength -= BytesTransferred;\r
 \r
        return true;\r
 }\r
@@ -212,7 +212,7 @@ static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_t* MSInterfaceInfo)
  *\r
  *  \return Boolean true if the command completed successfully, false otherwise.\r
  */\r
-static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_t* MSInterfaceInfo)\r
+static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)\r
 {\r
        uint32_t TotalLUNs      = (LUN_MEDIA_BLOCKS - 1);\r
        uint32_t MediaBlockSize = VIRTUAL_MEMORY_BLOCK_SIZE;\r
@@ -222,7 +222,7 @@ static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_t* MSInterfaceInfo)
        Endpoint_ClearIN();\r
        \r
        /* Succeed the command and update the bytes transferred counter */\r
-       MSInterfaceInfo->CommandBlock.DataTransferLength -= 8;\r
+       MSInterfaceInfo->State.CommandBlock.DataTransferLength -= 8;\r
        \r
        return true;\r
 }\r
@@ -235,12 +235,12 @@ static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_t* MSInterfaceInfo)
  *\r
  *  \return Boolean true if the command completed successfully, false otherwise.\r
  */\r
-static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_t* MSInterfaceInfo)\r
+static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)\r
 {\r
        uint8_t ReturnByte;\r
 \r
        /* Check to see if the SELF TEST bit is not set */\r
-       if (!(MSInterfaceInfo->CommandBlock.SCSICommandData[1] & (1 << 2)))\r
+       if (!(MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & (1 << 2)))\r
        {\r
                /* Only self-test supported - update SENSE key and fail the command */\r
                SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,\r
@@ -287,7 +287,7 @@ static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_t* MSInterfaceInfo)
        #endif\r
        \r
        /* Succeed the command and update the bytes transferred counter */\r
-       MSInterfaceInfo->CommandBlock.DataTransferLength = 0;\r
+       MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;\r
        \r
        return true;\r
 }\r
@@ -301,20 +301,20 @@ static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_t* MSInterfaceInfo)
  *\r
  *  \return Boolean true if the command completed successfully, false otherwise.\r
  */\r
-static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_t* MSInterfaceInfo, const bool IsDataRead)\r
+static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, const bool IsDataRead)\r
 {\r
        uint32_t BlockAddress;\r
        uint16_t TotalBlocks;\r
        \r
        /* Load in the 32-bit block address (SCSI uses big-endian, so have to do it byte-by-byte) */\r
-       ((uint8_t*)&BlockAddress)[3] = MSInterfaceInfo->CommandBlock.SCSICommandData[2];\r
-       ((uint8_t*)&BlockAddress)[2] = MSInterfaceInfo->CommandBlock.SCSICommandData[3];\r
-       ((uint8_t*)&BlockAddress)[1] = MSInterfaceInfo->CommandBlock.SCSICommandData[4];\r
-       ((uint8_t*)&BlockAddress)[0] = MSInterfaceInfo->CommandBlock.SCSICommandData[5];\r
+       ((uint8_t*)&BlockAddress)[3] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[2];\r
+       ((uint8_t*)&BlockAddress)[2] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[3];\r
+       ((uint8_t*)&BlockAddress)[1] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[4];\r
+       ((uint8_t*)&BlockAddress)[0] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[5];\r
 \r
        /* Load in the 16-bit total blocks (SCSI uses big-endian, so have to do it byte-by-byte) */\r
-       ((uint8_t*)&TotalBlocks)[1]  = MSInterfaceInfo->CommandBlock.SCSICommandData[7];\r
-       ((uint8_t*)&TotalBlocks)[0]  = MSInterfaceInfo->CommandBlock.SCSICommandData[8];\r
+       ((uint8_t*)&TotalBlocks)[1]  = MSInterfaceInfo->State.CommandBlock.SCSICommandData[7];\r
+       ((uint8_t*)&TotalBlocks)[0]  = MSInterfaceInfo->State.CommandBlock.SCSICommandData[8];\r
        \r
        /* Check if the block address is outside the maximum allowable value for the LUN */\r
        if (BlockAddress >= LUN_MEDIA_BLOCKS)\r
@@ -329,7 +329,7 @@ static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_t* MSInterfaceInfo, const
 \r
        #if (TOTAL_LUNS > 1)\r
        /* Adjust the given block address to the real media address based on the selected LUN */\r
-       BlockAddress += ((uint32_t)MSInterfaceInfo->CommandBlock.LUN * LUN_MEDIA_BLOCKS);\r
+       BlockAddress += ((uint32_t)MSInterfaceInfo->State.CommandBlock.LUN * LUN_MEDIA_BLOCKS);\r
        #endif\r
        \r
        /* Determine if the packet is a READ (10) or WRITE (10) command, call appropriate function */\r
@@ -339,7 +339,7 @@ static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_t* MSInterfaceInfo, const
          DataflashManager_WriteBlocks(MSInterfaceInfo, BlockAddress, TotalBlocks);\r
 \r
        /* Update the bytes transferred counter and succeed the command */\r
-       MSInterfaceInfo->CommandBlock.DataTransferLength -= ((uint32_t)TotalBlocks * VIRTUAL_MEMORY_BLOCK_SIZE);\r
+       MSInterfaceInfo->State.CommandBlock.DataTransferLength -= ((uint32_t)TotalBlocks * VIRTUAL_MEMORY_BLOCK_SIZE);\r
        \r
        return true;\r
 }\r