From 52a15387c427e83cf6ee7973086dae47648672ee Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 11 Mar 2021 15:22:31 +0100 Subject: [PATCH] UnbufferedSerial add is_tx_active() --- drivers/include/drivers/SerialBase.h | 6 ++++++ drivers/include/drivers/UnbufferedSerial.h | 8 ++++++++ drivers/source/SerialBase.cpp | 10 ++++++++++ drivers/source/UnbufferedSerial.cpp | 13 +++++++++++++ 4 files changed, 37 insertions(+) diff --git a/drivers/include/drivers/SerialBase.h b/drivers/include/drivers/SerialBase.h index 9288c271e15..33bb7a8741c 100644 --- a/drivers/include/drivers/SerialBase.h +++ b/drivers/include/drivers/SerialBase.h @@ -273,6 +273,12 @@ class SerialBase : private NonCopyable { */ int set_dma_usage_rx(DMAUsage usage); + /** Attempts to determine if the serial peripheral is already in use for TX + * + * @return Non-zero if the TX transaction is ongoing, 0 otherwise + */ + int is_tx_active(); + #if !defined(DOXYGEN_ONLY) protected: void start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t &callback, int event, unsigned char char_match); diff --git a/drivers/include/drivers/UnbufferedSerial.h b/drivers/include/drivers/UnbufferedSerial.h index a330d6e92bc..dc93e764aee 100644 --- a/drivers/include/drivers/UnbufferedSerial.h +++ b/drivers/include/drivers/UnbufferedSerial.h @@ -211,6 +211,14 @@ class UnbufferedSerial: */ void set_flow_control(Flow type, PinName flow1 = NC, PinName flow2 = NC); #endif // DEVICE_SERIAL_FC + +#if DEVICE_SERIAL_ASYNCH + /** Attempts to determine if the serial peripheral is already in use for TX + * + * @return Non-zero if the TX transaction is ongoing, 0 otherwise + */ + int is_tx_active(); +#endif // DEVICE_SERIAL_ASYNCH }; } // namespace mbed diff --git a/drivers/source/SerialBase.cpp b/drivers/source/SerialBase.cpp index 40bf7d0b618..3b56daff923 100644 --- a/drivers/source/SerialBase.cpp +++ b/drivers/source/SerialBase.cpp @@ -486,6 +486,16 @@ void SerialBase::interrupt_handler_asynch(void) } } +int SerialBase::is_tx_active(void) +{ + int result = 0; + lock(); + result = serial_tx_active(&_serial); + unlock(); + + return result; +} + #endif } // namespace mbed diff --git a/drivers/source/UnbufferedSerial.cpp b/drivers/source/UnbufferedSerial.cpp index cc86530344d..43477c06e62 100644 --- a/drivers/source/UnbufferedSerial.cpp +++ b/drivers/source/UnbufferedSerial.cpp @@ -122,6 +122,19 @@ void UnbufferedSerial::set_flow_control(Flow type, PinName flow1, PinName flow2) } #endif // DEVICE_SERIAL_FC +#if DEVICE_SERIAL_ASYNCH +int UnbufferedSerial::is_tx_active(void) +{ + int retval; + + lock(); + retval = SerialBase::is_tx_active(); + unlock(); + + return retval; +} +#endif // DEVICE_SERIAL_ASYNCH + } // namespace mbed #endif // #if DEVICE_SERIAL