153 lines
5.1 KiB
Diff
153 lines
5.1 KiB
Diff
|
From e690e2a17d9798ad22d961bd4ee2613593d68e44 Mon Sep 17 00:00:00 2001
|
||
|
From: Dylan Van Assche <me@dylanvanassche.be>
|
||
|
Date: Sun, 23 May 2021 20:00:42 +0200
|
||
|
Subject: [PATCH] at: wake only when sending AT commands
|
||
|
|
||
|
Allow the modem to enter soft sleep when
|
||
|
we don't talk to the modem using AT commands.
|
||
|
This was already the case in suspend, but
|
||
|
not during runtime. By only waking the modem
|
||
|
from soft sleep when we need to send
|
||
|
an AT command, we can save some power.
|
||
|
---
|
||
|
src/at.c | 36 +++++++++++++++++++++++-------------
|
||
|
src/gpio.c | 24 ++++++++++++++++++++++--
|
||
|
src/gpio.h | 2 ++
|
||
|
3 files changed, 47 insertions(+), 15 deletions(-)
|
||
|
|
||
|
diff --git a/src/at.c b/src/at.c
|
||
|
index a34025f..358d95a 100644
|
||
|
--- a/src/at.c
|
||
|
+++ b/src/at.c
|
||
|
@@ -6,6 +6,7 @@
|
||
|
|
||
|
#include "at.h"
|
||
|
#include "suspend.h"
|
||
|
+#include "gpio.h"
|
||
|
#include "gnss.h"
|
||
|
|
||
|
#include <fcntl.h>
|
||
|
@@ -52,6 +53,10 @@ gboolean at_send_command(struct EG25Mana
|
||
|
int ret, len = 0;
|
||
|
|
||
|
if (at_cmd) {
|
||
|
+ /* Wake up the modem from soft sleep before sending an AT command */
|
||
|
+ gpio_sequence_wake(manager);
|
||
|
+
|
||
|
+ /* Send AT command */
|
||
|
if (at_cmd->subcmd == NULL && at_cmd->value == NULL && at_cmd->expected == NULL)
|
||
|
len = sprintf(command, "AT+%s\r\n", at_cmd->cmd);
|
||
|
else if (at_cmd->subcmd == NULL && at_cmd->value == NULL)
|
||
|
@@ -69,23 +74,28 @@ gboolean at_send_command(struct EG25Mana
|
||
|
g_warning("Couldn't write full AT command: wrote %d/%d bytes", ret, len);
|
||
|
|
||
|
g_message("Sending command: %s", g_strstrip(command));
|
||
|
- } else if (manager->modem_state < EG25_STATE_CONFIGURED) {
|
||
|
- if (manager->modem_iface == MODEM_IFACE_MODEMMANAGER) {
|
||
|
+ } else {
|
||
|
+ /* Allow the modem to enter soft sleep again when we sent the AT command*/
|
||
|
+ gpio_sequence_sleep(manager);
|
||
|
+
|
||
|
+ if (manager->modem_state < EG25_STATE_CONFIGURED) {
|
||
|
+ if (manager->modem_iface == MODEM_IFACE_MODEMMANAGER) {
|
||
|
#ifdef HAVE_MMGLIB
|
||
|
- MMModemState modem_state = mm_modem_get_state(manager->mm_modem);
|
||
|
+ MMModemState modem_state = mm_modem_get_state(manager->mm_modem);
|
||
|
|
||
|
- if (manager->mm_modem && modem_state >= MM_MODEM_STATE_REGISTERED)
|
||
|
- modem_update_state(manager, modem_state);
|
||
|
- else
|
||
|
- manager->modem_state = EG25_STATE_CONFIGURED;
|
||
|
+ if (manager->mm_modem && modem_state >= MM_MODEM_STATE_REGISTERED)
|
||
|
+ modem_update_state(manager, modem_state);
|
||
|
+ else
|
||
|
+ manager->modem_state = EG25_STATE_CONFIGURED;
|
||
|
#endif
|
||
|
- } else {
|
||
|
- manager->modem_state = EG25_STATE_CONFIGURED;
|
||
|
+ } else {
|
||
|
+ manager->modem_state = EG25_STATE_CONFIGURED;
|
||
|
+ }
|
||
|
+ } else if (manager->modem_state == EG25_STATE_SUSPENDING) {
|
||
|
+ modem_suspend_post(manager);
|
||
|
+ } else if (manager->modem_state == EG25_STATE_RESETTING) {
|
||
|
+ manager->modem_state = EG25_STATE_POWERED;
|
||
|
}
|
||
|
- } else if (manager->modem_state == EG25_STATE_SUSPENDING) {
|
||
|
- modem_suspend_post(manager);
|
||
|
- } else if (manager->modem_state == EG25_STATE_RESETTING) {
|
||
|
- manager->modem_state = EG25_STATE_POWERED;
|
||
|
}
|
||
|
|
||
|
return FALSE;
|
||
|
diff --git a/src/gpio.c b/src/gpio.c
|
||
|
index a5d3bf0..617b69e 100644
|
||
|
--- a/src/gpio.c
|
||
|
+++ b/src/gpio.c
|
||
|
@@ -6,6 +6,8 @@
|
||
|
|
||
|
#include "gpio.h"
|
||
|
|
||
|
+#include <unistd.h>
|
||
|
+
|
||
|
#define GPIO_CHIP1_LABEL "1c20800.pinctrl"
|
||
|
#define GPIO_CHIP2_LABEL "1f02c00.pinctrl"
|
||
|
|
||
|
@@ -52,7 +54,6 @@ int gpio_sequence_shutdown(struct EG25Manager *manager)
|
||
|
int gpio_sequence_suspend(struct EG25Manager *manager)
|
||
|
{
|
||
|
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_APREADY], 1);
|
||
|
- gpiod_line_set_value(manager->gpio_out[GPIO_OUT_DTR], 1);
|
||
|
|
||
|
g_message("Executed suspend sequence");
|
||
|
|
||
|
@@ -62,13 +63,32 @@ int gpio_sequence_suspend(struct EG25Manager *manager)
|
||
|
int gpio_sequence_resume(struct EG25Manager *manager)
|
||
|
{
|
||
|
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_APREADY], 0);
|
||
|
- gpiod_line_set_value(manager->gpio_out[GPIO_OUT_DTR], 0);
|
||
|
|
||
|
g_message("Executed resume sequence");
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
+int gpio_sequence_wake(struct EG25Manager *manager)
|
||
|
+{
|
||
|
+ gpiod_line_set_value(manager->gpio_out[GPIO_OUT_DTR], 0);
|
||
|
+
|
||
|
+ /* Give the modem 5ms to wake from soft sleep */
|
||
|
+ usleep(5000);
|
||
|
+
|
||
|
+ g_message("Executed soft wake sequence");
|
||
|
+
|
||
|
+ return 0;
|
||
|
+}
|
||
|
+
|
||
|
+int gpio_sequence_sleep(struct EG25Manager *manager)
|
||
|
+{
|
||
|
+ gpiod_line_set_value(manager->gpio_out[GPIO_OUT_DTR], 1);
|
||
|
+ g_message("Executed soft sleep sequence");
|
||
|
+
|
||
|
+ return 0;
|
||
|
+}
|
||
|
+
|
||
|
static guint get_config_gpio(toml_table_t *config, const char *id)
|
||
|
{
|
||
|
toml_datum_t value = toml_int_in(config, id);
|
||
|
diff --git a/src/gpio.h b/src/gpio.h
|
||
|
index 8d94013..a041bdc 100644
|
||
|
--- a/src/gpio.h
|
||
|
+++ b/src/gpio.h
|
||
|
@@ -15,5 +15,7 @@ int gpio_sequence_poweron(struct EG25Manager *state);
|
||
|
int gpio_sequence_shutdown(struct EG25Manager *state);
|
||
|
int gpio_sequence_suspend(struct EG25Manager *state);
|
||
|
int gpio_sequence_resume(struct EG25Manager *state);
|
||
|
+int gpio_sequence_wake(struct EG25Manager *state);
|
||
|
+int gpio_sequence_sleep(struct EG25Manager *state);
|
||
|
|
||
|
gboolean gpio_check_poweroff(struct EG25Manager *manager, gboolean keep_down);
|
||
|
--
|
||
|
GitLab
|
||
|
|