1818#include  <zephyr/sys/poweroff.h> 
1919#include  <zephyr/sys/util.h> 
2020
21+ #define  NON_WAKEUP_RESET_REASON  (RESET_PIN | RESET_SOFTWARE | RESET_POR | RESET_DEBUG)
22+ 
2123#if  defined(CONFIG_GRTC_WAKEUP_ENABLE )
2224#include  <zephyr/drivers/timer/nrf_grtc_timer.h> 
2325#define  DEEP_SLEEP_TIME_S  2
@@ -29,15 +31,14 @@ static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
2931static  const  struct  device  * comp_dev  =  DEVICE_DT_GET (DT_NODELABEL (comp ));
3032#endif 
3133
32- void  print_reset_cause (void )
34+ void  print_reset_cause (uint32_t   reset_cause )
3335{
34- 	uint32_t  reset_cause ;
35- 
36- 	hwinfo_get_reset_cause (& reset_cause );
3736	if  (reset_cause  &  RESET_DEBUG ) {
3837		printf ("Reset by debugger.\n" );
3938	} else  if  (reset_cause  &  RESET_CLOCK ) {
4039		printf ("Wakeup from System OFF by GRTC.\n" );
40+ 	} else  if  (reset_cause  &  RESET_LOW_POWER_WAKE ) {
41+ 		printf ("Wakeup from System OFF by GPIO.\n" );
4142	} else   {
4243		printf ("Other wake up cause 0x%08X.\n" , reset_cause );
4344	}
@@ -46,6 +47,7 @@ void print_reset_cause(void)
4647int  main (void )
4748{
4849	int  rc ;
50+ 	uint32_t  reset_cause ;
4951	const  struct  device  * const  cons  =  DEVICE_DT_GET (DT_CHOSEN (zephyr_console ));
5052
5153	if  (!device_is_ready (cons )) {
@@ -54,11 +56,19 @@ int main(void)
5456	}
5557
5658	printf ("\n%s system off demo\n" , CONFIG_BOARD );
57- 	print_reset_cause ();
59+ 	hwinfo_get_reset_cause (& reset_cause );
60+ 	print_reset_cause (reset_cause );
5861
5962	if  (IS_ENABLED (CONFIG_APP_USE_RETAINED_MEM )) {
6063		bool  retained_ok  =  retained_validate ();
6164
65+ 		if  (reset_cause  &  NON_WAKEUP_RESET_REASON ) {
66+ 			retained .boots  =  0 ;
67+ 			retained .off_count  =  0 ;
68+ 			retained .uptime_sum  =  0 ;
69+ 			retained .uptime_latest  =  0 ;
70+ 			retained_ok  =  true;
71+ 		}
6272		/* Increment for this boot attempt and update. */ 
6373		retained .boots  +=  1 ;
6474		retained_update ();
0 commit comments