Skip to content

Commit 0f07ea0

Browse files
Dan-Lightsourcecalvinatintel
authored andcommitted
CDC-ACM - Fix slow write() performance and availableForWrite() logic
- Removed delay in write() function which caused slow TX performance - Removed timeout logic in write() function; moved to LMT side - Fixed logic in availableForWrite() - ring-buffer capacity is at most 1 less than actual size to avoid head index passing tail index Signed-off-by: Dan O'Donovan <dan@emutex.com>
1 parent 33f4380 commit 0f07ea0

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

cores/arduino/CDCSerialClass.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ int CDCSerialClass::availableForWrite(void)
8888
int tail = _tx_buffer->_iTail;
8989

9090
if (head >= tail)
91-
return SERIAL_BUFFER_SIZE - head + tail;
92-
return tail - head;
91+
return SERIAL_BUFFER_SIZE - head + tail - 1;
92+
return tail - head - 1;
9393
}
9494

9595
int CDCSerialClass::peek(void)
@@ -117,18 +117,12 @@ void CDCSerialClass::flush( void )
117117

118118
size_t CDCSerialClass::write( const uint8_t uc_data )
119119
{
120-
int timeout = 25; /* 250 milliseconds */
121-
122120
if (!opened)
123121
return(0);
124122

125123
do {
126124
_tx_buffer->store_char(uc_data);
127-
delay(10);
128-
timeout--;
129-
} while (_tx_buffer->_buffer_overflow && timeout);
130-
if (timeout > 0)
131-
return 1;
132-
else
133-
return 0;
125+
} while (_tx_buffer->_buffer_overflow);
126+
127+
return 1;
134128
}

0 commit comments

Comments
 (0)