diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-04-16 14:25:49 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-04-16 14:36:39 +0100 |
commit | d55dceff371c4080d179fb26e6f175927cc48768 (patch) | |
tree | 65598ecdc8142d4178b1f8b13dce37e871cc7016 /firmware/powermgmt.c | |
parent | 90960adf56d4798a23b8fdc7e6a9bb25dd0bf530 (diff) | |
download | rockbox-d55dceff371c4080d179fb26e6f175927cc48768.tar.gz rockbox-d55dceff371c4080d179fb26e6f175927cc48768.zip |
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
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r-- | firmware/powermgmt.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 2cafd4b759..c33ad387ae 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -823,7 +823,7 @@ void powermgmt_init(void) | |||
823 | } | 823 | } |
824 | 824 | ||
825 | /* Various hardware housekeeping tasks relating to shutting down the player */ | 825 | /* Various hardware housekeeping tasks relating to shutting down the player */ |
826 | void shutdown_hw(void) | 826 | void shutdown_hw(enum shutdown_type sd_type) |
827 | { | 827 | { |
828 | charging_algorithm_close(); | 828 | charging_algorithm_close(); |
829 | audio_stop(); | 829 | audio_stop(); |
@@ -863,7 +863,17 @@ void shutdown_hw(void) | |||
863 | eeprom chips are quite slow and might be still writing the last | 863 | eeprom chips are quite slow and might be still writing the last |
864 | byte. */ | 864 | byte. */ |
865 | sleep(HZ/4); | 865 | sleep(HZ/4); |
866 | power_off(); | 866 | |
867 | switch (sd_type) { | ||
868 | case SHUTDOWN_POWER_OFF: | ||
869 | default: | ||
870 | power_off(); | ||
871 | break; | ||
872 | |||
873 | case SHUTDOWN_REBOOT: | ||
874 | system_reboot(); | ||
875 | break; | ||
876 | } | ||
867 | } | 877 | } |
868 | 878 | ||
869 | void set_poweroff_timeout(int timeout) | 879 | void set_poweroff_timeout(int timeout) |
@@ -878,10 +888,9 @@ void reset_poweroff_timer(void) | |||
878 | set_sleep_timer(sleeptimer_duration); | 888 | set_sleep_timer(sleeptimer_duration); |
879 | } | 889 | } |
880 | 890 | ||
881 | void sys_poweroff(void) | ||
882 | { | ||
883 | #ifndef BOOTLOADER | 891 | #ifndef BOOTLOADER |
884 | logf("sys_poweroff()"); | 892 | static void sys_shutdown_common(void) |
893 | { | ||
885 | /* If the main thread fails to shut down the system, we will force a | 894 | /* If the main thread fails to shut down the system, we will force a |
886 | power off after an 20 second timeout - 28 seconds if recording */ | 895 | power off after an 20 second timeout - 28 seconds if recording */ |
887 | if (shutdown_timeout == 0) { | 896 | if (shutdown_timeout == 0) { |
@@ -899,9 +908,26 @@ void sys_poweroff(void) | |||
899 | shutdown_timeout += HZ*20; | 908 | shutdown_timeout += HZ*20; |
900 | #endif | 909 | #endif |
901 | } | 910 | } |
911 | } | ||
912 | #endif /* BOOTLOADER */ | ||
902 | 913 | ||
914 | void sys_poweroff(void) | ||
915 | { | ||
916 | #ifndef BOOTLOADER | ||
917 | logf("sys_poweroff()"); | ||
918 | sys_shutdown_common(); | ||
903 | queue_broadcast(SYS_POWEROFF, 0); | 919 | queue_broadcast(SYS_POWEROFF, 0); |
904 | #endif /* BOOTLOADER */ | 920 | #endif |
921 | } | ||
922 | |||
923 | /* not to be confused with system_reboot... :( */ | ||
924 | void sys_reboot(void) | ||
925 | { | ||
926 | #ifndef BOOTLOADER | ||
927 | logf("sys_reboot()"); | ||
928 | sys_shutdown_common(); | ||
929 | queue_broadcast(SYS_REBOOT, 0); | ||
930 | #endif | ||
905 | } | 931 | } |
906 | 932 | ||
907 | void cancel_shutdown(void) | 933 | void cancel_shutdown(void) |