Merge branch 'feature/refactor_ccompare_timer' into 'master'

esp8266: refactor CCOMPARE timer and system time by microseconds

See merge request sdk/ESP8266_RTOS_SDK!1060
This commit is contained in:
Dong Heng
2019-08-21 15:21:53 +08:00
7 changed files with 85 additions and 61 deletions

View File

@ -26,20 +26,6 @@ extern "C" {
typedef uint32_t esp_tick_t;
typedef uint32_t esp_irqflag_t;
static inline esp_tick_t soc_get_ticks(void)
{
esp_tick_t ticks;
__asm__ __volatile__(
"rsr %0, ccount\n"
: "=a"(ticks)
:
: "memory"
);
return ticks;
}
static inline esp_irqflag_t soc_save_local_irq(void)
{
esp_irqflag_t flag;
@ -102,6 +88,16 @@ static inline uint32_t soc_get_ccount(void)
return ticks;
}
static inline void soc_set_ccount(uint32_t ticks)
{
__asm__ __volatile__(
"wsr %0, ccount\n"
:
: "a"(ticks)
: "memory"
);
}
static inline void soc_clear_int_mask(uint32_t mask)
{
__asm__ __volatile__(

View File

@ -94,6 +94,18 @@
#define APB_CLK_FREQ CPU_CLK_FREQ
#define UART_CLK_FREQ APB_CLK_FREQ
#define TIMER_CLK_FREQ (APB_CLK_FREQ >> 8) // divided by 256
#define FREQ_1MHZ (1000 * 1000)
#define FREQ_1KHZ (1000)
#define CPU_FREQ_160MHZ (160 * 1000 * 1000)
#define CPU_FREQ_80MHz (80 * 1000 * 1000)
#define CPU_160M_TICKS_PRT_MS (CPU_FREQ_160MHZ / FREQ_1MHZ)
#define CPU_80M_TICKS_PRT_MS (CPU_FREQ_80MHz / FREQ_1KHZ)
#define CPU_160M_TICKS_PRT_US (CPU_FREQ_160MHZ / FREQ_1MHZ)
#define CPU_80M_TICKS_PRT_US (CPU_FREQ_80MHz / FREQ_1MHZ)
//}}
//Peripheral device base address define{{

View File

@ -202,26 +202,7 @@ esp_err_t esp_timer_delete(esp_timer_handle_t timer)
int64_t esp_timer_get_time()
{
extern esp_tick_t g_cpu_ticks;
extern uint64_t g_os_ticks;
extern uint64_t g_esp_os_us;
esp_irqflag_t flag;
esp_tick_t diff_ticks, ticks;
uint64_t time;
flag = soc_save_local_irq();
time = g_os_ticks * portTICK_PERIOD_MS * 1000;
ticks = soc_get_ticks();
if (ticks >= g_cpu_ticks) {
diff_ticks = ticks - g_cpu_ticks;
} else {
diff_ticks = ESP_TICKS_MAX - g_cpu_ticks + ticks;
}
time += diff_ticks / (_xt_tick_divisor * configTICK_RATE_HZ / (1000 * 1000));
soc_restore_local_irq(flag);
return (int64_t)time;
return (int64_t)g_esp_os_us;
}