Skip to content

Commit 0a1ae05

Browse files
committed
Deprecate wait/wait_ms APIs
1 parent 872ce93 commit 0a1ae05

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

drivers/UARTSerial.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "platform/mbed_poll.h"
2222

23-
#if MBED_CONF_RTOS_PRESENT
23+
#if MBED_CONF_RTOS_API_PRESENT
2424
#include "rtos/ThisThread.h"
2525
#else
2626
#include "platform/mbed_wait_api.h"
@@ -413,7 +413,7 @@ void UARTSerial::wait_ms(uint32_t millisec)
413413
/* wait_ms implementation for RTOS spins until exact microseconds - we
414414
* want to just sleep until next tick.
415415
*/
416-
#if MBED_CONF_RTOS_PRESENT
416+
#if MBED_CONF_RTOS_API_PRESENT
417417
rtos::ThisThread::sleep_for(millisec);
418418
#else
419419
::wait_ms(millisec);

platform/mbed_wait_api.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifndef MBED_WAIT_API_H
2626
#define MBED_WAIT_API_H
2727

28+
#include "mbed_toolchain.h"
29+
2830
#ifdef __cplusplus
2931
extern "C" {
3032
#endif
@@ -60,6 +62,10 @@ extern "C" {
6062
* microsecond precision up to 10 milliseconds. If delay is larger than 10 milliseconds and not in ISR, it is the same as
6163
* `wait_ms`. We recommend `wait_us` and `wait_ms` over `wait`.
6264
*/
65+
MBED_DEPRECATED_SINCE("mbed-os-5.13",
66+
"'wait'-named functions are now reserved for CPU-using delays that are safe to call from IRQ context. "
67+
"This call should be replaced by either a sleep call such as ThisThread::sleep_for (C++) or "
68+
"thread_sleep_for (C), or by a wait call such as wait_us(), depending on required behaviour.")
6369
void wait(float s);
6470

6571
/** Waits a number of milliseconds.
@@ -70,6 +76,9 @@ void wait(float s);
7076
* If the RTOS is present, it calls ThisThread::sleep_for(), which is same as CMSIS osDelay().
7177
* You can't call this from interrupts, and it doesn't lock hardware sleep.
7278
*/
79+
MBED_DEPRECATED_SINCE("mbed-os-5.13",
80+
"'wait'-named functions are now reserved for CPU-using delays that are safe to call from IRQ context. "
81+
"This sleeping call is replaced by ThisThread::sleep_for (C++) or thread_sleep_for (C).")
7382
void wait_ms(int ms);
7483

7584
/** Waits a number of microseconds.
@@ -79,7 +88,7 @@ void wait_ms(int ms);
7988
* @note
8089
* This function always spins to get the exact number of microseconds.
8190
* This will affect power and multithread performance. Therefore, spinning for
82-
* millisecond wait is not recommended, and wait_ms() should
91+
* millisecond wait is not recommended, and ThisThread::sleep_for should
8392
* be used instead.
8493
*
8594
* @note You may call this function from ISR context, but large delays may

platform/mbed_wait_api_rtos.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
void wait(float s)
3131
{
3232
if ((s >= 0.01f) && core_util_are_interrupts_enabled()) {
33-
wait_ms(s * 1000.0f);
33+
rtos::ThisThread::sleep_for(s * 1000.0f);
3434
return;
3535
}
3636

@@ -68,7 +68,7 @@ void wait_us(int us)
6868
{
6969
if (us > 10000) {
7070
MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_UNKNOWN),
71-
"wait_us blocks deep sleep, wait_ms recommended for long delays\n");
71+
"wait_us blocks sleep, ThisThread::sleep_for required for long delays\n");
7272
}
7373
const ticker_data_t *const ticker = get_us_ticker_data();
7474
uint32_t start = ticker_read(ticker);

rtos/ThisThread.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ uint32_t flags_wait_any_until(uint32_t flags, uint64_t millisec, bool clear = tr
147147
/** Sleep for a specified time period in millisec:
148148
@param millisec time delay value
149149
@note You cannot call this function from ISR context.
150+
@note The equivalent functionality is accessible in C via thread_sleep_for.
150151
*/
151152
void sleep_for(uint32_t millisec);
152153

@@ -156,6 +157,7 @@ void sleep_for(uint32_t millisec);
156157
@note You cannot call this function from ISR context.
157158
@note if millisec is equal to or lower than the current tick count, this
158159
returns immediately.
160+
@note The equivalent functionality is accessible in C via thread_sleep_until.
159161
*/
160162
void sleep_until(uint64_t millisec);
161163

0 commit comments

Comments
 (0)