1
0
Fork 0
forked from len0rd/rockbox

apps: Add ability to do a clean reboot

Allow a clean shutdown to end in either power off or reboot. Add a
new event SYS_REBOOT to signal it and sys_reboot() to trigger the
event. SYS_REBOOT signals a reboot request and should be listened
for alongside SYS_POWEROFF events.

Change-Id: I99ba7fb5feed2bb5a0a40a274e8466ad74fe3a43
This commit is contained in:
Aidan MacDonald 2022-04-16 14:25:49 +01:00
parent 90960adf56
commit d55dceff37
15 changed files with 72 additions and 14 deletions

View file

@ -668,6 +668,7 @@ void backlight_thread(void)
#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
#endif /* HAVE_BUTTON_LIGHT */
case SYS_REBOOT:
case SYS_POWEROFF: /* Lock backlight on poweroff so it doesn't */
locked = true; /* go off before power is actually cut. */
#if !defined(BOOTLOADER)

View file

@ -70,6 +70,12 @@ extern unsigned int power_thread_inputs;
#endif /* CONFIG_CHARGING */
enum shutdown_type
{
SHUTDOWN_POWER_OFF,
SHUTDOWN_REBOOT,
};
#if CONFIG_CHARGING == CHARGING_TARGET
/* Include target-specific definitions */
#include "powermgmt-target.h"
@ -164,8 +170,9 @@ void handle_auto_poweroff(void);
void set_car_adapter_mode(bool setting);
void reset_poweroff_timer(void);
void cancel_shutdown(void);
void shutdown_hw(void);
void shutdown_hw(enum shutdown_type sd_type);
void sys_poweroff(void);
void sys_reboot(void);
/* Returns true if the system should force shutdown for some reason -
* eg. low battery */
bool query_force_shutdown(void);

View file

@ -58,6 +58,7 @@
#define SYS_CHARGER_CONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 1)
#define SYS_CHARGER_DISCONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 2)
#define SYS_BATTERY_UPDATE MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 3)
#define SYS_REBOOT MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 4)
#define SYS_FS_CHANGED MAKE_SYS_EVENT(SYS_EVENT_CLS_FILESYS, 0)
#define SYS_HOTSWAP_INSERTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 0)
#define SYS_HOTSWAP_EXTRACTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 1)

View file

@ -823,7 +823,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 +863,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 +888,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 +908,26 @@ void sys_poweroff(void)
shutdown_timeout += HZ*20;
#endif
}
queue_broadcast(SYS_POWEROFF, 0);
}
#endif /* BOOTLOADER */
void sys_poweroff(void)
{
#ifndef BOOTLOADER
logf("sys_poweroff()");
sys_shutdown_common();
queue_broadcast(SYS_POWEROFF, 0);
#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)