2011-09-04 21:24:27 +02:00
|
|
|
/****************************************************************************
|
2012-01-22 17:42:49 +01:00
|
|
|
* drivers/power/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 <stdint.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
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
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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
|
|
|
{
|
2019-11-09 16:09:33 +01:00
|
|
|
if (g_pmglobals.governor->activity)
|
2011-09-04 21:24:27 +02:00
|
|
|
{
|
2019-11-09 16:09:33 +01:00
|
|
|
g_pmglobals.governor->activity(domain, priority);
|
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)
|
|
|
|
{
|
|
|
|
FAR struct pm_domain_s *pdom;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Get a convenience pointer to minimize all of the indexing */
|
|
|
|
|
|
|
|
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
|
|
|
|
pdom = &g_pmglobals.domain[domain];
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
DEBUGASSERT(state < PM_COUNT);
|
|
|
|
DEBUGASSERT(pdom->stay[state] < UINT16_MAX);
|
|
|
|
pdom->stay[state]++;
|
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
FAR struct pm_domain_s *pdom;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Get a convenience pointer to minimize all of the indexing */
|
|
|
|
|
|
|
|
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
|
|
|
|
pdom = &g_pmglobals.domain[domain];
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
DEBUGASSERT(state < PM_COUNT);
|
|
|
|
DEBUGASSERT(pdom->stay[state] > 0);
|
|
|
|
pdom->stay[state]--;
|
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
|
2019-01-27 18:19:26 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
FAR struct pm_domain_s *pdom;
|
|
|
|
|
|
|
|
/* Get a convenience pointer to minimize all of the indexing */
|
|
|
|
|
|
|
|
DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
|
|
|
|
pdom = &g_pmglobals.domain[domain];
|
|
|
|
|
|
|
|
return pdom->stay[state];
|
|
|
|
}
|
|
|
|
|
2015-12-30 01:29:24 +01:00
|
|
|
#endif /* CONFIG_PM */
|