From 338bd5a0385482ebf4dbfd7169b471d8f44a15ec Mon Sep 17 00:00:00 2001 From: ro8inmorgan Date: Sun, 18 May 2025 11:27:19 +0200 Subject: [PATCH 1/2] another change to suspend --- skeleton/SYSTEM/tg5040/bin/suspend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skeleton/SYSTEM/tg5040/bin/suspend b/skeleton/SYSTEM/tg5040/bin/suspend index b88b2e4c9..e26e618a6 100755 --- a/skeleton/SYSTEM/tg5040/bin/suspend +++ b/skeleton/SYSTEM/tg5040/bin/suspend @@ -58,7 +58,7 @@ main() { # echo 0 >/sys/class/rfkill/rfkill0/state >&2 echo "Suspending..." - echo mem >/sys/power/state + echo mem >/sys/power/state || true exit 0 } From 0fbbb454071d23f10e9a7891cfc885d9bd9bb804 Mon Sep 17 00:00:00 2001 From: ro8inmorgan Date: Sun, 18 May 2025 18:07:46 +0200 Subject: [PATCH 2/2] suspend fix --- skeleton/SYSTEM/tg5040/bin/suspend | 32 ++++++++++++++++++++++-------- workspace/all/common/api.c | 15 +++++--------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/skeleton/SYSTEM/tg5040/bin/suspend b/skeleton/SYSTEM/tg5040/bin/suspend index e26e618a6..5b6715a17 100755 --- a/skeleton/SYSTEM/tg5040/bin/suspend +++ b/skeleton/SYSTEM/tg5040/bin/suspend @@ -2,13 +2,13 @@ # set -eu exec 0<&- -wpa_running=0 -hciattach_running=0 -bluetoothd_running=0 +# wpa_running=0 +# hciattach_running=0 +# bluetoothd_running=0 # shellcheck disable=SC2317 resume() { - >&2 echo "Resuming from suspend..." + # >&2 echo "Unblocking wireless..." # echo 1 >/sys/class/rfkill/rfkill0/state || true @@ -28,11 +28,11 @@ resume() { # /etc/bluetooth/bluetoothd start || true # /usr/bin/bluetoothctl power on || true # fi + >&2 echo "Resumed from suspend..." + exit 0 } main() { - trap "resume" EXIT INT TERM HUP QUIT - >&2 echo "Preparing for suspend..." # if pgrep wpa_supplicant; then @@ -58,9 +58,25 @@ main() { # echo 0 >/sys/class/rfkill/rfkill0/state >&2 echo "Suspending..." - echo mem >/sys/power/state || true + max_attempts=20 + attempt=1 - exit 0 + while ! echo mem > /sys/power/state 2>/dev/null; do + >&2 echo "Suspend attempt $attempt failed. Checking for active wakeup sources..." + awk '{ if ($2 > 0 && NR > 1) print $1 " is active (" $2 " times)"; }' /sys/kernel/debug/wakeup_sources + + if [ "$attempt" -ge "$max_attempts" ]; then + >&2 echo "Maximum suspend attempts reached ($max_attempts). Giving up." + break + fi + + attempt=$((attempt + 1)) + >&2 echo "Retrying in 1 seconds..." + sleep 1 + done + + >&2 echo "Resuming..." + resume } main diff --git a/workspace/all/common/api.c b/workspace/all/common/api.c index 0a4ac041f..464c4e35f 100644 --- a/workspace/all/common/api.c +++ b/workspace/all/common/api.c @@ -2872,21 +2872,16 @@ static void PWR_waitForWake(void) { if(sleepDelay > 0) { SDL_Delay(200); if (SDL_GetTicks()-sleep_ticks>=sleepDelay) { // increased to two minutes - if (pwr.is_charging) { - sleep_ticks += 60000; // check again in a minute - continue; - } + // if (pwr.is_charging) { + // sleep_ticks += 60000; // check again in a minute + // continue; + // } if (PLAT_supportsDeepSleep()) { int ret = PWR_deepSleep(); if (ret == 0) { return; - } else if (deep_sleep_attempts < 3) { - LOG_warn("failed to enter deep sleep - retrying in 5 seconds\n"); - sleep_ticks += 5000; - deep_sleep_attempts++; - continue; } else { - LOG_warn("failed to enter deep sleep - powering off\n"); + LOG_info("failed to enter deep sleep - powering off\n"); } } if (pwr.can_poweroff) {