1 /*
2  * Copyright (c) 2022 Linaro Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <zephyr/pm/device.h>
10 #include <zephyr/devicetree.h>
11 #include <zephyr/sys/printk.h>
12 #include <zephyr/sys/__assert.h>
13 
main(void)14 int main(void)
15 {
16 	const struct device *const dev =
17 		DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
18 
19 	if (!device_is_ready(dev)) {
20 		printk("Console device not ready");
21 		return 0;
22 	}
23 
24 #if CONFIG_PM_DEVICE
25 	/* In PM_DEVICE modes, enable device as a wakeup source will prevent
26 	 * system to switch it off (clock off, set pins to sleep configuration, ...)
27 	 * It is not requested in CONFIG_PM mode only as in this case, device is not
28 	 * suspended before stop mode entry.
29 	 */
30 
31 	bool ret;
32 
33 	ret = pm_device_wakeup_is_capable(dev);
34 	if (!ret) {
35 		printk("Device is not wakeup capable\n");
36 	} else {
37 		printk("Device is wakeup capable\n");
38 
39 		ret = pm_device_wakeup_enable(dev, true);
40 		if (!ret) {
41 			printk("Could not enable wakeup source\n");
42 		} else {
43 			printk("Wakeup source enable ok\n");
44 		}
45 
46 		ret = pm_device_wakeup_is_enabled(dev);
47 		if (!ret) {
48 			printk("Wakeup source not enabled\n");
49 		} else {
50 			printk("Wakeup source enabled\n");
51 		}
52 	}
53 #endif
54 
55 	return 0;
56 }
57