]> granicus.if.org Git - esp-idf/commitdiff
deep sleep: power down RTC peripherals in EXT1 sleep
authorIvan Grokhotkov <ivan@espressif.com>
Fri, 16 Dec 2016 06:10:07 +0000 (14:10 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Fri, 16 Dec 2016 06:30:27 +0000 (14:30 +0800)
components/driver/include/driver/rtc_io.h
components/esp32/deep_sleep.c
components/esp32/include/esp_deep_sleep.h
components/esp32/test/test_deep_sleep.c

index 3f06b68505e62c7bff80b3da63e42db427c89269..3fc32876465bc3ccb8ff92f20a56101e26c5d9a2 100644 (file)
@@ -29,11 +29,11 @@ extern "C" {
 typedef struct {
     uint32_t reg;       /*!< Register of RTC pad, or 0 if not an RTC GPIO */
     uint32_t mux;       /*!< Bit mask for selecting digital pad or RTC pad */
-    uint32_t func;      /*!< Mask of RTC pad function */
+    uint32_t func;      /*!< Shift of pad function (FUN_SEL) field */
     uint32_t ie;        /*!< Mask of input enable */
     uint32_t pullup;    /*!< Mask of pullup enable */
     uint32_t pulldown;  /*!< Mask of pulldown enable */
-    uint32_t slpsel;    /*!< Mask of the bit to select pin as wakeup pin */
+    uint32_t slpsel;    /*!< If slpsel bit is set, slpie will be used as pad input enabled signal in sleep mode */
     uint32_t slpie;     /*!< Mask of input enable in sleep mode */
     uint32_t hold;      /*!< Mask of hold_force bit for RTC IO in RTC_CNTL_HOLD_FORCE_REG */
     int rtc_num;        /*!< RTC IO number, or -1 if not an RTC GPIO */
index c6a43c6f1c479d4cbccf2fbf337523dd01a4e9c7..28ab27270eb95e403638f0399b26c893cf1022c1 100644 (file)
@@ -172,8 +172,13 @@ esp_err_t esp_deep_sleep_enable_ext1_wakeup(uint64_t mask, esp_ext1_wakeup_mode_
         const rtc_gpio_desc_t* desc = &rtc_gpio_desc[gpio];
         int rtc_pin = desc->rtc_num;
         rtc_gpio_mask |= BIT(rtc_pin);
+        REG_SET_BIT(desc->reg, desc->ie);
         REG_SET_BIT(desc->reg, desc->slpsel);
         REG_SET_BIT(desc->reg, desc->slpie);
+        REG_CLR_BIT(desc->reg, desc->pulldown);
+        REG_CLR_BIT(desc->reg, desc->pullup);
+        REG_SET_BIT(desc->reg, desc->mux);
+        REG_SET_BIT(RTC_CNTL_HOLD_FORCE_REG, desc->hold);
     }
     REG_SET_BIT(RTC_CNTL_EXT_WAKEUP1_REG, RTC_CNTL_EXT_WAKEUP1_STATUS_CLR);
     REG_SET_FIELD(RTC_CNTL_EXT_WAKEUP1_REG, RTC_CNTL_EXT_WAKEUP1_SEL, rtc_gpio_mask);
@@ -240,7 +245,7 @@ static uint32_t get_power_down_flags()
     // power down RTC_PERIPH.
     if (s_pd_options[ESP_PD_DOMAIN_RTC_PERIPH] == ESP_PD_OPTION_AUTO) {
         if (s_wakeup_options &
-                (RTC_SAR_TRIG_EN | RTC_EXT_EVENT0_TRIG_EN | RTC_EXT_EVENT1_TRIG_EN)) {
+                (RTC_SAR_TRIG_EN | RTC_EXT_EVENT0_TRIG_EN)) {
             s_pd_options[ESP_PD_DOMAIN_RTC_PERIPH] = ESP_PD_OPTION_ON;
         }
     }
index 72bdf48c5330487436fbe467777a2eeeefe3a45d..8b28f5ffeb792080816e88fa0b6d48fb9a06b66a 100644 (file)
@@ -99,12 +99,6 @@ esp_err_t esp_deep_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level);
  * This function uses external wakeup feature of RTC controller.
  * It will work even if RTC peripherals are shut down during deep sleep.
  *
- * @note Currently this doesn't actually work if RTC_PERIPH domain is
- *       powered down. This is a known issue which will be resolved soon.
- *       For now, unless esp_deep_sleep_pd_config function is used to
- *       power down RTC_PERIPH domain, it will be kept on during deep sleep,
- *       slightly increasing power consumption.
- *
  * This feature can monitor any number of pins which are in RTC IOs.
  * Once any of the selected pins goes into the state given by level argument,
  * the chip will be woken up.
index 17636235f76265b16eecc34d57784b16c497ab6f..a47b6daf3f2b5bd671253e50845874bd0dc4308e 100644 (file)
@@ -25,20 +25,20 @@ static void do_deep_sleep_from_app_cpu()
     }
 }
 
-TEST_CASE("can wake up from deep sleep using timer", "[deepsleep]")
+TEST_CASE("wake up using timer", "[deepsleep]")
 {
     esp_deep_sleep_enable_timer_wakeup(2000000);
     esp_deep_sleep_start();
 }
 
-TEST_CASE("go into deep sleep from APP CPU and wake up using timer", "[deepsleep]")
+TEST_CASE("enter deep sleep on APP CPU and wake up using timer", "[deepsleep]")
 {
     esp_deep_sleep_enable_timer_wakeup(2000000);
     do_deep_sleep_from_app_cpu();
 }
 
 
-TEST_CASE("can wake up from deep sleep using ext0 (13 high)", "[deepsleep]")
+TEST_CASE("wake up using ext0 (13 high)", "[deepsleep]")
 {
     ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
     ESP_ERROR_CHECK(gpio_pullup_dis(GPIO_NUM_13));
@@ -47,7 +47,7 @@ TEST_CASE("can wake up from deep sleep using ext0 (13 high)", "[deepsleep]")
     esp_deep_sleep_start();
 }
 
-TEST_CASE("can wake up from deep sleep using ext0 (13 low)", "[deepsleep]")
+TEST_CASE("wake up using ext0 (13 low)", "[deepsleep]")
 {
     ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
     ESP_ERROR_CHECK(gpio_pullup_en(GPIO_NUM_13));
@@ -56,20 +56,38 @@ TEST_CASE("can wake up from deep sleep using ext0 (13 low)", "[deepsleep]")
     esp_deep_sleep_start();
 }
 
-TEST_CASE("can wake up from deep sleep using ext1 (13 high)", "[deepsleep]")
+TEST_CASE("wake up using ext1 when RTC_PERIPH is off (13 high)", "[deepsleep]")
+{
+    // This test needs external pulldown
+    ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
+    ESP_ERROR_CHECK(esp_deep_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH));
+    esp_deep_sleep_start();
+}
+
+TEST_CASE("wake up using ext1 when RTC_PERIPH is off (13 low)", "[deepsleep]")
+{
+    // This test needs external pullup
+    ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
+    ESP_ERROR_CHECK(esp_deep_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW));
+    esp_deep_sleep_start();
+}
+
+TEST_CASE("wake up using ext1 when RTC_PERIPH is on (13 high)", "[deepsleep]")
 {
     ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
     ESP_ERROR_CHECK(gpio_pullup_dis(GPIO_NUM_13));
     ESP_ERROR_CHECK(gpio_pulldown_en(GPIO_NUM_13));
+    ESP_ERROR_CHECK(esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON));
     ESP_ERROR_CHECK(esp_deep_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH));
     esp_deep_sleep_start();
 }
 
-TEST_CASE("can wake up from deep sleep using ext1 (13 low)", "[deepsleep]")
+TEST_CASE("wake up using ext1 when RTC_PERIPH is on (13 low)", "[deepsleep]")
 {
     ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
     ESP_ERROR_CHECK(gpio_pullup_en(GPIO_NUM_13));
     ESP_ERROR_CHECK(gpio_pulldown_dis(GPIO_NUM_13));
+    ESP_ERROR_CHECK(esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON));
     ESP_ERROR_CHECK(esp_deep_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW));
     esp_deep_sleep_start();
 }