feat(esp8266): Add API to get microseconds

This commit is contained in:
dongheng
2019-03-07 16:06:15 +08:00
parent 09e8cc0f95
commit 7fbb68f4ea
7 changed files with 139 additions and 70 deletions

View File

@ -164,5 +164,7 @@ uint32_t esp_get_time(void);
#endif /* CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS */
#define traceINCREASE_TICK_COUNT(_ticks) esp_increase_tick_cnt(_ticks)
#endif /* FREERTOS_CONFIG_H */

View File

@ -201,6 +201,8 @@ uint32_t xPortGetTickRateHz(void);
void _xt_enter_first_task(void);
void esp_increase_tick_cnt(const TickType_t ticks);
/* API compatible with esp-idf */
#define xTaskCreatePinnedToCore(pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask, tskNO_AFFINITY) \
xTaskCreate(pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask)

View File

@ -45,6 +45,7 @@
#include "esp8266/eagle_soc.h"
#include "rom/ets_sys.h"
#include "esp8266/rom_functions.h"
#include "driver/soc.h"
#define PORT_ASSERT(x) do { if (!(x)) {ets_printf("%s %u\n", "rtos_port", __LINE__); while(1){}; }} while (0)
@ -58,6 +59,9 @@ unsigned cpu_sr;
variable. */
static uint32_t uxCriticalNesting = 0;
esp_tick_t g_cpu_ticks = 0;
uint64_t g_os_ticks = 0;
void vPortEnterCritical(void);
void vPortExitCritical(void);
@ -137,8 +141,23 @@ void TASK_SW_ATTR SoftIsrHdl(void* arg)
ETS_NMI_UNLOCK();
}
void esp_increase_tick_cnt(const TickType_t ticks)
{
esp_irqflag_t flag;
flag = soc_save_local_irq();
g_cpu_ticks = soc_get_ticks();
g_os_ticks += ticks;
soc_restore_local_irq(flag);
}
void TASK_SW_ATTR xPortSysTickHandle(void)
{
g_cpu_ticks = soc_get_ticks();
g_os_ticks++;
if (xTaskIncrementTick() != pdFALSE) {
vTaskSwitchContext();
}
@ -169,6 +188,9 @@ portBASE_TYPE xPortStartScheduler(void)
vTaskSwitchContext();
/* Get ticks before RTOS starts */
g_cpu_ticks = soc_get_ticks();
/* Restore the context of the first task that is going to run. */
_xt_enter_first_task();