Move Dataflash operational checking code out from SCSI.c into the DataflashManager...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 22 Sep 2009 07:53:57 +0000 (07:53 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 22 Sep 2009 07:53:57 +0000 (07:53 +0000)
Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.c
Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.h
Demos/Device/ClassDriver/MassStorage/Lib/SCSI.c
Demos/Device/LowLevel/MassStorage/Lib/DataflashManager.c
Demos/Device/LowLevel/MassStorage/Lib/DataflashManager.h
Demos/Device/LowLevel/MassStorage/Lib/SCSI.c
LUFA/ManPages/FutureChanges.txt

index 3858d38..257f3b6 100644 (file)
@@ -490,3 +490,36 @@ void DataflashManager_ResetDataflashProtections(void)
        /* Deselect current dataflash chip */\r
        Dataflash_DeselectChip();\r
 }\r
+\r
+/** Performs a simple test on the attached Dataflash IC(s) to ensure that they are working.\r
+ *\r
+ *  \return Boolean true if all media chips are working, false otherwise\r
+ */\r
+bool DataflashManager_CheckDataflashOperation(void)\r
+{\r
+       uint8_t ReturnByte;\r
+\r
+       /* Test first Dataflash IC is present and responding to commands */\r
+       Dataflash_SelectChip(DATAFLASH_CHIP1);\r
+       Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);\r
+       ReturnByte = Dataflash_ReceiveByte();\r
+       Dataflash_DeselectChip();\r
+\r
+       /* If returned data is invalid, fail the command */\r
+       if (ReturnByte != DF_MANUFACTURER_ATMEL)\r
+         return false;\r
+\r
+       #if (DATAFLASH_TOTALCHIPS == 2)\r
+       /* Test second Dataflash IC is present and responding to commands */\r
+       Dataflash_SelectChip(DATAFLASH_CHIP2);\r
+       Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);\r
+       ReturnByte = Dataflash_ReceiveByte();\r
+       Dataflash_DeselectChip();\r
+\r
+       /* If returned data is invalid, fail the command */\r
+       if (ReturnByte != DF_MANUFACTURER_ATMEL)\r
+         return false;\r
+       #endif\r
+       \r
+       return true;\r
+}\r
index ace6231..89e21bb 100644 (file)
@@ -73,5 +73,6 @@
                void DataflashManager_ReadBlocks_RAM(const uint32_t BlockAddress, uint16_t TotalBlocks,\r
                                                     uint8_t* BufferPtr) ATTR_NON_NULL_PTR_ARG(3);\r
                void DataflashManager_ResetDataflashProtections(void);\r
+               bool DataflashManager_CheckDataflashOperation(void);\r
                \r
 #endif\r
index f400e20..771773b 100644 (file)
@@ -237,8 +237,6 @@ static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* MSInterface
  */\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->State.CommandBlock.SCSICommandData[1] & (1 << 2)))\r
        {\r
@@ -250,14 +248,8 @@ static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* MSInterfaceI
                return false;\r
        }\r
        \r
-       /* Test first Dataflash IC is present and responding to commands */\r
-       Dataflash_SelectChip(DATAFLASH_CHIP1);\r
-       Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);\r
-       ReturnByte = Dataflash_ReceiveByte();\r
-       Dataflash_DeselectChip();\r
-\r
-       /* If returned data is invalid, fail the command */\r
-       if (ReturnByte != DF_MANUFACTURER_ATMEL)\r
+       /* Check to see if all attached Dataflash ICs are functional */\r
+       if (!(DataflashManager_CheckDataflashOperation()))\r
        {\r
                /* Update SENSE key with a hardware error condition and return command fail */\r
                SCSI_SET_SENSE(SCSI_SENSE_KEY_HARDWARE_ERROR,\r
@@ -266,25 +258,6 @@ static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* MSInterfaceI
        \r
                return false;\r
        }\r
-\r
-       #if (DATAFLASH_TOTALCHIPS == 2)\r
-       /* Test second Dataflash IC is present and responding to commands */\r
-       Dataflash_SelectChip(DATAFLASH_CHIP2);\r
-       Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);\r
-       ReturnByte = Dataflash_ReceiveByte();\r
-       Dataflash_DeselectChip();\r
-\r
-       /* If returned data is invalid, fail the command */\r
-       if (ReturnByte != DF_MANUFACTURER_ATMEL)\r
-       {\r
-               /* Update SENSE key with a hardware error condition and return command fail */\r
-               SCSI_SET_SENSE(SCSI_SENSE_KEY_HARDWARE_ERROR,\r
-                              SCSI_ASENSE_NO_ADDITIONAL_INFORMATION,\r
-                              SCSI_ASENSEQ_NO_QUALIFIER);      \r
-       \r
-               return false;\r
-       }\r
-       #endif\r
        \r
        /* Succeed the command and update the bytes transferred counter */\r
        MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;\r
index 9cd0279..7d070f3 100644 (file)
@@ -488,3 +488,36 @@ void DataflashManager_ResetDataflashProtections(void)
        /* Deselect current dataflash chip */\r
        Dataflash_DeselectChip();\r
 }\r
+\r
+/** Performs a simple test on the attached Dataflash IC(s) to ensure that they are working.\r
+ *\r
+ *  \return Boolean true if all media chips are working, false otherwise\r
+ */\r
+bool DataflashManager_CheckDataflashOperation(void)\r
+{\r
+       uint8_t ReturnByte;\r
+\r
+       /* Test first Dataflash IC is present and responding to commands */\r
+       Dataflash_SelectChip(DATAFLASH_CHIP1);\r
+       Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);\r
+       ReturnByte = Dataflash_ReceiveByte();\r
+       Dataflash_DeselectChip();\r
+\r
+       /* If returned data is invalid, fail the command */\r
+       if (ReturnByte != DF_MANUFACTURER_ATMEL)\r
+         return false;\r
+\r
+       #if (DATAFLASH_TOTALCHIPS == 2)\r
+       /* Test second Dataflash IC is present and responding to commands */\r
+       Dataflash_SelectChip(DATAFLASH_CHIP2);\r
+       Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);\r
+       ReturnByte = Dataflash_ReceiveByte();\r
+       Dataflash_DeselectChip();\r
+\r
+       /* If returned data is invalid, fail the command */\r
+       if (ReturnByte != DF_MANUFACTURER_ATMEL)\r
+         return false;\r
+       #endif\r
+       \r
+       return true;\r
+}\r
index 1332fd3..b7b5a1e 100644 (file)
@@ -71,5 +71,6 @@
                void DataflashManager_ReadBlocks_RAM(const uint32_t BlockAddress, uint16_t TotalBlocks,\r
                                                     uint8_t* BufferPtr) ATTR_NON_NULL_PTR_ARG(3);\r
                void DataflashManager_ResetDataflashProtections(void);\r
+               bool DataflashManager_CheckDataflashOperation(void);\r
                \r
 #endif\r
index 53d773f..d0840d3 100644 (file)
@@ -239,12 +239,12 @@ static bool SCSI_Command_Read_Capacity_10(void)
  *  board, and indicates if they are present and functioning correctly. Only the Self-Test portion of the diagnostic command is\r
  *  supported.\r
  *\r
+ *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with\r
+ *\r
  *  \return Boolean true if the command completed successfully, false otherwise.\r
  */\r
 static bool SCSI_Command_Send_Diagnostic(void)\r
 {\r
-       uint8_t ReturnByte;\r
-\r
        /* Check to see if the SELF TEST bit is not set */\r
        if (!(CommandBlock.SCSICommandData[1] & (1 << 2)))\r
        {\r
@@ -256,14 +256,8 @@ static bool SCSI_Command_Send_Diagnostic(void)
                return false;\r
        }\r
        \r
-       /* Test first Dataflash IC is present and responding to commands */\r
-       Dataflash_SelectChip(DATAFLASH_CHIP1);\r
-       Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);\r
-       ReturnByte = Dataflash_ReceiveByte();\r
-       Dataflash_DeselectChip();\r
-\r
-       /* If returned data is invalid, fail the command */\r
-       if (ReturnByte != DF_MANUFACTURER_ATMEL)\r
+       /* Check to see if all attached Dataflash ICs are functional */\r
+       if (!(DataflashManager_CheckDataflashOperation()))\r
        {\r
                /* Update SENSE key with a hardware error condition and return command fail */\r
                SCSI_SET_SENSE(SCSI_SENSE_KEY_HARDWARE_ERROR,\r
@@ -272,25 +266,6 @@ static bool SCSI_Command_Send_Diagnostic(void)
        \r
                return false;\r
        }\r
-\r
-       #if (DATAFLASH_TOTALCHIPS == 2)\r
-       /* Test second Dataflash IC is present and responding to commands */\r
-       Dataflash_SelectChip(DATAFLASH_CHIP2);\r
-       Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);\r
-       ReturnByte = Dataflash_ReceiveByte();\r
-       Dataflash_DeselectChip();\r
-\r
-       /* If returned data is invalid, fail the command */\r
-       if (ReturnByte != DF_MANUFACTURER_ATMEL)\r
-       {\r
-               /* Update SENSE key with a hardware error condition and return command fail */\r
-               SCSI_SET_SENSE(SCSI_SENSE_KEY_HARDWARE_ERROR,\r
-                              SCSI_ASENSE_NO_ADDITIONAL_INFORMATION,\r
-                              SCSI_ASENSEQ_NO_QUALIFIER);      \r
-       \r
-               return false;\r
-       }\r
-       #endif\r
        \r
        /* Succeed the command and update the bytes transferred counter */\r
        CommandBlock.DataTransferLength = 0;\r
index c5fcbc5..c5f6fe2 100644 (file)
@@ -21,6 +21,7 @@
   *  - Add detailed overviews of how each demo works\r
   *  - Master LUFA include file rather than per-module includes\r
   *  - Change makefiles to allow for absolute LUFA location to be used\r
+  *  - Abstract out the physical media from the Mass Storage device demos\r
   *  - Make new demos\r
   *      -# Multiple-report HID device\r
   *      -# Dual Role Mouse Host/Keyboard Device\r