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 2022/05/10 13:21:27 UTC

[incubator-nuttx] 01/07: sched:cpuload_oneshot: add pm callcacks

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

commit 1c2583eaade3583a7eef1b12aed2efd9182555da
Author: zhuyanlin <zh...@xiaomi.com>
AuthorDate: Mon Apr 18 14:25:25 2022 +0800

    sched:cpuload_oneshot: add pm callcacks
    
    Signed-off-by: zhuyanlin <zh...@xiaomi.com>
---
 sched/sched/sched_cpuload_oneshot.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/sched/sched/sched_cpuload_oneshot.c b/sched/sched/sched_cpuload_oneshot.c
index 37eb796deb..985127dc0c 100644
--- a/sched/sched/sched_cpuload_oneshot.c
+++ b/sched/sched/sched_cpuload_oneshot.c
@@ -31,6 +31,7 @@
 #include <nuttx/arch.h>
 #include <nuttx/clock.h>
 #include <nuttx/lib/xorshift128.h>
+#include <nuttx/power/pm.h>
 #include <nuttx/timers/oneshot.h>
 
 #include "clock/clock.h"
@@ -98,6 +99,9 @@ struct sched_oneshot_s
   int32_t maxdelay;
   int32_t error;
 #endif
+#ifdef CONFIG_PM
+  struct pm_callback_s pm_cb;
+#endif
 };
 
 /****************************************************************************
@@ -225,6 +229,24 @@ static void nxsched_oneshot_callback(FAR struct oneshot_lowerhalf_s *lower,
   nxsched_oneshot_start();
 }
 
+#ifdef CONFIG_PM
+static void nxsched_oneshot_pmnotify(FAR struct pm_callback_s *cb,
+                                     int domain, enum pm_state_e pmstate)
+{
+  if (domain == PM_IDLE_DOMAIN)
+    {
+      if (pmstate == PM_RESTORE)
+        {
+          nxsched_oneshot_start();
+        }
+      else
+        {
+          ONESHOT_CANCEL(g_sched_oneshot.oneshot, NULL);
+        }
+    }
+}
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -281,6 +303,13 @@ void nxsched_oneshot_extclk(FAR struct oneshot_lowerhalf_s *lower)
   g_sched_oneshot.prng.z = g_sched_oneshot.prng.x << 25;
 #endif
 
+#ifdef CONFIG_PM
+  /* Register pm notify */
+
+  g_sched_oneshot.pm_cb.notify = nxsched_oneshot_pmnotify;
+  pm_register(&g_sched_oneshot.pm_cb);
+#endif
+
   /* Then start the oneshot */
 
   g_sched_oneshot.oneshot = lower;