mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 15:22:20 +02:00
improve poweroff sequence
When powering off the modem, we must assert the RESET line only when the modem has shut down (otherwise it'll cause a hard reset and won't allow the modem to shut down properly). This commit also polls the STATUS pin during poweroff and quits immediately once this pin goes high.
This commit is contained in:
18
src/gpio.c
18
src/gpio.c
@@ -64,11 +64,8 @@ int gpio_sequence_poweron(struct EG25Manager *manager)
|
||||
|
||||
int gpio_sequence_shutdown(struct EG25Manager *manager)
|
||||
{
|
||||
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_RESET], 1);
|
||||
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_DISABLE], 1);
|
||||
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_PWRKEY], 1);
|
||||
sleep(1);
|
||||
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_PWRKEY], 0);
|
||||
gpio_sequence_poweron(manager);
|
||||
|
||||
g_message("Executed power-off sequence");
|
||||
|
||||
@@ -175,6 +172,19 @@ int gpio_init(struct EG25Manager *manager)
|
||||
return 0;
|
||||
}
|
||||
|
||||
gboolean gpio_check_poweroff(struct EG25Manager *manager)
|
||||
{
|
||||
if (manager->gpio_in[GPIO_IN_STATUS] &&
|
||||
gpiod_line_get_value(manager->gpio_in[GPIO_IN_STATUS]) == 1) {
|
||||
|
||||
// Asserting RESET line to prevent modem from rebooting
|
||||
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_RESET], 1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void gpio_destroy(struct EG25Manager *manager)
|
||||
{
|
||||
int i;
|
||||
|
@@ -15,3 +15,5 @@ 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);
|
||||
|
||||
gboolean gpio_check_poweroff(struct EG25Manager *manager);
|
||||
|
@@ -25,6 +25,16 @@ static gboolean quit_timeout_cb(struct EG25Manager *manager)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean gpio_poll_cb(struct EG25Manager *manager)
|
||||
{
|
||||
if (gpio_check_poweroff(manager)) {
|
||||
quit_timeout_cb(manager);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean quit_app(struct EG25Manager *manager)
|
||||
{
|
||||
g_message("Request to quit...");
|
||||
@@ -33,10 +43,7 @@ static gboolean quit_app(struct EG25Manager *manager)
|
||||
g_message("Powering down the modem...");
|
||||
gpio_sequence_shutdown(manager);
|
||||
manager->modem_state = EG25_STATE_FINISHING;
|
||||
/*
|
||||
* TODO: add a polling function to check STATUS and RI pins state
|
||||
* (that way we could reduce the poweroff delay)
|
||||
*/
|
||||
g_timeout_add(500, G_SOURCE_FUNC(gpio_poll_cb), manager);
|
||||
g_timeout_add_seconds(30, G_SOURCE_FUNC(quit_timeout_cb), manager);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user