diff --git a/components/esp_timer/Kconfig b/components/esp_timer/Kconfig index 8bf69e49ca..8289d46691 100644 --- a/components/esp_timer/Kconfig +++ b/components/esp_timer/Kconfig @@ -32,6 +32,15 @@ menu "High resolution timer (esp_timer)" FreeRTOS timer task size, see "FreeRTOS timer task stack size" option in "FreeRTOS" menu. + config ESP_TIMER_INTERRUPT_LEVEL + int "Interrupt level" + default 1 + range 1 3 if IDF_TARGET_ESP32 + range 1 1 if !IDF_TARGET_ESP32 + help + It sets the interrupt level for esp_timer ISR in range 1..3. + A higher level (3) helps to decrease the ISR esp_timer latency. + choice ESP_TIMER_IMPL prompt "Hardware timer to use for esp_timer" default ESP_TIMER_IMPL_TG0_LAC if IDF_TARGET_ESP32 diff --git a/components/esp_timer/src/esp_timer_impl_frc_legacy.c b/components/esp_timer/src/esp_timer_impl_frc_legacy.c index 0fc85ed0b0..bf685da9b4 100644 --- a/components/esp_timer/src/esp_timer_impl_frc_legacy.c +++ b/components/esp_timer/src/esp_timer_impl_frc_legacy.c @@ -360,8 +360,9 @@ esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler) { s_alarm_handler = alarm_handler; + const int interrupt_lvl = (1 << CONFIG_ESP_TIMER_INTERRUPT_LEVEL) & ESP_INTR_FLAG_LEVELMASK; esp_err_t err = esp_intr_alloc(ETS_TIMER2_INTR_SOURCE, - ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM, + ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM | interrupt_lvl, &timer_alarm_isr, NULL, &s_timer_interrupt_handle); if (err != ESP_OK) { diff --git a/components/esp_timer/src/esp_timer_impl_lac.c b/components/esp_timer/src/esp_timer_impl_lac.c index f8ca8d5461..1aaa80bbca 100644 --- a/components/esp_timer/src/esp_timer_impl_lac.c +++ b/components/esp_timer/src/esp_timer_impl_lac.c @@ -222,8 +222,9 @@ esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler) REG_WRITE(LOAD_REG, 1); REG_SET_BIT(INT_CLR_REG, TIMG_LACT_INT_CLR); + const int interrupt_lvl = (1 << CONFIG_ESP_TIMER_INTERRUPT_LEVEL) & ESP_INTR_FLAG_LEVELMASK; esp_err_t err = esp_intr_alloc(INTR_SOURCE_LACT, - ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM, + ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM | interrupt_lvl, &timer_alarm_isr, NULL, &s_timer_interrupt_handle); if (err != ESP_OK) { diff --git a/components/esp_timer/src/esp_timer_impl_systimer.c b/components/esp_timer/src/esp_timer_impl_systimer.c index 3272fad348..a563d1b977 100644 --- a/components/esp_timer/src/esp_timer_impl_systimer.c +++ b/components/esp_timer/src/esp_timer_impl_systimer.c @@ -103,13 +103,14 @@ void esp_timer_impl_advance(int64_t time_us) esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler) { s_alarm_handler = alarm_handler; + const int interrupt_lvl = (1 << CONFIG_ESP_TIMER_INTERRUPT_LEVEL) & ESP_INTR_FLAG_LEVELMASK; #if SOC_SYSTIMER_INT_LEVEL int int_type = 0; #else int int_type = ESP_INTR_FLAG_EDGE; #endif // SOC_SYSTIMER_INT_LEVEL esp_err_t err = esp_intr_alloc(ETS_SYSTIMER_TARGET2_EDGE_INTR_SOURCE, - ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM | int_type, + ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM | int_type | interrupt_lvl, &timer_alarm_isr, NULL, &s_timer_interrupt_handle); if (err != ESP_OK) {