Skip to content

Commit fc8e8f6

Browse files
committed
Deprecate wait/wait_ms APIs
1 parent 04cb39d commit fc8e8f6

File tree

12 files changed

+40
-62
lines changed

12 files changed

+40
-62
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
@@ -23,7 +23,6 @@ set(unittest-test-sources
2323
stubs/EventQueue_stub.cpp
2424
stubs/FileHandle_stub.cpp
2525
stubs/us_ticker_stub.cpp
26-
stubs/mbed_wait_api_stub.cpp
2726
stubs/mbed_assert_stub.c
2827
stubs/mbed_poll_stub.cpp
2928
stubs/Timer_stub.cpp

UNITTESTS/stubs/UARTSerial_stub.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ int UARTSerial::enable_output(bool enabled)
130130
return 0;
131131
}
132132

133-
void UARTSerial::wait_ms(uint32_t millisec)
134-
{
135-
136-
}
137-
138133
void UARTSerial::set_flow_control(mbed::SerialBase::Flow, PinName, PinName)
139134
{
140135

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"
@@ -910,7 +910,7 @@ bool SPIFBlockDevice::_is_mem_ready()
910910
bool mem_ready = true;
911911

912912
do {
913-
wait_ms(1);
913+
rtos::ThisThread::sleep_for(1);
914914
retries++;
915915
//Read the Status Register from device
916916
if (SPIF_BD_ERROR_OK != _spi_send_general_command(SPIF_RDSR, SPI_NO_ADDRESS_COMMAND, NULL, 0, status_value,

drivers/UARTSerial.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@
1919
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN)
2020

2121
#include "platform/mbed_poll.h"
22-
23-
#if MBED_CONF_RTOS_PRESENT
24-
#include "rtos/ThisThread.h"
25-
#else
26-
#include "platform/mbed_wait_api.h"
27-
#endif
22+
#include "platform/mbed_thread.h"
2823

2924
namespace mbed {
3025

@@ -114,7 +109,7 @@ int UARTSerial::sync()
114109
while (!_txbuf.empty()) {
115110
api_unlock();
116111
// Doing better than wait would require TxIRQ to also do wake() when becoming empty. Worth it?
117-
wait_ms(1);
112+
thread_sleep_for(1);
118113
api_lock();
119114
}
120115

@@ -178,7 +173,7 @@ ssize_t UARTSerial::write(const void *buffer, size_t length)
178173
}
179174
do {
180175
api_unlock();
181-
wait_ms(1); // XXX todo - proper wait, WFE for non-rtos ?
176+
thread_sleep_for(1); // XXX todo - proper wait?
182177
api_lock();
183178
} while (_txbuf.full());
184179
}
@@ -221,7 +216,7 @@ ssize_t UARTSerial::read(void *buffer, size_t length)
221216
return -EAGAIN;
222217
}
223218
api_unlock();
224-
wait_ms(1); // XXX todo - proper wait, WFE for non-rtos ?
219+
thread_sleep_for(1); // XXX todo - proper wait?
225220
api_lock();
226221
}
227222

@@ -407,17 +402,6 @@ int UARTSerial::enable_output(bool enabled)
407402
return 0;
408403
}
409404

410-
void UARTSerial::wait_ms(uint32_t millisec)
411-
{
412-
/* wait_ms implementation for RTOS spins until exact microseconds - we
413-
* want to just sleep until next tick.
414-
*/
415-
#if MBED_CONF_RTOS_PRESENT
416-
rtos::ThisThread::sleep_for(millisec);
417-
#else
418-
::wait_ms(millisec);
419-
#endif
420-
}
421405
} //namespace mbed
422406

423407
#endif //(DEVICE_SERIAL && DEVICE_INTERRUPTIN)

drivers/UARTSerial.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,6 @@ class UARTSerial : private SerialBase, public FileHandle, private NonCopyable<UA
255255

256256
private:
257257

258-
void wait_ms(uint32_t millisec);
259-
260258
/** SerialBase lock override */
261259
virtual void lock(void);
262260

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/PlatformMutex.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
* - When the RTOS is absent, all methods are defined as noop.
3838
*/
3939

40-
#ifdef MBED_CONF_RTOS_PRESENT
40+
#ifdef MBED_CONF_RTOS_API_PRESENT
4141

42+
// rtos::Mutex is itself a dummy class if the RTOS API is present, but not the RTOS
4243
#include "rtos/Mutex.h"
4344
typedef rtos::Mutex PlatformMutex;
4445

platform/mbed_poll.cpp

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,7 @@
1616
*/
1717
#include "mbed_poll.h"
1818
#include "FileHandle.h"
19-
#if MBED_CONF_RTOS_PRESENT
20-
#include "rtos/Kernel.h"
21-
#include "rtos/ThisThread.h"
22-
using namespace rtos;
23-
#else
24-
#include "drivers/Timer.h"
25-
#include "drivers/LowPowerTimer.h"
26-
#endif
19+
#include "mbed_thread.h"
2720

2821
namespace mbed {
2922

@@ -39,23 +32,10 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
3932
* interested in. In future, his spinning behaviour will be replaced with
4033
* condition variables.
4134
*/
42-
#if MBED_CONF_RTOS_PRESENT
4335
uint64_t start_time = 0;
4436
if (timeout > 0) {
45-
start_time = Kernel::get_ms_count();
37+
start_time = get_ms_count();
4638
}
47-
#define TIME_ELAPSED() int64_t(Kernel::get_ms_count() - start_time)
48-
#else
49-
#if MBED_CONF_PLATFORM_POLL_USE_LOWPOWER_TIMER
50-
LowPowerTimer timer;
51-
#else
52-
Timer timer;
53-
#endif
54-
if (timeout > 0) {
55-
timer.start();
56-
}
57-
#define TIME_ELAPSED() timer.read_ms()
58-
#endif // MBED_CONF_RTOS_PRESENT
5939

6040
int count = 0;
6141
for (;;) {
@@ -78,14 +58,12 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
7858
}
7959

8060
/* Nothing selected - this is where timeout handling would be needed */
81-
if (timeout == 0 || (timeout > 0 && TIME_ELAPSED() > timeout)) {
61+
if (timeout == 0 || (timeout > 0 && int64_t(get_ms_count() - start_time) > timeout)) {
8262
break;
8363
}
84-
#ifdef MBED_CONF_RTOS_PRESENT
8564
// TODO - proper blocking
8665
// wait for condition variable, wait queue whatever here
87-
rtos::ThisThread::sleep_for(1);
88-
#endif
66+
thread_sleep_for(1);
8967
}
9068
return count;
9169
}

platform/mbed_wait_api.h

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

28+
#include "platform/mbed_toolchain.h"
2829
#include "platform/mbed_atomic.h"
2930
#include "device.h"
3031

@@ -62,7 +63,16 @@ extern "C" {
6263
* If the RTOS is present, this function spins to get the exact number of microseconds for
6364
* microsecond precision up to 10 milliseconds. If delay is larger than 10 milliseconds and not in ISR, it is the same as
6465
* `wait_ms`. We recommend `wait_us` and `wait_ms` over `wait`.
66+
*
67+
* @deprecated
68+
* 'wait' is deprecated in favor of explicit sleep functions. To sleep, 'wait' should be replaced by
69+
* 'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call
70+
* 'wait_us'. 'wait_us' is safe to call from ISR context.
6571
*/
72+
MBED_DEPRECATED_SINCE("mbed-os-5.14",
73+
"'wait' is deprecated in favor of explicit sleep functions. To sleep, 'wait' should be replaced by "
74+
"'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call "
75+
"'wait_us'. 'wait_us' is safe to call from ISR context.")
6676
void wait(float s);
6777

6878
/** Waits a number of milliseconds.
@@ -72,7 +82,16 @@ void wait(float s);
7282
* @note
7383
* If the RTOS is present, it calls ThisThread::sleep_for(), which is same as CMSIS osDelay().
7484
* You can't call this from interrupts, and it doesn't lock hardware sleep.
85+
*
86+
* @deprecated
87+
* 'wait_ms' is deprecated in favor of explicit sleep functions. To sleep, 'wait_ms' should be replaced by
88+
* 'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call
89+
* 'wait_us'. 'wait_us' is safe to call from ISR context.
7590
*/
91+
MBED_DEPRECATED_SINCE("mbed-os-5.14",
92+
"'wait_ms' is deprecated in favor of explicit sleep functions. To sleep, 'wait_ms' should be replaced by "
93+
"'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call "
94+
"'wait_us'. 'wait_us' is safe to call from ISR context.")
7695
void wait_ms(int ms);
7796

7897
/** Waits a number of microseconds.
@@ -82,7 +101,7 @@ void wait_ms(int ms);
82101
* @note
83102
* This function always spins to get the exact number of microseconds.
84103
* This will affect power and multithread performance. Therefore, spinning for
85-
* millisecond wait is not recommended, and wait_ms() should
104+
* millisecond wait is not recommended, and ThisThread::sleep_for should
86105
* be used instead.
87106
*
88107
* @note You may call this function from ISR context, but large delays may

platform/mbed_wait_api_rtos.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
*/
1717

1818
// This implementation of the wait functions will be compiled only
19-
// if the RTOS is present.
19+
// if the RTOS is present. Note that we still use these old
20+
// bare metal versions of wait and wait_ms rather than using
21+
// thread_sleep_for for backwards compatibility. People should
22+
// be prompted to shift via their deprecation.
2023
#ifdef MBED_CONF_RTOS_PRESENT
2124

2225
#include "platform/mbed_wait_api.h"
@@ -30,7 +33,7 @@
3033
void wait(float s)
3134
{
3235
if ((s >= 0.01f) && core_util_are_interrupts_enabled()) {
33-
wait_ms(s * 1000.0f);
36+
rtos::ThisThread::sleep_for(s * 1000.0f);
3437
return;
3538
}
3639

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)