1 /*
2  * Copyright 2022, NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdio.h>
8 
9 #include <zephyr/drivers/counter.h>
10 #include <zephyr/sys/poweroff.h>
11 #include <zephyr/sys_clock.h>
12 
main(void)13 int main(void)
14 {
15 	int ret;
16 	const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(rtc));
17 	struct counter_alarm_cfg alarm_cfg = { 0 };
18 
19 	if (!device_is_ready(dev)) {
20 		printf("Counter device not ready\n");
21 		return 0;
22 	}
23 
24 	ret = counter_start(dev);
25 	if (ret < 0) {
26 		printf("Could not start counter (%d)\n", ret);
27 		return 0;
28 	}
29 
30 	alarm_cfg.ticks = counter_us_to_ticks(dev, 10 * USEC_PER_SEC);
31 
32 	ret = counter_set_channel_alarm(dev, 0, &alarm_cfg);
33 	if (ret < 0) {
34 		printf("Could not set counter channel alarm (%d)\n", ret);
35 		return 0;
36 	}
37 
38 	printf("Wake-up alarm set for 10 seconds\n");
39 	printf("Powering off\n");
40 
41 	sys_poweroff();
42 
43 	return 0;
44 }
45