manager: always set the reset line when exiting

This splits the logic from gpio_check_poweroff into two separate
functions, allowing the caller more control over when the reset line is
asserted to force the modem to turn off.

Previously if the modem didn't respond to the power key sequence in
quit_app, gpio_check_poweroff wouldn't set the reset pin, and
eg25-manager could leave the modem running after exiting.
This commit is contained in:
Aren Moynihan
2024-09-07 11:53:57 -04:00
parent 3c5d455f20
commit c4b3b75047
3 changed files with 18 additions and 11 deletions

View File

@@ -434,16 +434,18 @@ int gpio_init(struct EG25Manager *manager, toml_table_t *config[])
return 0;
}
gboolean gpio_check_poweroff(struct EG25Manager *manager, gboolean keep_down)
void gpio_force_off(struct EG25Manager *manager)
{
if (manager->gpio_out[GPIO_OUT_RESET]) {
g_message("Setting the reset pin to ensure the modem stays off");
gpio_line_set_value(manager, GPIO_OUT_RESET, GPIOD_LINE_VALUE_ACTIVE);
}
}
gboolean gpio_check_poweroff(struct EG25Manager *manager)
{
if (manager->gpio_in[GPIO_IN_STATUS] &&
gpio_line_get_value(manager, GPIO_IN_STATUS) == GPIOD_LINE_VALUE_ACTIVE) {
if (keep_down && manager->gpio_out[GPIO_OUT_RESET]) {
// Asserting RESET line to prevent modem from rebooting
gpio_line_set_value(manager, GPIO_OUT_RESET, GPIOD_LINE_VALUE_ACTIVE);
}
return TRUE;
}

View File

@@ -18,4 +18,5 @@ 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);
void gpio_force_off(struct EG25Manager *manager);
gboolean gpio_check_poweroff(struct EG25Manager *manager);

View File

@@ -62,13 +62,17 @@ static gboolean quit_app(struct EG25Manager *manager)
gpio_sequence_shutdown(manager);
manager->modem_state = EG25_STATE_FINISHING;
for (i = 0; i < 30; i++) {
if (gpio_check_poweroff(manager, TRUE))
if (gpio_check_poweroff(manager)) {
g_message("Modem successfully powered down");
break;
}
sleep(1);
}
}
g_message("Modem down, quitting...");
gpio_force_off(manager);
g_message("Modem down, quitting...");
g_main_loop_quit(manager->loop);
return FALSE;
@@ -98,7 +102,7 @@ static gboolean modem_start(struct EG25Manager *manager)
libusb_free_device_list(devices, 1);
libusb_exit(ctx);
} else if (!gpio_check_poweroff(manager, FALSE)) {
} else if (!gpio_check_poweroff(manager)) {
g_message("STATUS is low, modem already powered");
should_boot = FALSE;
}