summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/iap/iap-core.c1
-rw-r--r--apps/misc.c18
-rw-r--r--apps/plugins/battery_bench.c1
-rw-r--r--apps/plugins/chessbox/chessbox.c3
-rw-r--r--apps/plugins/lastfm_scrobbler.c1
-rw-r--r--apps/plugins/lua/rocklib.c1
-rw-r--r--apps/plugins/mpegplayer/mpeg_misc.c1
-rw-r--r--apps/plugins/plugin_crt0.c3
-rw-r--r--apps/plugins/solitaire.c1
-rw-r--r--apps/recorder/recording.c3
-rw-r--r--apps/tagcache.c2
-rw-r--r--firmware/backlight.c1
-rw-r--r--firmware/export/powermgmt.h9
-rw-r--r--firmware/kernel/include/queue.h1
-rw-r--r--firmware/powermgmt.c38
15 files changed, 71 insertions, 13 deletions
diff --git a/apps/iap/iap-core.c b/apps/iap/iap-core.c
index 885ba2c188..ae05806ae9 100644
--- a/apps/iap/iap-core.c
+++ b/apps/iap/iap-core.c
@@ -364,6 +364,7 @@ static void iap_thread(void)
364 364
365 /* Handle poweroff message */ 365 /* Handle poweroff message */
366 case SYS_POWEROFF: 366 case SYS_POWEROFF:
367 case SYS_REBOOT:
367 { 368 {
368 iap_shutdown = true; 369 iap_shutdown = true;
369 break; 370 break;
diff --git a/apps/misc.c b/apps/misc.c
index 4d8c2e975a..d5e8bb5d98 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -288,7 +288,8 @@ static void system_restore(void)
288 tree_restore(); 288 tree_restore();
289} 289}
290 290
291static bool clean_shutdown(void (*callback)(void *), void *parameter) 291static bool clean_shutdown(enum shutdown_type sd_type,
292 void (*callback)(void *), void *parameter)
292{ 293{
293 long msg_id = -1; 294 long msg_id = -1;
294 295
@@ -392,7 +393,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
392 voice_wait(); 393 voice_wait();
393 } 394 }
394 395
395 shutdown_hw(); 396 shutdown_hw(sd_type);
396 } 397 }
397 return false; 398 return false;
398} 399}
@@ -605,8 +606,17 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame
605 return SYS_USB_CONNECTED; 606 return SYS_USB_CONNECTED;
606 607
607 case SYS_POWEROFF: 608 case SYS_POWEROFF:
608 if (!clean_shutdown(callback, parameter)) 609 case SYS_REBOOT:
609 return SYS_POWEROFF; 610 {
611 enum shutdown_type sd_type;
612 if (event == SYS_POWEROFF)
613 sd_type = SHUTDOWN_POWER_OFF;
614 else
615 sd_type = SHUTDOWN_REBOOT;
616
617 if (!clean_shutdown(sd_type, callback, parameter))
618 return event;
619 }
610 break; 620 break;
611#if CONFIG_CHARGING 621#if CONFIG_CHARGING
612 case SYS_CHARGER_CONNECTED: 622 case SYS_CHARGER_CONNECTED:
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c
index d8e29d73ca..17d3b918cf 100644
--- a/apps/plugins/battery_bench.c
+++ b/apps/plugins/battery_bench.c
@@ -462,6 +462,7 @@ static void thread(void)
462 in_usb_mode = false; 462 in_usb_mode = false;
463 break; 463 break;
464 case SYS_POWEROFF: 464 case SYS_POWEROFF:
465 case SYS_REBOOT:
465 exit_reason = "power off"; 466 exit_reason = "power off";
466 exit = true; 467 exit = true;
467 break; 468 break;
diff --git a/apps/plugins/chessbox/chessbox.c b/apps/plugins/chessbox/chessbox.c
index 13df4f177e..089cf7c400 100644
--- a/apps/plugins/chessbox/chessbox.c
+++ b/apps/plugins/chessbox/chessbox.c
@@ -222,6 +222,7 @@ static void cb_wt_callback ( void ) {
222 button = rb->button_get(false); 222 button = rb->button_get(false);
223 switch (button) { 223 switch (button) {
224 case SYS_POWEROFF: 224 case SYS_POWEROFF:
225 case SYS_REBOOT:
225 cb_sysevent = button; 226 cb_sysevent = button;
226#ifdef CB_RC_QUIT 227#ifdef CB_RC_QUIT
227 case CB_RC_QUIT: 228 case CB_RC_QUIT:
@@ -585,6 +586,7 @@ static struct cb_command cb_get_viewer_command (void) {
585 button = rb->button_get(true); 586 button = rb->button_get(true);
586 switch (button) { 587 switch (button) {
587 case SYS_POWEROFF: 588 case SYS_POWEROFF:
589 case SYS_REBOOT:
588 cb_sysevent = button; 590 cb_sysevent = button;
589#ifdef CB_RC_QUIT 591#ifdef CB_RC_QUIT
590 case CB_RC_QUIT: 592 case CB_RC_QUIT:
@@ -848,6 +850,7 @@ static struct cb_command cb_getcommand (void) {
848 button = rb->button_get(true); 850 button = rb->button_get(true);
849 switch (button) { 851 switch (button) {
850 case SYS_POWEROFF: 852 case SYS_POWEROFF:
853 case SYS_REBOOT:
851 cb_sysevent = button; 854 cb_sysevent = button;
852#ifdef CB_RC_QUIT 855#ifdef CB_RC_QUIT
853 case CB_RC_QUIT: 856 case CB_RC_QUIT:
diff --git a/apps/plugins/lastfm_scrobbler.c b/apps/plugins/lastfm_scrobbler.c
index 4d4940945d..7bd213b6d2 100644
--- a/apps/plugins/lastfm_scrobbler.c
+++ b/apps/plugins/lastfm_scrobbler.c
@@ -490,6 +490,7 @@ void thread(void)
490 rb->beep_play(1500, 100, 1000); 490 rb->beep_play(1500, 100, 1000);
491 break; 491 break;
492 case SYS_POWEROFF: 492 case SYS_POWEROFF:
493 case SYS_REBOOT:
493 gCache.force_flush = true; 494 gCache.force_flush = true;
494 /*fall through*/ 495 /*fall through*/
495 case EV_EXIT: 496 case EV_EXIT:
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 6131a479db..cadc8be6ac 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -1090,6 +1090,7 @@ LUALIB_API int luaopen_rock(lua_State *L)
1090 RB_CONSTANT(SYS_USB_DISCONNECTED), 1090 RB_CONSTANT(SYS_USB_DISCONNECTED),
1091 RB_CONSTANT(SYS_TIMEOUT), 1091 RB_CONSTANT(SYS_TIMEOUT),
1092 RB_CONSTANT(SYS_POWEROFF), 1092 RB_CONSTANT(SYS_POWEROFF),
1093 RB_CONSTANT(SYS_REBOOT),
1093 RB_CONSTANT(SYS_CHARGER_CONNECTED), 1094 RB_CONSTANT(SYS_CHARGER_CONNECTED),
1094 RB_CONSTANT(SYS_CHARGER_DISCONNECTED), 1095 RB_CONSTANT(SYS_CHARGER_DISCONNECTED),
1095 1096
diff --git a/apps/plugins/mpegplayer/mpeg_misc.c b/apps/plugins/mpegplayer/mpeg_misc.c
index c85285f4f8..31f0644212 100644
--- a/apps/plugins/mpegplayer/mpeg_misc.c
+++ b/apps/plugins/mpegplayer/mpeg_misc.c
@@ -192,6 +192,7 @@ int mpeg_sysevent_callback(int btn,
192 { 192 {
193 case SYS_USB_CONNECTED: 193 case SYS_USB_CONNECTED:
194 case SYS_POWEROFF: 194 case SYS_POWEROFF:
195 case SYS_REBOOT:
195 mpeg_sysevent_id = btn; 196 mpeg_sysevent_id = btn;
196 return ACTION_STD_CANCEL; 197 return ACTION_STD_CANCEL;
197 } 198 }
diff --git a/apps/plugins/plugin_crt0.c b/apps/plugins/plugin_crt0.c
index 680bb0723d..5564c5575f 100644
--- a/apps/plugins/plugin_crt0.c
+++ b/apps/plugins/plugin_crt0.c
@@ -141,6 +141,7 @@ void exit_on_usb(int button)
141 long result = rb->default_event_handler_ex(button, cleanup_wrapper, NULL); 141 long result = rb->default_event_handler_ex(button, cleanup_wrapper, NULL);
142 if (result == SYS_USB_CONNECTED) 142 if (result == SYS_USB_CONNECTED)
143 _exit(PLUGIN_USB_CONNECTED); 143 _exit(PLUGIN_USB_CONNECTED);
144 else if (result == SYS_POWEROFF) 144 else if (result == SYS_POWEROFF || result == SYS_REBOOT)
145 /* note: nobody actually pays attention to this exit code */
145 _exit(PLUGIN_POWEROFF); 146 _exit(PLUGIN_POWEROFF);
146} 147}
diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c
index b1ede16f90..ebc042f6db 100644
--- a/apps/plugins/solitaire.c
+++ b/apps/plugins/solitaire.c
@@ -2149,6 +2149,7 @@ static int solitaire( int skipmenu )
2149 break; 2149 break;
2150 2150
2151 case SYS_POWEROFF: 2151 case SYS_POWEROFF:
2152 case SYS_REBOOT:
2152 return SOLITAIRE_SAVE_AND_QUIT; 2153 return SOLITAIRE_SAVE_AND_QUIT;
2153 2154
2154 default: 2155 default:
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c
index b973d9750c..a54b762566 100644
--- a/apps/recorder/recording.c
+++ b/apps/recorder/recording.c
@@ -1534,7 +1534,8 @@ bool recording_screen(bool no_source)
1534 break; 1534 break;
1535 1535
1536 case SYS_POWEROFF: 1536 case SYS_POWEROFF:
1537 default_event_handler(SYS_POWEROFF); 1537 case SYS_REBOOT:
1538 default_event_handler(button);
1538 done = true; 1539 done = true;
1539 break; 1540 break;
1540 1541
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 8bc742112b..c18380854e 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -3989,6 +3989,7 @@ static bool check_event_queue(void)
3989 { 3989 {
3990 case Q_STOP_SCAN: 3990 case Q_STOP_SCAN:
3991 case SYS_POWEROFF: 3991 case SYS_POWEROFF:
3992 case SYS_REBOOT:
3992 case SYS_USB_CONNECTED: 3993 case SYS_USB_CONNECTED:
3993 return true; 3994 return true;
3994 } 3995 }
@@ -4944,6 +4945,7 @@ static void tagcache_thread(void)
4944 break ; 4945 break ;
4945 4946
4946 case SYS_POWEROFF: 4947 case SYS_POWEROFF:
4948 case SYS_REBOOT:
4947 break ; 4949 break ;
4948 4950
4949 case SYS_USB_CONNECTED: 4951 case SYS_USB_CONNECTED:
diff --git a/firmware/backlight.c b/firmware/backlight.c
index 1284db4659..9575ecdc22 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -668,6 +668,7 @@ void backlight_thread(void)
668#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ 668#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
669#endif /* HAVE_BUTTON_LIGHT */ 669#endif /* HAVE_BUTTON_LIGHT */
670 670
671 case SYS_REBOOT:
671 case SYS_POWEROFF: /* Lock backlight on poweroff so it doesn't */ 672 case SYS_POWEROFF: /* Lock backlight on poweroff so it doesn't */
672 locked = true; /* go off before power is actually cut. */ 673 locked = true; /* go off before power is actually cut. */
673#if !defined(BOOTLOADER) 674#if !defined(BOOTLOADER)
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index 3095d2c97b..6ae5ccfd13 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -70,6 +70,12 @@ extern unsigned int power_thread_inputs;
70 70
71#endif /* CONFIG_CHARGING */ 71#endif /* CONFIG_CHARGING */
72 72
73enum shutdown_type
74{
75 SHUTDOWN_POWER_OFF,
76 SHUTDOWN_REBOOT,
77};
78
73#if CONFIG_CHARGING == CHARGING_TARGET 79#if CONFIG_CHARGING == CHARGING_TARGET
74/* Include target-specific definitions */ 80/* Include target-specific definitions */
75#include "powermgmt-target.h" 81#include "powermgmt-target.h"
@@ -164,8 +170,9 @@ void handle_auto_poweroff(void);
164void set_car_adapter_mode(bool setting); 170void set_car_adapter_mode(bool setting);
165void reset_poweroff_timer(void); 171void reset_poweroff_timer(void);
166void cancel_shutdown(void); 172void cancel_shutdown(void);
167void shutdown_hw(void); 173void shutdown_hw(enum shutdown_type sd_type);
168void sys_poweroff(void); 174void sys_poweroff(void);
175void sys_reboot(void);
169/* Returns true if the system should force shutdown for some reason - 176/* Returns true if the system should force shutdown for some reason -
170 * eg. low battery */ 177 * eg. low battery */
171bool query_force_shutdown(void); 178bool query_force_shutdown(void);
diff --git a/firmware/kernel/include/queue.h b/firmware/kernel/include/queue.h
index 515a7e43a8..6740b88760 100644
--- a/firmware/kernel/include/queue.h
+++ b/firmware/kernel/include/queue.h
@@ -58,6 +58,7 @@
58#define SYS_CHARGER_CONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 1) 58#define SYS_CHARGER_CONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 1)
59#define SYS_CHARGER_DISCONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 2) 59#define SYS_CHARGER_DISCONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 2)
60#define SYS_BATTERY_UPDATE MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 3) 60#define SYS_BATTERY_UPDATE MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 3)
61#define SYS_REBOOT MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 4)
61#define SYS_FS_CHANGED MAKE_SYS_EVENT(SYS_EVENT_CLS_FILESYS, 0) 62#define SYS_FS_CHANGED MAKE_SYS_EVENT(SYS_EVENT_CLS_FILESYS, 0)
62#define SYS_HOTSWAP_INSERTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 0) 63#define SYS_HOTSWAP_INSERTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 0)
63#define SYS_HOTSWAP_EXTRACTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 1) 64#define SYS_HOTSWAP_EXTRACTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 1)
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 */
826void shutdown_hw(void) 826void 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
869void set_poweroff_timeout(int timeout) 879void 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
881void sys_poweroff(void)
882{
883#ifndef BOOTLOADER 891#ifndef BOOTLOADER
884 logf("sys_poweroff()"); 892static 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
914void 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... :( */
924void 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
907void cancel_shutdown(void) 933void cancel_shutdown(void)