File tree 1 file changed +8
-8
lines changed
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)
214
214
{
215
215
ring_buffer *buffer = &cdc_rx_buffer;
216
216
217
+ uint8_t enableInterrupts = ((__get_PRIMASK () & 0x1 ) == 0 );
218
+ __disable_irq ();
219
+
217
220
// if we have enough space enable OUT endpoint to receive more data
218
221
if (stalled && availableForStore () >= EPX_SIZE)
219
222
{
220
223
stalled = false ;
221
224
usb.epOut (CDC_ENDPOINT_OUT);
222
225
}
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 )
228
228
{
229
- unsigned char c = buffer->buffer [buffer->tail ];
229
+ c = buffer->buffer [buffer->tail ];
230
230
buffer->tail = (uint32_t )(buffer->tail + 1 ) % CDC_SERIAL_BUFFER_SIZE;
231
231
buffer->full = false ;
232
-
233
- return c;
234
232
}
233
+ if (enableInterrupts) __enable_irq ();
234
+ return c;
235
235
}
236
236
237
237
void Serial_::flush (void )
You can’t perform that action at this time.
0 commit comments