1 /*
2 * Copyright (c) 2019 Nordic Semiconductor ASA
3 * Copyright (c) 2020 Linaro Ltd.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 #include <stdio.h>
9 #include <zephyr/kernel.h>
10 #include <zephyr/init.h>
11 #include <zephyr/device.h>
12 #include <zephyr/drivers/gpio.h>
13 #include <zephyr/sys/poweroff.h>
14
15 #include <driverlib/ioc.h>
16
17 static const struct gpio_dt_spec sw0_gpio = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
18
19 #define BUSY_WAIT_S 5U
20 #define SLEEP_US 2000U
21 #define SLEEP_S 3U
22
23 extern void CC1352R1_LAUNCHXL_shutDownExtFlash(void);
24
main(void)25 int main(void)
26 {
27 uint32_t config, status;
28
29 printk("\n%s system off demo\n", CONFIG_BOARD);
30
31 /* Shut off external flash to save power */
32 CC1352R1_LAUNCHXL_shutDownExtFlash();
33
34 /* Configure to generate PORT event (wakeup) on button 1 press. */
35 if (!gpio_is_ready_dt(&sw0_gpio)) {
36 printk("%s: device not ready.\n", sw0_gpio.port->name);
37 return 0;
38 }
39
40 gpio_pin_configure_dt(&sw0_gpio, GPIO_INPUT);
41
42 /* Set wakeup bits for button gpio */
43 config = IOCPortConfigureGet(sw0_gpio.pin);
44 config |= IOC_WAKE_ON_LOW;
45 IOCPortConfigureSet(sw0_gpio.pin, IOC_PORT_GPIO, config);
46
47 printk("Busy-wait %u s\n", BUSY_WAIT_S);
48 k_busy_wait(BUSY_WAIT_S * USEC_PER_SEC);
49
50 printk("Sleep %u us (IDLE)\n", SLEEP_US);
51 k_usleep(SLEEP_US);
52
53 printk("Sleep %u s (STANDBY)\n", SLEEP_S);
54 k_sleep(K_SECONDS(SLEEP_S));
55
56 printk("Powering off; press BUTTON1 to restart\n");
57
58 /* Clear GPIO interrupt */
59 status = GPIO_getEventMultiDio(GPIO_DIO_ALL_MASK);
60 GPIO_clearEventMultiDio(status);
61
62 sys_poweroff();
63
64 return 0;
65 }
66