mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Diff: drivers/UARTSerial.cpp
- Revision:
- 189:f392fc9709a3
- Parent:
- 188:bcfe06ba3d64
--- a/drivers/UARTSerial.cpp Thu Nov 08 11:46:34 2018 +0000 +++ b/drivers/UARTSerial.cpp Wed Feb 20 22:31:08 2019 +0000 @@ -1,5 +1,6 @@ /* mbed Microcontroller Library * Copyright (c) 2006-2017 ARM Limited + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ #include "platform/mbed_poll.h" #if MBED_CONF_RTOS_PRESENT -#include "rtos/Thread.h" +#include "rtos/ThisThread.h" #else #include "platform/mbed_wait_api.h" #endif @@ -133,6 +134,23 @@ core_util_critical_section_exit(); } +/* Special synchronous write designed to work from critical section, such + * as in mbed_error_vprintf. + */ +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; @@ -142,6 +160,10 @@ 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 @@ -331,7 +353,7 @@ * want to just sleep until next tick. */ #if MBED_CONF_RTOS_PRESENT - rtos::Thread::wait(millisec); + rtos::ThisThread::sleep_for(millisec); #else ::wait_ms(millisec); #endif