diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2009-07-21 13:31:21 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2009-07-21 13:31:21 +0000 |
commit | e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7 (patch) | |
tree | 51ac5c80564fd76c93a357ee4d52a347384ac84b /Demos/Host/LowLevel/MassStorageHost | |
parent | 44179abcf85acb14fb3aff72ce50ae84281c0f2e (diff) | |
download | lufa-e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7.tar.gz lufa-e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7.tar.bz2 lufa-e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7.zip |
Added new USB_DeviceState variable to keep track of the current Device mode USB state.
Added new Endpoint_ClearStatusStage() convenience function to assist with the status stages of control transfers.
Removed vague USB_IsConnected global - test USB_DeviceState or USB_HostState explicitly to gain previous functionality.
Removed USB_IsSuspended global - test USB_DeviceState against DEVICE_STATE_Suspended instead.
Fixed possible enumeration errors from spinloops which may fail to exit if the USB connection is severed before the exit condition becomes true.
Diffstat (limited to 'Demos/Host/LowLevel/MassStorageHost')
-rw-r--r-- | Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c | 8 | ||||
-rw-r--r-- | Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c | 23 |
2 files changed, 16 insertions, 15 deletions
diff --git a/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c b/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c index 7ee7de138..d0518df1f 100644 --- a/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c +++ b/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c @@ -154,7 +154,7 @@ static uint8_t MassStore_WaitForDataReceived(void) }
/* Check to see if the device was disconnected, if so exit function */
- if (!(USB_IsConnected))
+ if (USB_HostState == HOST_STATE_Unattached)
return PIPE_RWSTREAM_DeviceDisconnected;
};
@@ -206,7 +206,11 @@ static uint8_t MassStore_SendReceiveData(void* BufferPtr) /* Acknowledge the packet */
Pipe_ClearOUT();
- while (!(Pipe_IsOUTReady()));
+ while (!(Pipe_IsOUTReady()))
+ {
+ if (USB_HostState == HOST_STATE_Unattached)
+ return PIPE_RWSTREAM_DeviceDisconnected;
+ }
}
/* Freeze used pipe after use */
diff --git a/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c b/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c index 1adec5bcf..6cfe669f6 100644 --- a/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c +++ b/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c @@ -171,14 +171,11 @@ void MassStorage_Task(void) break;
}
+ puts_P(PSTR("Mass Storage Disk Enumerated.\r\n"));
+
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
- puts_P(PSTR("Mass Storage Disk Enumerated.\r\n"));
-
- USB_HostState = HOST_STATE_Ready;
- break;
- case HOST_STATE_Ready:
/* Indicate device busy via the status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
@@ -241,7 +238,11 @@ void MassStorage_Task(void) {
Serial_TxByte('.');
- if ((ErrorCode = MassStore_TestUnitReady(0)) != 0)
+ /* Abort if device removed */
+ if (USB_HostState == HOST_STATE_Unattached)
+ break;
+
+ if ((ErrorCode = MassStore_TestUnitReady(0)) != PIPE_RWSTREAM_NoError)
{
ShowDiskReadError(PSTR("Test Unit Ready"), false, ErrorCode);
@@ -249,11 +250,7 @@ void MassStorage_Task(void) break;
}
}
- while ((SCSICommandStatus.Status != Command_Pass) && USB_IsConnected);
-
- /* Abort if device removed */
- if (!(USB_IsConnected))
- break;
+ while (SCSICommandStatus.Status != Command_Pass);
puts_P(PSTR("\r\nRetrieving Capacity... "));
@@ -320,7 +317,7 @@ void MassStorage_Task(void) while (!(Buttons_GetStatus() & BUTTONS_BUTTON1))
{
/* Abort if device removed */
- if (!(USB_IsConnected))
+ if (USB_HostState == HOST_STATE_Unattached)
break;
}
@@ -346,7 +343,7 @@ void MassStorage_Task(void) }
/* Abort if device removed */
- if (!(USB_IsConnected))
+ if (USB_HostState == HOST_STATE_Unattached)
break;
}
|