diff options
author | Thomas Jarosch <tomj@simonv.com> | 2011-03-08 19:33:25 +0000 |
---|---|---|
committer | Thomas Jarosch <tomj@simonv.com> | 2011-03-08 19:33:25 +0000 |
commit | 2ebe370ca1e4b5297cc1240b3b11e15ff168a184 (patch) | |
tree | 2d348abb3ccb0ad56479b088e4880c065de74c5b | |
parent | cbf889d3e2cbed5e1476b292137a5a43e75c941b (diff) | |
download | rockbox-2ebe370ca1e4b5297cc1240b3b11e15ff168a184.tar.gz rockbox-2ebe370ca1e4b5297cc1240b3b11e15ff168a184.zip |
Move handle_auto_poweroff() down so RaaA can call it.
Add two ifdefs needed for APPLICATION builds
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29542 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/powermgmt.c | 113 |
1 files changed, 60 insertions, 53 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index b0fea5949f..b1a08bff29 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -81,6 +81,10 @@ enum charge_state_type charge_state = DISCHARGING; | |||
81 | 81 | ||
82 | static int shutdown_timeout = 0; | 82 | static int shutdown_timeout = 0; |
83 | 83 | ||
84 | static void handle_auto_poweroff(void); | ||
85 | static int poweroff_timeout = 0; | ||
86 | static long last_event_tick; | ||
87 | |||
84 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | 88 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) |
85 | /* | 89 | /* |
86 | * Average battery voltage and charger voltage, filtered via a digital | 90 | * Average battery voltage and charger voltage, filtered via a digital |
@@ -110,11 +114,8 @@ static char power_stack[DEFAULT_STACK_SIZE/2 + POWERMGMT_DEBUG_STACK]; | |||
110 | #endif | 114 | #endif |
111 | static const char power_thread_name[] = "power"; | 115 | static const char power_thread_name[] = "power"; |
112 | 116 | ||
113 | static int poweroff_timeout = 0; | ||
114 | static int powermgmt_est_runningtime_min = -1; | 117 | static int powermgmt_est_runningtime_min = -1; |
115 | 118 | ||
116 | static long last_event_tick; | ||
117 | |||
118 | static int voltage_to_battery_level(int battery_millivolts); | 119 | static int voltage_to_battery_level(int battery_millivolts); |
119 | static void battery_status_update(void); | 120 | static void battery_status_update(void); |
120 | 121 | ||
@@ -288,56 +289,6 @@ static void battery_status_update(void) | |||
288 | send_battery_level_event(); | 289 | send_battery_level_event(); |
289 | } | 290 | } |
290 | 291 | ||
291 | /* | ||
292 | * We shut off in the following cases: | ||
293 | * 1) The unit is idle, not playing music | ||
294 | * 2) The unit is playing music, but is paused | ||
295 | * 3) The battery level has reached shutdown limit | ||
296 | * | ||
297 | * We do not shut off in the following cases: | ||
298 | * 1) The USB is connected | ||
299 | * 2) The charger is connected | ||
300 | * 3) We are recording, or recording with pause | ||
301 | * 4) The radio is playing | ||
302 | */ | ||
303 | static void handle_auto_poweroff(void) | ||
304 | { | ||
305 | long timeout = poweroff_timeout*60*HZ; | ||
306 | int audio_stat = audio_status(); | ||
307 | long tick = current_tick; | ||
308 | |||
309 | #if CONFIG_CHARGING | ||
310 | /* | ||
311 | * Inhibit shutdown as long as the charger is plugged in. If it is | ||
312 | * unplugged, wait for a timeout period and then shut down. | ||
313 | */ | ||
314 | if (charger_input_state == CHARGER || audio_stat == AUDIO_STATUS_PLAY) { | ||
315 | last_event_tick = current_tick; | ||
316 | } | ||
317 | #endif | ||
318 | |||
319 | if (!shutdown_timeout && query_force_shutdown()) { | ||
320 | backlight_on(); | ||
321 | sys_poweroff(); | ||
322 | } | ||
323 | |||
324 | if (timeout && | ||
325 | #if CONFIG_TUNER | ||
326 | !(get_radio_status() & FMRADIO_PLAYING) && | ||
327 | #endif | ||
328 | !usb_inserted() && | ||
329 | (audio_stat == 0 || | ||
330 | (audio_stat == (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE) && | ||
331 | !sleeptimer_active))) { | ||
332 | |||
333 | if (TIME_AFTER(tick, last_event_tick + timeout) && | ||
334 | TIME_AFTER(tick, storage_last_disk_activity() + timeout)) { | ||
335 | sys_poweroff(); | ||
336 | } | ||
337 | } else | ||
338 | handle_sleep_timer(); | ||
339 | } | ||
340 | |||
341 | #ifdef CURRENT_NORMAL /*check that we have a current defined in a config file*/ | 292 | #ifdef CURRENT_NORMAL /*check that we have a current defined in a config file*/ |
342 | 293 | ||
343 | /* | 294 | /* |
@@ -865,3 +816,59 @@ void handle_sleep_timer(void) | |||
865 | } | 816 | } |
866 | } | 817 | } |
867 | } | 818 | } |
819 | |||
820 | |||
821 | /* | ||
822 | * We shut off in the following cases: | ||
823 | * 1) The unit is idle, not playing music | ||
824 | * 2) The unit is playing music, but is paused | ||
825 | * 3) The battery level has reached shutdown limit | ||
826 | * | ||
827 | * We do not shut off in the following cases: | ||
828 | * 1) The USB is connected | ||
829 | * 2) The charger is connected | ||
830 | * 3) We are recording, or recording with pause | ||
831 | * 4) The radio is playing | ||
832 | */ | ||
833 | static void handle_auto_poweroff(void) | ||
834 | { | ||
835 | long timeout = poweroff_timeout*60*HZ; | ||
836 | int audio_stat = audio_status(); | ||
837 | long tick = current_tick; | ||
838 | |||
839 | #if CONFIG_CHARGING | ||
840 | /* | ||
841 | * Inhibit shutdown as long as the charger is plugged in. If it is | ||
842 | * unplugged, wait for a timeout period and then shut down. | ||
843 | */ | ||
844 | if (charger_input_state == CHARGER || audio_stat == AUDIO_STATUS_PLAY) { | ||
845 | last_event_tick = current_tick; | ||
846 | } | ||
847 | #endif | ||
848 | |||
849 | #ifndef APPLICATION | ||
850 | if (!shutdown_timeout && query_force_shutdown()) { | ||
851 | backlight_on(); | ||
852 | sys_poweroff(); | ||
853 | } | ||
854 | #endif | ||
855 | |||
856 | if (timeout && | ||
857 | #if CONFIG_TUNER | ||
858 | !(get_radio_status() & FMRADIO_PLAYING) && | ||
859 | #endif | ||
860 | !usb_inserted() && | ||
861 | (audio_stat == 0 || | ||
862 | (audio_stat == (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE) && | ||
863 | !sleeptimer_active))) { | ||
864 | |||
865 | if (TIME_AFTER(tick, last_event_tick + timeout) | ||
866 | #ifndef APPLICATION | ||
867 | && TIME_AFTER(tick, storage_last_disk_activity() + timeout) | ||
868 | #endif | ||
869 | ) { | ||
870 | sys_poweroff(); | ||
871 | } | ||
872 | } else | ||
873 | handle_sleep_timer(); | ||
874 | } | ||