diff options
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r-- | firmware/powermgmt.c | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index c1a546af72..bcf0659585 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * \/ \/ \/ \/ \/ | 7 | * \/ \/ \/ \/ \/ |
8 | * $Id$ | 8 | * $Id$ |
9 | * | 9 | * |
10 | * Copyright (C) 2002 by Heikki Hannikainen | 10 | * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese |
11 | * | 11 | * |
12 | * All files in this archive are subject to the GNU General Public License. | 12 | * All files in this archive are subject to the GNU General Public License. |
13 | * See the file COPYING in the source tree root for full license agreement. | 13 | * See the file COPYING in the source tree root for full license agreement. |
@@ -99,6 +99,7 @@ char charge_restart_level = CHARGE_RESTART_HI; | |||
99 | int powermgmt_last_cycle_startstop_min = 20; /* how many minutes ago was the charging started or stopped? */ | 99 | int powermgmt_last_cycle_startstop_min = 20; /* how many minutes ago was the charging started or stopped? */ |
100 | int powermgmt_last_cycle_level = 0; /* which level had the batteries at this time? */ | 100 | int powermgmt_last_cycle_level = 0; /* which level had the batteries at this time? */ |
101 | int trickle_sec = 0; /* how many seconds should the charger be enabled per minute for trickle charging? */ | 101 | int trickle_sec = 0; /* how many seconds should the charger be enabled per minute for trickle charging? */ |
102 | int charge_state = 0; /* at the beginning, the charger does nothing */ | ||
102 | #endif | 103 | #endif |
103 | 104 | ||
104 | 105 | ||
@@ -292,7 +293,6 @@ static void power_thread(void) | |||
292 | int charged_time = 0; | 293 | int charged_time = 0; |
293 | int charge_max_time_now = 0; | 294 | int charge_max_time_now = 0; |
294 | int charge_pause = 0; /* no charging pause at the beginning */ | 295 | int charge_pause = 0; /* no charging pause at the beginning */ |
295 | bool trickle_enabled = false; /* enable trickle charging only after a complete charging cycle */ | ||
296 | int trickle_time = 0; /* how many minutes trickle charging already? */ | 296 | int trickle_time = 0; /* how many minutes trickle charging already? */ |
297 | #endif | 297 | #endif |
298 | 298 | ||
@@ -372,6 +372,7 @@ static void power_thread(void) | |||
372 | /* disable charging for several hours from this point, just to be sure */ | 372 | /* disable charging for several hours from this point, just to be sure */ |
373 | charge_pause = CHARGE_PAUSE_LEN; | 373 | charge_pause = CHARGE_PAUSE_LEN; |
374 | /* no trickle charge here, because the charging cycle didn't end the right way */ | 374 | /* no trickle charge here, because the charging cycle didn't end the right way */ |
375 | charge_state = 0; /* 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */ | ||
375 | } else { | 376 | } else { |
376 | if (charged_time > CHARGE_MIN_TIME) { | 377 | if (charged_time > CHARGE_MIN_TIME) { |
377 | /* have charged continuously over the minimum charging time, | 378 | /* have charged continuously over the minimum charging time, |
@@ -396,9 +397,11 @@ static void power_thread(void) | |||
396 | /* disable charging for several hours from this point, just to be sure */ | 397 | /* disable charging for several hours from this point, just to be sure */ |
397 | charge_pause = CHARGE_PAUSE_LEN; | 398 | charge_pause = CHARGE_PAUSE_LEN; |
398 | /* enable trickle charging */ | 399 | /* enable trickle charging */ |
399 | trickle_enabled = true; | 400 | if (global_settings.trickle_charge) { |
400 | trickle_sec = CURRENT_NORMAL * 60 / CURRENT_CHARGING; /* first guess, maybe consider if LED backlight is on, disk is active,... */ | 401 | trickle_sec = CURRENT_NORMAL * 60 / CURRENT_CHARGING; /* first guess, maybe consider if LED backlight is on, disk is active,... */ |
401 | trickle_time = 0; | 402 | trickle_time = 0; |
403 | charge_state = 2; /* 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */ | ||
404 | } | ||
402 | } else { | 405 | } else { |
403 | /* if we didn't disable the charger in the previous test, check for low positive delta */ | 406 | /* if we didn't disable the charger in the previous test, check for low positive delta */ |
404 | delta = ( power_history[POWER_HISTORY_LEN-1] * 100 | 407 | delta = ( power_history[POWER_HISTORY_LEN-1] * 100 |
@@ -416,9 +419,11 @@ static void power_thread(void) | |||
416 | /* disable charging for several hours from this point, just to be sure */ | 419 | /* disable charging for several hours from this point, just to be sure */ |
417 | charge_pause = CHARGE_PAUSE_LEN; | 420 | charge_pause = CHARGE_PAUSE_LEN; |
418 | /* enable trickle charging */ | 421 | /* enable trickle charging */ |
419 | trickle_enabled = true; | 422 | if (global_settings.trickle_charge) { |
420 | trickle_sec = CURRENT_NORMAL * 60 / CURRENT_CHARGING; /* first guess, maybe consider if LED backlight is on, disk is active,... */ | 423 | trickle_sec = CURRENT_NORMAL * 60 / CURRENT_CHARGING; /* first guess, maybe consider if LED backlight is on, disk is active,... */ |
421 | trickle_time = 0; | 424 | trickle_time = 0; |
425 | charge_state = 2; /* 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */ | ||
426 | } | ||
422 | } | 427 | } |
423 | } | 428 | } |
424 | } | 429 | } |
@@ -426,12 +431,10 @@ static void power_thread(void) | |||
426 | } else { /* charged inserted but not enabled */ | 431 | } else { /* charged inserted but not enabled */ |
427 | 432 | ||
428 | /* trickle charging */ | 433 | /* trickle charging */ |
429 | if (trickle_enabled) { | 434 | if (charge_state > 1) { /* top off or trickle? */ |
430 | /* adjust trickle charge time */ | 435 | /* adjust trickle charge time */ |
431 | if ( ((trickle_time <= TOPOFF_MAX_TIME) | 436 | if ( ((charge_state == 2) && (power_history[POWER_HISTORY_LEN-1] > TOPOFF_VOLTAGE)) |
432 | && (power_history[POWER_HISTORY_LEN-1] > TOPOFF_VOLTAGE)) | 437 | || ((charge_state == 3) && (power_history[POWER_HISTORY_LEN-1] > TRICKLE_VOLTAGE)) ) { /* charging too much */ |
433 | || ((trickle_time > TOPOFF_MAX_TIME) | ||
434 | && (power_history[POWER_HISTORY_LEN-1] > TRICKLE_VOLTAGE)) ) { /* charging too much */ | ||
435 | trickle_sec--; | 438 | trickle_sec--; |
436 | } else { /* charging too less */ | 439 | } else { /* charging too less */ |
437 | trickle_sec++; | 440 | trickle_sec++; |
@@ -448,9 +451,12 @@ static void power_thread(void) | |||
448 | /* trickle charging long enough? */ | 451 | /* trickle charging long enough? */ |
449 | 452 | ||
450 | if (trickle_time++ > TRICKLE_MAX_TIME + TOPOFF_MAX_TIME) { | 453 | if (trickle_time++ > TRICKLE_MAX_TIME + TOPOFF_MAX_TIME) { |
451 | trickle_enabled = false; | ||
452 | trickle_sec = 0; /* show in debug menu that trickle is off */ | 454 | trickle_sec = 0; /* show in debug menu that trickle is off */ |
455 | charge_state = 0; /* 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */ | ||
453 | } | 456 | } |
457 | |||
458 | if ((charge_state == 2) && (trickle_time > TOPOFF_MAX_TIME)) /* change state? */ | ||
459 | charge_state = 3; /* 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */ | ||
454 | } | 460 | } |
455 | 461 | ||
456 | /* if battery is not full, enable charging */ | 462 | /* if battery is not full, enable charging */ |
@@ -475,12 +481,12 @@ static void power_thread(void) | |||
475 | charged_time = 0; | 481 | charged_time = 0; |
476 | 482 | ||
477 | charger_enable(true); | 483 | charger_enable(true); |
478 | 484 | charge_state = 1; /* 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */ | |
479 | /* clear the power history so that we don't use values before | 485 | /* clear the power history so that we don't use values before |
480 | * discharge for the long-term delta | 486 | * discharge for the long-term delta |
481 | */ | 487 | */ |
482 | for (i = 0; i < POWER_HISTORY_LEN-1; i++) | 488 | for (i = 0; i < POWER_HISTORY_LEN-1; i++) |
483 | power_history[i] = power_history[POWER_HISTORY_LEN-1]; | 489 | power_history[i] = power_history[POWER_HISTORY_LEN-1]; |
484 | } | 490 | } |
485 | } | 491 | } |
486 | } | 492 | } |
@@ -491,9 +497,9 @@ static void power_thread(void) | |||
491 | DEBUGF("power: charger disconnected, disabling\n"); | 497 | DEBUGF("power: charger disconnected, disabling\n"); |
492 | powermgmt_last_cycle_level = battery_level(); | 498 | powermgmt_last_cycle_level = battery_level(); |
493 | powermgmt_last_cycle_startstop_min = 0; | 499 | powermgmt_last_cycle_startstop_min = 0; |
494 | trickle_enabled = false; | ||
495 | trickle_sec = 0; /* show in debug menu that trickle is off */ | 500 | trickle_sec = 0; /* show in debug menu that trickle is off */ |
496 | charger_enable(false); | 501 | charger_enable(false); |
502 | charge_state = 0; /* 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */ | ||
497 | snprintf(power_message, POWER_MESSAGE_LEN, "Charger disc"); | 503 | snprintf(power_message, POWER_MESSAGE_LEN, "Charger disc"); |
498 | } | 504 | } |
499 | /* charger not inserted and disabled, so we're discharging */ | 505 | /* charger not inserted and disabled, so we're discharging */ |