pm: device: improve usage of the atomic flags field

- Use an enum for the available flags
- Use ATOMIC_DEFINE macro to declare the flag bit field
- Improve naming

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-07-14 11:05:34 +02:00 committed by Anas Nashif
commit 77728e16df
2 changed files with 14 additions and 15 deletions

View file

@ -67,6 +67,14 @@ enum pm_device_state {
/** Device PM get state control command. */
#define PM_DEVICE_STATE_GET 1
/** @brief Device PM flags. */
enum pm_device_flag {
/** Indicate if the device is busy or not. */
PM_DEVICE_FLAG_BUSY,
/** Number of flags (internal use only). */
PM_DEVICE_FLAG_COUNT
};
/**
* @brief Device PM info
*/
@ -78,8 +86,8 @@ struct pm_device {
/* Following are packed fields protected by #lock. */
/** Device pm enable flag */
bool enable : 1;
/* Following are packed fields accessed with atomic bit operations. */
atomic_t atomic_flags;
/* Device PM status flags. */
ATOMIC_DEFINE(flags, PM_DEVICE_FLAG_COUNT);
/** Device usage count */
uint32_t usage;
/** Device power state */
@ -90,11 +98,6 @@ struct pm_device {
struct k_condvar condvar;
};
/** Bit position in device_pm::atomic_flags that records whether the
* device is busy.
*/
#define PM_DEVICE_ATOMIC_FLAGS_BUSY_BIT 0
/**
* @brief Get name of device PM state
*

View file

@ -155,8 +155,7 @@ int pm_device_any_busy_check(void)
const struct device *dev = __device_start;
while (dev < __device_end) {
if (atomic_test_bit(&dev->pm->atomic_flags,
PM_DEVICE_ATOMIC_FLAGS_BUSY_BIT)) {
if (atomic_test_bit(dev->pm->flags, PM_DEVICE_FLAG_BUSY)) {
return -EBUSY;
}
++dev;
@ -167,8 +166,7 @@ int pm_device_any_busy_check(void)
int pm_device_busy_check(const struct device *dev)
{
if (atomic_test_bit(&dev->pm->atomic_flags,
PM_DEVICE_ATOMIC_FLAGS_BUSY_BIT)) {
if (atomic_test_bit(dev->pm->flags, PM_DEVICE_FLAG_BUSY)) {
return -EBUSY;
}
return 0;
@ -176,12 +174,10 @@ int pm_device_busy_check(const struct device *dev)
void pm_device_busy_set(const struct device *dev)
{
atomic_set_bit(&dev->pm->atomic_flags,
PM_DEVICE_ATOMIC_FLAGS_BUSY_BIT);
atomic_set_bit(dev->pm->flags, PM_DEVICE_FLAG_BUSY);
}
void pm_device_busy_clear(const struct device *dev)
{
atomic_clear_bit(&dev->pm->atomic_flags,
PM_DEVICE_ATOMIC_FLAGS_BUSY_BIT);
atomic_clear_bit(dev->pm->flags, PM_DEVICE_FLAG_BUSY);
}