Skip to content

Commit

Permalink
driver/timer: only re-enable alarm in callback when auto reload is true
Browse files Browse the repository at this point in the history
closes #7001
  • Loading branch information
L-KAYA committed Jun 25, 2021
1 parent 08bd291 commit 1138be5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 6 additions & 2 deletions components/driver/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,12 @@ static void IRAM_ATTR timer_isr_default(void *arg)
is_awoken = timer_obj->timer_isr_fun.fn(timer_obj->timer_isr_fun.args);
//Clear intrrupt status
timer_hal_clear_intr_status(&(timer_obj->hal));
//After the alarm has been triggered, we need enable it again, so it is triggered the next time.
timer_hal_set_alarm_enable(&(timer_obj->hal), TIMER_ALARM_EN);
//If the timer is set to auto reload, we need enable it again, so it is triggered the next time.
if (timer_hal_get_auto_reload(&timer_obj->hal)) {
timer_hal_set_alarm_enable(&(timer_obj->hal), TIMER_ALARM_EN);
} else {
timer_hal_set_alarm_enable(&(timer_obj->hal), TIMER_ALARM_DIS);
}
}
}
TIMER_EXIT_CRITICAL(&timer_spinlock[timer_obj->timer_isr_fun.isr_timer_group]);
Expand Down
6 changes: 1 addition & 5 deletions examples/peripherals/timer_group/example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ def test_examples_timergroup(env, extra_data): # type: (Any, Any) -> None
dut.expect('Timer Group without auto reload', timeout=5)
dut.expect('EVENT TIME')
event_time0 = dut.expect(re.compile(r'Time\s+:\s+(\d+\.\d+)\s+s'))[0]
dut.expect('Timer Group without auto reload', timeout=6)
dut.expect('EVENT TIME')
event_time1 = dut.expect(re.compile(r'Time\s+:\s+(\d+\.\d+)\s+s'))[0]
print('event0={}, event1={}'.format(event_time0, event_time1))
assert float(event_time1) - float(event_time0) < 5.001
print('event0={}'.format(event_time0))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion examples/system/eventfd/main/eventfd_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void eventfd_timer_init(int timer_idx, double timer_interval_sec)
.counter_dir = TIMER_COUNT_UP,
.counter_en = TIMER_PAUSE,
.alarm_en = TIMER_ALARM_EN,
.auto_reload = false,
.auto_reload = true,
};
ESP_ERROR_CHECK(timer_init(TIMER_GROUP_0, timer_idx, &config));

Expand Down

0 comments on commit 1138be5

Please sign in to comment.