File tree 1 file changed +17
-12
lines changed
hardware/arduino/sam/cores/arduino/USB
1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -309,18 +309,23 @@ Serial_::operator bool()
309
309
}
310
310
311
311
int32_t Serial_::readBreak () {
312
- // read the breakValue, using exclusive read
313
- int32_t ret = __LDREXW ((volatile uint32_t *)&breakValue);
314
-
315
- if (ret == -1 ) {
316
- // no new break value, clear exclusive access record
317
- __CLREX ();
318
- } else {
319
- // only set it to -1 (no break),
320
- // if a new value has not been written in the ISR,
321
- // using exclusive write
322
- __STREXW (-1 , (volatile uint32_t *)&breakValue);
323
- }
312
+ uint8_t enableInterrupts = ((__get_PRIMASK () & 0x1 ) == 0 &&
313
+ (__get_FAULTMASK () & 0x1 ) == 0 );
314
+
315
+ // disable interrupts,
316
+ // to avoid clearing a breakValue that might occur
317
+ // while processing the current break value
318
+ __disable_irq ();
319
+
320
+ int ret = breakValue;
321
+
322
+ breakValue = -1 ;
323
+
324
+ if (enableInterrupts)
325
+ {
326
+ // re-enable the interrupts
327
+ __enable_irq ();
328
+ }
324
329
325
330
return ret;
326
331
}
You can’t perform that action at this time.
0 commit comments