diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2008-12-24 16:58:41 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2008-12-24 16:58:41 +0000 |
commit | 3157e1395674a930c74e2ef4cc4ce78dffea8569 (patch) | |
tree | 5b2a9befc3b051caf0806995ebd32a5ab3bcf5ff /firmware/export | |
parent | 0f9729739f2fd90759c1caeca86e487c36f98834 (diff) | |
download | rockbox-3157e1395674a930c74e2ef4cc4ce78dffea8569.tar.gz rockbox-3157e1395674a930c74e2ef4cc4ce78dffea8569.zip |
Simplify powermgmt thread loops so it calls functions turn (no more power_thread_sleep). Do other target-friendly simplifications, generic battery switch handling and split sim-specific code. Whoever can, please verify charging on the Archos Recorder (due to change in the charger duty cycle code).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19579 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/export')
-rw-r--r-- | firmware/export/config-c200.h | 5 | ||||
-rw-r--r-- | firmware/export/config-e200.h | 5 | ||||
-rw-r--r-- | firmware/export/config-h100.h | 9 | ||||
-rw-r--r-- | firmware/export/config-h120.h | 8 | ||||
-rw-r--r-- | firmware/export/config-h300.h | 7 | ||||
-rw-r--r-- | firmware/export/config-iaudiom3.h | 3 | ||||
-rw-r--r-- | firmware/export/config-iaudiom5.h | 3 | ||||
-rw-r--r-- | firmware/export/config-iaudiox5.h | 3 | ||||
-rw-r--r-- | firmware/export/config-ipod4g.h | 7 | ||||
-rw-r--r-- | firmware/export/config-ipodnano.h | 6 | ||||
-rw-r--r-- | firmware/export/config-ipodvideo.h | 7 | ||||
-rw-r--r-- | firmware/export/config-ondiofm.h | 5 | ||||
-rw-r--r-- | firmware/export/config-ondiosp.h | 5 | ||||
-rw-r--r-- | firmware/export/config-recorder.h | 2 | ||||
-rw-r--r-- | firmware/export/config.h | 8 | ||||
-rw-r--r-- | firmware/export/power.h | 11 | ||||
-rw-r--r-- | firmware/export/powermgmt.h | 195 |
17 files changed, 153 insertions, 136 deletions
diff --git a/firmware/export/config-c200.h b/firmware/export/config-c200.h index e169606510..ac64f20e62 100644 --- a/firmware/export/config-c200.h +++ b/firmware/export/config-c200.h | |||
@@ -129,6 +129,11 @@ | |||
129 | /* define this if the unit can be powered or charged via USB */ | 129 | /* define this if the unit can be powered or charged via USB */ |
130 | #define HAVE_USB_POWER | 130 | #define HAVE_USB_POWER |
131 | 131 | ||
132 | /* define current usage levels */ | ||
133 | #define CURRENT_NORMAL 45 /* Should be nearly identical to E200 */ | ||
134 | #define CURRENT_BACKLIGHT 40 /* Screen is about 20, blue LEDs are another 20, so 40 if both */ | ||
135 | #define CURRENT_RECORD 40 /* flash player, so this is just unboosted current*/ | ||
136 | |||
132 | /** Non-simulator section **/ | 137 | /** Non-simulator section **/ |
133 | #ifndef SIMULATOR | 138 | #ifndef SIMULATOR |
134 | 139 | ||
diff --git a/firmware/export/config-e200.h b/firmware/export/config-e200.h index 3cae14cc87..b290a24952 100644 --- a/firmware/export/config-e200.h +++ b/firmware/export/config-e200.h | |||
@@ -123,6 +123,11 @@ | |||
123 | /* Hardware controlled charging? FIXME */ | 123 | /* Hardware controlled charging? FIXME */ |
124 | #define CONFIG_CHARGING CHARGING_SIMPLE | 124 | #define CONFIG_CHARGING CHARGING_SIMPLE |
125 | 125 | ||
126 | /* define current usage levels */ | ||
127 | #define CURRENT_NORMAL 45 /* Mike's measurements in Jan 2008 */ | ||
128 | #define CURRENT_BACKLIGHT 40 /* Screen is about 20, blue LEDs are another 20, so 40 if both */ | ||
129 | #define CURRENT_RECORD 40 /* flash player, so this is just unboosted current*/ | ||
130 | |||
126 | /* define this if the unit can be powered or charged via USB */ | 131 | /* define this if the unit can be powered or charged via USB */ |
127 | #define HAVE_USB_POWER | 132 | #define HAVE_USB_POWER |
128 | 133 | ||
diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h index 9c327f11fd..7f91e35fbf 100644 --- a/firmware/export/config-h100.h +++ b/firmware/export/config-h100.h | |||
@@ -110,9 +110,16 @@ | |||
110 | #define BATTERY_TYPES_COUNT 1 /* only one type */ | 110 | #define BATTERY_TYPES_COUNT 1 /* only one type */ |
111 | 111 | ||
112 | /* Hardware controlled charging */ | 112 | /* Hardware controlled charging */ |
113 | //#define CONFIG_CHARGING CHARGING_SIMPLE | 113 | |
114 | #define CONFIG_CHARGING CHARGING_MONITOR /* FIXME: remove that once monitoring is fixed properly */ | 114 | #define CONFIG_CHARGING CHARGING_MONITOR /* FIXME: remove that once monitoring is fixed properly */ |
115 | 115 | ||
116 | /* define current usage levels */ | ||
117 | #define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery */ | ||
118 | #define CURRENT_BACKLIGHT 23 /* from IriverBattery twiki page */ | ||
119 | #define CURRENT_SPDIF_OUT 10 /* optical SPDIF output on */ | ||
120 | #define CURRENT_RECORD 105 /* additional current while recording */ | ||
121 | #define CURRENT_REMOTE 8 /* additional current when remote connected */ | ||
122 | |||
116 | #ifndef SIMULATOR | 123 | #ifndef SIMULATOR |
117 | 124 | ||
118 | /* Define this if you have a Motorola SCF5249 */ | 125 | /* Define this if you have a Motorola SCF5249 */ |
diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h index d81fa07d93..b4a687b6d7 100644 --- a/firmware/export/config-h120.h +++ b/firmware/export/config-h120.h | |||
@@ -110,9 +110,15 @@ | |||
110 | #define BATTERY_TYPES_COUNT 1 /* only one type */ | 110 | #define BATTERY_TYPES_COUNT 1 /* only one type */ |
111 | 111 | ||
112 | /* Hardware controlled charging */ | 112 | /* Hardware controlled charging */ |
113 | //#define CONFIG_CHARGING CHARGING_SIMPLE | ||
114 | #define CONFIG_CHARGING CHARGING_MONITOR /* FIXME: remove that once monitoring is fixed properly */ | 113 | #define CONFIG_CHARGING CHARGING_MONITOR /* FIXME: remove that once monitoring is fixed properly */ |
115 | 114 | ||
115 | /* define current usage levels */ | ||
116 | #define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery */ | ||
117 | #define CURRENT_BACKLIGHT 23 /* from IriverBattery twiki page */ | ||
118 | #define CURRENT_SPDIF_OUT 10 /* optical SPDIF output on */ | ||
119 | #define CURRENT_RECORD 105 /* additional current while recording */ | ||
120 | #define CURRENT_REMOTE 8 /* additional current when remote connected */ | ||
121 | |||
116 | #ifndef SIMULATOR | 122 | #ifndef SIMULATOR |
117 | 123 | ||
118 | /* Define this if you have a Motorola SCF5249 */ | 124 | /* Define this if you have a Motorola SCF5249 */ |
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h index fa0046ac03..05d75fc4f0 100644 --- a/firmware/export/config-h300.h +++ b/firmware/export/config-h300.h | |||
@@ -112,6 +112,13 @@ | |||
112 | /* define this if the unit can be powered or charged via USB */ | 112 | /* define this if the unit can be powered or charged via USB */ |
113 | #define HAVE_USB_POWER | 113 | #define HAVE_USB_POWER |
114 | 114 | ||
115 | /* define current usage levels */ | ||
116 | #define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery from IriverRuntime wiki page */ | ||
117 | #define CURRENT_BACKLIGHT 23 /* FIXME: This needs to be measured, copied from H100 */ | ||
118 | #define CURRENT_RECORD 110 /* additional current while recording */ | ||
119 | #define CURRENT_MAX_CHG 650 /* maximum charging current */ | ||
120 | #define CURRENT_REMOTE 8 /* additional current when remote connected */ | ||
121 | |||
115 | /* define this if the unit can have USB charging disabled by user - | 122 | /* define this if the unit can have USB charging disabled by user - |
116 | * if USB/MAIN power is discernable and hardware doesn't compel charging */ | 123 | * if USB/MAIN power is discernable and hardware doesn't compel charging */ |
117 | #define HAVE_USB_CHARGING_ENABLE | 124 | #define HAVE_USB_CHARGING_ENABLE |
diff --git a/firmware/export/config-iaudiom3.h b/firmware/export/config-iaudiom3.h index f4ced651d0..a6e1028897 100644 --- a/firmware/export/config-iaudiom3.h +++ b/firmware/export/config-iaudiom3.h | |||
@@ -102,6 +102,9 @@ | |||
102 | /* Hardware controlled charging? FIXME */ | 102 | /* Hardware controlled charging? FIXME */ |
103 | #define CONFIG_CHARGING CHARGING_SIMPLE | 103 | #define CONFIG_CHARGING CHARGING_SIMPLE |
104 | 104 | ||
105 | /* define current usage levels */ | ||
106 | #define CURRENT_REMOTE 8 /* additional current when remote connected */ | ||
107 | |||
105 | #ifndef SIMULATOR | 108 | #ifndef SIMULATOR |
106 | 109 | ||
107 | /* Define this if your LCD can set contrast */ | 110 | /* Define this if your LCD can set contrast */ |
diff --git a/firmware/export/config-iaudiom5.h b/firmware/export/config-iaudiom5.h index 5ec6b77862..26cc9c5da6 100644 --- a/firmware/export/config-iaudiom5.h +++ b/firmware/export/config-iaudiom5.h | |||
@@ -105,6 +105,9 @@ | |||
105 | /* Hardware controlled charging? FIXME */ | 105 | /* Hardware controlled charging? FIXME */ |
106 | #define CONFIG_CHARGING CHARGING_SIMPLE | 106 | #define CONFIG_CHARGING CHARGING_SIMPLE |
107 | 107 | ||
108 | /* define current usage levels */ | ||
109 | #define CURRENT_REMOTE 8 /* additional current when remote connected */ | ||
110 | |||
108 | #ifndef SIMULATOR | 111 | #ifndef SIMULATOR |
109 | 112 | ||
110 | /* Define this if your LCD can set contrast */ | 113 | /* Define this if your LCD can set contrast */ |
diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h index 03b84606c9..8b1f9086bb 100644 --- a/firmware/export/config-iaudiox5.h +++ b/firmware/export/config-iaudiox5.h | |||
@@ -122,6 +122,9 @@ | |||
122 | /* Hardware controlled charging? FIXME */ | 122 | /* Hardware controlled charging? FIXME */ |
123 | #define CONFIG_CHARGING CHARGING_SIMPLE | 123 | #define CONFIG_CHARGING CHARGING_SIMPLE |
124 | 124 | ||
125 | /* define current usage levels */ | ||
126 | #define CURRENT_REMOTE 8 /* additional current when remote connected */ | ||
127 | |||
125 | #ifndef SIMULATOR | 128 | #ifndef SIMULATOR |
126 | 129 | ||
127 | /* define this if the backlight thread is used for fade, not for sim, needs | 130 | /* define this if the backlight thread is used for fade, not for sim, needs |
diff --git a/firmware/export/config-ipod4g.h b/firmware/export/config-ipod4g.h index 4a2207d1d6..89b14f9907 100644 --- a/firmware/export/config-ipod4g.h +++ b/firmware/export/config-ipod4g.h | |||
@@ -120,6 +120,13 @@ | |||
120 | /* define this if the unit can be powered or charged via USB */ | 120 | /* define this if the unit can be powered or charged via USB */ |
121 | #define HAVE_USB_POWER | 121 | #define HAVE_USB_POWER |
122 | 122 | ||
123 | /* define current usage levels */ | ||
124 | #define CURRENT_NORMAL 100 /* MP3: ~10.5h out of 1100mAh battery */ | ||
125 | #define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */ | ||
126 | #if defined(HAVE_RECORDING) | ||
127 | #define CURRENT_RECORD 35 /* FIXME: this needs adjusting */ | ||
128 | #endif | ||
129 | |||
123 | #ifndef SIMULATOR | 130 | #ifndef SIMULATOR |
124 | 131 | ||
125 | /* Define this if you have a PortalPlayer PP5020 */ | 132 | /* Define this if you have a PortalPlayer PP5020 */ |
diff --git a/firmware/export/config-ipodnano.h b/firmware/export/config-ipodnano.h index 7d6515fc0f..6017d0a2e8 100644 --- a/firmware/export/config-ipodnano.h +++ b/firmware/export/config-ipodnano.h | |||
@@ -115,6 +115,12 @@ | |||
115 | /* define this if the unit can be powered or charged via USB */ | 115 | /* define this if the unit can be powered or charged via USB */ |
116 | #define HAVE_USB_POWER | 116 | #define HAVE_USB_POWER |
117 | 117 | ||
118 | #define CURRENT_NORMAL 32 /* MP3: ~9h playback out of 300mAh battery */ | ||
119 | #define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */ | ||
120 | #if defined(HAVE_RECORDING) | ||
121 | #define CURRENT_RECORD 35 /* FIXME: this needs adjusting */ | ||
122 | #endif | ||
123 | |||
118 | #ifndef SIMULATOR | 124 | #ifndef SIMULATOR |
119 | 125 | ||
120 | /* Define this if you have a PortalPlayer PP5022 */ | 126 | /* Define this if you have a PortalPlayer PP5022 */ |
diff --git a/firmware/export/config-ipodvideo.h b/firmware/export/config-ipodvideo.h index fa6ddd304f..d04e562086 100644 --- a/firmware/export/config-ipodvideo.h +++ b/firmware/export/config-ipodvideo.h | |||
@@ -123,6 +123,13 @@ | |||
123 | /* define this if the unit can be powered or charged via USB */ | 123 | /* define this if the unit can be powered or charged via USB */ |
124 | #define HAVE_USB_POWER | 124 | #define HAVE_USB_POWER |
125 | 125 | ||
126 | /* define current usage levels */ | ||
127 | #define CURRENT_NORMAL 35 /* MP3: ~11h out of 400mAh battery (30GB) or ~17h out of 600mAh (60GB) */ | ||
128 | #define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */ | ||
129 | #if defined(HAVE_RECORDING) | ||
130 | #define CURRENT_RECORD 35 /* FIXME: this needs adjusting */ | ||
131 | #endif | ||
132 | |||
126 | #ifndef SIMULATOR | 133 | #ifndef SIMULATOR |
127 | 134 | ||
128 | /* Define this if you have a PortalPlayer PP5022 */ | 135 | /* Define this if you have a PortalPlayer PP5022 */ |
diff --git a/firmware/export/config-ondiofm.h b/firmware/export/config-ondiofm.h index 634433fcdb..8233728f1b 100644 --- a/firmware/export/config-ondiofm.h +++ b/firmware/export/config-ondiofm.h | |||
@@ -69,6 +69,11 @@ | |||
69 | /* define this if the unit can be powered or charged via USB */ | 69 | /* define this if the unit can be powered or charged via USB */ |
70 | #define HAVE_USB_POWER | 70 | #define HAVE_USB_POWER |
71 | 71 | ||
72 | /* define current usage levels */ | ||
73 | #define CURRENT_NORMAL 95 /* average, nearly proportional to 1/U */ | ||
74 | #define CURRENT_USB 1 /* host powered in USB mode; avoid zero-div */ | ||
75 | #define CURRENT_BACKLIGHT 0 /* no backlight */ | ||
76 | |||
72 | #ifndef SIMULATOR | 77 | #ifndef SIMULATOR |
73 | 78 | ||
74 | /* Define this if you have a SH7034 */ | 79 | /* Define this if you have a SH7034 */ |
diff --git a/firmware/export/config-ondiosp.h b/firmware/export/config-ondiosp.h index 3443b839b6..5fb7806d6a 100644 --- a/firmware/export/config-ondiosp.h +++ b/firmware/export/config-ondiosp.h | |||
@@ -58,6 +58,11 @@ | |||
58 | /* define this if the unit can be powered or charged via USB */ | 58 | /* define this if the unit can be powered or charged via USB */ |
59 | #define HAVE_USB_POWER | 59 | #define HAVE_USB_POWER |
60 | 60 | ||
61 | /* define current usage levels */ | ||
62 | #define CURRENT_NORMAL 95 /* average, nearly proportional to 1/U */ | ||
63 | #define CURRENT_USB 1 /* host powered in USB mode; avoid zero-div */ | ||
64 | #define CURRENT_BACKLIGHT 0 /* no backlight */ | ||
65 | |||
61 | #ifndef SIMULATOR | 66 | #ifndef SIMULATOR |
62 | 67 | ||
63 | /* Define this if you have a SH7034 */ | 68 | /* Define this if you have a SH7034 */ |
diff --git a/firmware/export/config-recorder.h b/firmware/export/config-recorder.h index e5fa3361cc..75aa2cf789 100644 --- a/firmware/export/config-recorder.h +++ b/firmware/export/config-recorder.h | |||
@@ -72,7 +72,7 @@ | |||
72 | #define NO_LOW_BATTERY_SHUTDOWN | 72 | #define NO_LOW_BATTERY_SHUTDOWN |
73 | 73 | ||
74 | /* Software controlled charging */ | 74 | /* Software controlled charging */ |
75 | #define CONFIG_CHARGING CHARGING_CONTROL | 75 | #define CONFIG_CHARGING CHARGING_TARGET |
76 | 76 | ||
77 | #ifndef SIMULATOR | 77 | #ifndef SIMULATOR |
78 | 78 | ||
diff --git a/firmware/export/config.h b/firmware/export/config.h index d8c14ddcef..1854f59d13 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h | |||
@@ -114,11 +114,13 @@ | |||
114 | #define X5_REMOTE 3 | 114 | #define X5_REMOTE 3 |
115 | 115 | ||
116 | /* CONFIG_CHARGING */ | 116 | /* CONFIG_CHARGING */ |
117 | |||
118 | /* Generic types */ | ||
117 | #define CHARGING_SIMPLE 1 /* Simple, hardware controlled charging */ | 119 | #define CHARGING_SIMPLE 1 /* Simple, hardware controlled charging */ |
118 | #define CHARGING_MONITOR 2 /* Hardware controlled charging with monitoring */ | 120 | #define CHARGING_MONITOR 2 /* Hardware controlled charging with monitoring */ |
119 | #define CHARGING_CONTROL 3 /* Software controlled charging */ | 121 | |
120 | #define CHARGING_TARGET 4 /* Anything the target implements that is not | 122 | /* Mostly target-specific code in the /target tree */ |
121 | a generic implementation */ | 123 | #define CHARGING_TARGET 3 |
122 | 124 | ||
123 | /* CONFIG_LCD */ | 125 | /* CONFIG_LCD */ |
124 | #define LCD_SSD1815 1 /* as used by Archos Recorders and Ondios */ | 126 | #define LCD_SSD1815 1 /* as used by Archos Recorders and Ondios */ |
diff --git a/firmware/export/power.h b/firmware/export/power.h index 747887921d..edf43f8cc8 100644 --- a/firmware/export/power.h +++ b/firmware/export/power.h | |||
@@ -21,11 +21,6 @@ | |||
21 | #ifndef _POWER_H_ | 21 | #ifndef _POWER_H_ |
22 | #define _POWER_H_ | 22 | #define _POWER_H_ |
23 | 23 | ||
24 | #if CONFIG_CHARGING == CHARGING_CONTROL | ||
25 | extern bool charger_enabled; | ||
26 | void charger_enable(bool on); | ||
27 | #endif | ||
28 | |||
29 | #if CONFIG_CHARGING | 24 | #if CONFIG_CHARGING |
30 | enum power_input_flags { | 25 | enum power_input_flags { |
31 | /* No external power source? Default. */ | 26 | /* No external power source? Default. */ |
@@ -82,9 +77,9 @@ bool power_input_present(void); | |||
82 | void power_off(void); | 77 | void power_off(void); |
83 | void ide_power_enable(bool on); | 78 | void ide_power_enable(bool on); |
84 | 79 | ||
85 | # if CONFIG_CHARGING == CHARGING_MONITOR | 80 | #if CONFIG_CHARGING >= CHARGING_MONITOR |
86 | bool charging_state(void); | 81 | bool charging_state(void); |
87 | # endif | 82 | #endif |
88 | 83 | ||
89 | #ifndef SIMULATOR | 84 | #ifndef SIMULATOR |
90 | 85 | ||
@@ -102,4 +97,4 @@ bool spdif_powered(void); | |||
102 | bool tuner_power(bool status); | 97 | bool tuner_power(bool status); |
103 | #endif | 98 | #endif |
104 | 99 | ||
105 | #endif | 100 | #endif /* _POWER_H_ */ |
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h index c333795ad7..5be3a39c1d 100644 --- a/firmware/export/powermgmt.h +++ b/firmware/export/powermgmt.h | |||
@@ -25,147 +25,101 @@ | |||
25 | 25 | ||
26 | #define POWER_HISTORY_LEN 2*60 /* 2 hours of samples, one per minute */ | 26 | #define POWER_HISTORY_LEN 2*60 /* 2 hours of samples, one per minute */ |
27 | 27 | ||
28 | #define CHARGE_END_SHORTD 6 /* stop when N minutes have passed with | 28 | enum charge_state_type |
29 | * avg delta being < -0.05 V */ | 29 | { |
30 | #define CHARGE_END_LONGD 50 /* stop when N minutes have passed with | 30 | /* sorted by increasing charging current */ |
31 | * avg delta being < -0.02 V */ | ||
32 | |||
33 | typedef enum { /* sorted by increasing charging current */ | ||
34 | #if CONFIG_CHARGING >= CHARGING_MONITOR | 31 | #if CONFIG_CHARGING >= CHARGING_MONITOR |
35 | CHARGE_STATE_DISABLED = -2, /* Disable charger use */ | 32 | CHARGE_STATE_DISABLED = -2, /* Disable charger use (safety measure) */ |
36 | CHARGE_STATE_ERROR = -1, /* Some error occurred that should not allow | 33 | CHARGE_STATE_ERROR = -1, /* Some error occurred that should not allow |
37 | further attempts without user intervention */ | 34 | turning on the charger again by software |
35 | without user intervention (ie. replug) */ | ||
38 | #endif | 36 | #endif |
39 | DISCHARGING = 0, | 37 | DISCHARGING = 0, |
40 | #if CONFIG_CHARGING >= CHARGING_MONITOR | 38 | #if CONFIG_CHARGING >= CHARGING_MONITOR |
41 | TRICKLE, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */ | 39 | TRICKLE, /* For NiCd, battery maintenence phase */ |
42 | /* For LiIon, the low-current precharge mode if battery | 40 | /* For LiIon, low-current precharge phase */ |
43 | was very low */ | 41 | TOPOFF, /* For NiCd, waiting for dead zone */ |
44 | TOPOFF, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */ | ||
45 | /* For LiIon, constant voltage phase */ | 42 | /* For LiIon, constant voltage phase */ |
46 | CHARGING, /* Can occur for all CONFIG_CHARGING options */ | 43 | CHARGING, /* For NiCd, main charge phase */ |
47 | /* For LiIon, the constant current phase */ | 44 | /* For LiIon, constant current phase */ |
48 | #endif | 45 | #endif |
49 | } charge_state_type; | 46 | }; |
50 | 47 | ||
51 | /* tells what the charger is doing */ | 48 | /* tells what the charger is doing */ |
52 | extern charge_state_type charge_state; | 49 | extern enum charge_state_type charge_state; |
53 | 50 | ||
54 | #ifdef CONFIG_CHARGING | 51 | #ifdef CONFIG_CHARGING |
55 | /* | 52 | /* |
56 | * Flag that the charger has been plugged in/removed: this is set for exactly | 53 | * Flag that the charger has been plugged in/removed: this is set for exactly |
57 | * one time through the power loop when the charger has been plugged in. | 54 | * one time through the power loop when the charger has been plugged in. |
58 | */ | 55 | */ |
59 | typedef enum { | 56 | enum charger_input_state_type |
57 | { | ||
60 | NO_CHARGER = 0, /* No charger is present */ | 58 | NO_CHARGER = 0, /* No charger is present */ |
61 | CHARGER_UNPLUGGED, /* Transitional state during CHARGER=>NO_CHARGER */ | 59 | CHARGER_UNPLUGGED, /* Transitional state during CHARGER=>NO_CHARGER */ |
62 | CHARGER_PLUGGED, /* Transitional state during NO_CHARGER=>CHARGER */ | 60 | CHARGER_PLUGGED, /* Transitional state during NO_CHARGER=>CHARGER */ |
63 | CHARGER /* Charger is present */ | 61 | CHARGER /* Charger is present */ |
64 | } charger_input_state_type; | 62 | }; |
65 | 63 | ||
66 | /* tells the state of the charge input */ | 64 | /* tells the state of the charge input */ |
67 | extern charger_input_state_type charger_input_state; | 65 | extern enum charger_input_state_type charger_input_state; |
66 | |||
67 | /* Power input status saved on the power thread each loop */ | ||
68 | extern unsigned int power_thread_inputs; | ||
69 | |||
70 | #endif /* CONFIG_CHARGING */ | ||
71 | |||
72 | #if CONFIG_CHARGING == CHARGING_TARGET | ||
73 | /* Include target-specific definitions */ | ||
74 | #include "powermgmt-target.h" | ||
68 | #endif | 75 | #endif |
69 | 76 | ||
70 | #ifndef SIMULATOR | 77 | #ifndef SIMULATOR |
71 | 78 | ||
72 | #if CONFIG_CHARGING == CHARGING_CONTROL | 79 | /* Generic current values that are really rather meaningless - config header |
73 | #define START_TOPOFF_CHG 85 /* Battery % to start at top-off */ | 80 | * should define proper numbers. */ |
74 | #define START_TRICKLE_CHG 95 /* Battery % to start at trickle */ | 81 | #ifndef CURRENT_NORMAL |
75 | 82 | #define CURRENT_NORMAL 145 /* usual current in mA */ | |
76 | #define POWER_MESSAGE_LEN 32 /* power thread status message */ | ||
77 | #define CHARGE_MAX_TIME_1500 450 /* minutes: maximum charging time for 1500 mAh batteries */ | ||
78 | /* actual max time depends also on BATTERY_CAPACITY! */ | ||
79 | #define CHARGE_MIN_TIME 10 /* minutes: minimum charging time */ | ||
80 | #define TOPOFF_MAX_TIME 90 /* After charging, go to top off charge. How long should top off charge be? */ | ||
81 | #define TOPOFF_VOLTAGE 5650 /* which voltage is best? (millivolts) */ | ||
82 | #define TRICKLE_MAX_TIME 12*60 /* After top off charge, go to trickle charge. How long should trickle charge be? */ | ||
83 | #define TRICKLE_VOLTAGE 5450 /* which voltage is best? (millivolts) */ | ||
84 | |||
85 | #define START_TOPOFF_SEC 25 /* initial trickle_sec for topoff */ | ||
86 | #define START_TRICKLE_SEC 15 /* initial trickle_sec for trickle */ | ||
87 | |||
88 | #define PID_DEADZONE 4 /* PID proportional deadzone */ | ||
89 | |||
90 | extern char power_message[POWER_MESSAGE_LEN]; | ||
91 | |||
92 | extern int long_delta; /* long term delta battery voltage */ | ||
93 | extern int short_delta; /* short term delta battery voltage */ | ||
94 | |||
95 | extern int powermgmt_last_cycle_startstop_min; /* how many minutes ago was the charging started or stopped? */ | ||
96 | extern int powermgmt_last_cycle_level; /* which level had the batteries at this time? */ | ||
97 | |||
98 | extern int pid_p; /* PID proportional term */ | ||
99 | extern int pid_i; /* PID integral term */ | ||
100 | extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */ | ||
101 | |||
102 | #endif /* CONFIG_CHARGING == CHARGING_CONTROL */ | ||
103 | |||
104 | #if defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM) /* Values for Ondio */ | ||
105 | # define CURRENT_NORMAL 95 /* average, nearly proportional to 1/U */ | ||
106 | # define CURRENT_USB 1 /* host powered in USB mode; avoid zero-div */ | ||
107 | # define CURRENT_BACKLIGHT 0 /* no backlight */ | ||
108 | #else /* Values for HD based jukeboxes */ | ||
109 | #ifdef IRIVER_H100_SERIES | ||
110 | # define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery */ | ||
111 | # define CURRENT_BACKLIGHT 23 /* from IriverBattery twiki page */ | ||
112 | # define CURRENT_SPDIF_OUT 10 /* optical SPDIF output on */ | ||
113 | # define CURRENT_RECORD 105 /* additional current while recording */ | ||
114 | #elif defined(IRIVER_H300_SERIES) | ||
115 | # define CURRENT_NORMAL 80 /* 16h playback on 1300mAh battery from IriverRuntime wiki page */ | ||
116 | # define CURRENT_BACKLIGHT 23 /* FIXME: This needs to be measured, copied from H100 */ | ||
117 | # define CURRENT_RECORD 110 /* additional current while recording */ | ||
118 | #elif defined(IPOD_NANO) /* iPOD Nano */ | ||
119 | # define CURRENT_NORMAL 32 /* MP3: ~9h playback out of 300mAh battery */ | ||
120 | # define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */ | ||
121 | #if defined(HAVE_RECORDING) | ||
122 | # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */ | ||
123 | #endif | 83 | #endif |
124 | #elif defined(IPOD_VIDEO) /* iPOD Video */ | 84 | |
125 | # define CURRENT_NORMAL 35 /* MP3: ~11h out of 400mAh battery (30GB) or ~17h out of 600mAh (60GB) */ | 85 | #ifndef CURRENT_BACKLIGHT |
126 | # define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */ | 86 | #define CURRENT_BACKLIGHT 30 /* additional current when backlight always on */ |
127 | #if defined(HAVE_RECORDING) | ||
128 | # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */ | ||
129 | #endif | 87 | #endif |
130 | #elif defined(SANSA_E200) /* Sandisk E200v1 */ | 88 | |
131 | # define CURRENT_NORMAL 45 /* Mike's measurements in Jan 2008 */ | 89 | #ifdef HAVE_RECORDING |
132 | # define CURRENT_BACKLIGHT 40 /* Screen is about 20, blue LEDs are another 20, so 40 if both */ | 90 | #ifndef CURRENT_RECORD |
133 | # define CURRENT_RECORD 40 /* flash player, so this is just unboosted current*/ | 91 | #define CURRENT_RECORD 35 /* additional recording current */ |
134 | #elif defined(SANSA_C200) /* Sandisk C200v1 */ | ||
135 | # define CURRENT_NORMAL 45 /* Should be nearly identical to E200 */ | ||
136 | # define CURRENT_BACKLIGHT 40 /* Screen is about 20, blue LEDs are another 20, so 40 if both */ | ||
137 | # define CURRENT_RECORD 40 /* flash player, so this is just unboosted current*/ | ||
138 | #elif defined(IPOD_4G) /* iPOD 4G */ | ||
139 | # define CURRENT_NORMAL 100 /* MP3: ~10.5h out of 1100mAh battery */ | ||
140 | # define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */ | ||
141 | #if defined(HAVE_RECORDING) | ||
142 | # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */ | ||
143 | #endif | 92 | #endif |
144 | #else /* Not iriver H1x0, H3x0, nor Archos Ondio, nor iPod nano/Video/4G, nor Sansas */ | 93 | #endif /* HAVE_RECORDING */ |
145 | # define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */ | 94 | |
146 | # define CURRENT_BACKLIGHT 30 /* additional current when backlight always on */ | 95 | #ifndef CURRENT_USB |
147 | #if defined(HAVE_RECORDING) | 96 | #define CURRENT_USB 500 /* usual current in mA in USB mode */ |
148 | # define CURRENT_RECORD 35 /* FIXME: this needs adjusting */ | ||
149 | #endif | 97 | #endif |
150 | #endif /* Not Archos Ondio */ | 98 | |
151 | #define CURRENT_USB 500 /* usual current in mA in USB mode */ | ||
152 | #ifdef HAVE_REMOTE_LCD | 99 | #ifdef HAVE_REMOTE_LCD |
153 | # define CURRENT_REMOTE 8 /* add. current when H100-remote connected */ | 100 | #define CURRENT_REMOTE 8 /* additional current when remote connected */ |
154 | #endif /* HAVE_REMOTE_LCD */ | 101 | #endif /* HAVE_REMOTE_LCD */ |
155 | 102 | ||
156 | # define CURRENT_MIN_CHG 70 /* minimum charge current */ | 103 | #if CONFIG_CHARGING |
157 | # define MIN_CHG_V 8500 /* at 8.5v charger voltage get CURRENT_MIN_CHG */ | 104 | #ifndef CURRENT_MAX_CHG |
158 | # ifdef IRIVER_H300_SERIES | 105 | #define CURRENT_MAX_CHG 350 /* maximum charging current */ |
159 | # define CURRENT_MAX_CHG 650 /* maximum charging current */ | 106 | #endif |
160 | # else | 107 | #endif /* CONFIG_CHARGING */ |
161 | # define CURRENT_MAX_CHG 350 /* maximum charging current */ | 108 | |
162 | # endif | 109 | #ifdef CHARGING_DEBUG_FILE |
163 | # define MAX_CHG_V 10250 /* anything over 10.25v gives CURRENT_MAX_CHG */ | 110 | #define POWERMGMT_DEBUG_STACK ((0x1000)/sizeof(long)) |
164 | #endif /* not ONDIO */ | 111 | #else |
112 | #define POWERMGMT_DEBUG_STACK 0 | ||
113 | #endif | ||
165 | 114 | ||
166 | #if CONFIG_CHARGING == CHARGING_TARGET | 115 | #ifndef BATT_AVE_SAMPLES |
167 | /* Include target-specific definitions */ | 116 | /* slw filter constant unless otherwise specified */ |
168 | #include "powermgmt-target.h" | 117 | #define BATT_AVE_SAMPLES 128 |
118 | #endif | ||
119 | |||
120 | #ifndef POWER_THREAD_STEP_TICKS | ||
121 | /* 2HZ sample rate unless otherwise specified */ | ||
122 | #define POWER_THREAD_STEP_TICKS (HZ/2) | ||
169 | #endif | 123 | #endif |
170 | 124 | ||
171 | extern unsigned short power_history[POWER_HISTORY_LEN]; | 125 | extern unsigned short power_history[POWER_HISTORY_LEN]; |
@@ -179,12 +133,6 @@ extern const unsigned short percent_to_volt_charge[11]; | |||
179 | /* Start up power management thread */ | 133 | /* Start up power management thread */ |
180 | void powermgmt_init(void); | 134 | void powermgmt_init(void); |
181 | 135 | ||
182 | /* Do target portion of init (for CHARGING_TARGET) - called on power thread */ | ||
183 | void powermgmt_init_target(void); | ||
184 | |||
185 | /* Handle frequent tasks and call charging_algorithm_small_step */ | ||
186 | void power_thread_sleep(int ticks); | ||
187 | |||
188 | #endif /* SIMULATOR */ | 136 | #endif /* SIMULATOR */ |
189 | 137 | ||
190 | /* Returns battery statust */ | 138 | /* Returns battery statust */ |
@@ -193,9 +141,15 @@ int battery_time(void); /* minutes */ | |||
193 | unsigned int battery_adc_voltage(void); /* voltage from ADC in millivolts */ | 141 | unsigned int battery_adc_voltage(void); /* voltage from ADC in millivolts */ |
194 | unsigned int battery_voltage(void); /* filtered batt. voltage in millivolts */ | 142 | unsigned int battery_voltage(void); /* filtered batt. voltage in millivolts */ |
195 | 143 | ||
144 | #ifdef HAVE_BATTERY_SWITCH | ||
145 | unsigned int input_millivolts(void); /* voltage that device is running from */ | ||
146 | |||
196 | /* Set the filtered battery voltage (to adjust it before beginning a charge | 147 | /* Set the filtered battery voltage (to adjust it before beginning a charge |
197 | cycle for instance where old, loaded readings will likely be invalid). */ | 148 | * cycle for instance where old, loaded readings will likely be invalid). |
198 | void set_filtered_battery_voltage(int millivolts); | 149 | * Also readjust when battery switch is opened or closed. |
150 | */ | ||
151 | void reset_battery_filter(int millivolts); | ||
152 | #endif /* HAVE_BATTERY_SWITCH */ | ||
199 | 153 | ||
200 | /* read unfiltered battery info */ | 154 | /* read unfiltered battery info */ |
201 | void battery_read_info(int *voltage, int *level); | 155 | void battery_read_info(int *voltage, int *level); |
@@ -203,13 +157,10 @@ void battery_read_info(int *voltage, int *level); | |||
203 | /* Tells if the battery level is safe for disk writes */ | 157 | /* Tells if the battery level is safe for disk writes */ |
204 | bool battery_level_safe(void); | 158 | bool battery_level_safe(void); |
205 | 159 | ||
206 | #ifdef TARGET_POWERMGMT_FILTER_CHARGE_STATE | ||
207 | int powermgmt_filter_charge_state(void); | ||
208 | #endif | ||
209 | |||
210 | void set_poweroff_timeout(int timeout); | 160 | void set_poweroff_timeout(int timeout); |
211 | void set_battery_capacity(int capacity); /* set local battery capacity value */ | 161 | void set_battery_capacity(int capacity); /* set local battery capacity value */ |
212 | void set_battery_type(int type); /* set local battery type */ | 162 | int get_battery_capacity(void); /* get local battery capacity value */ |
163 | void set_battery_type(int type); /* set local battery type */ | ||
213 | 164 | ||
214 | void set_sleep_timer(int seconds); | 165 | void set_sleep_timer(int seconds); |
215 | int get_sleep_timer(void); | 166 | int get_sleep_timer(void); |