Fix sansa c200 battery type comment.
[kugel-rb.git] / firmware / export / powermgmt.h
blobf083883ab9c4233610647cbf05ccb54714aadb62
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef _POWERMGMT_H_
22 #define _POWERMGMT_H_
24 #include <stdbool.h>
26 #define POWER_HISTORY_LEN 2*60 /* 2 hours of samples, one per minute */
28 #define CHARGE_END_SHORTD 6 /* stop when N minutes have passed with
29 * avg delta being < -0.05 V */
30 #define CHARGE_END_LONGD 50 /* stop when N minutes have passed with
31 * avg delta being < -0.02 V */
33 #if CONFIG_CHARGING >= CHARGING_MONITOR
34 typedef enum { /* sorted by increasing charging current */
35 DISCHARGING = 0,
36 TRICKLE, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */
37 TOPOFF, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */
38 CHARGING /* Can occur for all CONFIG_CHARGING options */
39 } charge_state_type;
41 /* tells what the charger is doing */
42 extern charge_state_type charge_state;
43 #endif /* CONFIG_CHARGING >= CHARGING_MONITOR */
45 #ifdef CONFIG_CHARGING
47 * Flag that the charger has been plugged in/removed: this is set for exactly
48 * one time through the power loop when the charger has been plugged in.
50 typedef enum {
51 NO_CHARGER,
52 CHARGER_UNPLUGGED, /* transient state */
53 CHARGER_PLUGGED, /* transient state */
54 CHARGER
55 } charger_input_state_type;
57 /* tells the state of the charge input */
58 extern charger_input_state_type charger_input_state;
59 #endif
61 #ifndef SIMULATOR
63 #if CONFIG_CHARGING == CHARGING_CONTROL
64 #define START_TOPOFF_CHG 85 /* Battery % to start at top-off */
65 #define START_TRICKLE_CHG 95 /* Battery % to start at trickle */
67 #define POWER_MESSAGE_LEN 32 /* power thread status message */
68 #define CHARGE_MAX_TIME_1500 450 /* minutes: maximum charging time for 1500 mAh batteries */
69 /* actual max time depends also on BATTERY_CAPACITY! */
70 #define CHARGE_MIN_TIME 10 /* minutes: minimum charging time */
71 #define TOPOFF_MAX_TIME 90 /* After charging, go to top off charge. How long should top off charge be? */
72 #define TOPOFF_VOLTAGE 5650 /* which voltage is best? (millivolts) */
73 #define TRICKLE_MAX_TIME 12*60 /* After top off charge, go to trickle charge. How long should trickle charge be? */
74 #define TRICKLE_VOLTAGE 5450 /* which voltage is best? (millivolts) */
76 #define START_TOPOFF_SEC 25 /* initial trickle_sec for topoff */
77 #define START_TRICKLE_SEC 15 /* initial trickle_sec for trickle */
79 #define PID_DEADZONE 4 /* PID proportional deadzone */
81 extern char power_message[POWER_MESSAGE_LEN];
83 extern int long_delta; /* long term delta battery voltage */
84 extern int short_delta; /* short term delta battery voltage */
86 extern int powermgmt_last_cycle_startstop_min; /* how many minutes ago was the charging started or stopped? */
87 extern int powermgmt_last_cycle_level; /* which level had the batteries at this time? */
89 extern int pid_p; /* PID proportional term */
90 extern int pid_i; /* PID integral term */
91 extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */
93 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
95 #ifdef HAVE_MMC /* Values for Ondio */
96 # define CURRENT_NORMAL 95 /* average, nearly proportional to 1/U */
97 # define CURRENT_USB 1 /* host powered in USB mode; avoid zero-div */
98 # define CURRENT_BACKLIGHT 0 /* no backlight */
99 #else /* Values for HD based jukeboxes */
100 #ifdef IRIVER_H100_SERIES
101 # define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery */
102 # define CURRENT_BACKLIGHT 23 /* from IriverBattery twiki page */
103 # define CURRENT_SPDIF_OUT 10 /* optical SPDIF output on */
104 # define CURRENT_RECORD 105 /* additional current while recording */
105 #elif defined(IRIVER_H300_SERIES)
106 # define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery from IriverRuntime wiki page */
107 # define CURRENT_BACKLIGHT 23 /* FIXME: This needs to be measured, copied from H100 */
108 # define CURRENT_RECORD 110 /* additional current while recording */
109 #elif defined(IPOD_NANO) /* iPOD Nano */
110 # define CURRENT_NORMAL 32 /* MP3: ~9h playback out of 300mAh battery */
111 # define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */
112 #if defined(HAVE_RECORDING)
113 # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
114 #endif
115 #elif defined(IPOD_VIDEO) /* iPOD Video */
116 # define CURRENT_NORMAL 35 /* MP3: ~11h out of 400mAh battery (30GB) or ~17h out of 600mAh (60GB) */
117 # define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */
118 #if defined(HAVE_RECORDING)
119 # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
120 #endif
121 #elif defined(SANSA_E200) /* Sandisk E200v1 */
122 # define CURRENT_NORMAL 45 /* Mike's measurements in Jan 2008 */
123 # define CURRENT_BACKLIGHT 40 /* Screen is about 20, blue LEDs are another 20, so 40 if both */
124 # define CURRENT_RECORD 40 /* flash player, so this is just unboosted current*/
125 #elif defined(SANSA_C200) /* Sandisk C200v1 */
126 # define CURRENT_NORMAL 45 /* Should be nearly identical to E200 */
127 # define CURRENT_BACKLIGHT 40 /* Screen is about 20, blue LEDs are another 20, so 40 if both */
128 # define CURRENT_RECORD 40 /* flash player, so this is just unboosted current*/
129 #else /* Not iriver H1x0, H3x0, nor Archos Ondio, nor iPod nano/Video, nor Sansas */
130 # define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */
131 # define CURRENT_BACKLIGHT 30 /* additional current when backlight always on */
132 #if defined(HAVE_RECORDING)
133 # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
134 #endif
135 #endif /* Not Archos Ondio */
136 #define CURRENT_USB 500 /* usual current in mA in USB mode */
137 #ifdef HAVE_REMOTE_LCD
138 # define CURRENT_REMOTE 8 /* add. current when H100-remote connected */
139 #endif /* HAVE_MMC */
141 # define CURRENT_MIN_CHG 70 /* minimum charge current */
142 # define MIN_CHG_V 8500 /* at 8.5v charger voltage get CURRENT_MIN_CHG */
143 # ifdef IRIVER_H300_SERIES
144 # define CURRENT_MAX_CHG 650 /* maximum charging current */
145 # else
146 # define CURRENT_MAX_CHG 350 /* maximum charging current */
147 # endif
148 # define MAX_CHG_V 10250 /* anything over 10.25v gives CURRENT_MAX_CHG */
149 #endif /* not HAVE_MMC */
151 extern unsigned short power_history[POWER_HISTORY_LEN];
152 extern const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT];
153 extern const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT];
154 extern const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11];
155 #if CONFIG_CHARGING
156 extern const unsigned short percent_to_volt_charge[11];
157 #endif
159 /* Start up power management thread */
160 void powermgmt_init(void);
162 #endif /* SIMULATOR */
164 /* Returns battery statust */
165 int battery_level(void); /* percent */
166 int battery_time(void); /* minutes */
167 unsigned int battery_adc_voltage(void); /* voltage from ADC in millivolts */
168 unsigned int battery_voltage(void); /* filtered batt. voltage in millivolts */
170 /* read unfiltered battery info */
171 void battery_read_info(int *voltage, int *level);
173 /* Tells if the battery level is safe for disk writes */
174 bool battery_level_safe(void);
176 void set_poweroff_timeout(int timeout);
177 void set_battery_capacity(int capacity); /* set local battery capacity value */
178 void set_battery_type(int type); /* set local battery type */
180 void set_sleep_timer(int seconds);
181 int get_sleep_timer(void);
182 void set_car_adapter_mode(bool setting);
183 void reset_poweroff_timer(void);
184 void cancel_shutdown(void);
185 void shutdown_hw(void);
186 void sys_poweroff(void);
187 #ifdef HAVE_ACCESSORY_SUPPLY
188 void accessory_supply_set(bool);
189 #endif
190 #endif