Changed all Device mode LowLevel demos and Device Class drivers so that the control...
[pub/USBasp.git] / Demos / Device / ClassDriver / MassStorageKeyboard / Lib / SCSI.c
index e4bf4d6..fed57f7 100644 (file)
@@ -85,8 +85,10 @@ SCSI_Request_Sense_Response_t SenseData =
  *  a command failure due to a ILLEGAL REQUEST.
  *
  *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with
+ *
+ *  \return Boolean true if the command completed successfully, false otherwise
  */
-bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
+bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
        bool CommandSuccess = false;
 
@@ -146,10 +148,9 @@ bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
  *
  *  \return Boolean true if the command completed successfully, false otherwise.
  */
-static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
+static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
-       uint16_t AllocationLength  = (((uint16_t)MSInterfaceInfo->State.CommandBlock.SCSICommandData[3] << 8) |
-                                                MSInterfaceInfo->State.CommandBlock.SCSICommandData[4]);
+       uint16_t AllocationLength  = SwapEndian_16(*(uint16_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[3]);
        uint16_t BytesTransferred  = (AllocationLength < sizeof(InquiryData))? AllocationLength :
                                                                               sizeof(InquiryData);
 
@@ -188,7 +189,7 @@ static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
  *
  *  \return Boolean true if the command completed successfully, false otherwise.
  */
-static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
+static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
        uint8_t  AllocationLength = MSInterfaceInfo->State.CommandBlock.SCSICommandData[4];
        uint8_t  BytesTransferred = (AllocationLength < sizeof(SenseData))? AllocationLength : sizeof(SenseData);
@@ -212,7 +213,7 @@ static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* MSInterfaceInf
  *
  *  \return Boolean true if the command completed successfully, false otherwise.
  */
-static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
+static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
        uint32_t LastBlockAddressInLUN = (LUN_MEDIA_BLOCKS - 1);
        uint32_t MediaBlockSize        = VIRTUAL_MEMORY_BLOCK_SIZE;
@@ -235,10 +236,8 @@ static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* MSInterface
  *
  *  \return Boolean true if the command completed successfully, false otherwise.
  */
-static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
+static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
-       uint8_t ReturnByte;
-
        /* Check to see if the SELF TEST bit is not set */
        if (!(MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & (1 << 2)))
        {
@@ -250,32 +249,8 @@ static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* MSInterfaceI
                return false;
        }
        
-       /* Test first Dataflash IC is present and responding to commands */
-       Dataflash_SelectChip(DATAFLASH_CHIP1);
-       Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);
-       ReturnByte = Dataflash_ReceiveByte();
-       Dataflash_DeselectChip();
-
-       /* If returned data is invalid, fail the command */
-       if (ReturnByte != DF_MANUFACTURER_ATMEL)
-       {
-               /* Update SENSE key with a hardware error condition and return command fail */
-               SCSI_SET_SENSE(SCSI_SENSE_KEY_HARDWARE_ERROR,
-                              SCSI_ASENSE_NO_ADDITIONAL_INFORMATION,
-                              SCSI_ASENSEQ_NO_QUALIFIER);      
-       
-               return false;
-       }
-
-       #if (DATAFLASH_TOTALCHIPS == 2)
-       /* Test second Dataflash IC is present and responding to commands */
-       Dataflash_SelectChip(DATAFLASH_CHIP2);
-       Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);
-       ReturnByte = Dataflash_ReceiveByte();
-       Dataflash_DeselectChip();
-
-       /* If returned data is invalid, fail the command */
-       if (ReturnByte != DF_MANUFACTURER_ATMEL)
+       /* Check to see if all attached Dataflash ICs are functional */
+       if (!(DataflashManager_CheckDataflashOperation()))
        {
                /* Update SENSE key with a hardware error condition and return command fail */
                SCSI_SET_SENSE(SCSI_SENSE_KEY_HARDWARE_ERROR,
@@ -284,7 +259,6 @@ static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* MSInterfaceI
        
                return false;
        }
-       #endif
        
        /* Succeed the command and update the bytes transferred counter */
        MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;
@@ -293,7 +267,7 @@ static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* MSInterfaceI
 }
 
 /** Command processing for an issued SCSI READ (10) or WRITE (10) command. This command reads in the block start address
- *  and total number of blocks to process, then calls the appropriate low-level dataflash routine to handle the actual
+ *  and total number of blocks to process, then calls the appropriate low-level Dataflash routine to handle the actual
  *  reading and writing of the data.
  *
  *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with
@@ -301,7 +275,8 @@ static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* MSInterfaceI
  *
  *  \return Boolean true if the command completed successfully, false otherwise.
  */
-static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, const bool IsDataRead)
+static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
+                                      const bool IsDataRead)
 {
        uint32_t BlockAddress;
        uint16_t TotalBlocks;