handle case where a short line, and the start of a line longer than (buffer - usbpack...
authorMichael Moon <triffid.hunter@gmail.com>
Sun, 22 Dec 2013 22:33:36 +0000 (09:33 +1100)
committerMichael Moon <triffid.hunter@gmail.com>
Sun, 22 Dec 2013 22:33:36 +0000 (09:33 +1100)
src/libs/USBDevice/USBSerial/USBSerial.cpp

index b7139a1..53533b8 100644 (file)
@@ -69,6 +69,15 @@ int USBSerial::_getc()
         usb->endpointSetInterrupt(CDC_BulkOut.bEndpointAddress, true);\r
         iprintf("rxbuf has room for another packet, interrupt enabled\n");\r
     }\r
+    else if ((rxbuf.free() < MAX_PACKET_SIZE_EPBULK) && (nl_in_rx == 0))\r
+    {\r
+        // handle potential deadlock where a short line, and the beginning of a very long line are bundled in one usb packet\r
+        rxbuf.flush();\r
+        flush_to_nl = true;\r
+\r
+        usb->endpointSetInterrupt(CDC_BulkOut.bEndpointAddress, true);\r
+        iprintf("rxbuf has room for another packet, interrupt enabled\n");\r
+    }\r
     if (nl_in_rx > 0)\r
         if (c == '\n' || c == '\r')\r
             nl_in_rx--;\r