Skip to content

UnbufferedSerial: add is_tx_active() #14420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions drivers/include/drivers/SerialBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ class SerialBase : private NonCopyable<SerialBase> {
*/
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);
Expand Down
8 changes: 8 additions & 0 deletions drivers/include/drivers/UnbufferedSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to reimplement the method. Just import it from the parent class:

using SerialBase::is_tx_active;

#endif // DEVICE_SERIAL_ASYNCH
};

} // namespace mbed
Expand Down
10 changes: 10 additions & 0 deletions drivers/source/SerialBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions drivers/source/UnbufferedSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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