diff options
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r-- | firmware/powermgmt.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index c3fa8cb45f..6d6aba523e 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -65,6 +65,8 @@ static int wrcount; | |||
65 | #define DEBUG_STACK 0 | 65 | #define DEBUG_STACK 0 |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | static int shutdown_timeout = 0; | ||
69 | |||
68 | #ifdef SIMULATOR /***********************************************************/ | 70 | #ifdef SIMULATOR /***********************************************************/ |
69 | 71 | ||
70 | int battery_level(void) | 72 | int battery_level(void) |
@@ -392,7 +394,7 @@ static void handle_auto_poweroff(void) | |||
392 | if(TIME_AFTER(current_tick, last_event_tick + timeout) && | 394 | if(TIME_AFTER(current_tick, last_event_tick + timeout) && |
393 | TIME_AFTER(current_tick, last_disk_activity + timeout)) | 395 | TIME_AFTER(current_tick, last_disk_activity + timeout)) |
394 | { | 396 | { |
395 | sys_poweroff(true); | 397 | sys_poweroff(); |
396 | } | 398 | } |
397 | } | 399 | } |
398 | else | 400 | else |
@@ -415,7 +417,7 @@ static void handle_auto_poweroff(void) | |||
415 | #endif | 417 | #endif |
416 | { | 418 | { |
417 | DEBUGF("Sleep timer timeout. Shutting off...\n"); | 419 | DEBUGF("Sleep timer timeout. Shutting off...\n"); |
418 | sys_poweroff(true); | 420 | sys_poweroff(); |
419 | } | 421 | } |
420 | } | 422 | } |
421 | } | 423 | } |
@@ -524,6 +526,14 @@ static void power_thread_sleep(int ticks) | |||
524 | sleep(small_ticks); | 526 | sleep(small_ticks); |
525 | ticks -= small_ticks; | 527 | ticks -= small_ticks; |
526 | 528 | ||
529 | /* If the power off timeout expires, the main thread has failed | ||
530 | to shut down the system, and we need to force a power off */ | ||
531 | if(shutdown_timeout) { | ||
532 | shutdown_timeout -= small_ticks; | ||
533 | if(shutdown_timeout <= 0) | ||
534 | power_off(); | ||
535 | } | ||
536 | |||
527 | #ifdef HAVE_ALARM_MOD | 537 | #ifdef HAVE_ALARM_MOD |
528 | power_thread_rtc_process(); | 538 | power_thread_rtc_process(); |
529 | #endif | 539 | #endif |
@@ -568,9 +578,6 @@ static void power_thread(void) | |||
568 | { | 578 | { |
569 | int i; | 579 | int i; |
570 | short *phps, *phpd; /* power history rotation pointers */ | 580 | short *phps, *phpd; /* power history rotation pointers */ |
571 | #if CONFIG_BATTERY == BATT_LIION2200 | ||
572 | int charging_current; | ||
573 | #endif | ||
574 | #ifdef HAVE_CHARGE_CTRL | 581 | #ifdef HAVE_CHARGE_CTRL |
575 | unsigned int target_voltage; /* desired topoff/trickle voltage level */ | 582 | unsigned int target_voltage; /* desired topoff/trickle voltage level */ |
576 | int charge_max_time_now = 0; /* max. charging duration, calculated at | 583 | int charge_max_time_now = 0; /* max. charging duration, calculated at |
@@ -606,11 +613,10 @@ static void power_thread(void) | |||
606 | tells us the charging current from the LTC1734. When DC is | 613 | tells us the charging current from the LTC1734. When DC is |
607 | connected (either via the external adapter, or via USB), we try | 614 | connected (either via the external adapter, or via USB), we try |
608 | to determine if it is actively charging or only maintaining the | 615 | to determine if it is actively charging or only maintaining the |
609 | charge. My tests show that ADC readings is below about 0x80 means | 616 | charge. My tests show that ADC readings below about 0x80 means |
610 | that the LTC1734 is only maintaining the charge. */ | 617 | that the LTC1734 is only maintaining the charge. */ |
611 | if(charger_inserted()) { | 618 | if(charger_inserted()) { |
612 | charging_current = adc_read(ADC_EXT_POWER); | 619 | if(adc_read(ADC_EXT_POWER) < 0x80) { |
613 | if(charging_current < 0x80) { | ||
614 | charge_state = TRICKLE; | 620 | charge_state = TRICKLE; |
615 | } else { | 621 | } else { |
616 | charge_state = CHARGING; | 622 | charge_state = CHARGING; |
@@ -878,12 +884,14 @@ void powermgmt_init(void) | |||
878 | 884 | ||
879 | #endif /* SIMULATOR */ | 885 | #endif /* SIMULATOR */ |
880 | 886 | ||
881 | void sys_poweroff(bool halt) | 887 | void sys_poweroff(void) |
882 | { | 888 | { |
883 | logf("sys_poweroff(%d)", halt); | 889 | logf("sys_poweroff()"); |
890 | /* If the main thread fails to shut down the system, we will force a | ||
891 | power off after an 8 second timeout */ | ||
892 | shutdown_timeout = HZ*8; | ||
893 | |||
884 | queue_post(&button_queue, SYS_POWEROFF, NULL); | 894 | queue_post(&button_queue, SYS_POWEROFF, NULL); |
885 | while(halt) | ||
886 | yield(); | ||
887 | } | 895 | } |
888 | 896 | ||
889 | /* Various hardware housekeeping tasks relating to shutting down the jukebox */ | 897 | /* Various hardware housekeeping tasks relating to shutting down the jukebox */ |