aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/HardwareSerial.cpp
diff options
context:
space:
mode:
authorPaulStoffregen <paul@pjrc.com>2014-07-18 07:01:26 -0700
committerPaulStoffregen <paul@pjrc.com>2014-07-18 07:01:26 -0700
commitbcc5488cbcddc8c3d7125fb59ac7edc054673ebc (patch)
treee490234dbc8facd41daa0b482f8331c3022bf8fb /cores/arduino/HardwareSerial.cpp
parentcb4ae51b425568c7d404798ec4010660c46a5638 (diff)
Add availableForWrite() to HardwareSerial
Diffstat (limited to 'cores/arduino/HardwareSerial.cpp')
-rw-r--r--cores/arduino/HardwareSerial.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp
index ed29641..29a3366 100644
--- a/cores/arduino/HardwareSerial.cpp
+++ b/cores/arduino/HardwareSerial.cpp
@@ -176,6 +176,21 @@ int HardwareSerial::read(void)
}
}
+int HardwareSerial::availableForWrite(void)
+{
+#if (SERIAL_TX_BUFFER_SIZE>256)
+ uint8_t oldSREG = SREG;
+ cli();
+#endif
+ tx_buffer_index_t head = _tx_buffer_head;
+ tx_buffer_index_t tail = _tx_buffer_tail;
+#if (SERIAL_TX_BUFFER_SIZE>256)
+ SREG = oldSREG;
+#endif
+ if (head >= tail) return SERIAL_TX_BUFFER_SIZE - 1 - head + tail;
+ return tail - head - 1;
+}
+
void HardwareSerial::flush()
{
// If we have never written a byte, no need to flush. This special