pm: adjust busy check API call return types and naming

Busy check APIs now return boolean type. Due to that change, the
function names have also been adjusted. The common name pattern for
boolean check type APIs is "PREFIX_is_CONDITION". For example,
"pm_device_is_busy".  pm_device_busy_check has been renamed to
pm_device_is_busy and pm_device_any_busy_check to pm_device_is_any_busy.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-07-29 11:07:27 +02:00 committed by Anas Nashif
commit 6c3beb928e
4 changed files with 20 additions and 23 deletions

View file

@ -344,7 +344,7 @@ static int transceive(const struct device *dev,
spi_context_lock(&spi->ctx, asynchronous, signal, config);
#ifdef CONFIG_PM_DEVICE
if (pm_device_busy_check(dev) != (-EBUSY)) {
if (!pm_device_is_busy(dev)) {
pm_device_busy_set(dev);
}
#endif /* CONFIG_PM_DEVICE */

View file

@ -162,10 +162,10 @@ void pm_device_busy_clear(const struct device *dev);
* Called by an application to see if any device is in the middle
* of a critical transaction that cannot be interrupted.
*
* @retval 0 if no device is busy
* @retval -EBUSY if any device is busy
* @retval false if no device is busy
* @retval true if any device is busy
*/
int pm_device_any_busy_check(void);
bool pm_device_is_any_busy(void);
/**
* @brief Check if a specific device is in the middle of a transaction
@ -175,15 +175,15 @@ int pm_device_any_busy_check(void);
*
* @param chk_dev Pointer to device structure of the specific device driver
* the caller is interested in.
* @retval 0 if the device is not busy
* @retval -EBUSY if the device is busy
* @retval false if the device is not busy
* @retval true if the device is busy
*/
int pm_device_busy_check(const struct device *chk_dev);
bool pm_device_is_busy(const struct device *chk_dev);
#else
static inline void pm_device_busy_set(const struct device *dev) {}
static inline void pm_device_busy_clear(const struct device *dev) {}
static inline int pm_device_any_busy_check(void) { return -ENOSYS; }
static inline int pm_device_busy_check(const struct device *chk_dev) { return -ENOSYS; }
static inline bool pm_device_is_any_busy(void) { return false; }
static inline bool pm_device_is_busy(const struct device *chk_dev) { return false; }
#endif
/** Alias for legacy use of device_pm_control_nop */

View file

@ -28,7 +28,7 @@ static bool should_suspend(const struct device *dev, enum pm_device_state state)
int rc;
enum pm_device_state current_state;
if (pm_device_busy_check(dev) != 0) {
if (pm_device_is_busy(dev) != 0) {
return false;
}
@ -150,26 +150,23 @@ int pm_device_state_get(const struct device *dev,
device_power_state);
}
int pm_device_any_busy_check(void)
bool pm_device_is_any_busy(void)
{
const struct device *dev = __device_start;
while (dev < __device_end) {
if (atomic_test_bit(dev->pm->flags, PM_DEVICE_FLAG_BUSY)) {
return -EBUSY;
return true;
}
++dev;
}
return 0;
return false;
}
int pm_device_busy_check(const struct device *dev)
bool pm_device_is_busy(const struct device *dev)
{
if (atomic_test_bit(dev->pm->flags, PM_DEVICE_FLAG_BUSY)) {
return -EBUSY;
}
return 0;
return atomic_test_bit(dev->pm->flags, PM_DEVICE_FLAG_BUSY);
}
void pm_device_busy_set(const struct device *dev)

View file

@ -280,7 +280,7 @@ static void test_enable_and_disable_automatic_runtime_pm(void)
* sets/clears busy status and validates status again.
*
* @see device_get_binding(), pm_device_busy_set(), pm_device_busy_clear(),
* pm_device_busy_check(), pm_device_any_busy_check(),
* pm_device_is_busy(), pm_device_is_any_busy(),
* pm_device_state_set()
*/
void test_dummy_device_pm(void)
@ -292,22 +292,22 @@ void test_dummy_device_pm(void)
dev = device_get_binding(DUMMY_PORT_2);
zassert_false((dev == NULL), NULL);
busy = pm_device_any_busy_check();
busy = pm_device_is_any_busy();
zassert_true((busy == 0), NULL);
/* Set device state to BUSY*/
pm_device_busy_set(dev);
busy = pm_device_any_busy_check();
busy = pm_device_is_any_busy();
zassert_false((busy == 0), NULL);
busy = pm_device_busy_check(dev);
busy = pm_device_is_busy(dev);
zassert_false((busy == 0), NULL);
/* Clear device BUSY state*/
pm_device_busy_clear(dev);
busy = pm_device_busy_check(dev);
busy = pm_device_is_busy(dev);
zassert_true((busy == 0), NULL);
test_build_suspend_device_list();