From a0bb05eb4c3ae99371f31af0df3a4531c2e6ee96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 8 Apr 2024 17:34:03 +0200 Subject: [PATCH] tests: drivers: uart: uart_pm: Call pm action from the thread context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/drivers/uart/uart_pm/src/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/drivers/uart/uart_pm/src/main.c b/tests/drivers/uart/uart_pm/src/main.c index 7f3782ee615..6b640853b90 100644 --- a/tests/drivers/uart/uart_pm/src/main.c +++ b/tests/drivers/uart/uart_pm/src/main.c @@ -203,36 +203,36 @@ ZTEST(uart_pm, test_uart_pm_poll_tx) 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);