1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 #define POWER_HISTORY_LEN 2*60 /* 2 hours of samples, one per minute */
24 #define CHARGE_END_SHORTD 6 /* stop when N minutes have passed with
25 * avg delta being < -0.05 V */
26 #define CHARGE_END_LONGD 50 /* stop when N minutes have passed with
27 * avg delta being < -0.02 V */
31 #if CONFIG_CHARGING == CHARGING_CONTROL
32 #define START_TOPOFF_CHG 85 /* Battery % to start at top-off */
33 #define START_TRICKLE_CHG 95 /* Battery % to start at trickle */
35 #define POWER_MESSAGE_LEN 32 /* power thread status message */
36 #define CHARGE_MAX_TIME_1500 450 /* minutes: maximum charging time for 1500 mAh batteries */
37 /* actual max time depends also on BATTERY_CAPACITY! */
38 #define CHARGE_MIN_TIME 10 /* minutes: minimum charging time */
39 #define TOPOFF_MAX_TIME 90 /* After charging, go to top off charge. How long should top off charge be? */
40 #define TOPOFF_VOLTAGE 565 /* which voltage is best? (centivolts) */
41 #define TRICKLE_MAX_TIME 12*60 /* After top off charge, go to trickle charge. How long should trickle charge be? */
42 #define TRICKLE_VOLTAGE 545 /* which voltage is best? (centivolts) */
44 #define START_TOPOFF_SEC 25 /* initial trickle_sec for topoff */
45 #define START_TRICKLE_SEC 15 /* initial trickle_sec for trickle */
47 #define PID_PCONST 2 /* PID proportional constant */
48 #define PID_DEADZONE 2 /* PID proportional deadzone */
50 extern char power_message
[POWER_MESSAGE_LEN
];
52 extern int long_delta
; /* long term delta battery voltage */
53 extern int short_delta
; /* short term delta battery voltage */
55 extern int powermgmt_last_cycle_startstop_min
; /* how many minutes ago was the charging started or stopped? */
56 extern int powermgmt_last_cycle_level
; /* which level had the batteries at this time? */
58 extern int pid_p
; /* PID proportional term */
59 extern int pid_i
; /* PID integral term */
60 extern int trickle_sec
; /* trickle charge: How many seconds per minute are we charging actually? */
62 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
64 #if CONFIG_CHARGING >= CHARGING_MONITOR
65 typedef enum { /* sorted by increasing charging current */
67 TRICKLE
, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */
68 TOPOFF
, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */
69 CHARGING
/* Can occur for all CONFIG_CHARGING options */
72 /* tells what the charger is doing */
73 extern charge_state_type charge_state
;
74 #endif /* CONFIG_CHARGING >= CHARGING_MONITOR */
76 #ifdef CONFIG_CHARGING
78 * Flag that the charger has been plugged in/removed: this is set for exactly
79 * one time through the power loop when the charger has been plugged in.
83 CHARGER_UNPLUGGED
, /* transient state */
84 CHARGER_PLUGGED
, /* transient state */
86 } charger_input_state_type
;
88 /* tells the state of the charge input */
89 extern charger_input_state_type charger_input_state
;
92 #ifdef HAVE_MMC /* Values for Ondio */
93 # define CURRENT_NORMAL 95 /* average, nearly proportional to 1/U */
94 # define CURRENT_USB 1 /* host powered in USB mode; avoid zero-div */
95 # define CURRENT_BACKLIGHT 0 /* no backlight */
96 #else /* Values for HD based jukeboxes */
97 #ifdef IRIVER_H100_SERIES
98 # define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery */
99 # define CURRENT_BACKLIGHT 23 /* from IriverBattery twiki page */
100 # define CURRENT_SPDIF_OUT 10 /* optical SPDIF output on */
101 # define CURRENT_RECORD 105 /* additional current while recording */
102 #elif defined(IRIVER_H300_SERIES)
103 # define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery from IriverRuntime wiki page */
104 # define CURRENT_BACKLIGHT 23 /* FIXME: This needs to be measured, copied from H100 */
105 # define CURRENT_RECORD 110 /* additional current while recording */
106 #elif defined(IPOD_ARCH) && (MODEL_NUMBER==4) /* iPOD Nano */
107 # define CURRENT_NORMAL 35 /* 8.5-9.0h playback out of 300mAh battery from IpodRuntime */
108 # define CURRENT_BACKLIGHT 20 /* FIXME: estimation took over from iPOD Video */
109 #if defined(HAVE_RECORDING)
110 # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
112 #elif defined(IPOD_ARCH) && (MODEL_NUMBER==5) /* iPOD Video */
113 # define CURRENT_NORMAL 50 /* 8h out of 400mAh battery (30GB) or 11h out of 600mAh (60GB) from IpodRuntime */
114 # define CURRENT_BACKLIGHT 20 /* estimation calculated from IpodRuntime measurement */
115 #if defined(HAVE_RECORDING)
116 # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
118 #else /* Not iriver H1x0, H3x0, nor Archos Ondio, nor iPODVideo */
119 # define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */
120 # define CURRENT_BACKLIGHT 30 /* additional current when backlight always on */
121 #if defined(HAVE_RECORDING)
122 # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
124 #endif /* Not Archos Ondio */
125 #define CURRENT_USB 500 /* usual current in mA in USB mode */
126 #ifdef HAVE_REMOTE_LCD
127 # define CURRENT_REMOTE 8 /* add. current when H100-remote connected */
128 #endif /* HAVE_MMC */
130 # define CURRENT_MIN_CHG 70 /* minimum charge current */
131 # define MIN_CHG_V 8500 /* at 8.5v charger voltage get CURRENT_MIN_CHG */
132 # ifdef IRIVER_H300_SERIES
133 # define CURRENT_MAX_CHG 650 /* maximum charging current */
135 # define CURRENT_MAX_CHG 350 /* maximum charging current */
137 # define MAX_CHG_V 10250 /* anything over 10.25v gives CURRENT_MAX_CHG */
138 #endif /* not HAVE_MMC */
140 extern unsigned short power_history
[POWER_HISTORY_LEN
];
142 /* Start up power management thread */
143 void powermgmt_init(void);
145 #endif /* SIMULATOR */
147 /* Returns battery statust */
148 int battery_level(void); /* percent */
149 int battery_time(void); /* minutes */
150 int battery_adc_voltage(void); /* voltage from ADC in centivolts */
151 unsigned int battery_voltage(void); /* filtered batt. voltage in centivolts */
153 /* read unfiltered battery info */
154 void battery_read_info(int *adc
, int *voltage
, int *level
);
156 /* Tells if the battery level is safe for disk writes */
157 bool battery_level_safe(void);
159 void set_poweroff_timeout(int timeout
);
160 void set_battery_capacity(int capacity
); /* set local battery capacity value */
161 void set_battery_type(int type
); /* set local battery type */
163 void set_sleep_timer(int seconds
);
164 int get_sleep_timer(void);
165 void set_car_adapter_mode(bool setting
);
166 void reset_poweroff_timer(void);
167 void cancel_shutdown(void);
168 void shutdown_hw(void);
169 void sys_poweroff(void);