Fix typo.
[Rockbox.git] / firmware / export / powermgmt.h
blob858b5015ecb49d0121ec8825de00773be00e2b76
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
19 #ifndef _POWERMGMT_H_
20 #define _POWERMGMT_H_
22 #include <stdbool.h>
24 #define POWER_HISTORY_LEN 2*60 /* 2 hours of samples, one per minute */
26 #define CHARGE_END_SHORTD 6 /* stop when N minutes have passed with
27 * avg delta being < -0.05 V */
28 #define CHARGE_END_LONGD 50 /* stop when N minutes have passed with
29 * avg delta being < -0.02 V */
31 #if CONFIG_CHARGING >= CHARGING_MONITOR
32 typedef enum { /* sorted by increasing charging current */
33 DISCHARGING = 0,
34 TRICKLE, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */
35 TOPOFF, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */
36 CHARGING /* Can occur for all CONFIG_CHARGING options */
37 } charge_state_type;
39 /* tells what the charger is doing */
40 extern charge_state_type charge_state;
41 #endif /* CONFIG_CHARGING >= CHARGING_MONITOR */
43 #ifdef CONFIG_CHARGING
45 * Flag that the charger has been plugged in/removed: this is set for exactly
46 * one time through the power loop when the charger has been plugged in.
48 typedef enum {
49 NO_CHARGER,
50 CHARGER_UNPLUGGED, /* transient state */
51 CHARGER_PLUGGED, /* transient state */
52 CHARGER
53 } charger_input_state_type;
55 /* tells the state of the charge input */
56 extern charger_input_state_type charger_input_state;
57 #endif
59 #ifndef SIMULATOR
61 #if CONFIG_CHARGING == CHARGING_CONTROL
62 #define START_TOPOFF_CHG 85 /* Battery % to start at top-off */
63 #define START_TRICKLE_CHG 95 /* Battery % to start at trickle */
65 #define POWER_MESSAGE_LEN 32 /* power thread status message */
66 #define CHARGE_MAX_TIME_1500 450 /* minutes: maximum charging time for 1500 mAh batteries */
67 /* actual max time depends also on BATTERY_CAPACITY! */
68 #define CHARGE_MIN_TIME 10 /* minutes: minimum charging time */
69 #define TOPOFF_MAX_TIME 90 /* After charging, go to top off charge. How long should top off charge be? */
70 #define TOPOFF_VOLTAGE 5650 /* which voltage is best? (millivolts) */
71 #define TRICKLE_MAX_TIME 12*60 /* After top off charge, go to trickle charge. How long should trickle charge be? */
72 #define TRICKLE_VOLTAGE 5450 /* which voltage is best? (millivolts) */
74 #define START_TOPOFF_SEC 25 /* initial trickle_sec for topoff */
75 #define START_TRICKLE_SEC 15 /* initial trickle_sec for trickle */
77 #define PID_DEADZONE 4 /* PID proportional deadzone */
79 extern char power_message[POWER_MESSAGE_LEN];
81 extern int long_delta; /* long term delta battery voltage */
82 extern int short_delta; /* short term delta battery voltage */
84 extern int powermgmt_last_cycle_startstop_min; /* how many minutes ago was the charging started or stopped? */
85 extern int powermgmt_last_cycle_level; /* which level had the batteries at this time? */
87 extern int pid_p; /* PID proportional term */
88 extern int pid_i; /* PID integral term */
89 extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */
91 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
93 #ifdef HAVE_MMC /* Values for Ondio */
94 # define CURRENT_NORMAL 95 /* average, nearly proportional to 1/U */
95 # define CURRENT_USB 1 /* host powered in USB mode; avoid zero-div */
96 # define CURRENT_BACKLIGHT 0 /* no backlight */
97 #else /* Values for HD based jukeboxes */
98 #ifdef IRIVER_H100_SERIES
99 # define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery */
100 # define CURRENT_BACKLIGHT 23 /* from IriverBattery twiki page */
101 # define CURRENT_SPDIF_OUT 10 /* optical SPDIF output on */
102 # define CURRENT_RECORD 105 /* additional current while recording */
103 #elif defined(IRIVER_H300_SERIES)
104 # define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery from IriverRuntime wiki page */
105 # define CURRENT_BACKLIGHT 23 /* FIXME: This needs to be measured, copied from H100 */
106 # define CURRENT_RECORD 110 /* additional current while recording */
107 #elif defined(IPOD_ARCH) && (MODEL_NUMBER==4) /* iPOD Nano */
108 # define CURRENT_NORMAL 35 /* 8.5-9.0h playback out of 300mAh battery from IpodRuntime */
109 # define CURRENT_BACKLIGHT 20 /* FIXME: estimation took over from iPOD Video */
110 #if defined(HAVE_RECORDING)
111 # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
112 #endif
113 #elif defined(IPOD_ARCH) && (MODEL_NUMBER==5) /* iPOD Video */
114 # define CURRENT_NORMAL 50 /* 8h out of 400mAh battery (30GB) or 11h out of 600mAh (60GB) from IpodRuntime */
115 # define CURRENT_BACKLIGHT 20 /* estimation calculated from IpodRuntime measurement */
116 #if defined(HAVE_RECORDING)
117 # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
118 #endif
119 #else /* Not iriver H1x0, H3x0, nor Archos Ondio, nor iPODVideo */
120 # define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */
121 # define CURRENT_BACKLIGHT 30 /* additional current when backlight always on */
122 #if defined(HAVE_RECORDING)
123 # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
124 #endif
125 #endif /* Not Archos Ondio */
126 #define CURRENT_USB 500 /* usual current in mA in USB mode */
127 #ifdef HAVE_REMOTE_LCD
128 # define CURRENT_REMOTE 8 /* add. current when H100-remote connected */
129 #endif /* HAVE_MMC */
131 # define CURRENT_MIN_CHG 70 /* minimum charge current */
132 # define MIN_CHG_V 8500 /* at 8.5v charger voltage get CURRENT_MIN_CHG */
133 # ifdef IRIVER_H300_SERIES
134 # define CURRENT_MAX_CHG 650 /* maximum charging current */
135 # else
136 # define CURRENT_MAX_CHG 350 /* maximum charging current */
137 # endif
138 # define MAX_CHG_V 10250 /* anything over 10.25v gives CURRENT_MAX_CHG */
139 #endif /* not HAVE_MMC */
141 extern unsigned short power_history[POWER_HISTORY_LEN];
142 extern const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT];
143 extern const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT];
144 extern const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11];
145 #if CONFIG_CHARGING
146 extern const unsigned short percent_to_volt_charge[11];
147 #endif
149 /* Start up power management thread */
150 void powermgmt_init(void);
152 #endif /* SIMULATOR */
154 /* Returns battery statust */
155 int battery_level(void); /* percent */
156 int battery_time(void); /* minutes */
157 unsigned int battery_adc_voltage(void); /* voltage from ADC in millivolts */
158 unsigned int battery_voltage(void); /* filtered batt. voltage in millivolts */
160 /* read unfiltered battery info */
161 void battery_read_info(int *voltage, int *level);
163 /* Tells if the battery level is safe for disk writes */
164 bool battery_level_safe(void);
166 void set_poweroff_timeout(int timeout);
167 void set_battery_capacity(int capacity); /* set local battery capacity value */
168 void set_battery_type(int type); /* set local battery type */
170 void set_sleep_timer(int seconds);
171 int get_sleep_timer(void);
172 void set_car_adapter_mode(bool setting);
173 void reset_poweroff_timer(void);
174 void cancel_shutdown(void);
175 void shutdown_hw(void);
176 void sys_poweroff(void);
178 #endif