You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/05/16 18:23:52 UTC

[incubator-nuttx] branch master updated: riscv/esp32c3: Fix RT timer issues

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 4a7f998  riscv/esp32c3: Fix RT timer issues
4a7f998 is described below

commit 4a7f998c335fa948ad9f940dd68d41b5bc8ff6e8
Author: Dong Heng <do...@espressif.com>
AuthorDate: Wed May 12 10:28:24 2021 +0800

    riscv/esp32c3: Fix RT timer issues
    
    1. Enable alarm if there is timer active
    2. Wake up main thread to delete timer
    3. Wake up main thread when timer is timeout in ISR
---
 arch/risc-v/src/esp32c3/esp32c3_rt_timer.c | 32 +++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c b/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c
index 4320d73..2d624b9 100644
--- a/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c
+++ b/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c
@@ -253,6 +253,7 @@ static void stop_rt_timer(FAR struct rt_timer_s *timer)
 
 static void delete_rt_timer(FAR struct rt_timer_s *timer)
 {
+  int ret;
   irqstate_t flags;
 
   flags = enter_critical_section();
@@ -273,6 +274,14 @@ static void delete_rt_timer(FAR struct rt_timer_s *timer)
   list_add_after(&s_toutlist, &timer->list);
   timer->state = RT_TIMER_DELETE;
 
+  /* Wake up thread to process deleted timers */
+
+  ret = nxsem_post(&s_toutsem);
+  if (ret < 0)
+    {
+      tmrerr("ERROR: Failed to post sem ret=%d\n", ret);
+    }
+
 exit:
   leave_critical_section(flags);
 }
@@ -387,20 +396,18 @@ static int rt_timer_thread(int argc, FAR char *argv[])
 
 static int rt_timer_isr(int irq, void *context, void *arg)
 {
+  int ret;
   irqstate_t flags;
   struct rt_timer_s *timer;
   uint64_t alarm;
   uint64_t counter;
+  bool wake = false;
   struct esp32c3_tim_dev_s *tim = s_esp32c3_tim_dev;
 
   /* Clear interrupt register status */
 
   ESP32C3_TIM_ACKINT(tim);
 
-  /* Wake up thread to process timeout timers */
-
-  nxsem_post(&s_toutsem);
-
   flags = enter_critical_section();
 
   /* Check if there is timer running */
@@ -428,6 +435,7 @@ static int rt_timer_isr(int irq, void *context, void *arg)
           list_delete(&timer->list);
           timer->state = RT_TIMER_TIMEOUT;
           list_add_after(&s_toutlist, &timer->list);
+          wake = true;
 
           /* Check if thers is timer running */
 
@@ -439,9 +447,23 @@ static int rt_timer_isr(int irq, void *context, void *arg)
               alarm = timer->alarm;
 
               ESP32C3_TIM_SETALRVL(tim, alarm);
-              ESP32C3_TIM_SETALRM(tim, true);
             }
         }
+
+      /* If there is timer in list, alarm should be enable */
+
+      ESP32C3_TIM_SETALRM(tim, true);
+    }
+
+  if (wake)
+    {
+      /* Wake up thread to process timeout timers */
+
+      ret = nxsem_post(&s_toutsem);
+      if (ret < 0)
+        {
+          tmrerr("ERROR: Failed to post sem ret=%d\n", ret);
+        }
     }
 
   leave_critical_section(flags);