summaryrefslogtreecommitdiffstats
path: root/firmware/powermgmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r--firmware/powermgmt.c61
1 files changed, 43 insertions, 18 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 2cafd4b759..95763dc950 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -190,18 +190,6 @@ int battery_current(void)
int current = CURRENT_NORMAL;
#ifndef BOOTLOADER
- if (usb_inserted()
-#ifdef HAVE_USB_POWER
- #if (CURRENT_USB < CURRENT_NORMAL)
- || usb_powered_only()
- #else
- && !usb_powered_only()
- #endif
-#endif
- ) {
- current = CURRENT_USB;
- }
-
#if defined(HAVE_BACKLIGHT) && defined(CURRENT_BACKLIGHT)
if (backlight_get_current_timeout() == 0) /* LED always on */
current += CURRENT_BACKLIGHT;
@@ -512,6 +500,12 @@ static void power_thread_rtc_process(void)
/* switch off unit if battery level is too low for reliable operation */
bool query_force_shutdown(void)
{
+#if CONFIG_CHARGING
+ /* It doesn't make sense to force shutdown when externally powered. */
+ if (power_input_present())
+ return false;
+#endif
+
#if defined(NO_LOW_BATTERY_SHUTDOWN)
return false;
#elif CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE
@@ -823,7 +817,7 @@ void powermgmt_init(void)
}
/* Various hardware housekeeping tasks relating to shutting down the player */
-void shutdown_hw(void)
+void shutdown_hw(enum shutdown_type sd_type)
{
charging_algorithm_close();
audio_stop();
@@ -863,7 +857,17 @@ void shutdown_hw(void)
eeprom chips are quite slow and might be still writing the last
byte. */
sleep(HZ/4);
- power_off();
+
+ switch (sd_type) {
+ case SHUTDOWN_POWER_OFF:
+ default:
+ power_off();
+ break;
+
+ case SHUTDOWN_REBOOT:
+ system_reboot();
+ break;
+ }
}
void set_poweroff_timeout(int timeout)
@@ -878,10 +882,9 @@ void reset_poweroff_timer(void)
set_sleep_timer(sleeptimer_duration);
}
-void sys_poweroff(void)
-{
#ifndef BOOTLOADER
- logf("sys_poweroff()");
+static void sys_shutdown_common(void)
+{
/* If the main thread fails to shut down the system, we will force a
power off after an 20 second timeout - 28 seconds if recording */
if (shutdown_timeout == 0) {
@@ -899,9 +902,26 @@ void sys_poweroff(void)
shutdown_timeout += HZ*20;
#endif
}
+}
+#endif /* BOOTLOADER */
+void sys_poweroff(void)
+{
+#ifndef BOOTLOADER
+ logf("sys_poweroff()");
+ sys_shutdown_common();
queue_broadcast(SYS_POWEROFF, 0);
-#endif /* BOOTLOADER */
+#endif
+}
+
+/* not to be confused with system_reboot... :( */
+void sys_reboot(void)
+{
+#ifndef BOOTLOADER
+ logf("sys_reboot()");
+ sys_shutdown_common();
+ queue_broadcast(SYS_REBOOT, 0);
+#endif
}
void cancel_shutdown(void)
@@ -935,6 +955,11 @@ static void set_sleep_timer(int seconds)
sleeptimer_duration = seconds;
}
+bool get_sleep_timer_active(void)
+{
+ return sleeptimer_active;
+}
+
int get_sleep_timer(void)
{
if (sleeptimer_active && (sleeptimer_endtick >= current_tick))