From 1447668695335d16e8d25b9bcb93f524c1dcc6b4 Mon Sep 17 00:00:00 2001 From: Adam Pippin Date: Fri, 17 Apr 2020 22:40:08 -0700 Subject: [PATCH] Change PowerManagement to signal stop and wait for tasks to exit before sleeping --- PowerManagement.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/PowerManagement.cpp b/PowerManagement.cpp index e6540d8..6f173e5 100644 --- a/PowerManagement.cpp +++ b/PowerManagement.cpp @@ -65,14 +65,18 @@ int PowerManagement(int pid, unsigned int signal) case POWER_STATE_IDLE: if (accumulator > SLEEP_TIMEOUT) { - sleep(); + if (Kernel_count_running_tasks() == 1) + { + sleep(); + } + else + { + Kernel_signal(SIGNAL_STOP); + } } break; } - // TODO: On sleep, signal "STOP" to all tasks and reschedule ourselves more frequently - // Wait until Kernel_count_running == 1, then put chip to sleep - return 0; }