xtensa/esp32: Fix Scheduler CPU Load feature using Oneshot Timer

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
This commit is contained in:
Gustavo Henrique Nihei 2022-02-25 10:09:53 -03:00 committed by Xiang Xiao
parent 36ac532c98
commit d2ada5f030
2 changed files with 32 additions and 25 deletions

View File

@ -85,19 +85,15 @@ static int esp32_oneshot_handler(int irq, void * context, void *arg)
{
int ret = OK;
struct esp32_oneshot_s *oneshot = (struct esp32_oneshot_s *)arg;
oneshot_handler_t handler;
void *handler_arg;
DEBUGASSERT(oneshot != NULL && oneshot->handler != NULL);
DEBUGASSERT(oneshot != NULL);
DEBUGASSERT(oneshot->handler != NULL);
tmrinfo("Oneshot handler triggered\n");
/* Stop timer
* Note: It's not necessary to disable the alarm because
* it automatically disables each time it expires.
*/
ESP32_TIM_STOP(oneshot->tim);
/* Disable int */
/* Disable interrupts */
ESP32_TIM_DISABLEINT(oneshot->tim);
@ -105,20 +101,25 @@ static int esp32_oneshot_handler(int irq, void * context, void *arg)
ret = ESP32_TIM_SETISR(oneshot->tim, NULL, NULL);
/* Call the callback */
oneshot->handler((void *)oneshot->arg);
/* Restore state */
oneshot->running = false;
oneshot->handler = NULL;
oneshot->arg = NULL;
/* Clear the Interrupt */
ESP32_TIM_ACKINT(oneshot->tim);
/* The timer is no longer running */
oneshot->running = false;
/* Forward the event, clearing out any vestiges */
handler = (oneshot_handler_t)oneshot->handler;
oneshot->handler = NULL;
handler_arg = (void *)oneshot->arg;
oneshot->arg = NULL;
/* Call the callback */
handler(handler_arg);
return ret;
}

View File

@ -117,20 +117,26 @@ static void esp32_oneshot_lh_handler(void *arg)
{
struct esp32_oneshot_lowerhalf_s *priv =
(struct esp32_oneshot_lowerhalf_s *)arg;
oneshot_callback_t callback;
FAR void *cb_arg;
DEBUGASSERT(priv != NULL);
DEBUGASSERT(priv->callback != NULL);
tmrinfo("Oneshot LH handler triggered\n");
/* Call the callback */
priv->callback(&priv->lh, priv->arg);
/* Restore state */
/* Sample and nullify BEFORE executing callback (in case the callback
* restarts the oneshot).
*/
callback = priv->callback;
cb_arg = priv->arg;
priv->callback = NULL;
priv->arg = NULL;
priv->arg = NULL;
/* Then perform the callback */
callback(&priv->lh, cb_arg);
}
/****************************************************************************