1919#include <zephyr/sys/util.h>
2020
2121#define NON_WAKEUP_RESET_REASON (RESET_PIN | RESET_SOFTWARE | RESET_POR | RESET_DEBUG)
22+ #include <zephyr/pm/device_runtime.h>
23+ #include <hal/nrf_gpio.h>
24+ #include <hal/nrf_memconf.h>
2225
2326#if defined(CONFIG_GRTC_WAKEUP_ENABLE )
2427#include <zephyr/drivers/timer/nrf_grtc_timer.h>
2831static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET (DT_ALIAS (sw0 ), gpios );
2932#endif
3033#if defined(CONFIG_LPCOMP_WAKEUP_ENABLE )
31- static const uint32_t port_sw1 = DT_PROP (DT_GPIO_CTLR_BY_IDX (DT_ALIAS (sw1 ), gpios , 0 ), port );
3234static const struct device * comp_dev = DEVICE_DT_GET (DT_NODELABEL (comp ));
3335#endif
3436
37+ static const struct gpio_dt_spec sw1 = GPIO_DT_SPEC_GET (DT_ALIAS (sw1 ), gpios );
38+ static const uint32_t port_sw1 = DT_PROP (DT_GPIO_CTLR_BY_IDX (DT_ALIAS (sw1 ), gpios , 0 ), port );
39+
3540int print_reset_cause (uint32_t reset_cause )
3641{
3742 int32_t ret ;
3843 uint32_t supported ;
3944
40- ret = hwinfo_get_supported_reset_cause ((uint32_t * ) & supported );
45+ ret = hwinfo_get_supported_reset_cause ((uint32_t * )& supported );
4146
4247 if (ret || !(reset_cause & supported )) {
4348 return - ENOTSUP ;
@@ -109,9 +114,9 @@ int main(void)
109114 int err = z_nrf_grtc_wakeup_prepare (DEEP_SLEEP_TIME_S * USEC_PER_SEC );
110115
111116 if (err < 0 ) {
112- printk ("Unable to prepare GRTC as a wake up source (err = %d).\n" , err );
117+ printf ("Unable to prepare GRTC as a wake up source (err = %d).\n" , err );
113118 } else {
114- printk ("Entering system off; wait %u seconds to restart\n" , DEEP_SLEEP_TIME_S );
119+ printf ("Entering system off; wait %u seconds to restart\n" , DEEP_SLEEP_TIME_S );
115120 }
116121#endif
117122#if defined(CONFIG_GPIO_WAKEUP_ENABLE )
@@ -122,24 +127,22 @@ int main(void)
122127 return 0 ;
123128 }
124129
125- rc = gpio_pin_configure_dt (& sw1 , GPIO_INPUT );
126- if (rc < 0 ) {
127- printf ("Could not configure sw1 GPIO (%d)\n" , rc );
128- return 0 ;
129- }
130-
131130 rc = gpio_pin_interrupt_configure_dt (& sw0 , GPIO_INT_LEVEL_ACTIVE );
132131 if (rc < 0 ) {
133132 printf ("Could not configure sw0 GPIO interrupt (%d)\n" , rc );
134133 return 0 ;
135134 }
136- //code reorder needed
137135#endif
138136#if defined(CONFIG_LPCOMP_WAKEUP_ENABLE )
139137 comparator_set_trigger (comp_dev , COMPARATOR_TRIGGER_BOTH_EDGES );
140138 comparator_trigger_is_pending (comp_dev );
141139 printf ("Entering system off; change signal level at comparator input to restart\n" );
142140#endif
141+ rc = gpio_pin_configure_dt (& sw1 , GPIO_INPUT );
142+ if (rc < 0 ) {
143+ printf ("Could not configure sw1 GPIO (%d)\n" , rc );
144+ return 0 ;
145+ }
143146
144147 rc = gpio_pin_interrupt_configure_dt (& sw1 , GPIO_INT_LEVEL_ACTIVE );
145148 if (rc < 0 ) {
@@ -165,6 +168,7 @@ int main(void)
165168 retained_update ();
166169 }
167170
171+ k_sleep (K_MSEC (4000 ));
168172 if (do_poweroff ) {
169173#if CONFIG_SOC_NRF54H20_CPUAPP
170174 /* Local RAM0 (TCM) is currently not used so retention can be disabled. */
0 commit comments