sched:cpuload_period: add pm callbacks
Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
This commit is contained in:
parent
1c2583eaad
commit
45fe3fb4c6
@ -30,6 +30,7 @@
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/lib/xorshift128.h>
|
||||
#include <nuttx/power/pm.h>
|
||||
#include <nuttx/timers/timer.h>
|
||||
|
||||
#ifdef CONFIG_CPULOAD_PERIOD
|
||||
@ -87,12 +88,18 @@
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_CPULOAD_ENTROPY > 0
|
||||
#if CONFIG_CPULOAD_ENTROPY > 0 || defined(CONFIG_PM)
|
||||
struct sched_period_s
|
||||
{
|
||||
#if CONFIG_CPULOAD_ENTROPY > 0
|
||||
struct xorshift128_state_s prng;
|
||||
uint32_t maxtimeout;
|
||||
int32_t error;
|
||||
#endif
|
||||
#ifdef CONFIG_PM
|
||||
FAR struct timer_lowerhalf_s *lower;
|
||||
struct pm_callback_s pm_cb;
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -107,7 +114,7 @@ static bool nxsched_period_callback(FAR uint32_t *next_interval_us,
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_CPULOAD_ENTROPY > 0
|
||||
#if CONFIG_CPULOAD_ENTROPY > 0 || defined(CONFIG_PM)
|
||||
static struct sched_period_s g_sched_period;
|
||||
#endif
|
||||
|
||||
@ -183,6 +190,24 @@ static bool nxsched_period_callback(FAR uint32_t *next_interval_us,
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
static void nxsched_period_pmnotify(FAR struct pm_callback_s *cb, int domain,
|
||||
enum pm_state_e pmstate)
|
||||
{
|
||||
if (domain == PM_IDLE_DOMAIN)
|
||||
{
|
||||
if (pmstate == PM_RESTORE)
|
||||
{
|
||||
g_sched_period.lower->ops->start(g_sched_period.lower);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_sched_period.lower->ops->stop(g_sched_period.lower);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -228,6 +253,15 @@ void nxsched_period_extclk(FAR struct timer_lowerhalf_s *lower)
|
||||
g_sched_period.prng.z = g_sched_period.prng.x << 25;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
g_sched_period.lower = lower;
|
||||
|
||||
/* Register pm notify */
|
||||
|
||||
g_sched_period.pm_cb.notify = nxsched_period_pmnotify;
|
||||
pm_register(&g_sched_period.pm_cb);
|
||||
#endif
|
||||
|
||||
/* Then start the period timer */
|
||||
|
||||
lower->ops->setcallback(lower, nxsched_period_callback, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user