summaryrefslogtreecommitdiff
path: root/fw
diff options
context:
space:
mode:
Diffstat (limited to 'fw')
-rw-r--r--fw/esp32/components/eos/cell_modem.c22
-rw-r--r--fw/esp32/components/eos/include/cell.h1
-rw-r--r--fw/esp32/components/eos/power.c27
3 files changed, 39 insertions, 11 deletions
diff --git a/fw/esp32/components/eos/cell_modem.c b/fw/esp32/components/eos/cell_modem.c
index 029abe1..ec81111 100644
--- a/fw/esp32/components/eos/cell_modem.c
+++ b/fw/esp32/components/eos/cell_modem.c
@@ -58,6 +58,7 @@ static char uart_buf[EOS_CELL_UART_SIZE_BUF];
static size_t uart_buf_len;
static char uart_buf_dirty = 0;
+static uint8_t RTC_NOINIT_ATTR modem_present;
static uint8_t RTC_NOINIT_ATTR modem_initialized;
static uint8_t RTC_NOINIT_ATTR uart_mode;
static uint8_t uart_mode_next = EOS_CELL_UART_MODE_NONE;
@@ -176,7 +177,9 @@ static void uart_event_task(void *pvParameters) {
r = at_expect("^OK", NULL, 500);
if (!r) {
r = eos_modem_atinit();
- if (r) {
+ if (!r) {
+ modem_present = 1;
+ } else {
_mode = EOS_CELL_UART_MODE_NONE;
ESP_LOGE(TAG, "Modem init failed");
}
@@ -337,7 +340,11 @@ static void modem_event_task(void *pvParameters) {
int r;
r = modem_atinit();
- if (r) ESP_LOGE(TAG, "Modem init failed");
+ if (!r) {
+ modem_present = 1;
+ } else {
+ ESP_LOGE(TAG, "Modem init failed");
+ }
break;
}
@@ -642,6 +649,7 @@ void eos_modem_init(void) {
if (eos_power_wakeup_cause() == EOS_PWR_WAKE_RST) {
uart_mode = EOS_CELL_UART_MODE_ATCMD;
+ modem_present = 0;
modem_initialized = 0;
modem_init_gpio();
}
@@ -773,6 +781,16 @@ int eos_modem_readln(char *buf, size_t buf_size, uint32_t timeout) {
return EOS_OK;
}
+int eos_modem_present(void) {
+ int rv;
+
+ xSemaphoreTake(mutex, portMAX_DELAY);
+ rv = modem_present;
+ xSemaphoreGive(mutex);
+
+ return rv;
+}
+
uint8_t eos_modem_get_mode(void) {
uint8_t ret;
diff --git a/fw/esp32/components/eos/include/cell.h b/fw/esp32/components/eos/include/cell.h
index 269615d..3ed2646 100644
--- a/fw/esp32/components/eos/include/cell.h
+++ b/fw/esp32/components/eos/include/cell.h
@@ -80,6 +80,7 @@ size_t eos_modem_write(void *data, size_t size);
size_t eos_modem_read(void *data, size_t size, uint32_t timeout);
int eos_modem_readln(char *buf, size_t buf_size, uint32_t timeout);
int eos_modem_resp(char *ok_str, char *err_str, uint32_t timeout);
+int eos_modem_present(void);
uint8_t eos_modem_get_mode(void);
size_t eos_modem_get_status(unsigned char *buffer);
int eos_modem_set_mode(uint8_t mode);
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;