Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions skeleton/SYSTEM/tg5040/bin/suspend
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
15 changes: 5 additions & 10 deletions workspace/all/common/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down