summaryrefslogtreecommitdiff
path: root/firmware/powermgmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r--firmware/powermgmt.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index fb2d886042..4c6db6d44c 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -185,7 +185,7 @@ static const short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
185#else /* NiMH */ 185#else /* NiMH */
186 /* original values were taken directly after charging, but it should show 186 /* original values were taken directly after charging, but it should show
187 100% after turning off the device for some hours, too */ 187 100% after turning off the device for some hours, too */
188 { 450, 481, 491, 497, 503, 507, 512, 514, 517, 525, 540 } 188 { 450, 481, 491, 497, 503, 507, 512, 514, 517, 525, 540 }
189 /* orig. values: ...,528,560 */ 189 /* orig. values: ...,528,560 */
190#endif 190#endif
191}; 191};
@@ -197,7 +197,7 @@ charger_input_state_type charger_input_state IDATA_ATTR;
197static const short percent_to_volt_charge[11] = 197static const short percent_to_volt_charge[11] =
198{ 198{
199#if CONFIG_BATTERY == BATT_LIPOL1300 199#if CONFIG_BATTERY == BATT_LIPOL1300
200 /* Calibrated for 1900 mAh Ionity battery (estimated 90% charge when 200 /* Calibrated for 1900 mAh Ionity battery (estimated 90% charge when
201 entering in trickle-charging). We will never reach 100%. */ 201 entering in trickle-charging). We will never reach 100%. */
202 340, 390, 394, 399, 400, 404, 407, 413, 417, 422, 426 202 340, 390, 394, 399, 400, 404, 407, 413, 417, 422, 426
203#else 203#else
@@ -243,11 +243,11 @@ int pid_i = 0; /* PID integral term */
243 */ 243 */
244static unsigned int battery_centivolts;/* filtered battery voltage, centvolts */ 244static unsigned int battery_centivolts;/* filtered battery voltage, centvolts */
245static unsigned int avgbat; /* average battery voltage (filtering) */ 245static unsigned int avgbat; /* average battery voltage (filtering) */
246#define BATT_AVE_SAMPLES 32 /* filter constant / @ 2Hz sample rate */ 246#define BATT_AVE_SAMPLES 32 /* filter constant / @ 2Hz sample rate */
247 247
248/* battery level (0-100%) of this minute, updated once per minute */ 248/* battery level (0-100%) of this minute, updated once per minute */
249static int battery_percent = -1; 249static int battery_percent = -1;
250static int battery_capacity = BATTERY_CAPACITY_MIN; /* default value, mAH */ 250static int battery_capacity = BATTERY_CAPACITY_DEFAULT; /* default value, mAh */
251static int battery_type = 0; 251static int battery_type = 0;
252 252
253/* Power history: power_history[0] is the newest sample */ 253/* Power history: power_history[0] is the newest sample */
@@ -348,7 +348,7 @@ static int voltage_to_percent(int voltage, const short* table)
348 else 348 else
349 if (voltage >= table[10]) 349 if (voltage >= table[10])
350 return 100; 350 return 100;
351 else { 351 else {
352 /* search nearest value */ 352 /* search nearest value */
353 int i = 0; 353 int i = 0;
354 while ((i < 10) && (table[i+1] < voltage)) 354 while ((i < 10) && (table[i+1] < voltage))
@@ -405,7 +405,7 @@ static void battery_status_update(void)
405 else 405 else
406#endif 406#endif
407 { 407 {
408 powermgmt_est_runningtime_min = level * battery_capacity / 100 408 powermgmt_est_runningtime_min = level * battery_capacity / 100
409 * 60 / runcurrent(); 409 * 60 / runcurrent();
410 } 410 }
411} 411}
@@ -515,7 +515,7 @@ static int runcurrent(void)
515 515
516/* Check to see whether or not we've received an alarm in the last second */ 516/* Check to see whether or not we've received an alarm in the last second */
517#ifdef HAVE_ALARM_MOD 517#ifdef HAVE_ALARM_MOD
518static void power_thread_rtc_process(void) 518static void power_thread_rtc_process(void)
519{ 519{
520 if (rtc_check_alarm_flag()) { 520 if (rtc_check_alarm_flag()) {
521 rtc_enable_alarm(false); 521 rtc_enable_alarm(false);
@@ -592,7 +592,7 @@ static void power_thread_sleep(int ticks)
592 } 592 }
593 break; 593 break;
594 } 594 }
595 595
596#endif /* HAVE_CHARGE_STATE */ 596#endif /* HAVE_CHARGE_STATE */
597 597
598 small_ticks = MIN(HZ/2, ticks); 598 small_ticks = MIN(HZ/2, ticks);
@@ -674,7 +674,7 @@ static void power_thread(void)
674 674
675 /* initialize the voltages for the exponential filter */ 675 /* initialize the voltages for the exponential filter */
676 676
677 avgbat = adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR * 677 avgbat = adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR *
678 BATT_AVE_SAMPLES; 678 BATT_AVE_SAMPLES;
679 battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000; 679 battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000;
680 680
@@ -682,7 +682,7 @@ static void power_thread(void)
682 fd = -1; 682 fd = -1;
683 wrcount = 0; 683 wrcount = 0;
684#endif 684#endif
685 685
686 while (1) 686 while (1)
687 { 687 {
688 /* rotate the power history */ 688 /* rotate the power history */
@@ -690,7 +690,7 @@ static void power_thread(void)
690 phps = phpd - 1; 690 phps = phpd - 1;
691 for (i = 0; i < POWER_HISTORY_LEN-1; i++) 691 for (i = 0; i < POWER_HISTORY_LEN-1; i++)
692 *phpd-- = *phps--; 692 *phpd-- = *phps--;
693 693
694 /* insert new value at the start, in centivolts 8-) */ 694 /* insert new value at the start, in centivolts 8-) */
695 power_history[0] = battery_centivolts; 695 power_history[0] = battery_centivolts;
696 696
@@ -732,7 +732,7 @@ static void power_thread(void)
732 } else { 732 } else {
733 charge_state = TOPOFF; 733 charge_state = TOPOFF;
734 target_voltage = TOPOFF_VOLTAGE; 734 target_voltage = TOPOFF_VOLTAGE;
735 } 735 }
736 } else { 736 } else {
737 /* 737 /*
738 * Start the charger full strength 738 * Start the charger full strength
@@ -743,8 +743,8 @@ static void power_thread(void)
743 if (charge_max_time_idle > i) { 743 if (charge_max_time_idle > i) {
744 charge_max_time_idle = i; 744 charge_max_time_idle = i;
745 } 745 }
746 charge_max_time_now = charge_max_time_idle; 746 charge_max_time_now = charge_max_time_idle;
747 747
748 snprintf(power_message, POWER_MESSAGE_LEN, 748 snprintf(power_message, POWER_MESSAGE_LEN,
749 "ChgAt %d%% max %dm", battery_level(), 749 "ChgAt %d%% max %dm", battery_level(),
750 charge_max_time_now); 750 charge_max_time_now);
@@ -895,7 +895,7 @@ static void power_thread(void)
895 * plugged in, but it doesn't appear to be necessary and will 895 * plugged in, but it doesn't appear to be necessary and will
896 * generate more heat [gvb]. 896 * generate more heat [gvb].
897 */ 897 */
898 898
899 pid_p = target_voltage - battery_centivolts; 899 pid_p = target_voltage - battery_centivolts;
900 if((pid_p > PID_DEADZONE) || (pid_p < -PID_DEADZONE)) 900 if((pid_p > PID_DEADZONE) || (pid_p < -PID_DEADZONE))
901 pid_p = pid_p * PID_PCONST; 901 pid_p = pid_p * PID_PCONST;
@@ -980,7 +980,7 @@ static void power_thread(void)
980 } 980 }
981 } 981 }
982 if(fd >= 0) { 982 if(fd >= 0) {
983 snprintf(debug_message, DEBUG_MESSAGE_LEN, 983 snprintf(debug_message, DEBUG_MESSAGE_LEN,
984 "%d, %d, %d, %d, %d, %d, %d, %d\n", 984 "%d, %d, %d, %d, %d, %d, %d, %d\n",
985 powermgmt_last_cycle_startstop_min, battery_centivolts, 985 powermgmt_last_cycle_startstop_min, battery_centivolts,
986 battery_percent, charger_input_state, charge_state, 986 battery_percent, charger_input_state, charge_state,
@@ -1002,7 +1002,7 @@ void powermgmt_init(void)
1002{ 1002{
1003 /* init history to 0 */ 1003 /* init history to 0 */
1004 memset(power_history, 0x00, sizeof(power_history)); 1004 memset(power_history, 0x00, sizeof(power_history));
1005 1005
1006 create_thread(power_thread, power_stack, sizeof(power_stack), 1006 create_thread(power_thread, power_stack, sizeof(power_stack),
1007 power_thread_name); 1007 power_thread_name);
1008} 1008}
@@ -1015,12 +1015,12 @@ void sys_poweroff(void)
1015 /* If the main thread fails to shut down the system, we will force a 1015 /* If the main thread fails to shut down the system, we will force a
1016 power off after an 8 second timeout */ 1016 power off after an 8 second timeout */
1017 shutdown_timeout = HZ*8; 1017 shutdown_timeout = HZ*8;
1018 1018
1019 queue_post(&button_queue, SYS_POWEROFF, NULL); 1019 queue_post(&button_queue, SYS_POWEROFF, NULL);
1020} 1020}
1021 1021
1022/* Various hardware housekeeping tasks relating to shutting down the jukebox */ 1022/* Various hardware housekeeping tasks relating to shutting down the jukebox */
1023void shutdown_hw(void) 1023void shutdown_hw(void)
1024{ 1024{
1025#ifndef SIMULATOR 1025#ifndef SIMULATOR
1026#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) 1026#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL)