Unverified Commit 3ee031ab authored by Earle F. Philhower, III's avatar Earle F. Philhower, III Committed by GitHub

Add ::overflow() return to SerialUART/SerialPIO (#547)

Matching the Arduino SoftwareSerial API
parent d1f9bce0
......@@ -127,7 +127,7 @@ void __not_in_flash_func(SerialPIO::_handleIRQ)() {
asm volatile("" ::: "memory"); // Ensure the queue is written before the written count advances
_writer = next_writer;
} else {
// TODO: Overflow
_overflow = true;
}
}
}
......@@ -146,6 +146,7 @@ SerialPIO::~SerialPIO() {
}
void SerialPIO::begin(unsigned long baud, uint16_t config) {
_overflow = false;
_baud = baud;
switch (config & SERIAL_PARITY_MASK) {
case SERIAL_PARITY_EVEN:
......@@ -289,6 +290,17 @@ int SerialPIO::read() {
return -1;
}
bool SerialPIO::overflow() {
CoreMutex m(&_mutex);
if (!_running || !m || (_rx == NOPIN)) {
return false;
}
bool hold = _overflow;
_overflow = false;
return hold;
}
int SerialPIO::available() {
CoreMutex m(&_mutex);
if (!_running || !m || (_rx == NOPIN)) {
......
......@@ -47,6 +47,7 @@ public:
virtual int availableForWrite() override;
virtual void flush() override;
virtual size_t write(uint8_t c) override;
bool overflow();
using Print::write;
operator bool() override;
......@@ -60,6 +61,7 @@ private:
int _bits;
uart_parity_t _parity;
int _stop;
bool _overflow;
mutex_t _mutex;
PIOProgram *_txPgm;
......
......@@ -131,6 +131,7 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
if (_running) {
end();
}
_overflow = false;
_queue = new uint8_t[_fifoSize];
_baud = baud;
uart_init(_uart, baud);
......@@ -271,6 +272,16 @@ int SerialUART::read() {
return -1;
}
bool SerialUART::overflow() {
CoreMutex m(&_mutex);
if (!_running || !m) {
return false;
}
bool hold = _overflow;
_overflow = false;
return hold;
}
int SerialUART::available() {
CoreMutex m(&_mutex);
if (!_running || !m) {
......@@ -387,7 +398,7 @@ void __not_in_flash_func(SerialUART::_handleIRQ)(bool inIRQ) {
// Avoid using division or mod because the HW divider could be in use
_writer = next_writer;
} else {
// TODO: Overflow
_overflow = true;
}
}
if (inIRQ) {
......
......@@ -60,6 +60,7 @@ public:
virtual size_t write(uint8_t c) override;
virtual size_t write(const uint8_t *p, size_t len) override;
using Print::write;
bool overflow();
operator bool() override;
// Not to be called by users, only from the IRQ handler. In public so that the C-language IQR callback can access it
......@@ -73,6 +74,7 @@ private:
int _baud;
mutex_t _mutex;
bool _polling = false;
bool _overflow;
// Lockless, IRQ-handled circular queue
uint32_t _writer;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment