feat(timer): refator timer group driver

1. add hal and low-level layer for timer group
2. add callback functions to handle interrupt
3. add timer deinit function
4. add timer spinlock take function
This commit is contained in:
chenjianqiang
2019-07-15 14:21:36 +08:00
parent 8c3cb232f0
commit 9f9da9ec96
27 changed files with 1460 additions and 331 deletions

View File

@@ -55,11 +55,12 @@ static void inline print_timer_counter(uint64_t counter_value)
*/
void IRAM_ATTR timer_group0_isr(void *para)
{
timer_spinlock_take(TIMER_GROUP_0);
int timer_idx = (int) para;
/* Retrieve the interrupt status and the counter value
from the timer that reported the interrupt */
timer_intr_t timer_intr = timer_group_intr_get_in_isr(TIMER_GROUP_0);
uint32_t timer_intr = timer_group_get_intr_status_in_isr(TIMER_GROUP_0);
uint64_t timer_counter_value = timer_group_get_counter_value_in_isr(TIMER_GROUP_0, timer_idx);
/* Prepare basic event data
@@ -73,12 +74,12 @@ void IRAM_ATTR timer_group0_isr(void *para)
and update the alarm time for the timer with without reload */
if (timer_intr & TIMER_INTR_T0) {
evt.type = TEST_WITHOUT_RELOAD;
timer_group_intr_clr_in_isr(TIMER_GROUP_0, TIMER_0);
timer_group_clr_intr_status_in_isr(TIMER_GROUP_0, TIMER_0);
timer_counter_value += (uint64_t) (TIMER_INTERVAL0_SEC * TIMER_SCALE);
timer_group_set_alarm_value_in_isr(TIMER_GROUP_0, timer_idx, timer_counter_value);
} else if (timer_intr & TIMER_INTR_T1) {
evt.type = TEST_WITH_RELOAD;
timer_group_intr_clr_in_isr(TIMER_GROUP_0, TIMER_1);
timer_group_clr_intr_status_in_isr(TIMER_GROUP_0, TIMER_1);
} else {
evt.type = -1; // not supported even type
}
@@ -89,6 +90,7 @@ void IRAM_ATTR timer_group0_isr(void *para)
/* Now just send the event data back to the main program task */
xQueueSendFromISR(timer_queue, &evt, NULL);
timer_spinlock_give(TIMER_GROUP_0);
}
/*
@@ -110,7 +112,7 @@ static void example_tg0_timer_init(int timer_idx,
config.intr_type = TIMER_INTR_LEVEL;
config.auto_reload = auto_reload;
#ifdef CONFIG_IDF_TARGET_ESP32S2BETA
config.clk_sel = TIMER_SRC_CLK_APB;
config.clk_src = TIMER_SRC_CLK_APB;
#endif
timer_init(TIMER_GROUP_0, timer_idx, &config);