Commit a9d5e129 authored by Dean Camera's avatar Dean Camera
Browse files

Changed over manual loops waiting for endpoints to be ready to use the library...

Changed over manual loops waiting for endpoints to be ready to use the library Endpoint_WaitUntilReady() function for robustness. Fixes issues with terminated transfers on the host locking up USB devices.
parent 4b35dd16
......@@ -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 */
......@@ -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 */
......
......@@ -70,7 +70,7 @@
#define LEDMASK_USB_BUSY (LEDS_LED2)
/** Total number of logical drives within the device - must be non-zero. */
#define TOTAL_LUNS 2
#define TOTAL_LUNS 1
/** Blocks in each LUN, calculated from the total capacity divided by the total number of Logical Units in the device. */
#define LUN_MEDIA_BLOCKS (VIRTUAL_MEMORY_BLOCKS / TOTAL_LUNS)
......
......@@ -62,11 +62,8 @@ static int CDC_putchar(char c, FILE *stream)
if (!(LineEncoding.BaudRateBPS))
return -1;
while (!(Endpoint_IsReadWriteAllowed()))
{
if (USB_DeviceState != DEVICE_STATE_Configured)
return -1;
}
if (Endpoint_WaitUntilReady())
return -1;
Endpoint_Write_Byte(c);
Endpoint_ClearIN();
......@@ -85,11 +82,8 @@ static int CDC_getchar(FILE *stream)
for (;;)
{
while (!(Endpoint_IsReadWriteAllowed()))
{
if (USB_DeviceState != DEVICE_STATE_Configured)
return -1;
}
if (Endpoint_WaitUntilReady())
return -1;
if (!(Endpoint_BytesInEndpoint()))
{
......@@ -327,11 +321,7 @@ void CDC_Task(void)
if (IsFull)
{
/* Wait until the endpoint is ready for another packet */
while (!(Endpoint_IsINReady()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
Endpoint_WaitUntilReady();
/* Send an empty packet to ensure that the host does not buffer data sent to it */
Endpoint_ClearIN();
......
......@@ -274,11 +274,7 @@ void CDC1_Task(void)
Endpoint_ClearIN();
/* Wait until the endpoint is ready for another packet */
while (!(Endpoint_IsINReady()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
Endpoint_WaitUntilReady();
/* Send an empty packet to ensure that the host does not buffer data sent to it */
Endpoint_ClearIN();
......@@ -329,11 +325,7 @@ void CDC2_Task(void)
Endpoint_ClearIN();
/* Wait until the endpoint is ready for the next packet */
while (!(Endpoint_IsINReady()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
Endpoint_WaitUntilReady();
/* Send an empty packet to prevent host buffering */
Endpoint_ClearIN();
......
......@@ -68,11 +68,8 @@ void DataflashManager_WriteBlocks(const uint32_t BlockAddress, uint16_t TotalBlo
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)
{
......@@ -88,11 +85,8 @@ void DataflashManager_WriteBlocks(const uint32_t BlockAddress, uint16_t TotalBlo
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 */
......@@ -203,11 +197,8 @@ void DataflashManager_ReadBlocks(const uint32_t BlockAddress, uint16_t TotalBloc
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)
{
......@@ -223,11 +214,8 @@ void DataflashManager_ReadBlocks(const uint32_t BlockAddress, uint16_t TotalBloc
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 */
......
......@@ -64,7 +64,7 @@
/** Total number of Logical Units (drives) in the device. The total device capacity is shared equally between
* each drive - this can be set to any positive non-zero amount.
*/
#define TOTAL_LUNS 2
#define TOTAL_LUNS 1
/** Blocks in each LUN, calculated from the total capacity divided by the total number of Logical Units in the device. */
#define LUN_MEDIA_BLOCKS (VIRTUAL_MEMORY_BLOCKS / TOTAL_LUNS)
......
......@@ -263,11 +263,7 @@ void CDC_Task(void)
if ((Tx_Buffer.Elements) && LineEncoding.BaudRateBPS)
{
/* Wait until Serial Tx Endpoint Ready for Read/Write */
while (!(Endpoint_IsReadWriteAllowed()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
Endpoint_WaitUntilReady();
/* Write the bytes from the buffer to the endpoint while space is available */
while (Tx_Buffer.Elements && Endpoint_IsReadWriteAllowed())
......@@ -287,11 +283,7 @@ void CDC_Task(void)
if (IsFull && !(Tx_Buffer.Elements))
{
/* Wait until Serial Tx Endpoint Ready for Read/Write */
while (!(Endpoint_IsReadWriteAllowed()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
Endpoint_WaitUntilReady();
/* Send an empty packet to terminate the transfer */
Endpoint_ClearIN();
......
......@@ -126,12 +126,7 @@ void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearIN();
while (!(Endpoint_IsReadWriteAllowed()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
Endpoint_WaitUntilReady();
}
Endpoint_ClearIN();
......@@ -156,12 +151,7 @@ void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, con
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearIN();
while (!(Endpoint_IsReadWriteAllowed()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
Endpoint_WaitUntilReady();
}
Endpoint_Write_Byte(Data);
......
......@@ -223,7 +223,7 @@ ISR(USB_GEN_vect, ISR_BLOCK)
}
#if defined(INTERRUPT_CONTROL_ENDPOINT)
ISR(USB_COM_vect, ISR_NOBLOCK)
ISR(USB_COM_vect, ISR_BLOCK)
{
uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();
......@@ -231,6 +231,6 @@ ISR(USB_COM_vect, ISR_NOBLOCK)
USB_INT_Clear(USB_INT_ENDPOINT_SETUP);
Endpoint_SelectEndpoint(PrevSelectedEndpoint);
Endpoint_SelectEndpoint(PrevSelectedEndpoint);
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment