pm: device: create struct pm_device initializer
Create a utility macro to initialize struct pm_device. The initializer is kept in the pm/device.h header. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
ae26b38870
commit
a89cc157af
2 changed files with 22 additions and 18 deletions
|
@ -831,27 +831,10 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
|
|||
(&DEVICE_NAME_GET(dev_name)), level, prio)
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
/* Use of DT_PROP_OR here is because we cant assume that 'wakeup-source`
|
||||
* will be a defined property for the binding of the devicetree node that
|
||||
* is associated with the device
|
||||
*/
|
||||
#define Z_DEVICE_STATE_DEFINE(node_id, dev_name) \
|
||||
static struct device_state Z_DEVICE_STATE_NAME(dev_name) \
|
||||
__attribute__((__section__(".z_devstate"))) = { \
|
||||
.pm = { \
|
||||
.usage = 0U, \
|
||||
.lock = Z_MUTEX_INITIALIZER( \
|
||||
Z_DEVICE_STATE_NAME(dev_name).pm.lock), \
|
||||
.condvar = Z_CONDVAR_INITIALIZER( \
|
||||
Z_DEVICE_STATE_NAME(dev_name).pm.condvar),\
|
||||
.state = PM_DEVICE_STATE_ACTIVE, \
|
||||
.flags = ATOMIC_INIT(COND_CODE_1( \
|
||||
DT_NODE_EXISTS(node_id), \
|
||||
(DT_PROP_OR( \
|
||||
node_id, wakeup_source, 0)), \
|
||||
(0)) << \
|
||||
PM_DEVICE_FLAGS_WS_CAPABLE), \
|
||||
}, \
|
||||
.pm = Z_PM_DEVICE_INIT(Z_DEVICE_STATE_NAME(dev_name), node_id) \
|
||||
};
|
||||
|
||||
#define Z_DEVICE_DEFINE_PM_INIT(dev_name, pm_control_fn) \
|
||||
|
|
|
@ -114,6 +114,27 @@ struct pm_device {
|
|||
struct k_condvar condvar;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Utility macro to initialize #pm_device.
|
||||
*
|
||||
* @note DT_PROP_OR is used to retrieve the wakeup_source property because
|
||||
* it may not be defined on all devices.
|
||||
*
|
||||
* @param obj Name of the #pm_device structure being initialized.
|
||||
* @param node_id Devicetree node for the initialized device (can be invalid).
|
||||
*/
|
||||
#define Z_PM_DEVICE_INIT(obj, node_id) \
|
||||
{ \
|
||||
.usage = 0U, \
|
||||
.lock = Z_MUTEX_INITIALIZER(obj.pm.lock), \
|
||||
.condvar = Z_CONDVAR_INITIALIZER(obj.pm.condvar), \
|
||||
.state = PM_DEVICE_STATE_ACTIVE, \
|
||||
.flags = ATOMIC_INIT(COND_CODE_1( \
|
||||
DT_NODE_EXISTS(node_id), \
|
||||
(DT_PROP_OR(node_id, wakeup_source, 0)),\
|
||||
(0)) << PM_DEVICE_FLAGS_WS_CAPABLE), \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Device power management control function callback.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue