File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -214,24 +214,24 @@ int Serial_::read(void)
214214{
215215 ring_buffer *buffer = &cdc_rx_buffer;
216216
217+ uint8_t enableInterrupts = ((__get_PRIMASK () & 0x1 ) == 0 );
218+ __disable_irq ();
219+
217220 // if we have enough space enable OUT endpoint to receive more data
218221 if (stalled && availableForStore () >= EPX_SIZE)
219222 {
220223 stalled = false ;
221224 usb.epOut (CDC_ENDPOINT_OUT);
222225 }
223- if (buffer->head == buffer->tail && !buffer->full )
224- {
225- return -1 ;
226- }
227- else
226+ int c = -1 ;
227+ if (buffer->head != buffer->tail || buffer->full )
228228 {
229- unsigned char c = buffer->buffer [buffer->tail ];
229+ c = buffer->buffer [buffer->tail ];
230230 buffer->tail = (uint32_t )(buffer->tail + 1 ) % CDC_SERIAL_BUFFER_SIZE;
231231 buffer->full = false ;
232-
233- return c;
234232 }
233+ if (enableInterrupts) __enable_irq ();
234+ return c;
235235}
236236
237237void Serial_::flush (void )
You can’t perform that action at this time.
0 commit comments