Ejemplo n.º 1
0
/* Disk acquire function that waits for disk to be ready */
int FSUSB_DiskAcquire(DISK_HANDLE_T *hDisk)
{
	DEBUGOUT("Waiting for ready...");
	for (;; ) {
		uint8_t ErrorCode = MS_Host_TestUnitReady(hDisk, 0);

		if (!(ErrorCode)) {
			break;
		}

		/* Check if an error other than a logical command error (device busy) received */
		if (ErrorCode != MS_ERROR_LOGICAL_CMD_FAILED) {
			DEBUGOUT("Failed\r\n");
			USB_Host_SetDeviceConfiguration(hDisk->Config.PortNumber, 0);
			return 0;
		}
	}
	DEBUGOUT("Done.\r\n");

	if (MS_Host_ReadDeviceCapacity(hDisk, 0, &DiskCapacity)) {
		DEBUGOUT("Error retrieving device capacity.\r\n");
		USB_Host_SetDeviceConfiguration(hDisk->Config.PortNumber, 0);
		return 0;
	}

	DEBUGOUT(("%lu blocks of %lu bytes.\r\n"), DiskCapacity.Blocks, DiskCapacity.BlockSize);
	return 1;
}
/* Disk acquire function that waits for disk to be ready */
int FSUSB_DiskAcquire(DISK_HANDLE_T *hDisk)
{
	PRINTDBG("\nWaiting for ready.");
	for (;; ) {
		uint8_t ErrorCode = MS_Host_TestUnitReady(hDisk, 0);

		if (!(ErrorCode)) {
			break;
		}

		/* Check if an error other than a logical command error (device busy) received */
		if (ErrorCode != MS_ERROR_LOGICAL_CMD_FAILED) {
			PRINTDBG("\nFailed.");
			USB_Host_SetDeviceConfiguration(hDisk->Config.PortNumber, 0);
			return(0);
		}
	}
	PRINTDBG("\nDone.");

	if (MS_Host_ReadDeviceCapacity(hDisk, 0, &DiskCapacity)) {
		PRINTDBG("\nError retrieving device capacity.");
		USB_Host_SetDeviceConfiguration(hDisk->Config.PortNumber, 0);
		return(0);
	}

	PRINTDBGA("\nPendrive size: %lu bytes.", (DiskCapacity.Blocks * DiskCapacity.BlockSize));

	return(1);
}