Skip to content

Commit edc6264

Browse files
committed
Replace deprecated wait calls
1 parent 0a1ae05 commit edc6264

File tree

18 files changed

+48
-45
lines changed

18 files changed

+48
-45
lines changed

TESTS/mbed_drivers/timeout/timeout_tests.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ void test_deepsleep(void)
315315
316316
* This should be replaced with a better function that checks if the
317317
* hardware buffers are empty. However, such an API does not exist now,
318-
* so we'll use the wait_ms() function for now.
318+
* so we'll use the ThisThread::sleep_for() function for now.
319319
*/
320-
wait_ms(20);
320+
ThisThread::sleep_for(20);
321321

322322
timer.start();
323323
timeout.attach_callback(mbed::callback(sem_callback, &sem), delay_us);

TESTS/mbed_hal/rtc/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void rtc_persist_test()
125125
rtc_write(start);
126126
rtc_free();
127127

128-
wait(WAIT_TIME);
128+
ThisThread::sleep_for(WAIT_TIME * 1000);
129129

130130
rtc_init();
131131
const uint32_t stop = rtc_read();
@@ -167,7 +167,7 @@ void rtc_range_test()
167167
for (uint32_t i = 0; i < sizeof(starts) / sizeof(starts[0]); i++) {
168168
const uint32_t start = starts[i];
169169
rtc_write(start);
170-
wait(WAIT_TIME);
170+
ThisThread::sleep_for(WAIT_TIME * 1000);
171171
const uint32_t stop = rtc_read();
172172
TEST_ASSERT_UINT32_WITHIN(WAIT_TOLERANCE, WAIT_TIME, stop - start);
173173
}

TESTS/mbed_platform/error_handling/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void test_error_logging_multithread()
228228
errThread[i] = new Thread(osPriorityNormal1, THREAD_STACK_SIZE, NULL, NULL);
229229
errThread[i]->start(callback(err_thread_func, &error_status[i]));
230230
}
231-
wait(2.0);
231+
ThisThread::sleep_for(2000);
232232
for (i = 0; i < NUM_TEST_THREADS; i++) {
233233
errThread[i]->join();
234234
}

TESTS/netsocket/dns/asynchronous_dns_cancel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,5 @@ void ASYNCHRONOUS_DNS_CANCEL()
8181

8282
delete[] data;
8383

84-
wait(5.0);
84+
ThisThread::sleep_for(5000);
8585
}

TESTS/netsocket/dns/asynchronous_dns_external_event_queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void ASYNCHRONOUS_DNS_EXTERNAL_EVENT_QUEUE()
7979
TEST_ASSERT_EQUAL(0, result_exp_timeout);
8080

8181
// Give event queue time to finalise before destructors
82-
wait(2.0);
82+
ThisThread::sleep_for(2000);
8383

8484
nsapi_dns_call_in_set(0);
8585
}

TESTS/netsocket/dns/asynchronous_dns_timeouts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void ASYNCHRONOUS_DNS_TIMEOUTS()
7474
TEST_ASSERT(result_exp_timeout > 0);
7575

7676
// Give event queue time to finalise before destructors
77-
wait(2.0);
77+
ThisThread::sleep_for(2000);
7878

7979
nsapi_dns_call_in_set(0);
8080
}

TESTS/netsocket/udp/udpsocket_echotest_burst.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void UDPSOCKET_ECHOTEST_BURST()
106106
} else if (recvd < 0) {
107107
pkg_fail += BURST_PKTS - j; // Assume all the following packets of the burst to be lost
108108
printf("[%02d] network error %d\n", i, recvd);
109-
wait(recv_timeout);
109+
ThisThread::sleep_for(recv_timeout * 1000);
110110
recv_timeout *= 2; // Back off,
111111
break;
112112
} else if (temp_addr != udp_addr) {

TESTS/netsocket/udp/udpsocket_sendto_repeat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void UDPSOCKET_SENDTO_REPEAT()
4545
break;
4646
}
4747
oom_earlier = true;
48-
wait(1);
48+
ThisThread::sleep_for(1000);
4949
continue;
5050
}
5151
oom_earlier = false;

TESTS/network/interface/networkinterface_status.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void NETWORKINTERFACE_STATUS_GET()
147147
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
148148

149149
while (net->get_connection_status() != NSAPI_STATUS_GLOBAL_UP) {
150-
wait(0.5);
150+
ThisThread::sleep_for(500);
151151
}
152152

153153
err = net->disconnect();

components/802.15.4_RF/atmel-rf-driver/source/NanostackRfPhyAtmel.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,14 @@ static void rf_if_reset_radio(void)
525525
#endif
526526
rf->IRQ.rise(0);
527527
rf->RST = 1;
528-
wait_ms(1);
528+
ThisThread::sleep_for(2);
529529
rf->RST = 0;
530-
wait_ms(10);
530+
ThisThread::sleep_for(10);
531531
CS_RELEASE();
532532
rf->SLP_TR = 0;
533-
wait_ms(10);
533+
ThisThread::sleep_for(10);
534534
rf->RST = 1;
535-
wait_ms(10);
535+
ThisThread::sleep_for(10);
536536

537537
rf->IRQ.rise(&rf_if_interrupt_handler);
538538
}
@@ -883,15 +883,16 @@ static uint8_t rf_if_read_rnd(void)
883883
rf_if_write_register(TRX_RPC, RX_RPC_CTRL | TRX_RPC_RSVD_1);
884884
}
885885

886-
wait_ms(1);
886+
887+
wait_ns(1000);
887888
temp = ((rf_if_read_register(PHY_RSSI) >> 5) << 6);
888-
wait_ms(1);
889+
wait_ns(1000);
889890
temp |= ((rf_if_read_register(PHY_RSSI) >> 5) << 4);
890-
wait_ms(1);
891+
wait_ns(1000);
891892
temp |= ((rf_if_read_register(PHY_RSSI) >> 5) << 2);
892-
wait_ms(1);
893+
wait_ns(1000);
893894
temp |= ((rf_if_read_register(PHY_RSSI) >> 5));
894-
wait_ms(1);
895+
wait_ns(1000);
895896
if (rf_part_num == PART_AT86RF233) {
896897
rf_if_write_register(TRX_RPC, tmp_rpc_val);
897898
}

components/802.15.4_RF/stm-s2lp-rf-driver/source/NanostackRfPhys2lp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,10 +1058,10 @@ static void rf_reset(void)
10581058
{
10591059
// Shutdown
10601060
rf->SDN = 1;
1061-
wait_ms(10);
1061+
ThisThread::sleep_for(10);
10621062
// Wake up
10631063
rf->SDN = 0;
1064-
wait_ms(10);
1064+
ThisThread::sleep_for(10);
10651065
}
10661066

10671067
static void rf_init(void)

components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@
139139
#if DEVICE_SPI
140140

141141
#include "SDBlockDevice.h"
142+
#include "rtos/ThisThread.h"
142143
#include "platform/mbed_debug.h"
143-
#include "platform/mbed_wait_api.h"
144144
#ifndef __STDC_FORMAT_MACROS
145145
#define __STDC_FORMAT_MACROS
146146
#endif
@@ -872,7 +872,7 @@ uint32_t SDBlockDevice::_go_idle_state()
872872
if (R1_IDLE_STATE == response) {
873873
break;
874874
}
875-
wait_ms(1);
875+
rtos::ThisThread::sleep_for(1);
876876
}
877877
return response;
878878
}

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "platform/Callback.h"
2929
#include "platform/mbed_critical.h"
3030
#include "platform/mbed_debug.h"
31-
#include "platform/mbed_wait_api.h"
31+
#include "rtos/ThisThread.h"
3232

3333
#ifndef MBED_CONF_ESP8266_DEBUG
3434
#define MBED_CONF_ESP8266_DEBUG false
@@ -49,6 +49,7 @@
4949
#define TRACE_GROUP "ESPI" // ESP8266 Interface
5050

5151
using namespace mbed;
52+
using namespace rtos;
5253

5354
#if defined MBED_CONF_ESP8266_TX && defined MBED_CONF_ESP8266_RX
5455
ESP8266Interface::ESP8266Interface()
@@ -425,7 +426,7 @@ nsapi_error_t ESP8266Interface::_reset()
425426
_rst_pin.rst_assert();
426427
// If you happen to use Pin7 CH_EN as reset pin, not needed otherwise
427428
// https://www.espressif.com/sites/default/files/documentation/esp8266_hardware_design_guidelines_en.pdf
428-
wait_ms(2); // Documentation says 200 us should have been enough, but experimentation shows that 1ms was not enough
429+
ThisThread::sleep_for(2); // Documentation says 200 us; need 2 ticks to get minimum 1 ms.
429430
_esp.flush();
430431
_rst_pin.rst_deassert();
431432
} else {

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
2424
#include "UARTSerial.h"
2525
#endif // #if DEVICE_SERIAL
26-
#include "mbed_wait_api.h"
26+
#include "ThisThread.h"
2727

2828
#define NETWORK_TIMEOUT 30 * 60 * 1000 // 30 minutes
2929
#define DEVICE_TIMEOUT 5 * 60 * 1000 // 5 minutes
@@ -45,6 +45,7 @@
4545

4646
using namespace mbed_cellular_util;
4747
using namespace mbed;
48+
using namespace rtos;
4849

4950
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
5051
AT_CellularBase(at), _is_connected(false), _is_blocking(true),
@@ -893,7 +894,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
893894
_cb_data.error == NSAPI_ERROR_OK) {
894895
if (!_apn) {
895896
char imsi[MAX_IMSI_LENGTH + 1];
896-
wait(1); // need to wait to access SIM in some modems
897+
ThisThread::sleep_for(1000); // need to wait to access SIM in some modems
897898
_cb_data.error = _device->open_information()->get_imsi(imsi, sizeof(imsi));
898899
if (_cb_data.error == NSAPI_ERROR_OK) {
899900
const char *apn_config = apnconfig(imsi);

features/cellular/framework/AT/AT_CellularSMS.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
#include <time.h>
1919
#include <stdlib.h>
2020
#include <stdio.h>
21-
#include "mbed_wait_api.h"
21+
#include "ThisThread.h"
2222
#include "AT_CellularSMS.h"
2323
#include "CellularUtil.h"
2424
#include "CellularLog.h"
2525

2626
using namespace mbed_cellular_util;
2727
using namespace mbed;
2828
using namespace std;
29+
using namespace rtos;
2930

3031
#define CTRL_Z "\x1a"
3132
#define ESC "\x1b"
@@ -419,14 +420,14 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
419420
int write_size = 0;
420421
int remove_plus_sign = (phone_number[0] == '+') ? 1 : 0;
421422

422-
wait_ms(_sim_wait_time);
423+
ThisThread::sleep_for(_sim_wait_time);
423424

424425
if (_mode == CellularSMSMmodeText) {
425426
_at.cmd_start("AT+CMGS=");
426427
_at.write_string(phone_number + remove_plus_sign);
427428
_at.cmd_stop();
428429

429-
wait_ms(_sim_wait_time);
430+
ThisThread::sleep_for(_sim_wait_time);
430431
_at.resp_start("> ", true);
431432

432433
if (_at.get_last_error() == NSAPI_ERROR_OK) {
@@ -489,7 +490,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
489490
_at.write_int((pdu_len - 2) / 2);
490491
_at.cmd_stop();
491492

492-
wait_ms(_sim_wait_time);
493+
ThisThread::sleep_for(_sim_wait_time);
493494
_at.resp_start("> ", true);
494495

495496
if (_at.get_last_error() == NSAPI_ERROR_OK) {
@@ -602,7 +603,7 @@ nsapi_size_or_error_t AT_CellularSMS::read_sms_from_index(int msg_index, char *b
602603
/*
603604
* +CMGR: <stat>,<oa>,<alpha>,<scts>[,<tooa>,<fo>,<pid>,<dcs>,<sca>,<tosca>,<length>]<CR><LF><data><CR><LF>OK<CR><LF>
604605
*/
605-
wait_ms(_sim_wait_time);
606+
ThisThread::sleep_for(_sim_wait_time);
606607
_at.cmd_start("AT+CMGR=");
607608
_at.write_int(msg_index);
608609
_at.cmd_stop();
@@ -661,7 +662,7 @@ nsapi_size_or_error_t AT_CellularSMS::read_sms(sms_info_t *sms, char *buf, char
661662
int pduSize;
662663

663664
for (int i = 0; i < sms->parts; i++) {
664-
wait_ms(_sim_wait_time);
665+
ThisThread::sleep_for(_sim_wait_time);
665666
_at.cmd_start("AT+CMGR=");
666667
_at.write_int(sms->msg_index[i]);
667668
_at.cmd_stop();
@@ -786,7 +787,7 @@ nsapi_size_or_error_t AT_CellularSMS::get_data_from_pdu(const char *pdu, sms_inf
786787
// read first the lower part of first octet as there is message type
787788
index++;
788789
tmp = hex_str_to_int(pdu + index, 1);
789-
//wait_ms(200);
790+
//ThisThread::sleep_for(200);
790791
if ((tmp & 0x03) == 0) {// SMS-DELIVER type, last two bits should be zero
791792
// UDH present? Check from first octets higher part
792793
tmp = hex_str_to_int(pdu + (--index), 1);
@@ -1114,7 +1115,7 @@ AT_CellularSMS::sms_info_t *AT_CellularSMS::get_oldest_sms_index()
11141115
nsapi_size_or_error_t err = 0;
11151116
while (current) {
11161117
if (_mode == CellularSMSMmodeText) {
1117-
wait_ms(_sim_wait_time);
1118+
ThisThread::sleep_for(_sim_wait_time);
11181119
err = read_sms_from_index(current->msg_index[0], NULL, 0, NULL, current->date);
11191120
if (err != 0) {
11201121
return NULL;

features/storage/nvstore/source/nvstore.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "mbed_critical.h"
2626
#include "mbed_assert.h"
2727
#include "mbed_error.h"
28-
#include "mbed_wait_api.h"
28+
#include "ThisThread.h"
2929
#include <algorithm>
3030
#include <string.h>
3131
#include <stdio.h>
@@ -837,7 +837,7 @@ int NVStore::init()
837837
init_attempts_val = core_util_atomic_incr_u32(&_init_attempts, 1);
838838
if (init_attempts_val != 1) {
839839
while (!_init_done) {
840-
wait_ms(1);
840+
rtos::ThisThread::sleep_for(1);
841841
}
842842
return NVSTORE_SUCCESS;
843843
}

usb/device/USBHID/USBMouse.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
#include "stdint.h"
1919
#include "USBMouse.h"
20-
#include "PlatformMutex.h"
20+
#include "ThisThread.h"
2121
#include "usb_phy_api.h"
22-
#include "mbed_wait_api.h"
2322

2423

2524
USBMouse::USBMouse(bool connect_blocking, MOUSE_TYPE mouse_type, uint16_t vendor_id, uint16_t product_id, uint16_t product_release):
@@ -157,7 +156,7 @@ bool USBMouse::double_click()
157156
_mutex.unlock();
158157
return false;
159158
}
160-
wait(0.1);
159+
rtos::ThisThread::sleep_for(100);
161160
bool ret = click(MOUSE_LEFT);
162161

163162
_mutex.unlock();
@@ -172,7 +171,7 @@ bool USBMouse::click(uint8_t button)
172171
_mutex.unlock();
173172
return false;
174173
}
175-
wait(0.01);
174+
rtos::ThisThread::sleep_for(10);
176175
bool ret = update(0, 0, 0, 0);
177176

178177
_mutex.unlock();

usb/device/USBHID/USBMouseKeyboard.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "stdint.h"
1919
#include "USBMouseKeyboard.h"
2020
#include "usb_phy_api.h"
21-
#include "mbed_wait_api.h"
21+
#include "ThisThread.h"
2222

2323
typedef struct {
2424
unsigned char usage;
@@ -709,7 +709,7 @@ bool USBMouseKeyboard::doubleClick()
709709
_mutex.unlock();
710710
return false;
711711
}
712-
wait(0.1);
712+
rtos::ThisThread::sleep_for(100);
713713
bool ret = click(MOUSE_LEFT);
714714

715715
_mutex.unlock();
@@ -724,7 +724,7 @@ bool USBMouseKeyboard::click(uint8_t button)
724724
_mutex.unlock();
725725
return false;
726726
}
727-
wait(0.01);
727+
rtos::ThisThread::sleep_for(10);
728728
bool ret = update(0, 0, 0, 0);
729729

730730
_mutex.unlock();

0 commit comments

Comments
 (0)