Skip to content
Snippets Groups Projects
Verified Commit 4a292ac0 authored by rahix's avatar rahix
Browse files

workaround(cdcacm): Fix CDC-ACM lockup on host hangup


This patch is a workaround for #54.  A lockup is detected if more than
4096 attempts to write to the USB FIFO fail.  If this condition is
detected, CDC-ACM is disabled until the next reboot.

Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 3ccec228
Branches
No related tags found
No related merge requests found
...@@ -199,10 +199,14 @@ uint8_t cdcacm_read(void) ...@@ -199,10 +199,14 @@ uint8_t cdcacm_read(void)
void cdcacm_write(uint8_t *data, int len) void cdcacm_write(uint8_t *data, int len)
{ {
while (acm_present()) { static int lockup_disable = 0;
// TODO: This might fail horribly if (acm_present() && !lockup_disable) {
if (acm_write(data, len) == len) { int ret = acm_write(data, len);
break; if (ret < 0) {
LOG_ERR("cdcacm", "fifo lockup detected");
lockup_disable = 1;
} else if (ret != len) {
LOG_WARN("cdcacm", "write length mismatch, got %d", ret);
} }
} }
} }
......
...@@ -329,10 +329,12 @@ int acm_read(uint8_t *buf, unsigned int len) ...@@ -329,10 +329,12 @@ int acm_read(uint8_t *buf, unsigned int len)
int acm_write(uint8_t *buf, unsigned int len) int acm_write(uint8_t *buf, unsigned int len)
{ {
unsigned int i = 0; unsigned int i = 0;
unsigned int failcount = 0;
/* Write data into the FIFO */ /* Write data into the FIFO */
while (len > 0) { while (len > 0) {
if (fifo_put8(&wfifo, buf[i]) == 0) { if (fifo_put8(&wfifo, buf[i]) == 0) {
failcount = 0;
/* Success */ /* Success */
i++; len--; i++; len--;
} else { } else {
...@@ -340,6 +342,10 @@ int acm_write(uint8_t *buf, unsigned int len) ...@@ -340,6 +342,10 @@ int acm_write(uint8_t *buf, unsigned int len)
if (wreq.reqlen == 0) { if (wreq.reqlen == 0) {
svc_in_to_host(&wreq); svc_in_to_host(&wreq);
} }
if (failcount++ > 4096) {
return -1;
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment