mirror of
https://github.com/apache/nuttx.git
synced 2026-09-21 13:25:12 +08:00
drivers/power: PM: Make power manager service available as soon as possible: (1) Initialize g_pmglobals at the definition, (2) skip hold the lock if OS isn't ready
This commit is contained in:
+4
-4
@@ -144,10 +144,6 @@ struct pm_domain_s
|
||||
|
||||
struct pm_global_s
|
||||
{
|
||||
/* The activity/state information for each PM domain */
|
||||
|
||||
struct pm_domain_s domain[CONFIG_PM_NDOMAINS];
|
||||
|
||||
/* This semaphore manages mutually exclusive access to the power management
|
||||
* registry. It must be initialized to the value 1.
|
||||
*/
|
||||
@@ -160,6 +156,10 @@ struct pm_global_s
|
||||
*/
|
||||
|
||||
dq_queue_t registry;
|
||||
|
||||
/* The activity/state information for each PM domain */
|
||||
|
||||
struct pm_domain_s domain[CONFIG_PM_NDOMAINS];
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -54,7 +54,16 @@
|
||||
|
||||
/* All PM global data: */
|
||||
|
||||
struct pm_global_s g_pmglobals;
|
||||
/* Initialize the registry and the PM global data structures. The PM
|
||||
* global data structure resides in .data which is zeroed at boot time. So
|
||||
* it is only required to initialize non-zero elements of the PM global
|
||||
* data structure here.
|
||||
*/
|
||||
|
||||
struct pm_global_s g_pmglobals =
|
||||
{
|
||||
SEM_INITIALIZER(1)
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@@ -80,14 +89,6 @@ struct pm_global_s g_pmglobals;
|
||||
|
||||
void pm_initialize(void)
|
||||
{
|
||||
/* Initialize the registry and the PM global data structures. The PM
|
||||
* global data structure resides in .bss which is zeroed at boot time. So
|
||||
* it is only required to initialize non-zero elements of the PM global
|
||||
* data structure here.
|
||||
*/
|
||||
|
||||
dq_init(&g_pmglobals.registry);
|
||||
nxsem_init(&g_pmglobals.regsem, 0, 1);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_PM */
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <queue.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/init.h>
|
||||
#include <nuttx/power/pm.h>
|
||||
|
||||
#include "pm.h"
|
||||
@@ -76,11 +77,19 @@ int pm_register(FAR struct pm_callback_s *callbacks)
|
||||
|
||||
/* Add the new entry to the end of the list of registered callbacks */
|
||||
|
||||
ret = pm_lock();
|
||||
if (ret == OK)
|
||||
if (OSINIT_OSREADY())
|
||||
{
|
||||
ret = pm_lock();
|
||||
if (ret == OK)
|
||||
{
|
||||
dq_addlast(&callbacks->entry, &g_pmglobals.registry);
|
||||
pm_unlock();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dq_addlast(&callbacks->entry, &g_pmglobals.registry);
|
||||
pm_unlock();
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user