diff options
author | Uros Majstorovic <majstor@majstor.org> | 2022-09-23 20:09:50 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2022-09-23 20:09:50 +0200 |
commit | 92458eb1934e0f104f4a397c2c09ab2d19693436 (patch) | |
tree | 76c63779b15c1ac562e1a6c122e3371c04ee2a51 /fw/esp32/components/eos/power.c | |
parent | 69ed847740e3efb5c5ff6319629c93d236150959 (diff) |
sleep respects modem_present flag
Diffstat (limited to 'fw/esp32/components/eos/power.c')
-rw-r--r-- | fw/esp32/components/eos/power.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/fw/esp32/components/eos/power.c b/fw/esp32/components/eos/power.c index c659481..b98c0ec 100644 --- a/fw/esp32/components/eos/power.c +++ b/fw/esp32/components/eos/power.c @@ -92,7 +92,7 @@ static void timer_handler(void *arg) { xQueueSendFromISR(power_queue, &evt, NULL); } -void power_sleep_stage1(void) { +static void power_sleep_stage1(int modem_wake_en) { gpio_config_t io_conf = {}; eos_modem_sleep(); @@ -107,12 +107,16 @@ void power_sleep_stage1(void) { gpio_isr_handler_add(POWER_GPIO_BTN, btn_wake_handler, NULL); gpio_isr_handler_add(POWER_GPIO_NET, net_wake_handler, NULL); - gpio_isr_handler_add(POWER_GPIO_UART, uart_wake_handler, NULL); + if (modem_wake_en) { + gpio_isr_handler_add(POWER_GPIO_UART, uart_wake_handler, NULL); + } esp_sleep_enable_gpio_wakeup(); gpio_wakeup_enable(POWER_GPIO_BTN, GPIO_INTR_LOW_LEVEL); gpio_wakeup_enable(POWER_GPIO_NET, GPIO_INTR_LOW_LEVEL); - gpio_wakeup_enable(POWER_GPIO_UART, GPIO_INTR_LOW_LEVEL); + if (modem_wake_en) { + gpio_wakeup_enable(POWER_GPIO_UART, GPIO_INTR_LOW_LEVEL); + } esp_timer_start_once(timer, 10 * 1000000); @@ -121,7 +125,7 @@ void power_sleep_stage1(void) { esp_pm_lock_release(power_lock_no_sleep); } -void power_sleep_stage2(uint8_t mode) { +static void power_sleep_stage2(int modem_wake_en, uint8_t mode) { switch (mode) { case EOS_PWR_SMODE_LIGHT: { ESP_LOGI(TAG, "LIGHT SLEEP"); @@ -135,7 +139,9 @@ void power_sleep_stage2(uint8_t mode) { gpio_deep_sleep_hold_en(); esp_sleep_enable_ext0_wakeup(POWER_GPIO_BTN, 0); - // esp_sleep_enable_ext1_wakeup((uint64_t)1 << POWER_GPIO_UART, ESP_EXT1_WAKEUP_ALL_LOW); + if (modem_wake_en) { + esp_sleep_enable_ext1_wakeup((uint64_t)1 << POWER_GPIO_UART, ESP_EXT1_WAKEUP_ALL_LOW); + } ESP_LOGI(TAG, "DEEP SLEEP"); @@ -146,7 +152,7 @@ void power_sleep_stage2(uint8_t mode) { } } -void power_wake_stage1(uint8_t source, uint8_t mode) { +static void power_wake_stage1(uint8_t source, uint8_t mode) { if (mode == EOS_PWR_SMODE_LIGHT) { gpio_config_t io_conf = {}; @@ -179,7 +185,7 @@ void power_wake_stage1(uint8_t source, uint8_t mode) { eos_net_wake(source, mode); } -void power_wake_stage2(uint8_t source, uint8_t mode) { +static void power_wake_stage2(uint8_t source, uint8_t mode) { eos_modem_wake(source, mode); gpio_set_intr_type(POWER_GPIO_BTN, GPIO_INTR_ANYEDGE); @@ -195,6 +201,7 @@ static void power_event_task(void *pvParameters) { uint8_t wakeup_cause; uint8_t mode; int sleep1, sleep2; + int modem_wake_en; mode = 0; source = 0; @@ -206,14 +213,16 @@ static void power_event_task(void *pvParameters) { sleep1 = 0; } sleep2 = 0; + modem_wake_en = 0; while (1) { if (xQueueReceive(power_queue, &evt, portMAX_DELAY)) { switch (evt.type) { case POWER_ETYPE_SLEEP1: { if (!sleep1) { + modem_wake_en = eos_modem_present(); mode = EOS_PWR_SMODE_LIGHT; - power_sleep_stage1(); + power_sleep_stage1(modem_wake_en); sleep1 = 1; sleep2 = 1; } @@ -223,7 +232,7 @@ static void power_event_task(void *pvParameters) { case POWER_ETYPE_SLEEP2: { if (sleep2) { mode = EOS_PWR_SMODE_DEEP; - power_sleep_stage2(mode); + power_sleep_stage2(modem_wake_en, mode); sleep2 = 0; } break; |