From 83be3f24a57548824e0d18752ca563be08694b30 Mon Sep 17 00:00:00 2001 From: Rajkumar Kanagaraj Date: Tue, 3 Mar 2020 09:55:36 -0800 Subject: [PATCH 1/4] Remove mbed wait deprecated APIs --- TESTS/lorawan/loraradio/main.cpp | 10 +-- TESTS/mbed_drivers/reset_reason/main.cpp | 6 +- TESTS/mbed_drivers/rtc/main.cpp | 2 +- TESTS/mbed_drivers/watchdog/main.cpp | 4 +- TESTS/mbed_hal/reset_reason/main.cpp | 6 +- TESTS/mbed_hal/rtc/main.cpp | 4 +- TESTS/mbed_hal/rtc_time/main.cpp | 2 +- TESTS/mbed_hal/watchdog/main.cpp | 4 +- .../mbed_hal_fpga_ci_test_shield/pwm/main.cpp | 4 +- .../condition_variable/main.cpp | 8 +-- TESTS/mbedmicro-rtos-mbed/mutex/main.cpp | 6 +- TESTS/mbedmicro-rtos-mbed/systimer/main.cpp | 4 +- TESTS/usb_device/basic/main.cpp | 14 ++-- TESTS/usb_device/msd/main.cpp | 2 +- TESTS/usb_device/serial/main.cpp | 70 +++++++++---------- UNITTESTS/stubs/mbed_wait_api_stub.cpp | 8 --- UNITTESTS/target_h/platform/mbed_wait_api.h | 2 - .../MbedTester.h | 2 +- drivers/CAN.h | 2 +- drivers/DigitalIn.h | 2 +- drivers/DigitalOut.h | 2 +- drivers/I2C.h | 2 +- drivers/InterruptIn.h | 2 +- drivers/PortOut.h | 4 +- drivers/PwmOut.h | 2 +- drivers/Ticker.h | 2 +- drivers/Timeout.h | 2 +- drivers/USBKeyboard.h | 2 +- drivers/USBMIDI.h | 4 +- drivers/USBMouse.h | 4 +- drivers/USBMouseKeyboard.h | 4 +- drivers/USBSerial.h | 2 +- .../TARGET_CORDIO_ODIN_W2/HCIDriver.cpp | 4 +- .../TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp | 8 +-- platform/mbed_rtc_time.h | 2 +- platform/mbed_wait_api.h | 59 ++++------------ platform/source/mbed_wait_api_no_rtos.c | 22 ------ platform/source/mbed_wait_api_rtos.cpp | 68 ------------------ rtos/ConditionVariable.h | 2 +- rtos/Thread.h | 4 +- 40 files changed, 115 insertions(+), 248 deletions(-) delete mode 100644 platform/source/mbed_wait_api_rtos.cpp diff --git a/TESTS/lorawan/loraradio/main.cpp b/TESTS/lorawan/loraradio/main.cpp index a581d0fe0e..d53b336ad6 100644 --- a/TESTS/lorawan/loraradio/main.cpp +++ b/TESTS/lorawan/loraradio/main.cpp @@ -61,7 +61,7 @@ static volatile event_t received_event; static void tx_done() { - wait_ms(2); + thread_sleep_for(2); TEST_ASSERT_EQUAL(EV_NONE, received_event); received_event = EV_TX_DONE; TEST_ASSERT_EQUAL(osOK, event_sem.release()); @@ -69,7 +69,7 @@ static void tx_done() static void tx_timeout() { - wait_ms(2); + thread_sleep_for(2); TEST_ASSERT_EQUAL(EV_NONE, received_event); received_event = EV_TX_TIMEOUT; TEST_ASSERT_EQUAL(osOK, event_sem.release()); @@ -77,7 +77,7 @@ static void tx_timeout() static void rx_done(const uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) { - wait_ms(2); + thread_sleep_for(2); TEST_ASSERT_EQUAL(EV_NONE, received_event); received_event = EV_RX_DONE; TEST_ASSERT_EQUAL(osOK, event_sem.release()); @@ -85,7 +85,7 @@ static void rx_done(const uint8_t *payload, uint16_t size, int16_t rssi, int8_t static void rx_timeout() { - wait_ms(2); + thread_sleep_for(2); TEST_ASSERT_EQUAL(EV_NONE, received_event); received_event = EV_RX_TIMEOUT; TEST_ASSERT_EQUAL(osOK, event_sem.release()); @@ -93,7 +93,7 @@ static void rx_timeout() static void rx_error() { - wait_ms(2); + thread_sleep_for(2); TEST_ASSERT_EQUAL(EV_NONE, received_event); received_event = EV_RX_ERROR; TEST_ASSERT_EQUAL(osOK, event_sem.release()); diff --git a/TESTS/mbed_drivers/reset_reason/main.cpp b/TESTS/mbed_drivers/reset_reason/main.cpp index 768d85b012..93ddd34cc0 100644 --- a/TESTS/mbed_drivers/reset_reason/main.cpp +++ b/TESTS/mbed_drivers/reset_reason/main.cpp @@ -103,7 +103,7 @@ static cmd_status_t handle_command(const char *key, const char *value) if (strcmp(key, MSG_KEY_DEVICE_RESET) == 0 && strcmp(value, MSG_VALUE_DEVICE_RESET_NVIC) == 0) { greentea_send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DEVICE_RESET_ACK); - wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. NVIC_SystemReset(); TEST_ASSERT_MESSAGE(0, "NVIC_SystemReset did not reset the device as expected."); return CMD_STATUS_ERROR; @@ -112,13 +112,13 @@ static cmd_status_t handle_command(const char *key, const char *value) #if DEVICE_WATCHDOG if (strcmp(key, MSG_KEY_DEVICE_RESET) == 0 && strcmp(value, MSG_VALUE_DEVICE_RESET_WATCHDOG) == 0) { greentea_send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DEVICE_RESET_ACK); - wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. watchdog_config_t config = { .timeout_ms = WDG_TIMEOUT_MS }; if (hal_watchdog_init(&config) != WATCHDOG_STATUS_OK) { TEST_ASSERT_MESSAGE(0, "hal_watchdog_init() error."); return CMD_STATUS_ERROR; } - wait_ms(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. + thread_sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); return CMD_STATUS_ERROR; } diff --git a/TESTS/mbed_drivers/rtc/main.cpp b/TESTS/mbed_drivers/rtc/main.cpp index 00478a10b7..8aee9831d7 100644 --- a/TESTS/mbed_drivers/rtc/main.cpp +++ b/TESTS/mbed_drivers/rtc/main.cpp @@ -451,7 +451,7 @@ void test_functional_count() set_time(CUSTOM_TIME_2); /* Wait 10 sec. */ - wait_ms(DELAY_10_SEC * MS_PER_SEC); + thread_sleep_for(DELAY_10_SEC * MS_PER_SEC); /* Get time. */ seconds = time(NULL); diff --git a/TESTS/mbed_drivers/watchdog/main.cpp b/TESTS/mbed_drivers/watchdog/main.cpp index 79503b3a4b..2afbd773b9 100644 --- a/TESTS/mbed_drivers/watchdog/main.cpp +++ b/TESTS/mbed_drivers/watchdog/main.cpp @@ -94,7 +94,7 @@ void test_stop() TEST_ASSERT_TRUE(watchdog.stop()); TEST_ASSERT_FALSE(watchdog.is_running()); // Make sure that a disabled watchdog does not reset the core. - wait_ms(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. + thread_sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. TEST_ASSERT_FALSE(watchdog.stop()); } @@ -173,7 +173,7 @@ utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const } greentea_send_kv(MSG_KEY_DEVICE_RESET, CASE_INDEX_START + CASE_INDEX_CURRENT); utest_printf("The device will now restart.\n"); - wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. NVIC_SystemReset(); return status; // Reset is instant so this line won't be reached. } diff --git a/TESTS/mbed_hal/reset_reason/main.cpp b/TESTS/mbed_hal/reset_reason/main.cpp index 4f51fa007e..65dad5b153 100644 --- a/TESTS/mbed_hal/reset_reason/main.cpp +++ b/TESTS/mbed_hal/reset_reason/main.cpp @@ -98,7 +98,7 @@ static cmd_status_t handle_command(const char *key, const char *value) if (strcmp(key, MSG_KEY_DEVICE_RESET) == 0 && strcmp(value, MSG_VALUE_DEVICE_RESET_NVIC) == 0) { greentea_send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DEVICE_RESET_ACK); - wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. NVIC_SystemReset(); TEST_ASSERT_MESSAGE(0, "NVIC_SystemReset did not reset the device as expected."); return CMD_STATUS_ERROR; @@ -107,13 +107,13 @@ static cmd_status_t handle_command(const char *key, const char *value) #if DEVICE_WATCHDOG if (strcmp(key, MSG_KEY_DEVICE_RESET) == 0 && strcmp(value, MSG_VALUE_DEVICE_RESET_WATCHDOG) == 0) { greentea_send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DEVICE_RESET_ACK); - wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. watchdog_config_t config = { .timeout_ms = WDG_TIMEOUT_MS }; if (hal_watchdog_init(&config) != WATCHDOG_STATUS_OK) { TEST_ASSERT_MESSAGE(0, "hal_watchdog_init() error."); return CMD_STATUS_ERROR; } - wait_ms(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. + thread_sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); return CMD_STATUS_ERROR; } diff --git a/TESTS/mbed_hal/rtc/main.cpp b/TESTS/mbed_hal/rtc/main.cpp index 0fb0911dc9..d1773846f0 100644 --- a/TESTS/mbed_hal/rtc/main.cpp +++ b/TESTS/mbed_hal/rtc/main.cpp @@ -61,9 +61,9 @@ void rtc_sleep_test_support(bool deepsleep_mode) * to allow for hardware serial buffers to completely flush. * This should be replaced with a better function that checks if the * hardware buffers are empty. However, such an API does not exist now, - * so we'll use the wait_ms() function for now. + * so we'll use the thread_sleep_for() function for now. */ - wait_ms(10); + thread_sleep_for(10); rtc_init(); diff --git a/TESTS/mbed_hal/rtc_time/main.cpp b/TESTS/mbed_hal/rtc_time/main.cpp index 2510418618..35b2e7b82a 100644 --- a/TESTS/mbed_hal/rtc_time/main.cpp +++ b/TESTS/mbed_hal/rtc_time/main.cpp @@ -187,7 +187,7 @@ void test_set_time_twice() TEST_ASSERT_EQUAL(true, (current_time == NEW_TIME)); /* Wait 2 seconds */ - wait_ms(2000); + thread_sleep_for(2000); /* set the time to NEW_TIME again and check it */ set_time(NEW_TIME); diff --git a/TESTS/mbed_hal/watchdog/main.cpp b/TESTS/mbed_hal/watchdog/main.cpp index bec743658d..b0b89457e4 100644 --- a/TESTS/mbed_hal/watchdog/main.cpp +++ b/TESTS/mbed_hal/watchdog/main.cpp @@ -100,7 +100,7 @@ void test_stop() TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&WDG_CONFIG_DEFAULT)); TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_stop()); // Make sure that a disabled watchdog does not reset the core. - wait_ms(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. + thread_sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_stop()); } @@ -170,7 +170,7 @@ utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const } greentea_send_kv(MSG_KEY_DEVICE_RESET, CASE_INDEX_START + CASE_INDEX_CURRENT); utest_printf("The device will now restart.\n"); - wait_ms(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. NVIC_SystemReset(); return status; // Reset is instant so this line won't be reached. } diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp b/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp index fd9bf5c8f1..e5351d5a63 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp +++ b/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp @@ -127,11 +127,11 @@ void fpga_pwm_period_fill_test(PinName pin, uint32_t period_ms, uint32_t fill_pr break; } - wait(PERIOD_FLOAT(period_ms)); + thread_sleep_for(period_ms); tester.io_metrics_start(); - wait(NUM_OF_PERIODS * PERIOD_FLOAT(period_ms)); + thread_sleep_for(NUM_OF_PERIODS * period_ms); tester.io_metrics_stop(); core_util_critical_section_exit(); diff --git a/TESTS/mbedmicro-rtos-mbed/condition_variable/main.cpp b/TESTS/mbedmicro-rtos-mbed/condition_variable/main.cpp index 4372f46240..998502d257 100644 --- a/TESTS/mbedmicro-rtos-mbed/condition_variable/main.cpp +++ b/TESTS/mbedmicro-rtos-mbed/condition_variable/main.cpp @@ -56,14 +56,14 @@ void test_notify_one() t1.start(increment_on_signal); t2.start(increment_on_signal); - wait_ms(TEST_DELAY); + ThisThread::sleep_for(TEST_DELAY); TEST_ASSERT_EQUAL(0, change_counter); mutex.lock(); cond.notify_one(); mutex.unlock(); - wait_ms(TEST_DELAY); + ThisThread::sleep_for(TEST_DELAY); TEST_ASSERT_EQUAL(1, change_counter); mutex.lock(); @@ -83,14 +83,14 @@ void test_notify_all() t1.start(increment_on_signal); t2.start(increment_on_signal); - wait_ms(TEST_DELAY); + ThisThread::sleep_for(TEST_DELAY); TEST_ASSERT_EQUAL(0, change_counter); mutex.lock(); cond.notify_all(); mutex.unlock(); - wait_ms(TEST_DELAY); + ThisThread::sleep_for(TEST_DELAY); TEST_ASSERT_EQUAL(2, change_counter); t1.join(); diff --git a/TESTS/mbedmicro-rtos-mbed/mutex/main.cpp b/TESTS/mbedmicro-rtos-mbed/mutex/main.cpp index f90dd0bdd6..481711b86e 100644 --- a/TESTS/mbedmicro-rtos-mbed/mutex/main.cpp +++ b/TESTS/mbedmicro-rtos-mbed/mutex/main.cpp @@ -155,7 +155,7 @@ void test_dual_thread_nolock(void) thread.start(callback(F, &mutex)); - wait_ms(TEST_DELAY); + ThisThread::sleep_for(TEST_DELAY); } void test_dual_thread_lock_unlock_thread(Mutex *mutex) @@ -184,7 +184,7 @@ void test_dual_thread_lock_unlock(void) mutex.unlock(); - wait_ms(TEST_DELAY); + ThisThread::sleep_for(TEST_DELAY); } void test_dual_thread_lock_trylock_thread(Mutex *mutex) @@ -228,7 +228,7 @@ void test_dual_thread_lock(void) thread.start(callback(F, &mutex)); - wait_ms(TEST_LONG_DELAY); + ThisThread::sleep_for(TEST_LONG_DELAY); mutex.unlock(); } diff --git a/TESTS/mbedmicro-rtos-mbed/systimer/main.cpp b/TESTS/mbedmicro-rtos-mbed/systimer/main.cpp index 69d3def634..f50d580a7a 100644 --- a/TESTS/mbedmicro-rtos-mbed/systimer/main.cpp +++ b/TESTS/mbedmicro-rtos-mbed/systimer/main.cpp @@ -303,9 +303,9 @@ void test_deepsleep(void) * This should be replaced with a better function that checks if the * hardware buffers are empty. However, such an API does not exist now, - * so we'll use the wait_ms() function for now. + * so we'll use the ThisThread::sleep_for() function for now. */ - wait_ms(10); + ThisThread::sleep_for(10); // Regular Timer might be disabled during deepsleep. LowPowerTimer lptimer; SysTimerTest st; diff --git a/TESTS/usb_device/basic/main.cpp b/TESTS/usb_device/basic/main.cpp index 6403f6a8db..8a6727948b 100644 --- a/TESTS/usb_device/basic/main.cpp +++ b/TESTS/usb_device/basic/main.cpp @@ -233,7 +233,7 @@ void ep_test_data_correctness() // Wait for host before terminating greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - wait_ms(100); + thread_sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -270,7 +270,7 @@ void ep_test_halt() // Wait for host before terminating greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - wait_ms(100); + thread_sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -307,7 +307,7 @@ void ep_test_parallel_transfers() // Wait for host before terminating greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - wait_ms(100); + thread_sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -345,7 +345,7 @@ void ep_test_parallel_transfers_ctrl() // Wait for host before terminating greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - wait_ms(100); + thread_sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -381,7 +381,7 @@ void ep_test_abort() greentea_send_kv("ep_test_abort", serial.get_serial_desc_string()); greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - wait_ms(100); + thread_sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -420,7 +420,7 @@ void ep_test_data_toggle() greentea_send_kv("ep_test_data_toggle", serial.get_serial_desc_string()); greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - wait_ms(100); + thread_sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -566,7 +566,7 @@ void device_suspend_resume_test() greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); printf("[2] suspend_count: %d resume_count: %d\n", serial.get_suspend_count(), serial.get_resume_count()); TEST_ASSERT_EQUAL_STRING("pass", _key); - wait_ms(5000); + thread_sleep_for(5000); printf("[3] suspend_count: %d resume_count: %d\n", serial.get_suspend_count(), serial.get_resume_count()); } } diff --git a/TESTS/usb_device/msd/main.cpp b/TESTS/usb_device/msd/main.cpp index 88e99cb64e..a59ae25597 100644 --- a/TESTS/usb_device/msd/main.cpp +++ b/TESTS/usb_device/msd/main.cpp @@ -440,7 +440,7 @@ void mount_unmount_and_data_test(BlockDevice *bd, FileSystem *fs) TEST_ASSERT_EQUAL_STRING("passed", _key); do { - wait_ms(1); + thread_sleep_for(1); } while (test_files_exist(fs_root)); TEST_ASSERT_EQUAL(false, test_files_exist(fs_root)); diff --git a/TESTS/usb_device/serial/main.cpp b/TESTS/usb_device/serial/main.cpp index d8fdcdbb70..46b7e0cc84 100644 --- a/TESTS/usb_device/serial/main.cpp +++ b/TESTS/usb_device/serial/main.cpp @@ -296,7 +296,7 @@ void test_cdc_usb_reconnect() usb_cdc.connect(); // Wait for the USB enumeration to complete. while (!usb_cdc.configured()) { - wait_ms(1); + thread_sleep_for(1); } TEST_ASSERT_TRUE(usb_cdc.configured()); TEST_ASSERT_FALSE(usb_cdc.ready()); @@ -305,7 +305,7 @@ void test_cdc_usb_reconnect() // Wait for the host to open the port. #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); TEST_ASSERT_TRUE(usb_cdc.configured()); @@ -316,12 +316,12 @@ void test_cdc_usb_reconnect() TEST_ASSERT_FALSE(usb_cdc.configured()); TEST_ASSERT_FALSE(usb_cdc.ready()); - wait_ms(USB_RECONNECT_DELAY_MS); + thread_sleep_for(USB_RECONNECT_DELAY_MS); // Connect the USB device again. usb_cdc.connect(); // Wait for the USB enumeration to complete. while (!usb_cdc.configured()) { - wait_ms(1); + thread_sleep_for(1); } TEST_ASSERT_TRUE(usb_cdc.configured()); TEST_ASSERT_FALSE(usb_cdc.ready()); @@ -330,7 +330,7 @@ void test_cdc_usb_reconnect() // Wait for the host to open the port again. #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); TEST_ASSERT_TRUE(usb_cdc.configured()); @@ -355,7 +355,7 @@ void test_cdc_rx_single_bytes() greentea_send_kv(MSG_KEY_SEND_BYTES_SINGLE, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); uint8_t buff = 0x01; @@ -369,7 +369,7 @@ void test_cdc_rx_single_bytes() } // Wait for the host to close its port. while (usb_cdc.ready()) { - wait_ms(1); + thread_sleep_for(1); } usb_cdc.disconnect(); } @@ -380,7 +380,7 @@ void tx_thread_fun(USBCDC *usb_cdc) uint8_t buff[TX_BUFF_SIZE] = { 0 }; while (event_flags.get() & EF_SEND) { if (!usb_cdc->send(buff, TX_BUFF_SIZE)) { - wait_ms(1); + thread_sleep_for(1); continue; } buff_val++; @@ -402,7 +402,7 @@ void test_cdc_rx_single_bytes_concurrent() greentea_send_kv(MSG_KEY_SEND_BYTES_SINGLE, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); Thread tx_thread; @@ -421,7 +421,7 @@ void test_cdc_rx_single_bytes_concurrent() tx_thread.join(); // Wait for the host to close its port. while (usb_cdc.ready()) { - wait_ms(1); + thread_sleep_for(1); } usb_cdc.disconnect(); } @@ -439,7 +439,7 @@ void test_cdc_rx_multiple_bytes() greentea_send_kv(MSG_KEY_SEND_BYTES_MULTIPLE, HOST_RX_BUFF_SIZE_RATIO); #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); uint8_t buff[RX_BUFF_SIZE] = { 0 }; @@ -460,7 +460,7 @@ void test_cdc_rx_multiple_bytes() } // Wait for the host to close its port. while (usb_cdc.ready()) { - wait_ms(1); + thread_sleep_for(1); } usb_cdc.disconnect(); } @@ -479,7 +479,7 @@ void test_cdc_rx_multiple_bytes_concurrent() greentea_send_kv(MSG_KEY_SEND_BYTES_MULTIPLE, HOST_RX_BUFF_SIZE_RATIO); #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); Thread tx_thread; @@ -505,7 +505,7 @@ void test_cdc_rx_multiple_bytes_concurrent() tx_thread.join(); // Wait for the host to close its port. while (usb_cdc.ready()) { - wait_ms(1); + thread_sleep_for(1); } usb_cdc.disconnect(); } @@ -524,7 +524,7 @@ void test_cdc_loopback() greentea_send_kv(MSG_KEY_LOOPBACK, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); uint8_t rx_buff, tx_buff; @@ -537,7 +537,7 @@ void test_cdc_loopback() } // Wait for the host to close its port. while (usb_cdc.ready()) { - wait_ms(1); + thread_sleep_for(1); } usb_cdc.disconnect(); } @@ -559,7 +559,7 @@ void test_serial_usb_reconnect() usb_serial.connect(); // Wait for the USB enumeration to complete. while (!usb_serial.configured()) { - wait_ms(1); + thread_sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_FALSE(usb_serial.connected()); @@ -569,10 +569,10 @@ void test_serial_usb_reconnect() // Wait for the host to open the port. #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif while (!usb_serial.connected()) { - wait_ms(1); + thread_sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_TRUE(usb_serial.connected()); @@ -584,12 +584,12 @@ void test_serial_usb_reconnect() TEST_ASSERT_FALSE(usb_serial.connected()); TEST_ASSERT_EQUAL_INT(0, usb_serial.readable()); - wait_ms(USB_RECONNECT_DELAY_MS); + thread_sleep_for(USB_RECONNECT_DELAY_MS); // Connect the USB device again. usb_serial.connect(); // Wait for the USB enumeration to complete. while (!usb_serial.configured()) { - wait_ms(1); + thread_sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_FALSE(usb_serial.connected()); @@ -599,10 +599,10 @@ void test_serial_usb_reconnect() // Wait for the host to open the port again. #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif while (!usb_serial.connected()) { - wait_ms(1); + thread_sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_TRUE(usb_serial.connected()); @@ -629,10 +629,10 @@ void test_serial_term_reopen() // Wait for the host to open the terminal. #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif while (!usb_serial.connected()) { - wait_ms(1); + thread_sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_TRUE(usb_serial.ready()); @@ -641,7 +641,7 @@ void test_serial_term_reopen() // Wait for the host to close the terminal. while (usb_serial.ready()) { - wait_ms(1); + thread_sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_FALSE(usb_serial.ready()); @@ -652,10 +652,10 @@ void test_serial_term_reopen() // Wait for the host to open the terminal again. #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif while (!usb_serial.connected()) { - wait_ms(1); + thread_sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_TRUE(usb_serial.ready()); @@ -664,7 +664,7 @@ void test_serial_term_reopen() // Wait for the host to close the terminal again. while (usb_serial.ready()) { - wait_ms(1); + thread_sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_FALSE(usb_serial.ready()); @@ -687,7 +687,7 @@ void test_serial_getc() greentea_send_kv(MSG_KEY_SEND_BYTES_SINGLE, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_serial.wait_ready(); for (int expected = 0xff; expected >= 0; expected--) { @@ -698,7 +698,7 @@ void test_serial_getc() } // Wait for the host to close its port. while (usb_serial.ready()) { - wait_ms(1); + thread_sleep_for(1); } usb_serial.disconnect(); } @@ -719,7 +719,7 @@ void test_serial_printf_scanf() greentea_send_kv(MSG_KEY_LOOPBACK, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_serial.wait_ready(); static const char fmt[] = "Formatted\nstring %i."; @@ -735,7 +735,7 @@ void test_serial_printf_scanf() } // Wait for the host to close its port. while (usb_serial.ready()) { - wait_ms(1); + thread_sleep_for(1); } usb_serial.disconnect(); } @@ -764,7 +764,7 @@ void test_serial_line_coding_change() greentea_send_kv(MSG_KEY_CHANGE_LINE_CODING, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - wait_ms(LINUX_HOST_DTR_FIX_DELAY_MS); + thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_serial.wait_ready(); usb_serial.attach(line_coding_changed_cb); @@ -805,7 +805,7 @@ void test_serial_line_coding_change() } // Wait for the host to close its port. while (usb_serial.ready()) { - wait_ms(1); + thread_sleep_for(1); } usb_serial.disconnect(); } diff --git a/UNITTESTS/stubs/mbed_wait_api_stub.cpp b/UNITTESTS/stubs/mbed_wait_api_stub.cpp index 68a265308c..af0e571cad 100644 --- a/UNITTESTS/stubs/mbed_wait_api_stub.cpp +++ b/UNITTESTS/stubs/mbed_wait_api_stub.cpp @@ -17,14 +17,6 @@ #include "mbed_wait_api.h" -void wait(float s) -{ -} - -void wait_ms(int ms) -{ -} - void wait_us(int us) { } diff --git a/UNITTESTS/target_h/platform/mbed_wait_api.h b/UNITTESTS/target_h/platform/mbed_wait_api.h index c3ba10698c..1659840652 100644 --- a/UNITTESTS/target_h/platform/mbed_wait_api.h +++ b/UNITTESTS/target_h/platform/mbed_wait_api.h @@ -22,8 +22,6 @@ extern "C" { #endif -void wait_ms(int ms); - void wait_us(int us); #ifdef __cplusplus diff --git a/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/MbedTester.h b/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/MbedTester.h index 16b450755a..62d6c0fd2a 100644 --- a/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/MbedTester.h +++ b/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/MbedTester.h @@ -59,7 +59,7 @@ * int toggle = 0; * while (1) { * tester.gpio_write(MbedTester::LogicalPinGPIO0, toggle, true); - * wait(0.5); + * thread_sleep_for(500); * toggle = !toggle; * } * } diff --git a/drivers/CAN.h b/drivers/CAN.h index ec9963ce8d..dfe75cf65f 100644 --- a/drivers/CAN.h +++ b/drivers/CAN.h @@ -154,7 +154,7 @@ public: * printf("Message received: %d\n\n", msg.data[0]); * led2 = !led2; * } - * wait(0.2); + * thread_sleep_for(200); * } * } * diff --git a/drivers/DigitalIn.h b/drivers/DigitalIn.h index a6adf0bc9c..b304594e29 100644 --- a/drivers/DigitalIn.h +++ b/drivers/DigitalIn.h @@ -46,7 +46,7 @@ namespace mbed { * if(enable) { * led = !led; * } - * wait(0.25); + * thread_sleep_for(250); * } * } * @endcode diff --git a/drivers/DigitalOut.h b/drivers/DigitalOut.h index c7896ac476..d29f227fd7 100644 --- a/drivers/DigitalOut.h +++ b/drivers/DigitalOut.h @@ -41,7 +41,7 @@ namespace mbed { * int main() { * while(1) { * led = !led; - * wait(0.2); + * thread_sleep_for(200); * } * } * @endcode diff --git a/drivers/I2C.h b/drivers/I2C.h index 0d48ba7e2a..82e9616c60 100644 --- a/drivers/I2C.h +++ b/drivers/I2C.h @@ -66,7 +66,7 @@ namespace mbed { * // set up configuration register (at 0x01) * i2c.write(addr8bit, cmd, 2); * - * wait(0.5); + * thread_sleep_for(500); * * // read temperature register * cmd[0] = 0x00; diff --git a/drivers/InterruptIn.h b/drivers/InterruptIn.h index 71d96324ba..467f079e1f 100644 --- a/drivers/InterruptIn.h +++ b/drivers/InterruptIn.h @@ -57,7 +57,7 @@ namespace mbed { * event.rise(&trigger); * while(1) { * led = !led; - * wait(0.25); + * thread_sleep_for(250); * } * } * @endcode diff --git a/drivers/PortOut.h b/drivers/PortOut.h index aa5b00722d..3889fb38c9 100644 --- a/drivers/PortOut.h +++ b/drivers/PortOut.h @@ -48,9 +48,9 @@ namespace mbed { * int main() { * while(1) { * ledport = LED_MASK; - * wait(1); + * thread_sleep_for(1000); * ledport = 0; - * wait(1); + * thread_sleep_for(1000); * } * } * @endcode diff --git a/drivers/PwmOut.h b/drivers/PwmOut.h index 1bf12f47b4..e8df82b9a8 100644 --- a/drivers/PwmOut.h +++ b/drivers/PwmOut.h @@ -43,7 +43,7 @@ namespace mbed { * int main() { * while(1) { * led = led + 0.01; - * wait(0.2); + * thread_sleep_for(200); * if(led == 1.0) { * led = 0; * } diff --git a/drivers/Ticker.h b/drivers/Ticker.h index dac0f99ded..49185b8971 100644 --- a/drivers/Ticker.h +++ b/drivers/Ticker.h @@ -61,7 +61,7 @@ namespace mbed { * } else { * led2 = !led2; * } - * wait(0.2); + * thread_sleep_for(200); * } * } * @endcode diff --git a/drivers/Timeout.h b/drivers/Timeout.h index bbf71c4c85..0dc4cc7130 100644 --- a/drivers/Timeout.h +++ b/drivers/Timeout.h @@ -52,7 +52,7 @@ namespace mbed { * timeout.attach(&attimeout, 5); * while(on) { * led = !led; - * wait(0.2); + * thread_sleep_for(200); * } * } * @endcode diff --git a/drivers/USBKeyboard.h b/drivers/USBKeyboard.h index e41d4360a1..d168344fd2 100644 --- a/drivers/USBKeyboard.h +++ b/drivers/USBKeyboard.h @@ -93,7 +93,7 @@ enum FUNCTION_KEY { * { * while (1) { * key.printf("Hello World\r\n"); - * wait(1); + * thread_sleep_for(1000); * } * } * diff --git a/drivers/USBMIDI.h b/drivers/USBMIDI.h index e36b63055e..6ead78e82e 100644 --- a/drivers/USBMIDI.h +++ b/drivers/USBMIDI.h @@ -49,9 +49,9 @@ * while (1) { * for(int i=48; i<83; i++) { // send some messages! * midi.write(MIDIMessage::NoteOn(i)); -* wait(0.25); +* thread_sleep_for(250); * midi.write(MIDIMessage::NoteOff(i)); -* wait(0.5); +* thread_sleep_for(500); * } * } * } diff --git a/drivers/USBMouse.h b/drivers/USBMouse.h index d9cd1a6442..66419d2397 100644 --- a/drivers/USBMouse.h +++ b/drivers/USBMouse.h @@ -69,7 +69,7 @@ enum MOUSE_TYPE { * while (1) * { * mouse.move(20, 0); - * wait(0.5); + * thread_sleep_for(500); * } * } * @@ -102,7 +102,7 @@ enum MOUSE_TYPE { * * mouse.move(x_screen, y_screen); * angle += 3; - * wait(0.01); + * thread_sleep_for(10); * } * } * diff --git a/drivers/USBMouseKeyboard.h b/drivers/USBMouseKeyboard.h index c7a2e34649..76676572e2 100644 --- a/drivers/USBMouseKeyboard.h +++ b/drivers/USBMouseKeyboard.h @@ -49,7 +49,7 @@ * { * key_mouse.move(20, 0); * key_mouse.printf("Hello From MBED\r\n"); - * wait(1); + * thread_sleep_for(1000); * } * } * @endcode @@ -68,7 +68,7 @@ * { * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2); * key_mouse.printf("Hello from MBED\r\n"); - * wait(1); + * thread_sleep_for(1000); * } * } * @endcode diff --git a/drivers/USBSerial.h b/drivers/USBSerial.h index 9f15849489..1861650063 100644 --- a/drivers/USBSerial.h +++ b/drivers/USBSerial.h @@ -43,7 +43,7 @@ * while(1) * { * serial.printf("I am a virtual serial port\n"); -* wait(1); +* thread_sleep_for(1000); * } * } * @endcode diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp index 5e94c19481..572670a4d8 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp @@ -150,9 +150,9 @@ void ble::vendor::odin_w2::HCIDriver::do_initialize() hci_rts = 1; // Flow Control is OFF shutdown = 0; // BT Power is OFF - wait_ms(20); + thread_sleep_for(20); shutdown = 1; // BT Power is ON - wait_ms(500); + thread_sleep_for(500); hci_rts = 0; // Flow Control is ON diff --git a/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp index fca3af9be8..650e587495 100644 --- a/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp @@ -96,13 +96,13 @@ public: output_mode(bt_device_wake_name, 0); output_mode(bt_power_name, 1); - wait_ms(500); + thread_sleep_for(500); bt_device_wake = 0; - wait_ms(500); + thread_sleep_for(500); bt_power = 1; - wait_ms(500); + thread_sleep_for(500); } virtual void do_terminate() { } @@ -312,7 +312,7 @@ private: service_pack_next = NULL; service_pack_index = 0; service_pack_transfered = true; - wait_ms(1000); + thread_sleep_for(1000); set_sleep_mode(); } diff --git a/platform/mbed_rtc_time.h b/platform/mbed_rtc_time.h index c3e82b93fe..e7c5e672b4 100644 --- a/platform/mbed_rtc_time.h +++ b/platform/mbed_rtc_time.h @@ -64,7 +64,7 @@ struct timeval { * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); * printf("Time as a custom formatted string = %s", buffer); * - * wait(1); + * thread_sleep_for(1000); * } * } * @endcode diff --git a/platform/mbed_wait_api.h b/platform/mbed_wait_api.h index d86a5d4813..a6f85be326 100644 --- a/platform/mbed_wait_api.h +++ b/platform/mbed_wait_api.h @@ -41,59 +41,26 @@ extern "C" { * @code * #include "mbed.h" * - * DigitalOut heartbeat(LED1); + * // Blinking rate in milliseconds + * #define BLINKING_RATE_MS 500 + * DigitalOut led(LED2); + * InterruptIn button(SW2); + * + * void blink_led() { + * led = 1; + * wait_us(BLINKING_RATE_MS * 1000); + * led = 0; + * } * * int main() { - * while (1) { - * heartbeat = 1; - * wait(0.5); - * heartbeat = 0; - * wait(0.5); + * button.fall(&blink_led); + * while(1) { + * // Do nothing * } * } * @endcode */ -/** Waits for a number of seconds, with microsecond resolution (within - * the accuracy of single precision floating point). - * - * @param s number of seconds to wait - * - * @note - * If the RTOS is present, this function spins to get the exact number of microseconds for - * microsecond precision up to 10 milliseconds. If delay is larger than 10 milliseconds and not in ISR, it is the same as - * `wait_ms`. We recommend `wait_us` and `wait_ms` over `wait`. - * - * @deprecated - * 'wait' is deprecated in favor of explicit sleep functions. To sleep, 'wait' should be replaced by - * 'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call - * 'wait_us'. 'wait_us' is safe to call from ISR context. - */ -MBED_DEPRECATED_SINCE("mbed-os-5.14", - "'wait' is deprecated in favor of explicit sleep functions. To sleep, 'wait' should be replaced by " - "'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call " - "'wait_us'. 'wait_us' is safe to call from ISR context.") -void wait(float s); - -/** Waits a number of milliseconds. - * - * @param ms the whole number of milliseconds to wait - * - * @note - * If the RTOS is present, it calls ThisThread::sleep_for(), which is same as CMSIS osDelay(). - * You can't call this from interrupts, and it doesn't lock hardware sleep. - * - * @deprecated - * 'wait_ms' is deprecated in favor of explicit sleep functions. To sleep, 'wait_ms' should be replaced by - * 'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call - * 'wait_us'. 'wait_us' is safe to call from ISR context. - */ -MBED_DEPRECATED_SINCE("mbed-os-5.14", - "'wait_ms' is deprecated in favor of explicit sleep functions. To sleep, 'wait_ms' should be replaced by " - "'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call " - "'wait_us'. 'wait_us' is safe to call from ISR context.") -void wait_ms(int ms); - /** Waits a number of microseconds. * * @param us the whole number of microseconds to wait diff --git a/platform/source/mbed_wait_api_no_rtos.c b/platform/source/mbed_wait_api_no_rtos.c index 5a53f998f9..ccac08db57 100644 --- a/platform/source/mbed_wait_api_no_rtos.c +++ b/platform/source/mbed_wait_api_no_rtos.c @@ -23,28 +23,6 @@ #include "hal/us_ticker_api.h" #include "hal/ticker_api.h" -// This implementation of the wait functions will be compiled only -// if the RTOS is not present. -#ifndef MBED_CONF_RTOS_PRESENT - -void wait(float s) -{ - wait_ms(s * 1000.0f); -} - -void wait_ms(int ms) -{ -#if DEVICE_LPTICKER - const ticker_data_t *const ticker = get_lp_ticker_data(); - uint32_t start = ticker_read(ticker); - while ((ticker_read(ticker) - start) < (uint32_t)(ms * 1000)); -#else - wait_us(ms * 1000); -#endif -} - -#endif // #ifndef MBED_CONF_RTOS_PRESENT - // This wait_us is used by both RTOS and non-RTOS builds /* The actual time delay may be 1 less usec */ diff --git a/platform/source/mbed_wait_api_rtos.cpp b/platform/source/mbed_wait_api_rtos.cpp deleted file mode 100644 index 163054753b..0000000000 --- a/platform/source/mbed_wait_api_rtos.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This implementation of the wait functions will be compiled only -// if the RTOS is present. Note that we still use these old -// bare metal versions of wait and wait_ms rather than using -// thread_sleep_for for backwards compatibility. People should -// be prompted to shift via their deprecation. -#ifdef MBED_CONF_RTOS_PRESENT - -#include "platform/mbed_wait_api.h" -#include "hal/us_ticker_api.h" -#include "rtos/ThisThread.h" -#include "platform/mbed_critical.h" -#include "platform/mbed_power_mgmt.h" -#include "platform/mbed_error.h" - -void wait(float s) -{ - if ((s >= 0.01f) && core_util_are_interrupts_enabled()) { - rtos::ThisThread::sleep_for(s * 1000.0f); - return; - } - - uint32_t us = (s * 1000000.0f); - const ticker_data_t *const ticker = get_us_ticker_data(); - uint32_t start = ticker_read(ticker); - if ((us >= 1000) && core_util_are_interrupts_enabled()) { - // Use the RTOS to wait for millisecond delays if possible - sleep_manager_lock_deep_sleep(); - rtos::ThisThread::sleep_for((uint32_t)us / 1000); - sleep_manager_unlock_deep_sleep(); - } - // Use busy waiting for sub-millisecond delays, or for the whole - // interval if interrupts are not enabled - while ((ticker_read(ticker) - start) < (uint32_t)us); -} - -/* The actual time delay may be up to one timer tick less - 1 msec */ -void wait_ms(int ms) -{ - if (core_util_is_isr_active() || !core_util_are_interrupts_enabled()) { -#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED - MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_INVALID_OPERATION), - "Deprecated behavior: milli-sec delay should not be used in interrupt.\n"); -#else - wait_us(ms * 1000); -#endif - } else { - rtos::ThisThread::sleep_for(ms); - } -} - -#endif // #if MBED_CONF_RTOS_PRESENT diff --git a/rtos/ConditionVariable.h b/rtos/ConditionVariable.h index 9f433f5a69..d3bcaf4ae2 100644 --- a/rtos/ConditionVariable.h +++ b/rtos/ConditionVariable.h @@ -140,7 +140,7 @@ struct Waiter; * // Mutex must be unlocked before the worker thread can acquire it. * mutex.unlock(); * - * wait(1.0); + * thread_sleep_for(1000); * } * * // Change done and notify waiters of this. diff --git a/rtos/Thread.h b/rtos/Thread.h index 10aa6176f6..62b2214516 100644 --- a/rtos/Thread.h +++ b/rtos/Thread.h @@ -59,14 +59,14 @@ namespace rtos { * void blink(DigitalOut *led) { * while (running) { * *led = !*led; - * wait(1); + * ThisThread::sleep_for(1000); * } * } * * // Spawns a thread to run blink for 5 seconds * int main() { * thread.start(callback(blink, &led1)); - * wait(5); + * ThisThread::sleep_for(5000); * running = false; * thread.join(); * } From 9739b565b22f55670cb1e5a971afcd3094b36cb1 Mon Sep 17 00:00:00 2001 From: Rajkumar Kanagaraj Date: Fri, 6 Mar 2020 07:51:15 -0800 Subject: [PATCH 2/4] Fix the CI build issue --- TESTS/lorawan/loraradio/main.cpp | 10 +-- TESTS/mbed_drivers/reset_reason/main.cpp | 6 +- TESTS/mbed_drivers/rtc/main.cpp | 2 +- TESTS/mbed_drivers/watchdog/main.cpp | 4 +- TESTS/mbed_hal/reset_reason/main.cpp | 6 +- TESTS/mbed_hal/rtc/main.cpp | 4 +- TESTS/mbed_hal/rtc_time/main.cpp | 2 +- TESTS/mbed_hal/watchdog/main.cpp | 4 +- .../mbed_hal_fpga_ci_test_shield/pwm/main.cpp | 4 +- TESTS/usb_device/basic/main.cpp | 14 ++-- TESTS/usb_device/msd/main.cpp | 2 +- TESTS/usb_device/serial/main.cpp | 70 +++++++++---------- .../MbedTester.h | 2 +- drivers/CAN.h | 2 +- drivers/DigitalIn.h | 2 +- drivers/DigitalOut.h | 2 +- drivers/I2C.h | 2 +- drivers/InterruptIn.h | 2 +- drivers/PortOut.h | 4 +- drivers/PwmOut.h | 2 +- drivers/Ticker.h | 2 +- drivers/Timeout.h | 2 +- drivers/USBKeyboard.h | 2 +- drivers/USBMIDI.h | 4 +- drivers/USBMouse.h | 4 +- drivers/USBMouseKeyboard.h | 4 +- drivers/USBSerial.h | 2 +- .../TARGET_CORDIO_ODIN_W2/HCIDriver.cpp | 4 +- .../TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp | 8 +-- .../COMPONENT_SMSC9220/smsc9220_emac.cpp | 4 +- platform/mbed_rtc_time.h | 2 +- rtos/ConditionVariable.h | 2 +- .../TARGET_ARM_SSG/TARGET_MPS2/SDK/ETH_MPS2.c | 12 ++-- targets/TARGET_NXP/USBHAL_LPC17.cpp | 2 +- .../TARGET_GR_LYCHEE/trng_api_esp32.cpp | 4 +- .../ONBOARD_TELIT_HE910.cpp | 6 +- 36 files changed, 105 insertions(+), 105 deletions(-) diff --git a/TESTS/lorawan/loraradio/main.cpp b/TESTS/lorawan/loraradio/main.cpp index d53b336ad6..fa9706e600 100644 --- a/TESTS/lorawan/loraradio/main.cpp +++ b/TESTS/lorawan/loraradio/main.cpp @@ -61,7 +61,7 @@ static volatile event_t received_event; static void tx_done() { - thread_sleep_for(2); + ThisThread::sleep_for(2); TEST_ASSERT_EQUAL(EV_NONE, received_event); received_event = EV_TX_DONE; TEST_ASSERT_EQUAL(osOK, event_sem.release()); @@ -69,7 +69,7 @@ static void tx_done() static void tx_timeout() { - thread_sleep_for(2); + ThisThread::sleep_for(2); TEST_ASSERT_EQUAL(EV_NONE, received_event); received_event = EV_TX_TIMEOUT; TEST_ASSERT_EQUAL(osOK, event_sem.release()); @@ -77,7 +77,7 @@ static void tx_timeout() static void rx_done(const uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) { - thread_sleep_for(2); + ThisThread::sleep_for(2); TEST_ASSERT_EQUAL(EV_NONE, received_event); received_event = EV_RX_DONE; TEST_ASSERT_EQUAL(osOK, event_sem.release()); @@ -85,7 +85,7 @@ static void rx_done(const uint8_t *payload, uint16_t size, int16_t rssi, int8_t static void rx_timeout() { - thread_sleep_for(2); + ThisThread::sleep_for(2); TEST_ASSERT_EQUAL(EV_NONE, received_event); received_event = EV_RX_TIMEOUT; TEST_ASSERT_EQUAL(osOK, event_sem.release()); @@ -93,7 +93,7 @@ static void rx_timeout() static void rx_error() { - thread_sleep_for(2); + ThisThread::sleep_for(2); TEST_ASSERT_EQUAL(EV_NONE, received_event); received_event = EV_RX_ERROR; TEST_ASSERT_EQUAL(osOK, event_sem.release()); diff --git a/TESTS/mbed_drivers/reset_reason/main.cpp b/TESTS/mbed_drivers/reset_reason/main.cpp index 93ddd34cc0..3c9a9519e3 100644 --- a/TESTS/mbed_drivers/reset_reason/main.cpp +++ b/TESTS/mbed_drivers/reset_reason/main.cpp @@ -103,7 +103,7 @@ static cmd_status_t handle_command(const char *key, const char *value) if (strcmp(key, MSG_KEY_DEVICE_RESET) == 0 && strcmp(value, MSG_VALUE_DEVICE_RESET_NVIC) == 0) { greentea_send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DEVICE_RESET_ACK); - thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + ThisThread::sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. NVIC_SystemReset(); TEST_ASSERT_MESSAGE(0, "NVIC_SystemReset did not reset the device as expected."); return CMD_STATUS_ERROR; @@ -112,13 +112,13 @@ static cmd_status_t handle_command(const char *key, const char *value) #if DEVICE_WATCHDOG if (strcmp(key, MSG_KEY_DEVICE_RESET) == 0 && strcmp(value, MSG_VALUE_DEVICE_RESET_WATCHDOG) == 0) { greentea_send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DEVICE_RESET_ACK); - thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + ThisThread::sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. watchdog_config_t config = { .timeout_ms = WDG_TIMEOUT_MS }; if (hal_watchdog_init(&config) != WATCHDOG_STATUS_OK) { TEST_ASSERT_MESSAGE(0, "hal_watchdog_init() error."); return CMD_STATUS_ERROR; } - thread_sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. + ThisThread::sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); return CMD_STATUS_ERROR; } diff --git a/TESTS/mbed_drivers/rtc/main.cpp b/TESTS/mbed_drivers/rtc/main.cpp index 8aee9831d7..8603fafbf4 100644 --- a/TESTS/mbed_drivers/rtc/main.cpp +++ b/TESTS/mbed_drivers/rtc/main.cpp @@ -451,7 +451,7 @@ void test_functional_count() set_time(CUSTOM_TIME_2); /* Wait 10 sec. */ - thread_sleep_for(DELAY_10_SEC * MS_PER_SEC); + ThisThread::sleep_for(DELAY_10_SEC * MS_PER_SEC); /* Get time. */ seconds = time(NULL); diff --git a/TESTS/mbed_drivers/watchdog/main.cpp b/TESTS/mbed_drivers/watchdog/main.cpp index 2afbd773b9..c81444945b 100644 --- a/TESTS/mbed_drivers/watchdog/main.cpp +++ b/TESTS/mbed_drivers/watchdog/main.cpp @@ -94,7 +94,7 @@ void test_stop() TEST_ASSERT_TRUE(watchdog.stop()); TEST_ASSERT_FALSE(watchdog.is_running()); // Make sure that a disabled watchdog does not reset the core. - thread_sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. + ThisThread::sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. TEST_ASSERT_FALSE(watchdog.stop()); } @@ -173,7 +173,7 @@ utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const } greentea_send_kv(MSG_KEY_DEVICE_RESET, CASE_INDEX_START + CASE_INDEX_CURRENT); utest_printf("The device will now restart.\n"); - thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + ThisThread::sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. NVIC_SystemReset(); return status; // Reset is instant so this line won't be reached. } diff --git a/TESTS/mbed_hal/reset_reason/main.cpp b/TESTS/mbed_hal/reset_reason/main.cpp index 65dad5b153..f44996315c 100644 --- a/TESTS/mbed_hal/reset_reason/main.cpp +++ b/TESTS/mbed_hal/reset_reason/main.cpp @@ -98,7 +98,7 @@ static cmd_status_t handle_command(const char *key, const char *value) if (strcmp(key, MSG_KEY_DEVICE_RESET) == 0 && strcmp(value, MSG_VALUE_DEVICE_RESET_NVIC) == 0) { greentea_send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DEVICE_RESET_ACK); - thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + ThisThread::sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. NVIC_SystemReset(); TEST_ASSERT_MESSAGE(0, "NVIC_SystemReset did not reset the device as expected."); return CMD_STATUS_ERROR; @@ -107,13 +107,13 @@ static cmd_status_t handle_command(const char *key, const char *value) #if DEVICE_WATCHDOG if (strcmp(key, MSG_KEY_DEVICE_RESET) == 0 && strcmp(value, MSG_VALUE_DEVICE_RESET_WATCHDOG) == 0) { greentea_send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DEVICE_RESET_ACK); - thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + ThisThread::sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. watchdog_config_t config = { .timeout_ms = WDG_TIMEOUT_MS }; if (hal_watchdog_init(&config) != WATCHDOG_STATUS_OK) { TEST_ASSERT_MESSAGE(0, "hal_watchdog_init() error."); return CMD_STATUS_ERROR; } - thread_sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. + ThisThread::sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. TEST_ASSERT_MESSAGE(0, "Watchdog did not reset the device as expected."); return CMD_STATUS_ERROR; } diff --git a/TESTS/mbed_hal/rtc/main.cpp b/TESTS/mbed_hal/rtc/main.cpp index d1773846f0..304e89ef52 100644 --- a/TESTS/mbed_hal/rtc/main.cpp +++ b/TESTS/mbed_hal/rtc/main.cpp @@ -61,9 +61,9 @@ void rtc_sleep_test_support(bool deepsleep_mode) * to allow for hardware serial buffers to completely flush. * This should be replaced with a better function that checks if the * hardware buffers are empty. However, such an API does not exist now, - * so we'll use the thread_sleep_for() function for now. + * so we'll use the ThisThread::sleep_for() function for now. */ - thread_sleep_for(10); + ThisThread::sleep_for(10); rtc_init(); diff --git a/TESTS/mbed_hal/rtc_time/main.cpp b/TESTS/mbed_hal/rtc_time/main.cpp index 35b2e7b82a..c4c47b38a1 100644 --- a/TESTS/mbed_hal/rtc_time/main.cpp +++ b/TESTS/mbed_hal/rtc_time/main.cpp @@ -187,7 +187,7 @@ void test_set_time_twice() TEST_ASSERT_EQUAL(true, (current_time == NEW_TIME)); /* Wait 2 seconds */ - thread_sleep_for(2000); + ThisThread::sleep_for(2000); /* set the time to NEW_TIME again and check it */ set_time(NEW_TIME); diff --git a/TESTS/mbed_hal/watchdog/main.cpp b/TESTS/mbed_hal/watchdog/main.cpp index b0b89457e4..683e360169 100644 --- a/TESTS/mbed_hal/watchdog/main.cpp +++ b/TESTS/mbed_hal/watchdog/main.cpp @@ -100,7 +100,7 @@ void test_stop() TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&WDG_CONFIG_DEFAULT)); TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_stop()); // Make sure that a disabled watchdog does not reset the core. - thread_sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. + ThisThread::sleep_for(2 * WDG_TIMEOUT_MS); // Watchdog should fire before twice the timeout value. TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_stop()); } @@ -170,7 +170,7 @@ utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const } greentea_send_kv(MSG_KEY_DEVICE_RESET, CASE_INDEX_START + CASE_INDEX_CURRENT); utest_printf("The device will now restart.\n"); - thread_sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. + ThisThread::sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush. NVIC_SystemReset(); return status; // Reset is instant so this line won't be reached. } diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp b/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp index e5351d5a63..489f68be3f 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp +++ b/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp @@ -127,11 +127,11 @@ void fpga_pwm_period_fill_test(PinName pin, uint32_t period_ms, uint32_t fill_pr break; } - thread_sleep_for(period_ms); + ThisThread::sleep_for(period_ms); tester.io_metrics_start(); - thread_sleep_for(NUM_OF_PERIODS * period_ms); + ThisThread::sleep_for(NUM_OF_PERIODS * period_ms); tester.io_metrics_stop(); core_util_critical_section_exit(); diff --git a/TESTS/usb_device/basic/main.cpp b/TESTS/usb_device/basic/main.cpp index 8a6727948b..efa559cac3 100644 --- a/TESTS/usb_device/basic/main.cpp +++ b/TESTS/usb_device/basic/main.cpp @@ -233,7 +233,7 @@ void ep_test_data_correctness() // Wait for host before terminating greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - thread_sleep_for(100); + ThisThread::sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -270,7 +270,7 @@ void ep_test_halt() // Wait for host before terminating greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - thread_sleep_for(100); + ThisThread::sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -307,7 +307,7 @@ void ep_test_parallel_transfers() // Wait for host before terminating greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - thread_sleep_for(100); + ThisThread::sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -345,7 +345,7 @@ void ep_test_parallel_transfers_ctrl() // Wait for host before terminating greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - thread_sleep_for(100); + ThisThread::sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -381,7 +381,7 @@ void ep_test_abort() greentea_send_kv("ep_test_abort", serial.get_serial_desc_string()); greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - thread_sleep_for(100); + ThisThread::sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -420,7 +420,7 @@ void ep_test_data_toggle() greentea_send_kv("ep_test_data_toggle", serial.get_serial_desc_string()); greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); #if EP_DBG - thread_sleep_for(100); + ThisThread::sleep_for(100); printf("cnt_cb_set_conf = %lu\r\n", serial.get_cnt_cb_set_conf()); printf("cnt_cb_set_intf = %lu\r\n", serial.get_cnt_cb_set_intf()); printf("cnt_cb_bulk_out = %lu\r\n", serial.get_cnt_cb_bulk_out()); @@ -566,7 +566,7 @@ void device_suspend_resume_test() greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); printf("[2] suspend_count: %d resume_count: %d\n", serial.get_suspend_count(), serial.get_resume_count()); TEST_ASSERT_EQUAL_STRING("pass", _key); - thread_sleep_for(5000); + ThisThread::sleep_for(5000); printf("[3] suspend_count: %d resume_count: %d\n", serial.get_suspend_count(), serial.get_resume_count()); } } diff --git a/TESTS/usb_device/msd/main.cpp b/TESTS/usb_device/msd/main.cpp index a59ae25597..fdd0a6ab1d 100644 --- a/TESTS/usb_device/msd/main.cpp +++ b/TESTS/usb_device/msd/main.cpp @@ -440,7 +440,7 @@ void mount_unmount_and_data_test(BlockDevice *bd, FileSystem *fs) TEST_ASSERT_EQUAL_STRING("passed", _key); do { - thread_sleep_for(1); + ThisThread::sleep_for(1); } while (test_files_exist(fs_root)); TEST_ASSERT_EQUAL(false, test_files_exist(fs_root)); diff --git a/TESTS/usb_device/serial/main.cpp b/TESTS/usb_device/serial/main.cpp index 46b7e0cc84..0d56736b03 100644 --- a/TESTS/usb_device/serial/main.cpp +++ b/TESTS/usb_device/serial/main.cpp @@ -296,7 +296,7 @@ void test_cdc_usb_reconnect() usb_cdc.connect(); // Wait for the USB enumeration to complete. while (!usb_cdc.configured()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } TEST_ASSERT_TRUE(usb_cdc.configured()); TEST_ASSERT_FALSE(usb_cdc.ready()); @@ -305,7 +305,7 @@ void test_cdc_usb_reconnect() // Wait for the host to open the port. #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); TEST_ASSERT_TRUE(usb_cdc.configured()); @@ -316,12 +316,12 @@ void test_cdc_usb_reconnect() TEST_ASSERT_FALSE(usb_cdc.configured()); TEST_ASSERT_FALSE(usb_cdc.ready()); - thread_sleep_for(USB_RECONNECT_DELAY_MS); + ThisThread::sleep_for(USB_RECONNECT_DELAY_MS); // Connect the USB device again. usb_cdc.connect(); // Wait for the USB enumeration to complete. while (!usb_cdc.configured()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } TEST_ASSERT_TRUE(usb_cdc.configured()); TEST_ASSERT_FALSE(usb_cdc.ready()); @@ -330,7 +330,7 @@ void test_cdc_usb_reconnect() // Wait for the host to open the port again. #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); TEST_ASSERT_TRUE(usb_cdc.configured()); @@ -355,7 +355,7 @@ void test_cdc_rx_single_bytes() greentea_send_kv(MSG_KEY_SEND_BYTES_SINGLE, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); uint8_t buff = 0x01; @@ -369,7 +369,7 @@ void test_cdc_rx_single_bytes() } // Wait for the host to close its port. while (usb_cdc.ready()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } usb_cdc.disconnect(); } @@ -380,7 +380,7 @@ void tx_thread_fun(USBCDC *usb_cdc) uint8_t buff[TX_BUFF_SIZE] = { 0 }; while (event_flags.get() & EF_SEND) { if (!usb_cdc->send(buff, TX_BUFF_SIZE)) { - thread_sleep_for(1); + ThisThread::sleep_for(1); continue; } buff_val++; @@ -402,7 +402,7 @@ void test_cdc_rx_single_bytes_concurrent() greentea_send_kv(MSG_KEY_SEND_BYTES_SINGLE, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); Thread tx_thread; @@ -421,7 +421,7 @@ void test_cdc_rx_single_bytes_concurrent() tx_thread.join(); // Wait for the host to close its port. while (usb_cdc.ready()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } usb_cdc.disconnect(); } @@ -439,7 +439,7 @@ void test_cdc_rx_multiple_bytes() greentea_send_kv(MSG_KEY_SEND_BYTES_MULTIPLE, HOST_RX_BUFF_SIZE_RATIO); #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); uint8_t buff[RX_BUFF_SIZE] = { 0 }; @@ -460,7 +460,7 @@ void test_cdc_rx_multiple_bytes() } // Wait for the host to close its port. while (usb_cdc.ready()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } usb_cdc.disconnect(); } @@ -479,7 +479,7 @@ void test_cdc_rx_multiple_bytes_concurrent() greentea_send_kv(MSG_KEY_SEND_BYTES_MULTIPLE, HOST_RX_BUFF_SIZE_RATIO); #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); Thread tx_thread; @@ -505,7 +505,7 @@ void test_cdc_rx_multiple_bytes_concurrent() tx_thread.join(); // Wait for the host to close its port. while (usb_cdc.ready()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } usb_cdc.disconnect(); } @@ -524,7 +524,7 @@ void test_cdc_loopback() greentea_send_kv(MSG_KEY_LOOPBACK, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_cdc.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_cdc.wait_ready(); uint8_t rx_buff, tx_buff; @@ -537,7 +537,7 @@ void test_cdc_loopback() } // Wait for the host to close its port. while (usb_cdc.ready()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } usb_cdc.disconnect(); } @@ -559,7 +559,7 @@ void test_serial_usb_reconnect() usb_serial.connect(); // Wait for the USB enumeration to complete. while (!usb_serial.configured()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_FALSE(usb_serial.connected()); @@ -569,10 +569,10 @@ void test_serial_usb_reconnect() // Wait for the host to open the port. #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif while (!usb_serial.connected()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_TRUE(usb_serial.connected()); @@ -584,12 +584,12 @@ void test_serial_usb_reconnect() TEST_ASSERT_FALSE(usb_serial.connected()); TEST_ASSERT_EQUAL_INT(0, usb_serial.readable()); - thread_sleep_for(USB_RECONNECT_DELAY_MS); + ThisThread::sleep_for(USB_RECONNECT_DELAY_MS); // Connect the USB device again. usb_serial.connect(); // Wait for the USB enumeration to complete. while (!usb_serial.configured()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_FALSE(usb_serial.connected()); @@ -599,10 +599,10 @@ void test_serial_usb_reconnect() // Wait for the host to open the port again. #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif while (!usb_serial.connected()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_TRUE(usb_serial.connected()); @@ -629,10 +629,10 @@ void test_serial_term_reopen() // Wait for the host to open the terminal. #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif while (!usb_serial.connected()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_TRUE(usb_serial.ready()); @@ -641,7 +641,7 @@ void test_serial_term_reopen() // Wait for the host to close the terminal. while (usb_serial.ready()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_FALSE(usb_serial.ready()); @@ -652,10 +652,10 @@ void test_serial_term_reopen() // Wait for the host to open the terminal again. #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif while (!usb_serial.connected()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_TRUE(usb_serial.ready()); @@ -664,7 +664,7 @@ void test_serial_term_reopen() // Wait for the host to close the terminal again. while (usb_serial.ready()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } TEST_ASSERT_TRUE(usb_serial.configured()); TEST_ASSERT_FALSE(usb_serial.ready()); @@ -687,7 +687,7 @@ void test_serial_getc() greentea_send_kv(MSG_KEY_SEND_BYTES_SINGLE, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_serial.wait_ready(); for (int expected = 0xff; expected >= 0; expected--) { @@ -698,7 +698,7 @@ void test_serial_getc() } // Wait for the host to close its port. while (usb_serial.ready()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } usb_serial.disconnect(); } @@ -719,7 +719,7 @@ void test_serial_printf_scanf() greentea_send_kv(MSG_KEY_LOOPBACK, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_serial.wait_ready(); static const char fmt[] = "Formatted\nstring %i."; @@ -735,7 +735,7 @@ void test_serial_printf_scanf() } // Wait for the host to close its port. while (usb_serial.ready()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } usb_serial.disconnect(); } @@ -764,7 +764,7 @@ void test_serial_line_coding_change() greentea_send_kv(MSG_KEY_CHANGE_LINE_CODING, MSG_VALUE_DUMMY); #if LINUX_HOST_DTR_FIX usb_serial.wait_ready(); - thread_sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); + ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS); #endif usb_serial.wait_ready(); usb_serial.attach(line_coding_changed_cb); @@ -805,7 +805,7 @@ void test_serial_line_coding_change() } // Wait for the host to close its port. while (usb_serial.ready()) { - thread_sleep_for(1); + ThisThread::sleep_for(1); } usb_serial.disconnect(); } diff --git a/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/MbedTester.h b/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/MbedTester.h index 62d6c0fd2a..7e73b818df 100644 --- a/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/MbedTester.h +++ b/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/MbedTester.h @@ -59,7 +59,7 @@ * int toggle = 0; * while (1) { * tester.gpio_write(MbedTester::LogicalPinGPIO0, toggle, true); - * thread_sleep_for(500); + * ThisThread::sleep_for(500); * toggle = !toggle; * } * } diff --git a/drivers/CAN.h b/drivers/CAN.h index dfe75cf65f..66d6ad422d 100644 --- a/drivers/CAN.h +++ b/drivers/CAN.h @@ -154,7 +154,7 @@ public: * printf("Message received: %d\n\n", msg.data[0]); * led2 = !led2; * } - * thread_sleep_for(200); + * ThisThread::sleep_for(200); * } * } * diff --git a/drivers/DigitalIn.h b/drivers/DigitalIn.h index b304594e29..1dfddcd0cc 100644 --- a/drivers/DigitalIn.h +++ b/drivers/DigitalIn.h @@ -46,7 +46,7 @@ namespace mbed { * if(enable) { * led = !led; * } - * thread_sleep_for(250); + * ThisThread::sleep_for(250); * } * } * @endcode diff --git a/drivers/DigitalOut.h b/drivers/DigitalOut.h index d29f227fd7..dd910cc4c8 100644 --- a/drivers/DigitalOut.h +++ b/drivers/DigitalOut.h @@ -41,7 +41,7 @@ namespace mbed { * int main() { * while(1) { * led = !led; - * thread_sleep_for(200); + * ThisThread::sleep_for(200); * } * } * @endcode diff --git a/drivers/I2C.h b/drivers/I2C.h index 82e9616c60..96bf440815 100644 --- a/drivers/I2C.h +++ b/drivers/I2C.h @@ -66,7 +66,7 @@ namespace mbed { * // set up configuration register (at 0x01) * i2c.write(addr8bit, cmd, 2); * - * thread_sleep_for(500); + * ThisThread::sleep_for(500); * * // read temperature register * cmd[0] = 0x00; diff --git a/drivers/InterruptIn.h b/drivers/InterruptIn.h index 467f079e1f..a5ac24eb04 100644 --- a/drivers/InterruptIn.h +++ b/drivers/InterruptIn.h @@ -57,7 +57,7 @@ namespace mbed { * event.rise(&trigger); * while(1) { * led = !led; - * thread_sleep_for(250); + * ThisThread::sleep_for(250); * } * } * @endcode diff --git a/drivers/PortOut.h b/drivers/PortOut.h index 3889fb38c9..5fb5c7f3a4 100644 --- a/drivers/PortOut.h +++ b/drivers/PortOut.h @@ -48,9 +48,9 @@ namespace mbed { * int main() { * while(1) { * ledport = LED_MASK; - * thread_sleep_for(1000); + * ThisThread::sleep_for(1000); * ledport = 0; - * thread_sleep_for(1000); + * ThisThread::sleep_for(1000); * } * } * @endcode diff --git a/drivers/PwmOut.h b/drivers/PwmOut.h index e8df82b9a8..a004ca0914 100644 --- a/drivers/PwmOut.h +++ b/drivers/PwmOut.h @@ -43,7 +43,7 @@ namespace mbed { * int main() { * while(1) { * led = led + 0.01; - * thread_sleep_for(200); + * ThisThread::sleep_for(200); * if(led == 1.0) { * led = 0; * } diff --git a/drivers/Ticker.h b/drivers/Ticker.h index 49185b8971..61238d264e 100644 --- a/drivers/Ticker.h +++ b/drivers/Ticker.h @@ -61,7 +61,7 @@ namespace mbed { * } else { * led2 = !led2; * } - * thread_sleep_for(200); + * ThisThread::sleep_for(200); * } * } * @endcode diff --git a/drivers/Timeout.h b/drivers/Timeout.h index 0dc4cc7130..bd312a3ef7 100644 --- a/drivers/Timeout.h +++ b/drivers/Timeout.h @@ -52,7 +52,7 @@ namespace mbed { * timeout.attach(&attimeout, 5); * while(on) { * led = !led; - * thread_sleep_for(200); + * ThisThread::sleep_for(200); * } * } * @endcode diff --git a/drivers/USBKeyboard.h b/drivers/USBKeyboard.h index d168344fd2..d9f6d0bb91 100644 --- a/drivers/USBKeyboard.h +++ b/drivers/USBKeyboard.h @@ -93,7 +93,7 @@ enum FUNCTION_KEY { * { * while (1) { * key.printf("Hello World\r\n"); - * thread_sleep_for(1000); + * ThisThread::sleep_for(1000); * } * } * diff --git a/drivers/USBMIDI.h b/drivers/USBMIDI.h index 6ead78e82e..3d7582b767 100644 --- a/drivers/USBMIDI.h +++ b/drivers/USBMIDI.h @@ -49,9 +49,9 @@ * while (1) { * for(int i=48; i<83; i++) { // send some messages! * midi.write(MIDIMessage::NoteOn(i)); -* thread_sleep_for(250); +* ThisThread::sleep_for(250); * midi.write(MIDIMessage::NoteOff(i)); -* thread_sleep_for(500); +* ThisThread::sleep_for(500); * } * } * } diff --git a/drivers/USBMouse.h b/drivers/USBMouse.h index 66419d2397..f74e8267b2 100644 --- a/drivers/USBMouse.h +++ b/drivers/USBMouse.h @@ -69,7 +69,7 @@ enum MOUSE_TYPE { * while (1) * { * mouse.move(20, 0); - * thread_sleep_for(500); + * ThisThread::sleep_for(500); * } * } * @@ -102,7 +102,7 @@ enum MOUSE_TYPE { * * mouse.move(x_screen, y_screen); * angle += 3; - * thread_sleep_for(10); + * ThisThread::sleep_for(10); * } * } * diff --git a/drivers/USBMouseKeyboard.h b/drivers/USBMouseKeyboard.h index 76676572e2..54144ba64f 100644 --- a/drivers/USBMouseKeyboard.h +++ b/drivers/USBMouseKeyboard.h @@ -49,7 +49,7 @@ * { * key_mouse.move(20, 0); * key_mouse.printf("Hello From MBED\r\n"); - * thread_sleep_for(1000); + * ThisThread::sleep_for(1000); * } * } * @endcode @@ -68,7 +68,7 @@ * { * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2); * key_mouse.printf("Hello from MBED\r\n"); - * thread_sleep_for(1000); + * ThisThread::sleep_for(1000); * } * } * @endcode diff --git a/drivers/USBSerial.h b/drivers/USBSerial.h index 1861650063..8103739376 100644 --- a/drivers/USBSerial.h +++ b/drivers/USBSerial.h @@ -43,7 +43,7 @@ * while(1) * { * serial.printf("I am a virtual serial port\n"); -* thread_sleep_for(1000); +* ThisThread::sleep_for(1000); * } * } * @endcode diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp index 572670a4d8..4813161922 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp @@ -150,9 +150,9 @@ void ble::vendor::odin_w2::HCIDriver::do_initialize() hci_rts = 1; // Flow Control is OFF shutdown = 0; // BT Power is OFF - thread_sleep_for(20); + ThisThread::sleep_for(20); shutdown = 1; // BT Power is ON - thread_sleep_for(500); + ThisThread::sleep_for(500); hci_rts = 0; // Flow Control is ON diff --git a/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp index 650e587495..ad024aec38 100644 --- a/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp @@ -96,13 +96,13 @@ public: output_mode(bt_device_wake_name, 0); output_mode(bt_power_name, 1); - thread_sleep_for(500); + ThisThread::sleep_for(500); bt_device_wake = 0; - thread_sleep_for(500); + ThisThread::sleep_for(500); bt_power = 1; - thread_sleep_for(500); + ThisThread::sleep_for(500); } virtual void do_terminate() { } @@ -312,7 +312,7 @@ private: service_pack_next = NULL; service_pack_index = 0; service_pack_transfered = true; - thread_sleep_for(1000); + ThisThread::sleep_for(1000); set_sleep_mode(); } diff --git a/features/netsocket/emac-drivers/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp b/features/netsocket/emac-drivers/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp index a4b2a8d479..ca97bc6a8d 100644 --- a/features/netsocket/emac-drivers/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp +++ b/features/netsocket/emac-drivers/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp @@ -210,7 +210,7 @@ bool SMSC9220_EMAC::power_up() this)); /* Initialize the hardware */ - enum smsc9220_error_t init_successful = smsc9220_init(dev, &wait_ms); + enum smsc9220_error_t init_successful = smsc9220_init(dev, &ThisThread::sleep_for); if (init_successful != SMSC9220_ERROR_NONE) { return false; } @@ -236,7 +236,7 @@ bool SMSC9220_EMAC::power_up() &SMSC9220_EMAC::link_status_task)); /* Allow the Link Status task to detect the initial link state */ - wait_ms(10); + ThisThread::sleep_for(10); _link_status_task_handle = mbed::mbed_event_queue()->call_every( LINK_STATUS_TASK_PERIOD_MS, mbed::callback(this, diff --git a/platform/mbed_rtc_time.h b/platform/mbed_rtc_time.h index e7c5e672b4..f85796ba5b 100644 --- a/platform/mbed_rtc_time.h +++ b/platform/mbed_rtc_time.h @@ -64,7 +64,7 @@ struct timeval { * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); * printf("Time as a custom formatted string = %s", buffer); * - * thread_sleep_for(1000); + * ThisThread::sleep_for(1000); * } * } * @endcode diff --git a/rtos/ConditionVariable.h b/rtos/ConditionVariable.h index d3bcaf4ae2..630f67ff76 100644 --- a/rtos/ConditionVariable.h +++ b/rtos/ConditionVariable.h @@ -140,7 +140,7 @@ struct Waiter; * // Mutex must be unlocked before the worker thread can acquire it. * mutex.unlock(); * - * thread_sleep_for(1000); + * ThisThread::sleep_for(1000); * } * * // Change done and notify waiters of this. diff --git a/targets/TARGET_ARM_SSG/TARGET_MPS2/SDK/ETH_MPS2.c b/targets/TARGET_ARM_SSG/TARGET_MPS2/SDK/ETH_MPS2.c index 3910871cd9..22e23b5322 100644 --- a/targets/TARGET_ARM_SSG/TARGET_MPS2/SDK/ETH_MPS2.c +++ b/targets/TARGET_ARM_SSG/TARGET_MPS2/SDK/ETH_MPS2.c @@ -57,7 +57,7 @@ unsigned int smsc9220_mac_regread(unsigned char regoffset, unsigned int *data) timedout = 50; do { val = SMSC9220->BYTE_TEST; // A no-op read. - wait_ms(1); + thread_sleep_for(1); timedout--; } while(timedout && (SMSC9220->MAC_CSR_CMD & ((unsigned int)1 << 31))); @@ -91,7 +91,7 @@ unsigned int smsc9220_mac_regwrite(unsigned char regoffset, unsigned int data) timedout = 50; do { read = SMSC9220->BYTE_TEST; // A no-op read. - wait_ms(1); + thread_sleep_for(1); timedout--; } while(timedout && (SMSC9220->MAC_CSR_CMD & ((unsigned int)1 << 31))); @@ -125,7 +125,7 @@ unsigned int smsc9220_phy_regread(unsigned char regoffset, unsigned short *data) val = 0; timedout = 50; do { - wait_ms(1); + thread_sleep_for(1); timedout--; smsc9220_mac_regread(SMSC9220_MAC_MII_ACC,&val); } while(timedout && (val & ((unsigned int)1 << 0))); @@ -165,7 +165,7 @@ unsigned int smsc9220_phy_regwrite(unsigned char regoffset, unsigned short data) do { - wait_ms(1); + thread_sleep_for(1); timedout--; smsc9220_mac_regread(SMSC9220_MAC_MII_ACC, &phycmd); } while(timedout && (phycmd & (1 << 0))); @@ -196,7 +196,7 @@ unsigned int smsc9220_soft_reset(void) SMSC9220->HW_CFG |= 1; do { - wait_ms(1); + thread_sleep_for(1); timedout--; } while(timedout && (SMSC9220->HW_CFG & 1)); @@ -223,7 +223,7 @@ unsigned int smsc9220_wait_eeprom(void) timedout = 50; do { - wait_ms(1); + thread_sleep_for(1); timedout--; } while(timedout && (SMSC9220->E2P_CMD & ((unsigned int) 1 << 31))); diff --git a/targets/TARGET_NXP/USBHAL_LPC17.cpp b/targets/TARGET_NXP/USBHAL_LPC17.cpp index 5f8f60ce91..f511cf8b03 100644 --- a/targets/TARGET_NXP/USBHAL_LPC17.cpp +++ b/targets/TARGET_NXP/USBHAL_LPC17.cpp @@ -411,7 +411,7 @@ void USBPhyHw::init(USBPhyEvents *events) LPC_PINCON->PINSEL4 |= 0x00040000; // Connect must be low for at least 2.5uS - wait(0.3); + ThisThread::sleep_for(300); // Disable control endpoints SIEsetEndpointStatus(EP0IN, SIE_SES_DA); diff --git a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/trng_api_esp32.cpp b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/trng_api_esp32.cpp index c2fd9c6ca1..d2f1b17c8f 100644 --- a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/trng_api_esp32.cpp +++ b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/trng_api_esp32.cpp @@ -47,7 +47,7 @@ extern "C" void trng_init_esp32(void) GPIOPM3 &= ~0x4000; /* Output mode */ GPIOP3 |= 0x4000; /* Outputs hi level */ - wait_ms(5); + ThisThread::sleep_for(5); GPIOP5 |= 0x0008; /* Outputs hi level */ } } @@ -84,7 +84,7 @@ extern "C" int trng_get_bytes_esp32(uint8_t *output, size_t length, size_t *outp } if (ret != 0) { retry_cnt++; - wait_ms(100); + ThisThread::sleep_for(100); } } if (retry_cnt >= RETRY_CNT_MAX) { diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/TARGET_MTS_DRAGONFLY_F413RH/ONBOARD_TELIT_HE910.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/TARGET_MTS_DRAGONFLY_F413RH/ONBOARD_TELIT_HE910.cpp index d2369de561..d5307b6382 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/TARGET_MTS_DRAGONFLY_F413RH/ONBOARD_TELIT_HE910.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/TARGET_MTS_DRAGONFLY_F413RH/ONBOARD_TELIT_HE910.cpp @@ -49,7 +49,7 @@ nsapi_error_t ONBOARD_TELIT_HE910::soft_power_on() /* keep the power line low for 200 milisecond */ press_power_button(200); /* give modem a little time to respond */ - wait_ms(100); + ThisThread::sleep_for(100); // From Telit_xE910 Global form factor App note: It is mandatory to avoid sending data to the serial ports during the first 200ms of the module start-up. rtos::ThisThread::sleep_for(200); return NSAPI_ERROR_OK; @@ -64,7 +64,7 @@ nsapi_error_t ONBOARD_TELIT_HE910::soft_power_off() * If 3G_ON_OFF pin is kept low for more than a second, a controlled disconnect and shutdown takes * place, Due to the network disconnect, shut-off can take up to 30 seconds. However, we wait for 10 * seconds only */ - wait_ms(10 * 1000); + ThisThread::sleep_for(10 * 1000); return NSAPI_ERROR_OK; } @@ -74,7 +74,7 @@ void ONBOARD_TELIT_HE910::press_power_button(int time_ms) gpio_init_out_ex(&gpio, MDMPWRON, 1); gpio_write(&gpio, 0); - wait_ms(time_ms); + ThisThread::sleep_for(time_ms); gpio_write(&gpio, 1); } From cbb15ad9ac58c1df622f911daaa3a33bb2d5c5a6 Mon Sep 17 00:00:00 2001 From: Rajkumar Kanagaraj Date: Tue, 31 Mar 2020 17:14:49 +0100 Subject: [PATCH 3/4] ThisThread::sleep_for is asserted when the PWM test case calls this API with IRQ masked, so wait_us is used to fix this issue as PWM testes to be executed with interrupt disabled to avoid context switch. --- TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp b/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp index 489f68be3f..5220221a10 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp +++ b/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp @@ -127,11 +127,11 @@ void fpga_pwm_period_fill_test(PinName pin, uint32_t period_ms, uint32_t fill_pr break; } - ThisThread::sleep_for(period_ms); + wait_us(PERIOD_US(period_ms)); tester.io_metrics_start(); - ThisThread::sleep_for(NUM_OF_PERIODS * period_ms); + wait_us(NUM_OF_PERIODS * PERIOD_US(period_ms)); tester.io_metrics_stop(); core_util_critical_section_exit(); From 3d128e861b5942c8afcc0bfc6cc960597c9d4b81 Mon Sep 17 00:00:00 2001 From: Rajkumar Kanagaraj Date: Fri, 6 Mar 2020 07:51:15 -0800 Subject: [PATCH 4/4] - Fix the CI build issue. - Incorporate the review comment. --- TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp | 1 + .../TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.c | 2 +- .../TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.h | 4 ++-- .../TARGET_RZ_A1XX/TARGET_GR_LYCHEE/trng_api_esp32.cpp | 7 +++++-- .../TARGET_MTS_DRAGONFLY_F413RH/ONBOARD_TELIT_HE910.cpp | 6 +++--- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp b/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp index 5220221a10..7124fce635 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp +++ b/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp @@ -127,6 +127,7 @@ void fpga_pwm_period_fill_test(PinName pin, uint32_t period_ms, uint32_t fill_pr break; } + // wait_us is safe to call as this test disable the IRQs on execution. wait_us(PERIOD_US(period_ms)); tester.io_metrics_start(); diff --git a/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.c b/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.c index 5c929a740c..3ef7501f18 100644 --- a/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.c +++ b/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.c @@ -859,7 +859,7 @@ uint32_t smsc9220_get_tx_data_fifo_size( enum smsc9220_error_t smsc9220_init( const struct smsc9220_eth_dev_t* dev, - void(* wait_ms_function)(int)) + void(* wait_ms_function)(uint32_t)) { uint32_t phyreset = 0; enum smsc9220_error_t error = SMSC9220_ERROR_NONE; diff --git a/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.h b/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.h index 3c60f45bbb..296bb59745 100644 --- a/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.h +++ b/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.h @@ -38,7 +38,7 @@ struct smsc9220_eth_dev_cfg_t { struct smsc9220_eth_dev_data_t { uint32_t state; /*!< Indicates if the SMSC9220 driver is initialized and enabled */ - void (*wait_ms) (int);/*!< function pointer to system's millisec delay + void (*wait_ms) (uint32_t);/*!< function pointer to system's millisec delay function, will be used for delays */ uint32_t ongoing_packet_length;/*!< size in bytes of the packet is being sent */ @@ -195,7 +195,7 @@ enum smsc9220_fifo_level_irq_pos_t{ * \return error code /ref smsc9220_error_t */ enum smsc9220_error_t smsc9220_init(const struct smsc9220_eth_dev_t* dev, - void(* wait_ms_function)(int)); + void(* wait_ms_function)(uint32_t)); /** * \brief Reads the MAC register. diff --git a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/trng_api_esp32.cpp b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/trng_api_esp32.cpp index d2f1b17c8f..d99a1e1cbd 100644 --- a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/trng_api_esp32.cpp +++ b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/trng_api_esp32.cpp @@ -17,6 +17,7 @@ #if DEVICE_TRNG #include "drivers/I2C.h" #include "platform/mbed_wait_api.h" +#include "rtos/ThisThread.h" #define ESP32_I2C_ADDR (0x28<<1) #define RETRY_CNT_MAX (20) @@ -47,7 +48,9 @@ extern "C" void trng_init_esp32(void) GPIOPM3 &= ~0x4000; /* Output mode */ GPIOP3 |= 0x4000; /* Outputs hi level */ - ThisThread::sleep_for(5); + + rtos::ThisThread::sleep_for(5); + GPIOP5 |= 0x0008; /* Outputs hi level */ } } @@ -84,7 +87,7 @@ extern "C" int trng_get_bytes_esp32(uint8_t *output, size_t length, size_t *outp } if (ret != 0) { retry_cnt++; - ThisThread::sleep_for(100); + rtos::ThisThread::sleep_for(100); } } if (retry_cnt >= RETRY_CNT_MAX) { diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/TARGET_MTS_DRAGONFLY_F413RH/ONBOARD_TELIT_HE910.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/TARGET_MTS_DRAGONFLY_F413RH/ONBOARD_TELIT_HE910.cpp index d5307b6382..cc6d08bb06 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/TARGET_MTS_DRAGONFLY_F413RH/ONBOARD_TELIT_HE910.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/TARGET_MTS_DRAGONFLY_F413RH/ONBOARD_TELIT_HE910.cpp @@ -49,7 +49,7 @@ nsapi_error_t ONBOARD_TELIT_HE910::soft_power_on() /* keep the power line low for 200 milisecond */ press_power_button(200); /* give modem a little time to respond */ - ThisThread::sleep_for(100); + rtos::ThisThread::sleep_for(100); // From Telit_xE910 Global form factor App note: It is mandatory to avoid sending data to the serial ports during the first 200ms of the module start-up. rtos::ThisThread::sleep_for(200); return NSAPI_ERROR_OK; @@ -64,7 +64,7 @@ nsapi_error_t ONBOARD_TELIT_HE910::soft_power_off() * If 3G_ON_OFF pin is kept low for more than a second, a controlled disconnect and shutdown takes * place, Due to the network disconnect, shut-off can take up to 30 seconds. However, we wait for 10 * seconds only */ - ThisThread::sleep_for(10 * 1000); + rtos::ThisThread::sleep_for(10 * 1000); return NSAPI_ERROR_OK; } @@ -74,7 +74,7 @@ void ONBOARD_TELIT_HE910::press_power_button(int time_ms) gpio_init_out_ex(&gpio, MDMPWRON, 1); gpio_write(&gpio, 0); - ThisThread::sleep_for(time_ms); + rtos::ThisThread::sleep_for(time_ms); gpio_write(&gpio, 1); }