From c90179beb535e38b2964daeed084af9969c314c2 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 13 Aug 2024 19:36:32 -0400 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4rt=5Fthread=5Fsleep=E9=81=97?= =?UTF-8?q?=E7=95=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/efm32/application.c | 10 +++++----- bsp/efm32/dev_accel.c | 4 ++-- bsp/efm32/drv_leuart.c | 2 +- bsp/efm32/drv_usart.c | 4 ++-- bsp/sep6200/application/application.c | 6 +++--- documentation/thread/thread.md | 5 ++--- examples/libc/ex6.c | 2 +- examples/libc/ex7.c | 2 +- examples/libc/file.c | 2 +- 9 files changed, 18 insertions(+), 19 deletions(-) diff --git a/bsp/efm32/application.c b/bsp/efm32/application.c index e1b871bada..40f7b9411f 100644 --- a/bsp/efm32/application.c +++ b/bsp/efm32/application.c @@ -475,7 +475,7 @@ void rt_demo_thread_entry(void* parameter) struct efm32_accel_result_t result; rt_kprintf(">>> waiting\n"); - rt_thread_sleep(6000); + rt_thread_delay(6000); rt_kprintf(">>> start\n"); while(1) { @@ -483,7 +483,7 @@ void rt_demo_thread_entry(void* parameter) rt_kprintf("Accel x: %x\n", result.x); rt_kprintf("Accel y: %x\n", result.y); rt_kprintf("Accel z: %x\n\n", result.z); - rt_thread_sleep(200); + rt_thread_delay(200); } } #endif @@ -644,7 +644,7 @@ void rt_demo_thread_entry(void* parameter) } /* start display photos */ - rt_thread_sleep(100); + rt_thread_delay(100); do { /* get a photo */ @@ -680,7 +680,7 @@ void rt_demo_thread_entry(void* parameter) } rtgui_send(photo_app, &event.win.parent, sizeof(event)); - rt_thread_sleep(2000); + rt_thread_delay(2000); } while (dirent != RT_NULL); closedir(dir); @@ -694,7 +694,7 @@ void rt_demo_thread_entry(void* parameter) emu_em2_enable(); while(1) { - rt_thread_sleep(10); + rt_thread_delay(10); } } diff --git a/bsp/efm32/dev_accel.c b/bsp/efm32/dev_accel.c index d5b9e0565b..fc90cad873 100644 --- a/bsp/efm32/dev_accel.c +++ b/bsp/efm32/dev_accel.c @@ -629,7 +629,7 @@ rt_err_t efm_accel_auto_zero(rt_uint8_t mode, rt_tick_t period) accel_debug("Accel: Offset %+d %+d %+d\n", *(rt_int16_t *)&cmd[1], \ *(rt_int16_t *)&cmd[3], *(rt_int16_t *)&cmd[5]); #endif - rt_thread_sleep(1); + rt_thread_delay(1); } } else @@ -695,7 +695,7 @@ rt_err_t efm_accel_auto_zero(rt_uint8_t mode, rt_tick_t period) { max.z = sum.z; } - rt_thread_sleep(1); + rt_thread_delay(1); } while (accelInTime); accel_debug("Accel: Min %+d %+d %+d, max %+d %+d %+d\n", diff --git a/bsp/efm32/drv_leuart.c b/bsp/efm32/drv_leuart.c index bf1720b8ad..8534f4b194 100644 --- a/bsp/efm32/drv_leuart.c +++ b/bsp/efm32/drv_leuart.c @@ -437,7 +437,7 @@ static rt_ssize_t rt_leuart_write ( // { // while(leuart->state & LEUART_STATE_TX_BUSY) // { -// rt_thread_sleep(LEUART_WAIT_TIME_TX); +// rt_thread_delay(LEUART_WAIT_TIME_TX); // } // } // TODO: This function blocks the process diff --git a/bsp/efm32/drv_usart.c b/bsp/efm32/drv_usart.c index 1c97556eac..e12b1c3da9 100644 --- a/bsp/efm32/drv_usart.c +++ b/bsp/efm32/drv_usart.c @@ -633,7 +633,7 @@ static rt_ssize_t rt_usart_write ( // { // while(usart->state & USART_STATE_TX_BUSY) // { - // rt_thread_sleep(USART_WAIT_TIME_TX); + // rt_thread_delay(USART_WAIT_TIME_TX); // } // } } @@ -699,7 +699,7 @@ static rt_ssize_t rt_usart_write ( // { // while(usart->state & USART_STATE_TX_BUSY) // { -// rt_thread_sleep(USART_WAIT_TIME_TX); +// rt_thread_delay(USART_WAIT_TIME_TX); // } // } write_size = size; diff --git a/bsp/sep6200/application/application.c b/bsp/sep6200/application/application.c index 5a032933b4..6627e4726e 100644 --- a/bsp/sep6200/application/application.c +++ b/bsp/sep6200/application/application.c @@ -22,7 +22,7 @@ void rt_init_thread_entry(void *parameter) { while(1){ - rt_thread_sleep(200); + rt_thread_delay(200); rt_hw_console_output("init thread\n"); } } @@ -30,7 +30,7 @@ void rt_init_thread_entry(void *parameter) void rt_test1_thread_entry(void *parameter) { while(1){ - rt_thread_sleep(800); + rt_thread_delay(800); rt_hw_console_output("test1 thread\n"); } } @@ -38,7 +38,7 @@ void rt_test1_thread_entry(void *parameter) void rt_test2_thread_entry(void *parameter) { while(1){ - rt_thread_sleep(300); + rt_thread_delay(300); rt_hw_console_output("test2 thread\n"); } } diff --git a/documentation/thread/thread.md b/documentation/thread/thread.md index ab1058d67c..4c384cd747 100644 --- a/documentation/thread/thread.md +++ b/documentation/thread/thread.md @@ -353,16 +353,15 @@ The `rt_thread_yield()` function is similar to the `rt_schedule()` function, but In practical applications, we sometimes need to delay the current thread running for a period of time and re-run at a specified time. This is called "thread sleep". Thread sleep can use the following three function interfaces: ```c -rt_err_t rt_thread_sleep(rt_tick_t tick); rt_err_t rt_thread_delay(rt_tick_t tick); rt_err_t rt_thread_mdelay(rt_int32_t ms); ``` -These three function interfaces have the same effect. Calling them can cause the current thread to suspend for a specified period of time. After, the thread will wake up and enter the ready state again. This function accepts a parameter that specifies the sleep time of the thread. The parameters and return values of the thread sleep interface rt_thread_sleep/delay/mdelay() are as follows: +These three function interfaces have the same effect. Calling them can cause the current thread to suspend for a specified period of time. After, the thread will wake up and enter the ready state again. This function accepts a parameter that specifies the sleep time of the thread. The parameters and return values of the thread sleep interface rt_thread_delay/mdelay() are as follows: |**Parameters**|Description | | -------- | ------------------------------------------------------------ | -| tick/ms | Thread sleep time:
The input parameter tick of rt_thread_sleep/rt_thread_delay is in units of 1 OS Tick;
The input parameter ms of rt_thread_mdelay is in units of 1ms; | +| tick/ms | Thread sleep time:
The input parameter tick of rt_thread_delay is in units of 1 OS Tick;
The input parameter ms of rt_thread_mdelay is in units of 1ms; | |**Return**| —— | | RT_EOK | Successful operation. | diff --git a/examples/libc/ex6.c b/examples/libc/ex6.c index ba687aa46f..20ab0d8e5d 100644 --- a/examples/libc/ex6.c +++ b/examples/libc/ex6.c @@ -12,7 +12,7 @@ #include #include -#define usleep rt_thread_sleep +#define usleep rt_thread_delay static void *test_thread(void *v_param) { return NULL; diff --git a/examples/libc/ex7.c b/examples/libc/ex7.c index d1f05dbdcd..b1969c8663 100644 --- a/examples/libc/ex7.c +++ b/examples/libc/ex7.c @@ -18,7 +18,7 @@ #include #include -#define usleep rt_thread_sleep +#define usleep rt_thread_delay /* Our event variable using a condition variable contruct. */ typedef struct { diff --git a/examples/libc/file.c b/examples/libc/file.c index 878d3a98d7..918fca3b86 100644 --- a/examples/libc/file.c +++ b/examples/libc/file.c @@ -57,7 +57,7 @@ FINSH_FUNCTION_EXPORT(libc_lseek, lseek test for libc); void sleep(int tick) { - rt_thread_sleep(tick); + rt_thread_delay(tick); } int libc_fseek(void)