2011-09-04 21:24:27 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* drivers/power/pm.h
|
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
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-12-30 01:19:03 +01:00
|
|
|
#ifndef __DRIVERS_POWER_PM_H
|
|
|
|
#define __DRIVERS_POWER_PM_H
|
2011-09-04 21:24:27 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <queue.h>
|
|
|
|
|
2017-10-09 17:57:56 +02:00
|
|
|
#include <nuttx/semaphore.h>
|
2016-01-21 18:54:26 +01:00
|
|
|
#include <nuttx/clock.h>
|
|
|
|
#include <nuttx/power/pm.h>
|
2018-08-27 21:28:48 +02:00
|
|
|
#include <nuttx/wdog.h>
|
2021-12-21 08:38:38 +01:00
|
|
|
#include <nuttx/wqueue.h>
|
2011-09-04 21:24:27 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-04-08 15:15:32 +02:00
|
|
|
* Pre-processor Definitions
|
2011-09-04 21:24:27 +02:00
|
|
|
****************************************************************************/
|
2019-10-29 01:28:41 +01:00
|
|
|
|
2011-09-04 21:24:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_lock
|
|
|
|
*
|
2018-02-01 19:03:55 +01:00
|
|
|
* Description:
|
2011-09-04 21:24:27 +02:00
|
|
|
* Lock the power management registry. NOTE: This function may return
|
|
|
|
* an error if a signal is received while what (errno == EINTR).
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-10-04 23:22:27 +02:00
|
|
|
#define pm_lock() nxsem_wait(&g_pmglobals.regsem);
|
2011-09-04 21:24:27 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_unlock
|
|
|
|
*
|
2018-02-01 19:03:55 +01:00
|
|
|
* Description:
|
2011-09-04 21:24:27 +02:00
|
|
|
* Unlock the power management registry.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
#define pm_unlock() nxsem_post(&g_pmglobals.regsem);
|
2011-09-04 21:24:27 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
2018-11-10 14:30:23 +01:00
|
|
|
|
2016-03-27 21:03:47 +02:00
|
|
|
/* This describes the activity and state for one domain */
|
2011-09-04 21:24:27 +02:00
|
|
|
|
2016-03-27 21:03:47 +02:00
|
|
|
struct pm_domain_s
|
2011-09-04 21:24:27 +02:00
|
|
|
{
|
2019-11-09 16:09:33 +01:00
|
|
|
/* The current state for this PM domain (as determined by an
|
|
|
|
* explicit call to pm_changestate())
|
2011-09-04 21:24:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t state;
|
2018-11-10 14:30:23 +01:00
|
|
|
|
2018-08-27 21:16:34 +02:00
|
|
|
/* The power state lock count */
|
|
|
|
|
|
|
|
uint16_t stay[PM_COUNT];
|
2021-12-21 08:38:38 +01:00
|
|
|
|
|
|
|
/* Auto update or not */
|
|
|
|
|
|
|
|
bool auto_update;
|
|
|
|
|
|
|
|
#if defined(CONFIG_SCHED_WORKQUEUE)
|
|
|
|
/* The worker of update callback */
|
|
|
|
|
|
|
|
struct work_s update_work;
|
|
|
|
#endif
|
2022-02-14 08:32:40 +01:00
|
|
|
|
|
|
|
/* A pointer to the PM governor instance */
|
|
|
|
|
|
|
|
FAR const struct pm_governor_s *governor;
|
2016-03-27 21:03:47 +02:00
|
|
|
};
|
|
|
|
|
2019-11-09 16:09:33 +01:00
|
|
|
/* This structure encapsulates all of the global data used by the PM system */
|
2016-03-27 21:03:47 +02:00
|
|
|
|
|
|
|
struct pm_global_s
|
|
|
|
{
|
2011-09-04 21:24:27 +02:00
|
|
|
/* This semaphore manages mutually exclusive access to the power management
|
|
|
|
* registry. It must be initialized to the value 1.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sem_t regsem;
|
|
|
|
|
2018-08-27 21:22:11 +02:00
|
|
|
/* registry is a doubly-linked list of registered power management
|
2011-09-04 21:24:27 +02:00
|
|
|
* callback structures. To ensure mutually exclusive access, this list
|
|
|
|
* must be locked by calling pm_lock() before it is accessed.
|
|
|
|
*/
|
|
|
|
|
2018-08-27 21:22:11 +02:00
|
|
|
dq_queue_t registry;
|
2018-08-27 21:24:13 +02:00
|
|
|
|
2019-11-09 16:09:33 +01:00
|
|
|
/* The state information for each PM domain */
|
2018-08-27 21:24:13 +02:00
|
|
|
|
|
|
|
struct pm_domain_s domain[CONFIG_PM_NDOMAINS];
|
2011-09-04 21:24:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
# define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
# define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* All PM global data: */
|
|
|
|
|
|
|
|
EXTERN struct pm_global_s g_pmglobals;
|
|
|
|
|
2021-04-01 08:20:14 +02:00
|
|
|
/****************************************************************************
|
2011-09-04 21:24:27 +02:00
|
|
|
* Public Function Prototypes
|
2021-04-01 08:20:14 +02:00
|
|
|
****************************************************************************/
|
2011-09-04 21:24:27 +02:00
|
|
|
|
2021-12-21 08:38:38 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: pm_auto_updatestate
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function update the domain state and notify the power system.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* domain - The PM domain to check
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pm_auto_updatestate(int domain);
|
|
|
|
|
2011-09-04 21:24:27 +02:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CONFIG_PM */
|
2015-12-30 01:19:03 +01:00
|
|
|
#endif /* #define __DRIVERS_POWER_PM_H */
|