deep sleep: power down RTC peripherals in EXT1 sleep

This commit is contained in:
Ivan Grokhotkov 2016-12-16 14:10:07 +08:00
parent 616d1d32f1
commit 609d852834
4 changed files with 34 additions and 17 deletions

View 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 */

View 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;
}
}

View 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.

View 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(gpio_pullup_dis(GPIO_NUM_13));
ESP_ERROR_CHECK(gpio_pulldown_en(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("can wake up from deep sleep using ext1 (13 low)", "[deepsleep]")
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("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();
}