8000 Add Serial UART break reporting (#1130) · uPesy/arduino-pico@9a241b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a241b0

Browse files
authored
Add Serial UART break reporting (earlephilhower#1130)
Added SerialUART::getBreakReceived()
1 parent e3f2f87 commit 9a241b0

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed
< 8000 div class="pt-0">

cores/rp2040/SerialUART.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
200200
} else {
201201
// Polling mode has no IRQs used
202202
}
203+
_break = false;
203204
_running = true;
204205
}
205206

@@ -365,6 +366,25 @@ SerialUART::operator bool() {
365366
return _running;
366367
}
367368

369+
bool SerialUART::getBreakReceived() {
370+
if (!_running) {
371+
return false;
372+
}
373+
374+
if (_polling) {
375+
_handleIRQ(false);
376+
} else {
377+
_pumpFIFO();
378+
}
379+
380+
mutex_enter_blocking(&_fifoMutex);
381+
bool break_received = _break;
382+
_break = false;
383+
mutex_exit(&_fifoMutex);
384+
385+
return break_received;
386+
}
387+
368388
void arduino::serialEvent1Run(void) {
369389
if (serialEvent1 && Serial1.available()) {
370390
serialEvent1();
@@ -391,8 +411,12 @@ void __not_in_flash_func(SerialUART::_handleIRQ)(bool inIRQ) {
391411
uart_get_hw(_uart)->icr = UART_UARTICR_RTIC_BITS | UART_UARTICR_RXIC_BITS;
392412
while (uart_is_readable(_uart)) {
393413
uint32_t raw = uart_get_hw(_uart)->dr;
394-
if (raw & 0x700) {
395-
// Framing, Parity, or Break. Ignore this bad char
414+
if (raw & 0x400) {
415+
// break!
416+
_break = true;
417+
continue;
418+
} else if (raw & 0x300) {
419+
// Framing, Parity Error. Ignore this bad char
396420
continue;
397421
}
398422
uint8_t val = raw & 0xff;

cores/rp2040/SerialUART.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class SerialUART : public HardwareSerial {
7171
// Not to be called by users, only from the IRQ handler. In public so that the C-language IQR callback can access it
7272
void _handleIRQ(bool inIRQ = true);
7373

74+
// Allows the user to sleep until a break is received (self-clears the flag
75+
// on read)
76+
bool getBreakReceived();
77+
7478
private:
7579
bool _running = false;
7680
uart_inst_t *_uart;
@@ -81,6 +85,7 @@ class SerialUART : public HardwareSerial {
8185
mutex_t _mutex;
8286
bool _polling = false;
8387
bool _overflow;
88+
bool _break;
8489

8590
// Lockless, IRQ-handled circular queue
8691
uint32_t _writer;

0 commit comments

Comments
 (0)
0