Skip to content
Snippets Groups Projects
Commit 19ae0eb4 authored by Cristian Maglie's avatar Cristian Maglie
Browse files

USB-CDC: access to rx buffer is now ISR-protected

parent 9f678cb4
No related branches found
No related tags found
No related merge requests found
......@@ -214,24 +214,24 @@ int Serial_::read(void)
{
ring_buffer *buffer = &cdc_rx_buffer;
uint8_t enableInterrupts = ((__get_PRIMASK() & 0x1) == 0);
__disable_irq();
// if we have enough space enable OUT endpoint to receive more data
if (stalled && availableForStore() >= EPX_SIZE)
{
stalled = false;
usb.epOut(CDC_ENDPOINT_OUT);
}
if (buffer->head == buffer->tail && !buffer->full)
{
return -1;
}
else
int c = -1;
if (buffer->head != buffer->tail || buffer->full)
{
unsigned char c = buffer->buffer[buffer->tail];
c = buffer->buffer[buffer->tail];
buffer->tail = (uint32_t)(buffer->tail + 1) % CDC_SERIAL_BUFFER_SIZE;
buffer->full = false;
return c;
}
if (enableInterrupts) __enable_irq();
return c;
}
void Serial_::flush(void)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment