mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-28 13:40:37 +08:00
feat(newib): Add "usleep" and "sleep" function
This commit is contained in:
@ -17,7 +17,6 @@ uint32_t Wait_SPI_Idle();
|
|||||||
|
|
||||||
void uart_div_modify(uint32_t uart_no, uint32_t baud_div);
|
void uart_div_modify(uint32_t uart_no, uint32_t baud_div);
|
||||||
|
|
||||||
void ets_delay_us(uint32_t us);
|
|
||||||
int ets_io_vprintf(int (*putc)(int), const char* fmt, va_list ap);
|
int ets_io_vprintf(int (*putc)(int), const char* fmt, va_list ap);
|
||||||
|
|
||||||
void system_soft_wdt_feed();
|
void system_soft_wdt_feed();
|
||||||
|
@ -97,6 +97,16 @@ extern uint32_t WDEV_INTEREST_EVENT;
|
|||||||
*/
|
*/
|
||||||
void os_delay_us(uint16_t us);
|
void os_delay_us(uint16_t us);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CPU do while loop for some time.
|
||||||
|
* In FreeRTOS task, please call FreeRTOS apis.
|
||||||
|
*
|
||||||
|
* @param uint32_t us : Delay time in us.
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*/
|
||||||
|
void ets_delay_us(uint32_t us);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Register the print output function.
|
* @brief Register the print output function.
|
||||||
*
|
*
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
#include "esp_timer.h"
|
#include "esp_timer.h"
|
||||||
|
#include "rom/ets_sys.h"
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
@ -141,3 +142,26 @@ clock_t _times_r(struct _reent *r, struct tms *tms)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int usleep(useconds_t us)
|
||||||
|
{
|
||||||
|
const int us_per_tick = portTICK_PERIOD_MS * 1000;
|
||||||
|
|
||||||
|
if (us < us_per_tick) {
|
||||||
|
ets_delay_us((uint32_t) us);
|
||||||
|
} else {
|
||||||
|
/* since vTaskDelay(1) blocks for anywhere between 0 and portTICK_PERIOD_MS,
|
||||||
|
* round up to compensate.
|
||||||
|
*/
|
||||||
|
vTaskDelay((us + us_per_tick - 1) / us_per_tick);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int sleep(unsigned int seconds)
|
||||||
|
{
|
||||||
|
vTaskDelay(seconds * (1000 / portTICK_PERIOD_MS));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user