tests: drivers: uart: uart_pm: Call pm action from the thread context
PM action shall be called from the thread context thus switching to
k_work instead of the k_timer.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
diff --git a/tests/drivers/uart/uart_pm/src/main.c b/tests/drivers/uart/uart_pm/src/main.c
index 7f3782e..6b64085 100644
--- a/tests/drivers/uart/uart_pm/src/main.c
+++ b/tests/drivers/uart/uart_pm/src/main.c
@@ -203,36 +203,36 @@
communication_verify(dev, true);
}
-static void timeout(struct k_timer *timer)
+static void work_handler(struct k_work *work)
{
- const struct device *uart = k_timer_user_data_get(timer);
+ const struct device *dev = DEVICE_DT_GET(UART_NODE);
- action_run(uart, PM_DEVICE_ACTION_SUSPEND, 0);
+ action_run(dev, PM_DEVICE_ACTION_SUSPEND, 0);
}
-static K_TIMER_DEFINE(pm_timer, timeout, NULL);
-
/* Test going into low power state after interrupting poll out. Use various
* delays to test interruption at multiple places.
*/
ZTEST(uart_pm, test_uart_pm_poll_tx_interrupted)
{
+ static struct k_work_delayable dwork;
+ static struct k_work_sync sync;
const struct device *dev;
char str[] = "test";
dev = DEVICE_DT_GET(UART_NODE);
zassert_true(device_is_ready(dev), "uart device is not ready");
- k_timer_user_data_set(&pm_timer, (void *)dev);
+ k_work_init_delayable(&dwork, work_handler);
for (int i = 1; i < 100; i++) {
- k_timer_start(&pm_timer, K_USEC(i * 10), K_NO_WAIT);
+ k_work_schedule(&dwork, K_USEC(i * 10));
for (int j = 0; j < sizeof(str); j++) {
uart_poll_out(dev, str[j]);
}
- k_timer_status_sync(&pm_timer);
+ k_work_flush_delayable(&dwork, &sync);
action_run(dev, PM_DEVICE_ACTION_RESUME, 0);