2020EventGroupHandle_t user_event_group ;
2121
2222#if defined(CONFIG_ENABLE_SLP_KEY ) || defined(CONFIG_ENABLE_BLE_IF )
23- static EventBits_t slp_wait_bits = 0 ;
24- static EventBits_t rst_wait_bits = 0 ;
23+ static EventBits_t sleep_wait_bits = 0 ;
24+ static EventBits_t reset_wait_bits = 0 ;
2525
2626static void os_pwr_task_handle (void * pvParameters )
2727{
@@ -30,22 +30,22 @@ static void os_pwr_task_handle(void *pvParameters)
3030 while (1 ) {
3131 xEventGroupWaitBits (
3232 user_event_group ,
33- OS_PWR_SLP_BIT | OS_PWR_RST_BIT ,
33+ OS_PWR_SLEEP_BIT | OS_PWR_RESET_BIT ,
3434 pdFALSE ,
3535 pdFALSE ,
3636 portMAX_DELAY
3737 );
3838
3939 EventBits_t uxBits = xEventGroupGetBits (user_event_group );
40- if (uxBits & OS_PWR_SLP_BIT ) {
40+ if (uxBits & OS_PWR_SLEEP_BIT ) {
4141 for (int i = 3 ; i > 0 ; i -- ) {
4242 ESP_LOGW (OS_PWR_TAG , "sleeping in %ds" , i );
4343 vTaskDelay (1000 / portTICK_RATE_MS );
4444 }
4545
4646 xEventGroupWaitBits (
4747 user_event_group ,
48- slp_wait_bits ,
48+ sleep_wait_bits ,
4949 pdFALSE ,
5050 pdTRUE ,
5151 portMAX_DELAY
@@ -67,36 +67,36 @@ static void os_pwr_task_handle(void *pvParameters)
6767
6868 ESP_LOGW (OS_PWR_TAG , "sleep now" );
6969 esp_deep_sleep_start ();
70- } else if (uxBits & OS_PWR_RST_BIT ) {
70+ } else if (uxBits & OS_PWR_RESET_BIT ) {
7171 for (int i = 3 ; i > 0 ; i -- ) {
72- ESP_LOGW (OS_PWR_TAG , "restarting in %ds" , i );
72+ ESP_LOGW (OS_PWR_TAG , "resetting in %ds" , i );
7373 vTaskDelay (1000 / portTICK_RATE_MS );
7474 }
7575
7676 xEventGroupWaitBits (
7777 user_event_group ,
78- rst_wait_bits ,
78+ reset_wait_bits ,
7979 pdFALSE ,
8080 pdTRUE ,
8181 portMAX_DELAY
8282 );
8383
84- ESP_LOGW (OS_PWR_TAG , "restart now" );
84+ ESP_LOGW (OS_PWR_TAG , "reset now" );
8585 esp_restart ();
8686 }
8787 }
8888}
8989
90- void os_pwr_slp_wait (EventBits_t bits )
90+ void os_pwr_sleep_wait (EventBits_t bits )
9191{
9292 if (bits ) {
93- slp_wait_bits = bits ;
94- xEventGroupSetBits (user_event_group , OS_PWR_SLP_BIT );
93+ sleep_wait_bits = bits ;
94+ xEventGroupSetBits (user_event_group , OS_PWR_SLEEP_BIT );
9595 } else {
9696#ifdef CONFIG_ENABLE_SLP_KEY
9797 esp_sleep_pd_config (ESP_PD_DOMAIN_RTC_PERIPH , ESP_PD_OPTION_ON );
9898 rtc_gpio_set_direction (CONFIG_SLP_KEY_PIN , RTC_GPIO_MODE_INPUT_ONLY );
99- #ifdef CONFIG_ENABLE_SLP_KEY_LOW
99+ #ifdef CONFIG_SLP_KEY_ACTIVE_LOW
100100 rtc_gpio_pulldown_dis (CONFIG_SLP_KEY_PIN );
101101 rtc_gpio_pullup_en (CONFIG_SLP_KEY_PIN );
102102 esp_sleep_enable_ext1_wakeup (1ULL << CONFIG_SLP_KEY_PIN , ESP_EXT1_WAKEUP_ALL_LOW );
@@ -111,13 +111,13 @@ void os_pwr_slp_wait(EventBits_t bits)
111111 }
112112}
113113
114- void os_pwr_rst_wait (EventBits_t bits )
114+ void os_pwr_reset_wait (EventBits_t bits )
115115{
116116 if (bits ) {
117- rst_wait_bits = bits ;
118- xEventGroupSetBits (user_event_group , OS_PWR_RST_BIT );
117+ reset_wait_bits = bits ;
118+ xEventGroupSetBits (user_event_group , OS_PWR_RESET_BIT );
119119 } else {
120- ESP_LOGW (OS_PWR_TAG , "restart now" );
120+ ESP_LOGW (OS_PWR_TAG , "reset now" );
121121 esp_restart ();
122122 }
123123}
@@ -127,6 +127,14 @@ void os_init(void)
127127{
128128 user_event_group = xEventGroupCreate ();
129129
130+ #ifdef CONFIG_ENABLE_SLP_KEY
131+ if (esp_sleep_get_wakeup_cause () != ESP_SLEEP_WAKEUP_UNDEFINED ) {
132+ ESP_LOGW (OS_PWR_TAG , "resuming from sleep mode" );
133+ } else {
134+ os_pwr_sleep_wait (0 );
135+ }
136+ #endif
137+
130138#if defined(CONFIG_ENABLE_SLP_KEY ) || defined(CONFIG_ENABLE_BLE_IF )
131139 xTaskCreatePinnedToCore (os_pwr_task_handle , "osPwrT" , 2048 , NULL , 5 , NULL , 0 );
132140#endif
0 commit comments