mirror of https://github.com/ARMmbed/mbed-os.git
Add support for UARTSerial::write from critical section
parent
d30ae07b6e
commit
1094c08129
|
@ -134,6 +134,23 @@ void UARTSerial::sigio(Callback<void()> func)
|
|||
core_util_critical_section_exit();
|
||||
}
|
||||
|
||||
/* Special synchronous write designed to work from critical section, such
|
||||
* as in mbed_error_vfprintf.
|
||||
*/
|
||||
ssize_t UARTSerial::write_unbuffered(const char *buf_ptr, size_t length)
|
||||
{
|
||||
while (!_txbuf.empty()) {
|
||||
tx_irq();
|
||||
}
|
||||
|
||||
for (size_t data_written = 0; data_written < length; data_written++) {
|
||||
SerialBase::_base_putc(*buf_ptr++);
|
||||
data_written++;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
ssize_t UARTSerial::write(const void *buffer, size_t length)
|
||||
{
|
||||
size_t data_written = 0;
|
||||
|
@ -143,6 +160,10 @@ ssize_t UARTSerial::write(const void *buffer, size_t length)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (core_util_in_critical_section()) {
|
||||
return write_unbuffered(buf_ptr, length);
|
||||
}
|
||||
|
||||
api_lock();
|
||||
|
||||
// Unlike read, we should write the whole thing if blocking. POSIX only
|
||||
|
|
|
@ -238,6 +238,9 @@ private:
|
|||
/** Release mutex */
|
||||
virtual void api_unlock(void);
|
||||
|
||||
/** Unbuffered write - invoked when write called from critical section */
|
||||
ssize_t write_unbuffered(const char *buf_ptr, size_t length);
|
||||
|
||||
/** Software serial buffers
|
||||
* By default buffer size is 256 for TX and 256 for RX. Configurable through mbed_app.json
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue