aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Device/LowLevel
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-07-21 02:48:41 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-07-21 02:48:41 +0000
commit67f390fe746ccc4d1dceac23f590eb1723cb7ff2 (patch)
treeeafc8a4dcb64a038afcb16fcae8d48033dc74249 /Demos/Device/LowLevel
parentbf50959b8016adbf6b295178b26b8173514dd060 (diff)
downloadlufa-67f390fe746ccc4d1dceac23f590eb1723cb7ff2.tar.gz
lufa-67f390fe746ccc4d1dceac23f590eb1723cb7ff2.tar.bz2
lufa-67f390fe746ccc4d1dceac23f590eb1723cb7ff2.zip
Add explicit guards to all device mode tasks to ensure the device is connected and configured before running the task, to prevent any user tasks from locking up the main USB task if the device has not been properly configured.
Diffstat (limited to 'Demos/Device/LowLevel')
-rw-r--r--Demos/Device/LowLevel/AudioInput/AudioInput.c4
-rw-r--r--Demos/Device/LowLevel/AudioOutput/AudioOutput.c4
-rw-r--r--Demos/Device/LowLevel/CDC/CDC.c4
-rw-r--r--Demos/Device/LowLevel/DualCDC/DualCDC.c8
-rw-r--r--Demos/Device/LowLevel/GenericHID/GenericHID.c70
-rw-r--r--Demos/Device/LowLevel/Joystick/Joystick.c42
-rw-r--r--Demos/Device/LowLevel/Keyboard/Keyboard.c16
-rw-r--r--Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c112
-rw-r--r--Demos/Device/LowLevel/MIDI/MIDI.c7
-rw-r--r--Demos/Device/LowLevel/Mouse/Mouse.c12
-rw-r--r--Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c4
-rw-r--r--Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c139
12 files changed, 224 insertions, 198 deletions
diff --git a/Demos/Device/LowLevel/AudioInput/AudioInput.c b/Demos/Device/LowLevel/AudioInput/AudioInput.c
index 50e7f4df4..5656b05d1 100644
--- a/Demos/Device/LowLevel/AudioInput/AudioInput.c
+++ b/Demos/Device/LowLevel/AudioInput/AudioInput.c
@@ -151,6 +151,10 @@ void EVENT_USB_UnhandledControlPacket(void)
/** Task to manage the Audio interface, reading in ADC samples from the microphone, and them to the host. */
void USB_Audio_Task(void)
{
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
/* Check to see if the streaming interface is selected, if not the host is not receiving audio */
if (!(StreamingAudioInterfaceSelected))
return;
diff --git a/Demos/Device/LowLevel/AudioOutput/AudioOutput.c b/Demos/Device/LowLevel/AudioOutput/AudioOutput.c
index 9661f0342..6d22009dc 100644
--- a/Demos/Device/LowLevel/AudioOutput/AudioOutput.c
+++ b/Demos/Device/LowLevel/AudioOutput/AudioOutput.c
@@ -180,6 +180,10 @@ void EVENT_USB_UnhandledControlPacket(void)
*/
void USB_Audio_Task(void)
{
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
/* Check to see if the streaming interface is selected, if not the host is not receiving audio */
if (!(StreamingAudioInterfaceSelected))
return;
diff --git a/Demos/Device/LowLevel/CDC/CDC.c b/Demos/Device/LowLevel/CDC/CDC.c
index ac0623a4d..d8263b11f 100644
--- a/Demos/Device/LowLevel/CDC/CDC.c
+++ b/Demos/Device/LowLevel/CDC/CDC.c
@@ -254,6 +254,10 @@ void CDC_Task(void)
"Joystick Pressed\r\n",
};
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
#if 0
/* NOTE: Here you can use the notification endpoint to send back line state changes to the host, for the special RS-232
* handshake signal lines (and some error states), via the CONTROL_LINE_IN_* masks and the following code:
diff --git a/Demos/Device/LowLevel/DualCDC/DualCDC.c b/Demos/Device/LowLevel/DualCDC/DualCDC.c
index 1031068ad..862945e63 100644
--- a/Demos/Device/LowLevel/DualCDC/DualCDC.c
+++ b/Demos/Device/LowLevel/DualCDC/DualCDC.c
@@ -229,6 +229,10 @@ void CDC1_Task(void)
uint8_t JoyStatus_LCL = Joystick_GetStatus();
static bool ActionSent = false;
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
char* JoystickStrings[] =
{
"Joystick Up\r\n",
@@ -288,6 +292,10 @@ void CDC1_Task(void)
*/
void CDC2_Task(void)
{
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
/* Select the Serial Rx Endpoint */
Endpoint_SelectEndpoint(CDC2_RX_EPNUM);
diff --git a/Demos/Device/LowLevel/GenericHID/GenericHID.c b/Demos/Device/LowLevel/GenericHID/GenericHID.c
index f46749472..5c6d1ee47 100644
--- a/Demos/Device/LowLevel/GenericHID/GenericHID.c
+++ b/Demos/Device/LowLevel/GenericHID/GenericHID.c
@@ -202,47 +202,47 @@ void CreateGenericHIDReport(uint8_t* DataArray)
void HID_Task(void)
{
- /* Check if the USB system is connected to a host */
- if (USB_IsConnected)
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
+ Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM);
+
+ /* Check to see if a packet has been sent from the host */
+ if (Endpoint_IsOUTReceived())
{
- Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM);
-
- /* Check to see if a packet has been sent from the host */
- if (Endpoint_IsOUTReceived())
+ /* Check to see if the packet contains data */
+ if (Endpoint_IsReadWriteAllowed())
{
- /* Check to see if the packet contains data */
- if (Endpoint_IsReadWriteAllowed())
- {
- /* Create a temporary buffer to hold the read in report from the host */
- uint8_t GenericData[GENERIC_REPORT_SIZE];
-
- /* Read Generic Report Data */
- Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData));
-
- /* Process Generic Report Data */
- ProcessGenericHIDReport(GenericData);
- }
+ /* Create a temporary buffer to hold the read in report from the host */
+ uint8_t GenericData[GENERIC_REPORT_SIZE];
+
+ /* Read Generic Report Data */
+ Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData));
+
+ /* Process Generic Report Data */
+ ProcessGenericHIDReport(GenericData);
+ }
- /* Finalize the stream transfer to send the last packet */
- Endpoint_ClearOUT();
- }
+ /* Finalize the stream transfer to send the last packet */
+ Endpoint_ClearOUT();
+ }
- Endpoint_SelectEndpoint(GENERIC_IN_EPNUM);
+ Endpoint_SelectEndpoint(GENERIC_IN_EPNUM);
+
+ /* Check to see if the host is ready to accept another packet */
+ if (Endpoint_IsINReady())
+ {
+ /* Create a temporary buffer to hold the report to send to the host */
+ uint8_t GenericData[GENERIC_REPORT_SIZE];
- /* Check to see if the host is ready to accept another packet */
- if (Endpoint_IsINReady())
- {
- /* Create a temporary buffer to hold the report to send to the host */
- uint8_t GenericData[GENERIC_REPORT_SIZE];
-
- /* Create Generic Report Data */
- CreateGenericHIDReport(GenericData);
+ /* Create Generic Report Data */
+ CreateGenericHIDReport(GenericData);
- /* Write Generic Report Data */
- Endpoint_Write_Stream_LE(&GenericData, sizeof(GenericData));
+ /* Write Generic Report Data */
+ Endpoint_Write_Stream_LE(&GenericData, sizeof(GenericData));
- /* Finalize the stream transfer to send the last packet */
- Endpoint_ClearIN();
- }
+ /* Finalize the stream transfer to send the last packet */
+ Endpoint_ClearIN();
}
}
diff --git a/Demos/Device/LowLevel/Joystick/Joystick.c b/Demos/Device/LowLevel/Joystick/Joystick.c
index 42ae62caa..e11747537 100644
--- a/Demos/Device/LowLevel/Joystick/Joystick.c
+++ b/Demos/Device/LowLevel/Joystick/Joystick.c
@@ -181,28 +181,28 @@ bool GetNextReport(USB_JoystickReport_Data_t* ReportData)
/** Function to manage HID report generation and transmission to the host. */
void HID_Task(void)
{
- /* Check if the USB System is connected to a Host */
- if (USB_IsConnected)
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
+ /* Select the Joystick Report Endpoint */
+ Endpoint_SelectEndpoint(JOYSTICK_EPNUM);
+
+ /* Check to see if the host is ready for another packet */
+ if (Endpoint_IsINReady())
{
- /* Select the Joystick Report Endpoint */
- Endpoint_SelectEndpoint(JOYSTICK_EPNUM);
-
- /* Check to see if the host is ready for another packet */
- if (Endpoint_IsINReady())
- {
- USB_JoystickReport_Data_t JoystickReportData;
-
- /* Create the next HID report to send to the host */
- GetNextReport(&JoystickReportData);
+ USB_JoystickReport_Data_t JoystickReportData;
- /* Write Joystick Report Data */
- Endpoint_Write_Stream_LE(&JoystickReportData, sizeof(JoystickReportData));
-
- /* Finalize the stream transfer to send the last packet */
- Endpoint_ClearIN();
-
- /* Clear the report data afterwards */
- memset(&JoystickReportData, 0, sizeof(JoystickReportData));
- }
+ /* Create the next HID report to send to the host */
+ GetNextReport(&JoystickReportData);
+
+ /* Write Joystick Report Data */
+ Endpoint_Write_Stream_LE(&JoystickReportData, sizeof(JoystickReportData));
+
+ /* Finalize the stream transfer to send the last packet */
+ Endpoint_ClearIN();
+
+ /* Clear the report data afterwards */
+ memset(&JoystickReportData, 0, sizeof(JoystickReportData));
}
}
diff --git a/Demos/Device/LowLevel/Keyboard/Keyboard.c b/Demos/Device/LowLevel/Keyboard/Keyboard.c
index 252714808..9950484ba 100644
--- a/Demos/Device/LowLevel/Keyboard/Keyboard.c
+++ b/Demos/Device/LowLevel/Keyboard/Keyboard.c
@@ -377,13 +377,13 @@ void ReceiveNextReport(void)
/** Function to manage HID report generation and transmission to the host, when in report mode. */
void HID_Task(void)
{
- /* Check if the USB system is connected to a host */
- if (USB_IsConnected)
- {
- /* Send the next keypress report to the host */
- SendNextReport();
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
+ /* Send the next keypress report to the host */
+ SendNextReport();
- /* Process the LED report sent from the host */
- ReceiveNextReport();
- }
+ /* Process the LED report sent from the host */
+ ReceiveNextReport();
}
diff --git a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c
index ddfe05a4b..c60f08f9c 100644
--- a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c
+++ b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c
@@ -212,6 +212,10 @@ void Keyboard_HID_Task(void)
{
uint8_t JoyStatus_LCL = Joystick_GetStatus();
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
/* Check if board button is not pressed, if so mouse mode enabled */
if (!(Buttons_GetStatus() & BUTTONS_BUTTON1))
{
@@ -228,51 +232,47 @@ void Keyboard_HID_Task(void)
if (JoyStatus_LCL & JOY_PRESS)
KeyboardReportData.KeyCode[0] = 0x08; // E
}
-
- /* Check if the USB system is connected to a host and report protocol mode is enabled */
- if (USB_IsConnected)
+
+ /* Select the Keyboard Report Endpoint */
+ Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM);
+
+ /* Check if Keyboard Endpoint Ready for Read/Write */
+ if (Endpoint_IsReadWriteAllowed())
{
- /* Select the Keyboard Report Endpoint */
- Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM);
-
- /* Check if Keyboard Endpoint Ready for Read/Write */
- if (Endpoint_IsReadWriteAllowed())
- {
- /* Write Keyboard Report Data */
- Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));
-
- /* Finalize the stream transfer to send the last packet */
- Endpoint_ClearIN();
-
- /* Clear the report data afterwards */
- memset(&KeyboardReportData, 0, sizeof(KeyboardReportData));
- }
-
- /* Select the Keyboard LED Report Endpoint */
- Endpoint_SelectEndpoint(KEYBOARD_OUT_EPNUM);
-
- /* Check if Keyboard LED Endpoint Ready for Read/Write */
- if (Endpoint_IsReadWriteAllowed())
- {
- /* Read in the LED report from the host */
- uint8_t LEDStatus = Endpoint_Read_Byte();
- uint8_t LEDMask = LEDS_LED2;
-
- if (LEDStatus & 0x01) // NUM Lock
- LEDMask |= LEDS_LED1;
-
- if (LEDStatus & 0x02) // CAPS Lock
- LEDMask |= LEDS_LED3;
+ /* Write Keyboard Report Data */
+ Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));
+
+ /* Finalize the stream transfer to send the last packet */
+ Endpoint_ClearIN();
+
+ /* Clear the report data afterwards */
+ memset(&KeyboardReportData, 0, sizeof(KeyboardReportData));
+ }
+
+ /* Select the Keyboard LED Report Endpoint */
+ Endpoint_SelectEndpoint(KEYBOARD_OUT_EPNUM);
+
+ /* Check if Keyboard LED Endpoint Ready for Read/Write */
+ if (Endpoint_IsReadWriteAllowed())
+ {
+ /* Read in the LED report from the host */
+ uint8_t LEDStatus = Endpoint_Read_Byte();
+ uint8_t LEDMask = LEDS_LED2;
+
+ if (LEDStatus & 0x01) // NUM Lock
+ LEDMask |= LEDS_LED1;
+
+ if (LEDStatus & 0x02) // CAPS Lock
+ LEDMask |= LEDS_LED3;
- if (LEDStatus & 0x04) // SCROLL Lock
- LEDMask |= LEDS_LED4;
+ if (LEDStatus & 0x04) // SCROLL Lock
+ LEDMask |= LEDS_LED4;
- /* Set the status LEDs to the current Keyboard LED status */
- LEDs_SetAllLEDs(LEDMask);
+ /* Set the status LEDs to the current Keyboard LED status */
+ LEDs_SetAllLEDs(LEDMask);
- /* Handshake the OUT Endpoint - clear endpoint and ready for next report */
- Endpoint_ClearOUT();
- }
+ /* Handshake the OUT Endpoint - clear endpoint and ready for next report */
+ Endpoint_ClearOUT();
}
}
@@ -283,6 +283,10 @@ void Mouse_HID_Task(void)
{
uint8_t JoyStatus_LCL = Joystick_GetStatus();
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
/* Check if board button is pressed, if so mouse mode enabled */
if (Buttons_GetStatus() & BUTTONS_BUTTON1)
{
@@ -300,23 +304,19 @@ void Mouse_HID_Task(void)
MouseReportData.Button = (1 << 0);
}
- /* Check if the USB system is connected to a host and report protocol mode is enabled */
- if (USB_IsConnected)
- {
- /* Select the Mouse Report Endpoint */
- Endpoint_SelectEndpoint(MOUSE_IN_EPNUM);
+ /* Select the Mouse Report Endpoint */
+ Endpoint_SelectEndpoint(MOUSE_IN_EPNUM);
- /* Check if Mouse Endpoint Ready for Read/Write */
- if (Endpoint_IsReadWriteAllowed())
- {
- /* Write Mouse Report Data */
- Endpoint_Write_Stream_LE(&MouseReportData, sizeof(MouseReportData));
+ /* Check if Mouse Endpoint Ready for Read/Write */
+ if (Endpoint_IsReadWriteAllowed())
+ {
+ /* Write Mouse Report Data */
+ Endpoint_Write_Stream_LE(&MouseReportData, sizeof(MouseReportData));
- /* Finalize the stream transfer to send the last packet */
- Endpoint_ClearIN();
+ /* Finalize the stream transfer to send the last packet */
+ Endpoint_ClearIN();
- /* Clear the report data afterwards */
- memset(&MouseReportData, 0, sizeof(MouseReportData));
- }
+ /* Clear the report data afterwards */
+ memset(&MouseReportData, 0, sizeof(MouseReportData));
}
}
diff --git a/Demos/Device/LowLevel/MIDI/MIDI.c b/Demos/Device/LowLevel/MIDI/MIDI.c
index 84d377854..954cbcbf6 100644
--- a/Demos/Device/LowLevel/MIDI/MIDI.c
+++ b/Demos/Device/LowLevel/MIDI/MIDI.c
@@ -116,16 +116,17 @@ void MIDI_Task(void)
{
static uint8_t PrevJoystickStatus;
- /* Select the MIDI IN stream */
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
Endpoint_SelectEndpoint(MIDI_STREAM_IN_EPNUM);
- /* Check if endpoint is ready to be written to */
if (Endpoint_IsINReady())
{
uint8_t MIDICommand = 0;
uint8_t MIDIPitch;
- /* Get current joystick mask, XOR with previous to detect joystick changes */
uint8_t JoystickStatus = Joystick_GetStatus();
uint8_t JoystickChanges = (JoystickStatus ^ PrevJoystickStatus);
diff --git a/Demos/Device/LowLevel/Mouse/Mouse.c b/Demos/Device/LowLevel/Mouse/Mouse.c
index 60eb7fad7..febb36450 100644
--- a/Demos/Device/LowLevel/Mouse/Mouse.c
+++ b/Demos/Device/LowLevel/Mouse/Mouse.c
@@ -313,10 +313,10 @@ void SendNextReport(void)
/** Task to manage HID report generation and transmission to the host, when in report mode. */
void Mouse_Task(void)
{
- /* Check if the USB system is connected to a host */
- if (USB_IsConnected)
- {
- /* Send the next mouse report to the host */
- SendNextReport();
- }
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
+ /* Send the next mouse report to the host */
+ SendNextReport();
}
diff --git a/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c b/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c
index d77d25b6b..1c0e0304c 100644
--- a/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c
+++ b/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c
@@ -284,6 +284,10 @@ void Ethernet_Task(void)
outgoing frames should be loaded into the FrameOUT structure. Both structures can only hold a single
Ethernet frame at a time, so the FrameInBuffer bool is used to indicate when the buffers contain data. */
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
/* Check if a frame has been written to the IN frame buffer */
if (FrameIN.FrameInBuffer)
{
diff --git a/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c b/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c
index c48c33c08..9160dd107 100644
--- a/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c
+++ b/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c
@@ -204,89 +204,90 @@ void EVENT_USB_UnhandledControlPacket(void)
/** Task to manage CDC data transmission and reception to and from the host, from and to the physical USART. */
void CDC_Task(void)
{
- if (USB_IsConnected)
- {
+ /* Device must be connected and configured for the task to run */
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ return;
+
#if 0
- /* NOTE: Here you can use the notification endpoint to send back line state changes to the host, for the special RS-232
- handshake signal lines (and some error states), via the CONTROL_LINE_IN_* masks and the following code:
- */
+ /* NOTE: Here you can use the notification endpoint to send back line state changes to the host, for the special RS-232
+ handshake signal lines (and some error states), via the CONTROL_LINE_IN_* masks and the following code:
+ */
- USB_Notification_Header_t Notification = (USB_Notification_Header_t)
- {
- .NotificationType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),
- .Notification = NOTIF_SerialState,
- .wValue = 0,
- .wIndex = 0,
- .wLength = sizeof(uint16_t),
- };
-
- uint16_t LineStateMask;
-
- // Set LineStateMask here to a mask of CONTROL_LINE_IN_* masks to set the input handshake line states to send to the host
+ USB_Notification_Header_t Notification = (USB_Notification_Header_t)
+ {
+ .NotificationType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),
+ .Notification = NOTIF_SerialState,
+ .wValue = 0,
+ .wIndex = 0,
+ .wLength = sizeof(uint16_t),
+ };
- Endpoint_SelectEndpoint(CDC_NOTIFICATION_EPNUM);
- Endpoint_Write_Stream_LE(&Notification, sizeof(Notification));
- Endpoint_Write_Stream_LE(&LineStateMask, sizeof(LineStateMask));
- Endpoint_ClearIN();
+ uint16_t LineStateMask;
+
+ // Set LineStateMask here to a mask of CONTROL_LINE_IN_* masks to set the input handshake line states to send to the host
+
+ Endpoint_SelectEndpoint(CDC_NOTIFICATION_EPNUM);
+ Endpoint_Write_Stream_LE(&Notification, sizeof(Notification));
+ Endpoint_Write_Stream_LE(&LineStateMask, sizeof(LineStateMask));
+ Endpoint_ClearIN();
#endif
- /* Select the Serial Rx Endpoint */
- Endpoint_SelectEndpoint(CDC_RX_EPNUM);
-
- /* Check to see if a packet has been received from the host */
- if (Endpoint_IsOUTReceived())
+ /* Select the Serial Rx Endpoint */
+ Endpoint_SelectEndpoint(CDC_RX_EPNUM);
+
+ /* Check to see if a packet has been received from the host */
+ if (Endpoint_IsOUTReceived())
+ {
+ /* Read the bytes in from the endpoint into the buffer while space is available */
+ while (Endpoint_BytesInEndpoint() && (Rx_Buffer.Elements != BUFF_STATICSIZE))
{
- /* Read the bytes in from the endpoint into the buffer while space is available */
- while (Endpoint_BytesInEndpoint() && (Rx_Buffer.Elements != BUFF_STATICSIZE))
- {
- /* Store each character from the endpoint */
- Buffer_StoreElement(&Rx_Buffer, Endpoint_Read_Byte());
- }
-
- /* Check to see if all bytes in the current packet have been read */
- if (!(Endpoint_BytesInEndpoint()))
- {
- /* Clear the endpoint buffer */
- Endpoint_ClearOUT();
- }
+ /* Store each character from the endpoint */
+ Buffer_StoreElement(&Rx_Buffer, Endpoint_Read_Byte());
}
- /* Check if Rx buffer contains data - if so, send it */
- if (Rx_Buffer.Elements)
- Serial_TxByte(Buffer_GetElement(&Rx_Buffer));
+ /* Check to see if all bytes in the current packet have been read */
+ if (!(Endpoint_BytesInEndpoint()))
+ {
+ /* Clear the endpoint buffer */
+ Endpoint_ClearOUT();
+ }
+ }
+
+ /* Check if Rx buffer contains data - if so, send it */
+ if (Rx_Buffer.Elements)
+ Serial_TxByte(Buffer_GetElement(&Rx_Buffer));
+
+ /* Select the Serial Tx Endpoint */
+ Endpoint_SelectEndpoint(CDC_TX_EPNUM);
- /* Select the Serial Tx Endpoint */
- Endpoint_SelectEndpoint(CDC_TX_EPNUM);
+ /* Check if the Tx buffer contains anything to be sent to the host */
+ if (Tx_Buffer.Elements)
+ {
+ /* Wait until Serial Tx Endpoint Ready for Read/Write */
+ while (!(Endpoint_IsReadWriteAllowed()));
+
+ /* Write the bytes from the buffer to the endpoint while space is available */
+ while (Tx_Buffer.Elements && Endpoint_IsReadWriteAllowed())
+ {
+ /* Write each byte retreived from the buffer to the endpoint */
+ Endpoint_Write_Byte(Buffer_GetElement(&Tx_Buffer));
+ }
+
+ /* Remember if the packet to send completely fills the endpoint */
+ bool IsFull = (Endpoint_BytesInEndpoint() == CDC_TXRX_EPSIZE);
+
+ /* Send the data */
+ Endpoint_ClearIN();
- /* Check if the Tx buffer contains anything to be sent to the host */
- if (Tx_Buffer.Elements)
+ /* If no more data to send and the last packet filled the endpoint, send an empty packet to release
+ * the buffer on the receiver (otherwise all data will be cached until a non-full packet is received) */
+ if (IsFull && !(Tx_Buffer.Elements))
{
/* Wait until Serial Tx Endpoint Ready for Read/Write */
while (!(Endpoint_IsReadWriteAllowed()));
-
- /* Write the bytes from the buffer to the endpoint while space is available */
- while (Tx_Buffer.Elements && Endpoint_IsReadWriteAllowed())
- {
- /* Write each byte retreived from the buffer to the endpoint */
- Endpoint_Write_Byte(Buffer_GetElement(&Tx_Buffer));
- }
-
- /* Remember if the packet to send completely fills the endpoint */
- bool IsFull = (Endpoint_BytesInEndpoint() == CDC_TXRX_EPSIZE);
-
- /* Send the data */
- Endpoint_ClearIN();
- /* If no more data to send and the last packet filled the endpoint, send an empty packet to release
- * the buffer on the receiver (otherwise all data will be cached until a non-full packet is received) */
- if (IsFull && !(Tx_Buffer.Elements))
- {
- /* Wait until Serial Tx Endpoint Ready for Read/Write */
- while (!(Endpoint_IsReadWriteAllowed()));
-
- /* Send an empty packet to terminate the transfer */
- Endpoint_ClearIN();
- }
+ /* Send an empty packet to terminate the transfer */
+ Endpoint_ClearIN();
}
}
}