Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for IDFGH-10379: Delay in esp_timer task callback prevents dispatch of ESP_TIMER_ISR callbacks (IDFGH-10380) #11637

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion components/esp_timer/src/esp_timer_impl_lac.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ static intr_handler_t s_alarm_handler = NULL;
/* Spinlock used to protect access to the hardware registers. */
portMUX_TYPE s_time_update_lock = portMUX_INITIALIZER_UNLOCKED;

/* Alarm values to generate interrupt on match */
static uint64_t timestamp_id[2] = { UINT64_MAX, UINT64_MAX };

void esp_timer_impl_lock(void)
{
Expand Down Expand Up @@ -152,7 +154,6 @@ int64_t esp_timer_get_time(void) __attribute__((alias("esp_timer_impl_get_time")

void IRAM_ATTR esp_timer_impl_set_alarm_id(uint64_t timestamp, unsigned alarm_id)
{
static uint64_t timestamp_id[2] = { UINT64_MAX, UINT64_MAX };
portENTER_CRITICAL_SAFE(&s_time_update_lock);
timestamp_id[alarm_id] = timestamp;
timestamp = MIN(timestamp_id[0], timestamp_id[1]);
Expand Down Expand Up @@ -180,6 +181,24 @@ void IRAM_ATTR esp_timer_impl_set_alarm_id(uint64_t timestamp, unsigned alarm_id
portEXIT_CRITICAL_SAFE(&s_time_update_lock);
}

static void IRAM_ATTR esp_timer_impl_update_alarm() {
portENTER_CRITICAL_SAFE(&s_time_update_lock);
int this_timestamp = 1;
int other_timestamp = 0;
if (timestamp_id[0] < timestamp_id[1]) {
this_timestamp = 0;
other_timestamp = 1;
}

if (timestamp_id[other_timestamp] != UINT64_MAX) {
esp_timer_impl_set_alarm_id(UINT64_MAX, this_timestamp);
} else {
timestamp_id[this_timestamp] = UINT64_MAX;
}

portEXIT_CRITICAL_SAFE(&s_time_update_lock);
}

void IRAM_ATTR esp_timer_impl_set_alarm(uint64_t timestamp)
{
esp_timer_impl_set_alarm_id(timestamp, 0);
Expand All @@ -190,6 +209,9 @@ static void IRAM_ATTR timer_alarm_isr(void *arg)
#if ISR_HANDLERS == 1
/* Clear interrupt status */
REG_WRITE(INT_CLR_REG, TIMG_LACT_INT_CLR);

esp_timer_impl_update_alarm();

/* Call the upper layer handler */
(*s_alarm_handler)(arg);
#else
Expand Down