Skip to content

Commit

Permalink
ESP32: Fix hwtimers regression
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer committed Dec 28, 2020
1 parent 8fd9925 commit 62c0288
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions platforms/esp32/src/esp32_hw_timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,33 @@ IRAM bool mgos_hw_timers_dev_set(struct mgos_hw_timer_info *ti, int usecs,
* interrupt shortage. Ideally, we'd use a single shared interrupt for all
* the timers but esp_intr_set_in_iram does not work with shared ints yet.
*/
if (dd->inth == NULL &&
timer_isr_register(dd->tgn, dd->tn, (void (*)(void *)) mgos_hw_timers_isr,
ti, 0, &dd->inth) != ESP_OK) {
LOG(LL_ERROR, ("Couldn't allocate into for HW timer"));
return false;
uint32_t mask = (1 << tn);
if (dd->inth == NULL) {
int intr_source = 0;
switch (dd->tgn) {
case TIMER_GROUP_0:
default:
intr_source = ETS_TG0_T0_LEVEL_INTR_SOURCE + tn;
break;
case TIMER_GROUP_1:
intr_source = ETS_TG1_T0_LEVEL_INTR_SOURCE + tn;
break;
}
uint32_t status_reg = (uint32_t) &tg->int_st_timers.val;
if (esp_intr_alloc_intrstatus(intr_source, 0, status_reg, mask,
(void (*)(void *)) mgos_hw_timers_isr, ti,
&dd->inth) != ESP_OK) {
LOG(LL_ERROR, ("Couldn't allocate into for HW timer"));
return false;
}
}

if (esp_intr_set_in_iram(dd->inth, (flags & MGOS_ESP32_HW_TIMER_IRAM) != 0) !=
ESP_OK) {
return false;
}

tg->int_ena.val |= (1 << tn);
tg->int_ena.val |= mask;

/* Start the timer */
tg->hw_timer[tn].config.enable = true;
Expand Down

0 comments on commit 62c0288

Please sign in to comment.