X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7..21cc9c9e19ce6bd757410cc6da29b5dc2ee8041c:/Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.c diff --git a/Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.c b/Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.c index 5f12d02b4..6646278ee 100644 --- a/Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.c +++ b/Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.c @@ -43,7 +43,7 @@ * the pre-selected data OUT endpoint. This routine reads in OS sized blocks from the endpoint and writes * them to the dataflash in Dataflash page sized blocks. * - * \param[in] MSInterfaceInfo Pointer to a structure containing a Mass Storage Class configuration and state. + * \param[in] MSInterfaceInfo Pointer to a structure containing a Mass Storage Class configuration and state * \param[in] BlockAddress Data block starting address for the write sequence * \param[in] TotalBlocks Number of blocks of data to write */ @@ -69,11 +69,8 @@ void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, co Dataflash_SendAddressBytes(0, CurrDFPageByte); /* Wait until endpoint is ready before continuing */ - while (!(Endpoint_IsReadWriteAllowed())) - { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; - } + if (Endpoint_WaitUntilReady()) + return; while (TotalBlocks) { @@ -89,11 +86,8 @@ void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, co Endpoint_ClearOUT(); /* Wait until the host has sent another packet */ - while (!(Endpoint_IsReadWriteAllowed())) - { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; - } + if (Endpoint_WaitUntilReady()) + return; } /* Check if end of dataflash page reached */ @@ -183,7 +177,7 @@ void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, co * the pre-selected data IN endpoint. This routine reads in Dataflash page sized blocks from the Dataflash * and writes them in OS sized blocks to the endpoint. * - * \param[in] MSInterfaceInfo Pointer to a structure containing a Mass Storage Class configuration and state. + * \param[in] MSInterfaceInfo Pointer to a structure containing a Mass Storage Class configuration and state * \param[in] BlockAddress Data block starting address for the read sequence * \param[in] TotalBlocks Number of blocks of data to read */ @@ -205,11 +199,8 @@ void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, con Dataflash_SendByte(0x00); /* Wait until endpoint is ready before continuing */ - while (!(Endpoint_IsReadWriteAllowed())) - { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; - } + if (Endpoint_WaitUntilReady()) + return; while (TotalBlocks) { @@ -225,11 +216,8 @@ void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, con Endpoint_ClearIN(); /* Wait until the endpoint is ready for more data */ - while (!(Endpoint_IsReadWriteAllowed())) - { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; - } + if (Endpoint_WaitUntilReady()) + return; } /* Check if end of dataflash page reached */ @@ -502,3 +490,36 @@ void DataflashManager_ResetDataflashProtections(void) /* Deselect current dataflash chip */ Dataflash_DeselectChip(); } + +/** Performs a simple test on the attached Dataflash IC(s) to ensure that they are working. + * + * \return Boolean true if all media chips are working, false otherwise + */ +bool DataflashManager_CheckDataflashOperation(void) +{ + uint8_t ReturnByte; + + /* 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) + 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) + return false; + #endif + + return true; +}