Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7bde03c

Browse files
committed
Merge branch 'feature/newlib_add_sleep' into 'master'
Add "usleep" and "sleep" function See merge request sdk/ESP8266_RTOS_SDK!573
2 parents 08355fc + 7bd6fc0 commit 7bde03c

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

components/esp8266/include/esp8266/rom_functions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ uint32_t Wait_SPI_Idle();
1717

1818
void uart_div_modify(uint32_t uart_no, uint32_t baud_div);
1919

20-
void ets_delay_us(uint32_t us);
2120
int ets_io_vprintf(int (*putc)(int), const char* fmt, va_list ap);
2221

2322
void system_soft_wdt_feed();

components/esp8266/include/rom/ets_sys.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ extern uint32_t WDEV_INTEREST_EVENT;
9797
*/
9898
void os_delay_us(uint16_t us);
9999

100+
/**
101+
* @brief CPU do while loop for some time.
102+
* In FreeRTOS task, please call FreeRTOS apis.
103+
*
104+
* @param uint32_t us : Delay time in us.
105+
*
106+
* @return None
107+
*/
108+
void ets_delay_us(uint32_t us);
109+
100110
/**
101111
* @brief Register the print output function.
102112
*

components/newlib/newlib/port/time.c

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

2020
#include "esp_system.h"
2121
#include "esp_timer.h"
22+
#include "rom/ets_sys.h"
2223

2324
#include "FreeRTOS.h"
2425
#include "task.h"
@@ -141,3 +142,26 @@ clock_t _times_r(struct _reent *r, struct tms *tms)
141142

142143
return 0;
143144
}
145+
146+
int usleep(useconds_t us)
147+
{
148+
const int us_per_tick = portTICK_PERIOD_MS * 1000;
149+
150+
if (us < us_per_tick) {
151+
ets_delay_us((uint32_t) us);
152+
} else {
153+
/* since vTaskDelay(1) blocks for anywhere between 0 and portTICK_PERIOD_MS,
154+
* round up to compensate.
155+
*/
156+
vTaskDelay((us + us_per_tick - 1) / us_per_tick);
157+
}
158+
159+
return 0;
160+
}
161+
162+
unsigned int sleep(unsigned int seconds)
163+
{
164+
vTaskDelay(seconds * (1000 / portTICK_PERIOD_MS));
165+
166+
return 0;
167+
}

0 commit comments

Comments
 (0)