\r
Endpoint_ClearIN();\r
\r
- /* Acknowledge status stage */\r
- while (!(Endpoint_IsOUTReceived()));\r
- Endpoint_ClearOUT();\r
+ Endpoint_ClearStatusStage();\r
}\r
\r
break;\r
{\r
Endpoint_ClearSETUP();\r
\r
- while (!(Endpoint_IsOUTReceived()));\r
-\r
+ while (!(Endpoint_IsOUTReceived()))\r
+ { \r
+ if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+ return;\r
+ }\r
+ \r
for (uint8_t i = 0; i < sizeof(LineCoding); i++)\r
*(LineCodingData++) = Endpoint_Read_Byte();\r
\r
Endpoint_ClearOUT();\r
\r
- /* Acknowledge status stage */\r
- while (!(Endpoint_IsINReady()));\r
- Endpoint_ClearIN();\r
+ Endpoint_ClearStatusStage();\r
}\r
\r
break;\r
{\r
Endpoint_ClearSETUP();\r
\r
- /* Acknowledge status stage */\r
- while (!(Endpoint_IsINReady()));\r
- Endpoint_ClearIN();\r
+ Endpoint_ClearStatusStage();\r
}\r
\r
break;\r
/** Reads or writes a block of EEPROM or FLASH memory to or from the appropriate CDC data endpoint, depending\r
* on the AVR910 protocol command issued.\r
*\r
- * \param Command Single character AVR910 protocol command indicating what memory operation to perform\r
+ * \param[in] Command Single character AVR910 protocol command indicating what memory operation to perform\r
*/\r
static void ReadWriteMemoryBlock(const uint8_t Command)\r
{\r
while (!(Endpoint_IsReadWriteAllowed()))\r
{\r
Endpoint_ClearOUT();\r
- while (!(Endpoint_IsOUTReceived()));\r
+\r
+ while (!(Endpoint_IsOUTReceived()))\r
+ {\r
+ if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+ return 0;\r
+ }\r
}\r
\r
/* Fetch the next byte from the OUT endpoint */\r
/** Writes the next response byte to the CDC data IN endpoint, and sends the endpoint back if needed to free up the\r
* bank when full ready for the next byte in the packet to the host.\r
*\r
- * \param Response Next response byte to send to the host\r
+ * \param[in] Response Next response byte to send to the host\r
*/\r
static void WriteNextResponseByte(const uint8_t Response)\r
{\r
if (!(Endpoint_IsReadWriteAllowed()))\r
{\r
Endpoint_ClearIN();\r
- while (!(Endpoint_IsINReady()));\r
+ \r
+ while (!(Endpoint_IsINReady()))\r
+ { \r
+ if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+ return;\r
+ }\r
}\r
\r
/* Write the next byte to the OUT endpoint */\r
/* If a full endpoint's worth of data was sent, we need to send an empty packet afterwards to signal end of transfer */\r
if (IsEndpointFull)\r
{\r
- while (!(Endpoint_IsINReady()));\r
+ while (!(Endpoint_IsINReady()))\r
+ { \r
+ if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+ return;\r
+ }\r
+\r
Endpoint_ClearIN();\r
}\r
\r
/* Wait until the data has been sent to the host */\r
- while (!(Endpoint_IsINReady()));\r
+ while (!(Endpoint_IsINReady()))\r
+ { \r
+ if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+ return;\r
+ }\r
\r
/* Select the OUT endpoint */\r
Endpoint_SelectEndpoint(CDC_RX_EPNUM);\r