aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers/USB
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-08-01 14:03:13 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-08-01 14:03:13 +0000
commitff09cf9c73bbc2623a8c1420918747840382cc5b (patch)
tree41967f96971d3e1ed2a00f5449f3c83b5a19eba3 /LUFA/Drivers/USB
parentfb0e6597b611731e31b5d1285e52fc81a5ffd559 (diff)
downloadlufa-ff09cf9c73bbc2623a8c1420918747840382cc5b.tar.gz
lufa-ff09cf9c73bbc2623a8c1420918747840382cc5b.tar.bz2
lufa-ff09cf9c73bbc2623a8c1420918747840382cc5b.zip
Fix XPLAINBridge project discarding characters from the USB interface due to a double read from the endpoint.
Make XPLAINBridge and USBtoSerial projects more reliable by forcing a flush if the UART-to-USB buffer becomes nearly full. Reduce locking in the LightweightRingBuffer.h header files by only locking on the update of the buffer count, and require insertions and removals from each buffer to occur in only one execution thread. Fix CDC_*_ReceiveByte() returning 0 when the interface is not configured, instead of the new -1 error value. Fix CDC_Host_ReceiveByte() not re-freezing the pipe if no packet has been received. Remove redundant Pipe token set commands in the CDC and RNDIS host class drivers.
Diffstat (limited to 'LUFA/Drivers/USB')
-rw-r--r--LUFA/Drivers/USB/Class/Device/CDC.c21
-rw-r--r--LUFA/Drivers/USB/Class/Device/CDC.h2
-rw-r--r--LUFA/Drivers/USB/Class/Host/CDC.c28
-rw-r--r--LUFA/Drivers/USB/Class/Host/CDC.h2
-rw-r--r--LUFA/Drivers/USB/Class/Host/RNDIS.c6
5 files changed, 27 insertions, 32 deletions
diff --git a/LUFA/Drivers/USB/Class/Device/CDC.c b/LUFA/Drivers/USB/Class/Device/CDC.c
index 026ac269a..39154608e 100644
--- a/LUFA/Drivers/USB/Class/Device/CDC.c
+++ b/LUFA/Drivers/USB/Class/Device/CDC.c
@@ -133,7 +133,7 @@ void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
}
uint8_t CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
- char* const Data,
+ const char* const Data,
const uint16_t Length)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
@@ -219,20 +219,21 @@ uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterface
int16_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
{
- uint8_t ReceivedByte = -1;
-
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
- return 0;
+ return -1;
+
+ int16_t ReceivedByte = -1;
Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);
- if (!(Endpoint_IsOUTReceived()))
- return -1;
- else if (Endpoint_BytesInEndpoint())
- ReceivedByte = Endpoint_Read_Byte();
+ if (Endpoint_IsOUTReceived())
+ {
+ if (Endpoint_BytesInEndpoint())
+ ReceivedByte = Endpoint_Read_Byte();
- if (!(Endpoint_BytesInEndpoint()))
- Endpoint_ClearOUT();
+ if (!(Endpoint_BytesInEndpoint()))
+ Endpoint_ClearOUT();
+ }
return ReceivedByte;
}
diff --git a/LUFA/Drivers/USB/Class/Device/CDC.h b/LUFA/Drivers/USB/Class/Device/CDC.h
index 3ada8f7af..1b0b86810 100644
--- a/LUFA/Drivers/USB/Class/Device/CDC.h
+++ b/LUFA/Drivers/USB/Class/Device/CDC.h
@@ -214,7 +214,7 @@
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
- char* const Data,
+ const char* const Data,
const uint16_t Length) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
/** Sends a given byte to the attached USB host, if connected. If a host is not connected when the function is called, the
diff --git a/LUFA/Drivers/USB/Class/Host/CDC.c b/LUFA/Drivers/USB/Class/Host/CDC.c
index 5fb232c09..b9e4c9ebf 100644
--- a/LUFA/Drivers/USB/Class/Host/CDC.c
+++ b/LUFA/Drivers/USB/Class/Host/CDC.c
@@ -205,7 +205,6 @@ void CDC_Host_USBTask(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo)
return;
Pipe_SelectPipe(CDCInterfaceInfo->Config.NotificationPipeNumber);
- Pipe_SetPipeToken(PIPE_TOKEN_IN);
Pipe_Unfreeze();
if (Pipe_IsINReceived())
@@ -285,7 +284,7 @@ uint8_t CDC_Host_SendBreak(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo,
}
uint8_t CDC_Host_SendString(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo,
- char* const Data,
+ const char* const Data,
const uint16_t Length)
{
if ((USB_HostState != HOST_STATE_Configured) || !(CDCInterfaceInfo->State.IsActive))
@@ -333,7 +332,6 @@ uint16_t CDC_Host_BytesReceived(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo
return 0;
Pipe_SelectPipe(CDCInterfaceInfo->Config.DataINPipeNumber);
- Pipe_SetPipeToken(PIPE_TOKEN_IN);
Pipe_Unfreeze();
if (Pipe_IsINReceived())
@@ -360,25 +358,25 @@ uint16_t CDC_Host_BytesReceived(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo
int16_t CDC_Host_ReceiveByte(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo)
{
- uint8_t ReceivedByte = -1;
-
if ((USB_HostState != HOST_STATE_Configured) || !(CDCInterfaceInfo->State.IsActive))
- return 0;
+ return -1;
+ int16_t ReceivedByte = -1;
+
Pipe_SelectPipe(CDCInterfaceInfo->Config.DataINPipeNumber);
- Pipe_SetPipeToken(PIPE_TOKEN_IN);
Pipe_Unfreeze();
- if (!(Pipe_IsINReceived()))
- return -1;
- else if (Pipe_BytesInPipe())
- ReceivedByte = Pipe_Read_Byte();
+ if (Pipe_IsINReceived())
+ {
+ if (Pipe_BytesInPipe())
+ ReceivedByte = Pipe_Read_Byte();
- if (!(Pipe_BytesInPipe()))
- Pipe_ClearIN();
-
- Pipe_Freeze();
+ if (!(Pipe_BytesInPipe()))
+ Pipe_ClearIN();
+ }
+ Pipe_Freeze();
+
return ReceivedByte;
}
diff --git a/LUFA/Drivers/USB/Class/Host/CDC.h b/LUFA/Drivers/USB/Class/Host/CDC.h
index 56bcf3147..3e9d055e4 100644
--- a/LUFA/Drivers/USB/Class/Host/CDC.h
+++ b/LUFA/Drivers/USB/Class/Host/CDC.h
@@ -217,7 +217,7 @@
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t CDC_Host_SendString(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo,
- char* const Data,
+ const char* const Data,
const uint16_t Length) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
/** Sends a given byte to the attached USB device, if connected. If a device is not connected when the function is called, the
diff --git a/LUFA/Drivers/USB/Class/Host/RNDIS.c b/LUFA/Drivers/USB/Class/Host/RNDIS.c
index b189535f0..cddd5cbb5 100644
--- a/LUFA/Drivers/USB/Class/Host/RNDIS.c
+++ b/LUFA/Drivers/USB/Class/Host/RNDIS.c
@@ -386,12 +386,9 @@ bool RNDIS_Host_IsPacketReceived(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfac
return false;
Pipe_SelectPipe(RNDISInterfaceInfo->Config.DataINPipeNumber);
- Pipe_SetPipeToken(PIPE_TOKEN_IN);
Pipe_Unfreeze();
-
- PacketWaiting = Pipe_IsINReceived();
-
+ PacketWaiting = Pipe_IsINReceived();
Pipe_Freeze();
return PacketWaiting;
@@ -407,7 +404,6 @@ uint8_t RNDIS_Host_ReadPacket(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceIn
return PIPE_READYWAIT_DeviceDisconnected;
Pipe_SelectPipe(RNDISInterfaceInfo->Config.DataINPipeNumber);
- Pipe_SetPipeToken(PIPE_TOKEN_IN);
Pipe_Unfreeze();
if (!(Pipe_IsReadWriteAllowed()))