Skip to content

Commit 73953c2

Browse files
committed
Deprecate wait/wait_ms APIs
1 parent c451e8c commit 73953c2

File tree

9 files changed

+34
-10
lines changed

9 files changed

+34
-10
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ set(unittest-test-sources
2626
stubs/CellularUtil_stub.cpp
2727
stubs/us_ticker_stub.cpp
2828
stubs/mbed_assert_stub.c
29-
stubs/mbed_wait_api_stub.cpp
29+
stubs/ThisThread_stub.cpp
3030
)

UNITTESTS/features/cellular/framework/AT/athandler/unittest.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ set(unittest-test-sources
2525
stubs/EventQueue_stub.cpp
2626
stubs/FileHandle_stub.cpp
2727
stubs/us_ticker_stub.cpp
28-
stubs/mbed_wait_api_stub.cpp
2928
stubs/mbed_assert_stub.c
3029
stubs/mbed_poll_stub.cpp
3130
stubs/Timer_stub.cpp

UNITTESTS/stubs/ThisThread_stub.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
namespace rtos {
2121

22+
void ThisThread::sleep_for(uint32_t millisec)
23+
{
24+
}
25+
2226
void ThisThread::sleep_until(uint64_t millisec)
2327
{
2428
}

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616

1717
#include "SPIFBlockDevice.h"
18+
#include "rtos/ThisThread.h"
1819
#include "mbed_critical.h"
1920

2021
#include <string.h>
21-
#include "mbed_wait_api.h"
2222

2323
#include "mbed_trace.h"
2424
#define TRACE_GROUP "SPIF"
@@ -937,7 +937,7 @@ bool SPIFBlockDevice::_is_mem_ready()
937937
bool mem_ready = true;
938938

939939
do {
940-
wait_ms(1);
940+
rtos::ThisThread::sleep_for(1);
941941
retries++;
942942
//Read the Status Register from device
943943
if (SPIF_BD_ERROR_OK != _spi_send_general_command(SPIF_RDSR, SPI_NO_ADDRESS_COMMAND, NULL, 0, status_value,

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"
@@ -412,7 +412,7 @@ void UARTSerial::wait_ms(uint32_t millisec)
412412
/* wait_ms implementation for RTOS spins until exact microseconds - we
413413
* want to just sleep until next tick.
414414
*/
415-
#if MBED_CONF_RTOS_PRESENT
415+
#if MBED_CONF_RTOS_API_PRESENT
416416
rtos::ThisThread::sleep_for(millisec);
417417
#else
418418
::wait_ms(millisec);

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "ATHandler.h"
2222
#include "mbed_poll.h"
2323
#include "FileHandle.h"
24-
#include "mbed_wait_api.h"
2524
#include "mbed_debug.h"
2625
#include "rtos/ThisThread.h"
2726
#include "Kernel.h"

platform/mbed_wait_api.h

Lines changed: 21 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
@@ -59,7 +61,16 @@ extern "C" {
5961
* If the RTOS is present, this function spins to get the exact number of microseconds for
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`.
64+
*
65+
* @deprecated
66+
* 'wait' is deprecated in favor of explicit sleep functions. To sleep, 'wait' should be replaced by
67+
* 'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call
68+
* 'wait_us'. 'wait_us' is safe to call from ISR context.
6269
*/
70+
MBED_DEPRECATED_SINCE("mbed-os-5.13",
71+
"'wait' is deprecated in favor of explicit sleep functions. To sleep, 'wait' should be replaced by "
72+
"'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call "
73+
"'wait_us'. 'wait_us' is safe to call from ISR context.")
6374
void wait(float s);
6475

6576
/** Waits a number of milliseconds.
@@ -69,7 +80,16 @@ void wait(float s);
6980
* @note
7081
* If the RTOS is present, it calls ThisThread::sleep_for(), which is same as CMSIS osDelay().
7182
* You can't call this from interrupts, and it doesn't lock hardware sleep.
83+
*
84+
* @deprecated
85+
* 'wait_ms' is deprecated in favor of explicit sleep functions. To sleep, 'wait_ms' should be replaced by
86+
* 'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call
87+
* 'wait_us'. 'wait_us' is safe to call from ISR context.
7288
*/
89+
MBED_DEPRECATED_SINCE("mbed-os-5.13",
90+
"'wait_ms' is deprecated in favor of explicit sleep functions. To sleep, 'wait_ms' should be replaced by "
91+
"'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call "
92+
"'wait_us'. 'wait_us' is safe to call from ISR context.")
7393
void wait_ms(int ms);
7494

7595
/** Waits a number of microseconds.
@@ -79,7 +99,7 @@ void wait_ms(int ms);
7999
* @note
80100
* This function always spins to get the exact number of microseconds.
81101
* This will affect power and multithread performance. Therefore, spinning for
82-
* millisecond wait is not recommended, and wait_ms() should
102+
* millisecond wait is not recommended, and ThisThread::sleep_for should
83103
* be used instead.
84104
*
85105
* @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)