2011-09-04 21:24:27 +02:00
|
|
|
/****************************************************************************
|
2022-08-01 11:31:49 +02:00
|
|
|
* drivers/power/pm/pm_activity.c
|
2011-09-04 21:24:27 +02:00
|
|
|
*
|
2021-03-31 11:15:31 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2011-09-04 21:24:27 +02:00
|
|
|
*
|
2021-03-31 11:15:31 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-09-04 21:24:27 +02:00
|
|
|
*
|
2021-03-31 11:15:31 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2011-09-04 21:24:27 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2016-03-27 21:37:28 +02:00
|
|
|
#include <assert.h>
|
2022-06-16 12:21:36 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2016-03-27 21:37:28 +02:00
|
|
|
|
2012-01-22 17:42:49 +01:00
|
|
|
#include <nuttx/power/pm.h>
|
2011-09-04 21:24:27 +02:00
|
|
|
#include <nuttx/clock.h>
|
2016-02-14 14:32:58 +01:00
|
|
|
#include <nuttx/irq.h>
|
2011-09-04 21:24:27 +02:00
|
|
|
|
2015-12-30 01:29:24 +01:00
|
|
|
#include "pm.h"
|
2011-09-04 21:24:27 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
2022-06-10 14:34:20 +02:00
|
|
|
/****************************************************************************
|
2022-06-16 12:21:36 +02:00
|
|
|
* Private Data
|
2022-06-10 14:34:20 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
static struct pm_wakelock_s g_wakelock[CONFIG_PM_NDOMAINS][PM_COUNT];
|
2022-06-10 14:34:20 +02:00
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
2022-06-10 14:34:20 +02:00
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
static void pm_waklock_cb(wdparm_t arg)
|
2022-06-10 14:34:20 +02:00
|
|
|
{
|
2022-06-16 12:21:36 +02:00
|
|
|
pm_wakelock_relax((FAR struct pm_wakelock_s *)arg);
|
2022-06-10 14:34:20 +02:00
|
|
|
}
|
|
|
|
|
2022-06-20 12:16:42 +02:00
|
|
|
#ifdef CONFIG_PM_PROCFS
|
|
|
|
static void pm_wakelock_stats_rm(FAR struct pm_wakelock_s *wakelock)
|
|
|
|
{
|
|
|
|
FAR struct pm_domain_s *pdom = &g_pmglobals.domain[wakelock->domain];
|
|
|
|
|
|
|
|
dq_rem(&wakelock->fsnode, &pdom->wakelockall);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pm_wakelock_stats(FAR struct pm_wakelock_s *wakelock, bool stay)
|
|
|
|
{
|
|
|
|
FAR struct pm_domain_s *pdom = &g_pmglobals.domain[wakelock->domain];
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
if (stay)
|
|
|
|
{
|
2023-06-21 11:17:59 +02:00
|
|
|
if (!dq_inqueue(&wakelock->fsnode, &pdom->wakelockall))
|
2022-06-20 12:16:42 +02:00
|
|
|
{
|
|
|
|
dq_addlast(&wakelock->fsnode, &pdom->wakelockall);
|
|
|
|
}
|
|
|
|
|
|
|
|
clock_systime_timespec(&wakelock->start);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clock_systime_timespec(&ts);
|
|
|
|
clock_timespec_subtract(&ts, &wakelock->start, &ts);
|
|
|
|
clock_timespec_add(&ts, &wakelock->elapse, &wakelock->elapse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2022-07-22 06:10:50 +02:00
|
|
|
# define pm_wakelock_stats_rm(w)
|
|
|
|
# define pm_wakelock_stats(w, s)
|
2022-06-20 12:16:42 +02:00
|
|
|
#endif
|
|
|
|
|
2011-09-04 21:24:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_activity
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called by a device driver to indicate that it is
|
2021-04-01 08:20:14 +02:00
|
|
|
* performing meaningful activities (non-idle). This increments an
|
|
|
|
* activity count and/or will restart a idle timer and prevent entering
|
|
|
|
* reduced power states.
|
2011-09-04 21:24:27 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2016-03-27 21:03:47 +02:00
|
|
|
* domain - The domain of the PM activity
|
2011-09-05 00:16:10 +02:00
|
|
|
* priority - Activity priority, range 0-9. Larger values correspond to
|
2011-09-04 21:24:27 +02:00
|
|
|
* higher priorities. Higher priority activity can prevent the system
|
2011-09-05 00:16:10 +02:00
|
|
|
* from entering reduced power states for a longer period of time.
|
2011-09-04 21:24:27 +02:00
|
|
|
*
|
2021-04-01 08:20:14 +02:00
|
|
|
* As an example, a button press might be higher priority activity
|
|
|
|
* because it means that the user is actively interacting with the
|
|
|
|
* device.
|
2011-09-04 21:24:27 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler (this is the ONLY
|
|
|
|
* PM function that may be called from an interrupt handler!).
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-03-27 21:03:47 +02:00
|
|
|
void pm_activity(int domain, int priority)
|
2011-09-04 21:24:27 +02:00
|
|
|
{
|
2021-12-21 08:38:38 +01:00
|
|
|
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
|
|
|
|
|
2022-02-14 08:32:40 +01:00
|
|
|
if (g_pmglobals.domain[domain].governor->activity)
|
2011-09-04 21:24:27 +02:00
|
|
|
{
|
2022-02-14 08:32:40 +01:00
|
|
|
g_pmglobals.domain[domain].governor->activity(domain, priority);
|
2011-09-04 21:24:27 +02:00
|
|
|
}
|
2021-12-21 08:38:38 +01:00
|
|
|
|
|
|
|
pm_auto_updatestate(domain);
|
2011-09-04 21:24:27 +02:00
|
|
|
}
|
|
|
|
|
2018-08-27 21:16:34 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_stay
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called by a device driver to indicate that it is
|
|
|
|
* performing meaningful activities (non-idle), needs the power at kept
|
|
|
|
* last the specified level.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* domain - The domain of the PM activity
|
|
|
|
* state - The state want to stay.
|
|
|
|
*
|
2021-04-01 08:20:14 +02:00
|
|
|
* As an example, media player might stay in normal state during playback.
|
2018-08-27 21:16:34 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pm_stay(int domain, enum pm_state_e state)
|
2022-06-16 12:21:36 +02:00
|
|
|
{
|
|
|
|
DEBUGASSERT(state < PM_COUNT);
|
|
|
|
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
|
|
|
|
|
|
|
|
pm_wakelock_stay(&g_wakelock[domain][state]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_relax
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called by a device driver to indicate that it is
|
|
|
|
* idle now, could relax the previous requested power level.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* domain - The domain of the PM activity
|
|
|
|
* state - The state want to relax.
|
|
|
|
*
|
|
|
|
* As an example, media player might relax power level after playback.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pm_relax(int domain, enum pm_state_e state)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(state < PM_COUNT);
|
|
|
|
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
|
|
|
|
|
|
|
|
pm_wakelock_relax(&g_wakelock[domain][state]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_staytimeout
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called by a device driver to indicate that it is
|
2022-07-22 06:10:50 +02:00
|
|
|
* performing meaningful activities (non-idle), needs the power kept at
|
|
|
|
* the last the specified level.
|
|
|
|
* And this will timeout after time (ms), menas auto pm_relax
|
2022-06-16 12:21:36 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* domain - The domain of the PM activity
|
2022-07-22 06:10:50 +02:00
|
|
|
* state - The state want to stay.
|
|
|
|
* ms - The timeout value ms
|
2022-06-16 12:21:36 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pm_staytimeout(int domain, enum pm_state_e state, int ms)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(state < PM_COUNT);
|
|
|
|
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
|
|
|
|
|
|
|
|
pm_wakelock_staytimeout(&g_wakelock[domain][state], ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_staycount
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called to get current stay count.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* domain - The domain of the PM activity
|
|
|
|
* state - The state want to relax.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Current pm stay count
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
uint32_t pm_staycount(int domain, enum pm_state_e state)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(state < PM_COUNT);
|
|
|
|
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
|
|
|
|
|
|
|
|
return pm_wakelock_staycount(&g_wakelock[domain][state]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_wakelock_init
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is used to init struct pm_wakelock_s
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pm_wakelock_init(FAR struct pm_wakelock_s *wakelock,
|
|
|
|
FAR const char *name, int domain,
|
|
|
|
enum pm_state_e state)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(wakelock);
|
|
|
|
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
|
|
|
|
DEBUGASSERT(state < PM_COUNT);
|
|
|
|
|
2022-06-22 08:46:51 +02:00
|
|
|
memset(wakelock, 0, sizeof(*wakelock));
|
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
strlcpy(wakelock->name, name, sizeof(wakelock->name));
|
|
|
|
|
|
|
|
wakelock->domain = domain;
|
|
|
|
wakelock->state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_wakelock_uninit
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Uninit wakelock ID
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* wakelock - wakelock ID
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pm_wakelock_uninit(FAR struct pm_wakelock_s *wakelock)
|
2018-08-27 21:16:34 +02:00
|
|
|
{
|
|
|
|
FAR struct pm_domain_s *pdom;
|
2022-06-16 12:21:36 +02:00
|
|
|
FAR struct dq_queue_s *dq;
|
|
|
|
FAR struct wdog_s *wdog;
|
2018-08-27 21:16:34 +02:00
|
|
|
irqstate_t flags;
|
2022-06-16 12:21:36 +02:00
|
|
|
int domain;
|
|
|
|
|
|
|
|
DEBUGASSERT(wakelock);
|
2018-08-27 21:16:34 +02:00
|
|
|
|
|
|
|
/* Get a convenience pointer to minimize all of the indexing */
|
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
domain = wakelock->domain;
|
|
|
|
pdom = &g_pmglobals.domain[domain];
|
|
|
|
dq = &pdom->wakelock[wakelock->state];
|
2022-06-20 12:07:52 +02:00
|
|
|
wdog = &wakelock->wdog;
|
2018-08-27 21:16:34 +02:00
|
|
|
|
2022-12-30 06:42:31 +01:00
|
|
|
flags = pm_domain_lock(domain);
|
2022-06-16 12:21:36 +02:00
|
|
|
|
|
|
|
if (wakelock->count > 0)
|
|
|
|
{
|
|
|
|
dq_rem(&wakelock->node, dq);
|
|
|
|
}
|
|
|
|
|
|
|
|
wakelock->count = 0;
|
|
|
|
wd_cancel(wdog);
|
2022-06-20 12:16:42 +02:00
|
|
|
pm_wakelock_stats_rm(wakelock);
|
2022-06-16 12:21:36 +02:00
|
|
|
|
2022-12-30 06:42:31 +01:00
|
|
|
pm_domain_unlock(domain, flags);
|
2022-06-16 12:21:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_wakelock_stay
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called by a device driver to indicate that it is
|
|
|
|
* performing meaningful activities (non-idle), needs the power kept at
|
|
|
|
* least the specified level.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* wakelock - wakelock ID
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pm_wakelock_stay(FAR struct pm_wakelock_s *wakelock)
|
|
|
|
{
|
|
|
|
FAR struct pm_domain_s *pdom;
|
|
|
|
FAR struct dq_queue_s *dq;
|
|
|
|
irqstate_t flags;
|
|
|
|
int domain;
|
|
|
|
|
|
|
|
DEBUGASSERT(wakelock);
|
|
|
|
|
|
|
|
/* Get a convenience pointer to minimize all of the indexing */
|
|
|
|
|
|
|
|
domain = wakelock->domain;
|
|
|
|
pdom = &g_pmglobals.domain[domain];
|
|
|
|
dq = &pdom->wakelock[wakelock->state];
|
|
|
|
|
2022-12-30 06:42:31 +01:00
|
|
|
flags = pm_domain_lock(domain);
|
2022-06-16 12:21:36 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(wakelock->count < UINT32_MAX);
|
|
|
|
if (wakelock->count++ == 0)
|
|
|
|
{
|
|
|
|
dq_addfirst(&wakelock->node, dq);
|
2022-06-20 12:16:42 +02:00
|
|
|
pm_wakelock_stats(wakelock, true);
|
2022-06-16 12:21:36 +02:00
|
|
|
}
|
|
|
|
|
2022-12-30 06:42:31 +01:00
|
|
|
pm_domain_unlock(domain, flags);
|
2021-12-21 08:38:38 +01:00
|
|
|
|
|
|
|
pm_auto_updatestate(domain);
|
2018-08-27 21:16:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2022-06-16 12:21:36 +02:00
|
|
|
* Name: pm_wakelock_relax
|
2018-08-27 21:16:34 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called by a device driver to indicate that it is
|
|
|
|
* idle now, could relax the previous requested power level.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2022-06-16 12:21:36 +02:00
|
|
|
* wakelock - wakelock ID
|
2018-08-27 21:16:34 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
void pm_wakelock_relax(FAR struct pm_wakelock_s *wakelock)
|
2018-08-27 21:16:34 +02:00
|
|
|
{
|
|
|
|
FAR struct pm_domain_s *pdom;
|
2022-06-16 12:21:36 +02:00
|
|
|
FAR struct dq_queue_s *dq;
|
2018-08-27 21:16:34 +02:00
|
|
|
irqstate_t flags;
|
2022-06-16 12:21:36 +02:00
|
|
|
int domain;
|
|
|
|
|
|
|
|
DEBUGASSERT(wakelock);
|
2018-08-27 21:16:34 +02:00
|
|
|
|
|
|
|
/* Get a convenience pointer to minimize all of the indexing */
|
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
domain = wakelock->domain;
|
|
|
|
pdom = &g_pmglobals.domain[domain];
|
|
|
|
dq = &pdom->wakelock[wakelock->state];
|
2018-08-27 21:16:34 +02:00
|
|
|
|
2022-12-30 06:42:31 +01:00
|
|
|
flags = pm_domain_lock(domain);
|
2022-06-16 12:21:36 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(wakelock->count > 0);
|
|
|
|
if (--wakelock->count == 0)
|
|
|
|
{
|
|
|
|
dq_rem(&wakelock->node, dq);
|
2022-06-20 12:16:42 +02:00
|
|
|
pm_wakelock_stats(wakelock, false);
|
2022-06-16 12:21:36 +02:00
|
|
|
}
|
|
|
|
|
2022-12-30 06:42:31 +01:00
|
|
|
pm_domain_unlock(domain, flags);
|
2021-12-21 08:38:38 +01:00
|
|
|
|
|
|
|
pm_auto_updatestate(domain);
|
2018-08-27 21:16:34 +02:00
|
|
|
}
|
|
|
|
|
2022-06-10 14:34:20 +02:00
|
|
|
/****************************************************************************
|
2022-06-16 12:21:36 +02:00
|
|
|
* Name: pm_wakelock_staytimeout
|
2022-06-10 14:34:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called by a device driver to indicate that it is
|
|
|
|
* performing meaningful activities (non-idle), needs the power at kept
|
|
|
|
* last the specified level.
|
2022-06-16 12:21:36 +02:00
|
|
|
* And this will be timeout after time (ms), menas auto pm_wakelock_relax
|
2022-06-10 14:34:20 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2022-06-16 12:21:36 +02:00
|
|
|
* wakelock - wakelock ID
|
|
|
|
* ms - The timeout value ms
|
2022-06-10 14:34:20 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
void pm_wakelock_staytimeout(FAR struct pm_wakelock_s *wakelock, int ms)
|
2022-06-10 14:34:20 +02:00
|
|
|
{
|
|
|
|
FAR struct pm_domain_s *pdom;
|
2022-06-16 12:21:36 +02:00
|
|
|
FAR struct dq_queue_s *dq;
|
2022-06-10 14:34:20 +02:00
|
|
|
FAR struct wdog_s *wdog;
|
|
|
|
irqstate_t flags;
|
2022-06-16 12:21:36 +02:00
|
|
|
int domain;
|
2022-06-10 14:34:20 +02:00
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
DEBUGASSERT(wakelock);
|
|
|
|
|
|
|
|
/* Get a convenience pointer to minimize all of the indexing */
|
2022-06-10 14:34:20 +02:00
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
domain = wakelock->domain;
|
|
|
|
pdom = &g_pmglobals.domain[domain];
|
|
|
|
dq = &pdom->wakelock[wakelock->state];
|
2022-06-20 12:07:52 +02:00
|
|
|
wdog = &wakelock->wdog;
|
2022-06-10 14:34:20 +02:00
|
|
|
|
2022-12-30 06:42:31 +01:00
|
|
|
flags = pm_domain_lock(domain);
|
2022-06-10 14:34:20 +02:00
|
|
|
|
|
|
|
if (!WDOG_ISACTIVE(wdog))
|
|
|
|
{
|
2022-06-16 12:21:36 +02:00
|
|
|
DEBUGASSERT(wakelock->count < UINT32_MAX);
|
|
|
|
if (wakelock->count++ == 0)
|
|
|
|
{
|
|
|
|
dq_addfirst(&wakelock->node, dq);
|
2022-06-20 12:16:42 +02:00
|
|
|
pm_wakelock_stats(wakelock, true);
|
2022-06-16 12:21:36 +02:00
|
|
|
}
|
2022-06-10 14:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (TICK2MSEC(wd_gettime(wdog)) < ms)
|
|
|
|
{
|
2022-06-16 12:21:36 +02:00
|
|
|
wd_start(wdog, MSEC2TICK(ms), pm_waklock_cb, (wdparm_t)wakelock);
|
2022-06-10 14:34:20 +02:00
|
|
|
}
|
|
|
|
|
2022-12-30 06:42:31 +01:00
|
|
|
pm_domain_unlock(domain, flags);
|
2022-06-10 14:34:20 +02:00
|
|
|
|
|
|
|
pm_auto_updatestate(domain);
|
|
|
|
}
|
|
|
|
|
2019-01-27 18:19:26 +01:00
|
|
|
/****************************************************************************
|
2022-06-16 12:21:36 +02:00
|
|
|
* Name: pm_wakelock_staycount
|
2019-01-27 18:19:26 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2022-06-16 12:21:36 +02:00
|
|
|
* This function is called to get current stay count in this wakelock ID
|
2019-01-27 18:19:26 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2022-06-16 12:21:36 +02:00
|
|
|
* wakelock - wakelock ID
|
2019-01-27 18:19:26 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2022-06-16 12:21:36 +02:00
|
|
|
* Current pm stay count in this wakelock ID
|
2019-01-27 18:19:26 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
int pm_wakelock_staycount(FAR struct pm_wakelock_s *wakelock)
|
2019-01-27 18:19:26 +01:00
|
|
|
{
|
2022-06-16 12:21:36 +02:00
|
|
|
DEBUGASSERT(wakelock);
|
2019-01-27 18:19:26 +01:00
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
return wakelock->count;
|
|
|
|
}
|
2019-01-27 18:19:26 +01:00
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_wakelock_global_init
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called to setup global wakelock when system init
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pm_wakelock_global_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int j;
|
2019-01-27 18:19:26 +01:00
|
|
|
|
2022-06-16 12:21:36 +02:00
|
|
|
for (i = 0; i < CONFIG_PM_NDOMAINS; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < PM_COUNT; j++)
|
|
|
|
{
|
|
|
|
pm_wakelock_init(&g_wakelock[i][j], "system", i, j);
|
|
|
|
}
|
|
|
|
}
|
2019-01-27 18:19:26 +01:00
|
|
|
}
|
|
|
|
|
2015-12-30 01:29:24 +01:00
|
|
|
#endif /* CONFIG_PM */
|