2003-02-07 09:41:57 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef _POWERMGMT_H_
|
|
|
|
#define _POWERMGMT_H_
|
|
|
|
|
|
|
|
#define POWER_HISTORY_LEN 2*60 /* 2 hours of samples, one per minute */
|
|
|
|
|
2006-03-04 09:48:53 +00:00
|
|
|
#define CHARGE_END_SHORTD 6 /* stop when N minutes have passed with
|
2003-02-07 09:41:57 +00:00
|
|
|
* avg delta being < -0.05 V */
|
2006-03-04 09:48:53 +00:00
|
|
|
#define CHARGE_END_LONGD 50 /* stop when N minutes have passed with
|
|
|
|
* avg delta being < -0.02 V */
|
2005-03-03 07:25:43 +00:00
|
|
|
|
2003-02-14 15:09:12 +00:00
|
|
|
#ifndef SIMULATOR
|
2003-02-07 09:41:57 +00:00
|
|
|
|
2006-06-06 22:23:52 +00:00
|
|
|
#if CONFIG_CHARGING == CHARGING_CONTROL
|
2005-03-23 20:53:37 +00:00
|
|
|
#define START_TOPOFF_CHG 85 /* Battery % to start at top-off */
|
|
|
|
#define START_TRICKLE_CHG 95 /* Battery % to start at trickle */
|
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
#define POWER_MESSAGE_LEN 32 /* power thread status message */
|
|
|
|
#define CHARGE_MAX_TIME_1500 450 /* minutes: maximum charging time for 1500 mAh batteries */
|
|
|
|
/* actual max time depends also on BATTERY_CAPACITY! */
|
|
|
|
#define CHARGE_MIN_TIME 10 /* minutes: minimum charging time */
|
|
|
|
#define TOPOFF_MAX_TIME 90 /* After charging, go to top off charge. How long should top off charge be? */
|
|
|
|
#define TOPOFF_VOLTAGE 565 /* which voltage is best? (centivolts) */
|
|
|
|
#define TRICKLE_MAX_TIME 12*60 /* After top off charge, go to trickle charge. How long should trickle charge be? */
|
|
|
|
#define TRICKLE_VOLTAGE 545 /* which voltage is best? (centivolts) */
|
|
|
|
|
2005-03-03 07:25:43 +00:00
|
|
|
#define START_TOPOFF_SEC 25 /* initial trickle_sec for topoff */
|
|
|
|
#define START_TRICKLE_SEC 15 /* initial trickle_sec for trickle */
|
|
|
|
|
2005-03-23 20:53:37 +00:00
|
|
|
#define PID_PCONST 2 /* PID proportional constant */
|
|
|
|
#define PID_DEADZONE 2 /* PID proportional deadzone */
|
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
extern char power_message[POWER_MESSAGE_LEN];
|
2005-03-03 07:25:43 +00:00
|
|
|
|
|
|
|
extern int long_delta; /* long term delta battery voltage */
|
|
|
|
extern int short_delta; /* short term delta battery voltage */
|
2003-02-07 09:41:57 +00:00
|
|
|
|
|
|
|
extern int powermgmt_last_cycle_startstop_min; /* how many minutes ago was the charging started or stopped? */
|
|
|
|
extern int powermgmt_last_cycle_level; /* which level had the batteries at this time? */
|
|
|
|
|
2005-03-23 20:53:37 +00:00
|
|
|
extern int pid_p; /* PID proportional term */
|
|
|
|
extern int pid_i; /* PID integral term */
|
2003-02-07 09:41:57 +00:00
|
|
|
extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */
|
|
|
|
|
2006-06-06 22:23:52 +00:00
|
|
|
#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
|
2003-02-07 09:41:57 +00:00
|
|
|
|
2006-06-06 22:23:52 +00:00
|
|
|
#if CONFIG_CHARGING >= CHARGING_MONITOR
|
|
|
|
typedef enum { /* sorted by increasing charging current */
|
2006-10-30 11:33:38 +00:00
|
|
|
DISCHARGING = 0,
|
2006-06-06 22:23:52 +00:00
|
|
|
TRICKLE, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */
|
|
|
|
TOPOFF, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */
|
|
|
|
CHARGING /* Can occur for all CONFIG_CHARGING options */
|
2005-03-03 07:25:43 +00:00
|
|
|
} charge_state_type;
|
|
|
|
|
|
|
|
/* tells what the charger is doing */
|
|
|
|
extern charge_state_type charge_state;
|
2006-06-06 22:23:52 +00:00
|
|
|
#endif /* CONFIG_CHARGING >= CHARGING_MONITOR */
|
2004-02-05 13:44:04 +00:00
|
|
|
|
2006-06-06 22:23:52 +00:00
|
|
|
#ifdef CONFIG_CHARGING
|
2006-01-19 07:47:34 +00:00
|
|
|
/*
|
|
|
|
* Flag that the charger has been plugged in/removed: this is set for exactly
|
|
|
|
* one time through the power loop when the charger has been plugged in.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
NO_CHARGER,
|
|
|
|
CHARGER_UNPLUGGED, /* transient state */
|
|
|
|
CHARGER_PLUGGED, /* transient state */
|
|
|
|
CHARGER
|
|
|
|
} charger_input_state_type;
|
|
|
|
|
|
|
|
/* tells the state of the charge input */
|
|
|
|
extern charger_input_state_type charger_input_state;
|
|
|
|
#endif
|
|
|
|
|
2004-10-15 18:18:15 +00:00
|
|
|
#ifdef HAVE_MMC /* Values for Ondio */
|
2005-07-05 07:09:19 +00:00
|
|
|
# define CURRENT_NORMAL 95 /* average, nearly proportional to 1/U */
|
|
|
|
# define CURRENT_USB 1 /* host powered in USB mode; avoid zero-div */
|
|
|
|
# define CURRENT_BACKLIGHT 0 /* no backlight */
|
2004-10-15 18:18:15 +00:00
|
|
|
#else /* Values for HD based jukeboxes */
|
2006-11-11 01:18:57 +00:00
|
|
|
#ifdef IRIVER_H100_SERIES
|
|
|
|
# define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery */
|
|
|
|
# define CURRENT_BACKLIGHT 23 /* from IriverBattery twiki page */
|
|
|
|
# define CURRENT_SPDIF_OUT 10 /* optical SPDIF output on */
|
|
|
|
# define CURRENT_RECORD 105 /* additional current while recording */
|
|
|
|
#elif defined(IRIVER_H300_SERIES)
|
2007-05-15 21:21:52 +00:00
|
|
|
# define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery from IriverRuntime wiki page */
|
|
|
|
# define CURRENT_BACKLIGHT 23 /* FIXME: This needs to be measured, copied from H100 */
|
|
|
|
# define CURRENT_RECORD 110 /* additional current while recording */
|
|
|
|
#else /* Not iriver H1x0, H3x0, nor Archos Ondio */
|
|
|
|
# define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */
|
|
|
|
# define CURRENT_BACKLIGHT 30 /* additional current when backlight always on */
|
|
|
|
#if defined(HAVE_RECORDING)
|
2006-11-11 01:18:57 +00:00
|
|
|
# define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
|
|
|
|
#endif
|
2007-05-15 21:21:52 +00:00
|
|
|
#endif /* Not Archos Ondio */
|
|
|
|
#define CURRENT_USB 500 /* usual current in mA in USB mode */
|
2006-11-11 01:18:57 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
# define CURRENT_REMOTE 8 /* add. current when H100-remote connected */
|
2007-05-15 21:21:52 +00:00
|
|
|
#endif /* HAVE_MMC */
|
2005-07-05 07:09:19 +00:00
|
|
|
|
|
|
|
# define CURRENT_MIN_CHG 70 /* minimum charge current */
|
|
|
|
# define MIN_CHG_V 8500 /* at 8.5v charger voltage get CURRENT_MIN_CHG */
|
2006-01-19 07:47:34 +00:00
|
|
|
# ifdef IRIVER_H300_SERIES
|
|
|
|
# define CURRENT_MAX_CHG 650 /* maximum charging current */
|
|
|
|
# else
|
|
|
|
# define CURRENT_MAX_CHG 350 /* maximum charging current */
|
|
|
|
# endif
|
2005-07-05 07:09:19 +00:00
|
|
|
# define MAX_CHG_V 10250 /* anything over 10.25v gives CURRENT_MAX_CHG */
|
2006-01-19 07:47:34 +00:00
|
|
|
#endif /* not HAVE_MMC */
|
2005-03-03 07:25:43 +00:00
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
extern unsigned short power_history[POWER_HISTORY_LEN];
|
|
|
|
|
|
|
|
/* Start up power management thread */
|
2003-08-25 08:57:49 +00:00
|
|
|
void powermgmt_init(void);
|
2003-02-07 09:41:57 +00:00
|
|
|
|
|
|
|
#endif /* SIMULATOR */
|
|
|
|
|
2006-11-11 01:18:57 +00:00
|
|
|
/* Returns battery statust */
|
|
|
|
int battery_level(void); /* percent */
|
2003-02-07 09:41:57 +00:00
|
|
|
int battery_time(void); /* minutes */
|
2006-11-11 01:18:57 +00:00
|
|
|
int battery_adc_voltage(void); /* voltage from ADC in centivolts */
|
2006-01-25 18:29:56 +00:00
|
|
|
unsigned int battery_voltage(void); /* filtered batt. voltage in centivolts */
|
|
|
|
|
2006-10-30 11:33:38 +00:00
|
|
|
/* read unfiltered battery info */
|
|
|
|
void battery_read_info(int *adc, int *voltage, int *level);
|
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
/* Tells if the battery level is safe for disk writes */
|
|
|
|
bool battery_level_safe(void);
|
|
|
|
|
2006-11-11 01:18:57 +00:00
|
|
|
/* Tells if battery is in critical power saving state */
|
|
|
|
bool battery_level_critical(void);
|
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
void set_poweroff_timeout(int timeout);
|
|
|
|
void set_battery_capacity(int capacity); /* set local battery capacity value */
|
2005-03-03 07:25:43 +00:00
|
|
|
void set_battery_type(int type); /* set local battery type */
|
2003-02-07 09:41:57 +00:00
|
|
|
|
|
|
|
void set_sleep_timer(int seconds);
|
|
|
|
int get_sleep_timer(void);
|
2003-10-17 14:49:00 +00:00
|
|
|
void set_car_adapter_mode(bool setting);
|
2004-06-22 07:16:31 +00:00
|
|
|
void reset_poweroff_timer(void);
|
2006-04-16 17:32:54 +00:00
|
|
|
void cancel_shutdown(void);
|
2005-02-06 09:57:57 +00:00
|
|
|
void shutdown_hw(void);
|
2005-09-14 09:08:26 +00:00
|
|
|
void sys_poweroff(void);
|
2003-02-07 09:41:57 +00:00
|
|
|
|
|
|
|
#endif
|