Skip to content

Commit f3bcd32

Browse files
connectivity_bridge: refactor to use pm device runtime
Refactor applications.connectivity_bridge to use pm device runtime. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 4a05846 commit f3bcd32

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

applications/connectivity_bridge/src/modules/uart_handler.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
#include <zephyr/types.h>
88
#include <zephyr/sys/ring_buffer.h>
9+
#include <zephyr/sys/atomic.h>
910
#include <zephyr/drivers/uart.h>
10-
#include <zephyr/pm/device.h>
11+
#include <zephyr/pm/device_runtime.h>
1112

1213
#define MODULE uart_handler
1314
#include "module_state_event.h"
@@ -39,6 +40,10 @@ static const struct device *devices[] = {
3940
#define UART_SET_PM_STATE false
4041
#endif
4142

43+
#if UART_SET_PM_STATE
44+
atomic_t device_pm_requested = ATOMIC_INIT(0);
45+
#endif
46+
4247
struct uart_rx_buf {
4348
atomic_t ref_counter;
4449
size_t len;
@@ -231,14 +236,23 @@ static void set_uart_power_state(uint8_t dev_idx, bool active)
231236
{
232237
#if UART_SET_PM_STATE
233238
const struct device *dev = devices[dev_idx];
239+
const char *action;
234240
int err;
235-
enum pm_device_action action;
236241

237-
action = active ? PM_DEVICE_ACTION_RESUME : PM_DEVICE_ACTION_SUSPEND;
242+
if (active) {
243+
if (!atomic_test_and_set_bit(&device_pm_requested, dev_idx)) {
244+
action = "pm_device_runtime_get";
245+
err = pm_device_runtime_get(dev);
246+
}
247+
} else {
248+
if (atomic_test_and_clear_bit(&device_pm_requested, dev_idx)) {
249+
action = "pm_device_runtime_put";
250+
err = pm_device_runtime_put(dev);
251+
}
252+
}
238253

239-
err = pm_device_action_run(dev, action);
240-
if ((err < 0) && (err != -EALREADY)) {
241-
LOG_ERR("pm_device_action_run failed: %d", err);
254+
if (err < 0) {
255+
LOG_ERR("%s failed: %d", action, err);
242256
}
243257
#endif
244258
}

0 commit comments

Comments
 (0)