Dataflash_SendAddressBytes(0, CurrDFPageByte);\r
\r
/* Wait until endpoint is ready before continuing */\r
- while (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- if (USB_DeviceState == DEVICE_STATE_Unattached)\r
- return;\r
- }\r
+ if (Endpoint_WaitUntilReady())\r
+ return;\r
\r
while (TotalBlocks)\r
{\r
Endpoint_ClearOUT();\r
\r
/* Wait until the host has sent another packet */\r
- while (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- if (USB_DeviceState == DEVICE_STATE_Unattached)\r
- return;\r
- }\r
+ if (Endpoint_WaitUntilReady())\r
+ return;\r
}\r
\r
/* Check if end of dataflash page reached */\r
Dataflash_SendByte(0x00);\r
\r
/* Wait until endpoint is ready before continuing */\r
- while (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- if (USB_DeviceState == DEVICE_STATE_Unattached)\r
- return;\r
- }\r
+ if (Endpoint_WaitUntilReady())\r
+ return;\r
\r
while (TotalBlocks)\r
{\r
Endpoint_ClearIN();\r
\r
/* Wait until the endpoint is ready for more data */\r
- while (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- if (USB_DeviceState == DEVICE_STATE_Unattached)\r
- return;\r
- }\r
+ if (Endpoint_WaitUntilReady())\r
+ return;\r
}\r
\r
/* Check if end of dataflash page reached */\r
/* 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