summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/ypr0/powermgmt-ypr0.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/ypr0/powermgmt-ypr0.c')
-rw-r--r--firmware/target/hosted/ypr0/powermgmt-ypr0.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/firmware/target/hosted/ypr0/powermgmt-ypr0.c b/firmware/target/hosted/ypr0/powermgmt-ypr0.c
new file mode 100644
index 0000000000..5701e9f02f
--- /dev/null
+++ b/firmware/target/hosted/ypr0/powermgmt-ypr0.c
@@ -0,0 +1,133 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: powermgmt-sim.c 29543 2011-03-08 19:33:30Z thomasjfox $
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include "system.h"
21#include <time.h>
22#include "kernel.h"
23#include "powermgmt.h"
24#include "ascodec-target.h"
25#include "stdio.h"
26
27#if 0 /*still unused*/
28/* The battery manufacturer's website shows discharge curves down to 3.0V,
29 so 'dangerous' and 'shutoff' levels of 3.4V and 3.3V should be safe.
30 */
31const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
32{
33 3550
34};
35
36const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
37{
38 3450
39};
40
41/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
42const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
43{
44 { 3300, 3692, 3740, 3772, 3798, 3828, 3876, 3943, 4013, 4094, 4194 }
45};
46
47#if CONFIG_CHARGING
48/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
49const unsigned short percent_to_volt_charge[11] =
50{
51 3417, 3802, 3856, 3888, 3905, 3931, 3973, 4025, 4084, 4161, 4219
52};
53#endif /* CONFIG_CHARGING */
54#endif
55
56#define BATT_MINMVOLT 3450 /* minimum millivolts of battery */
57#define BATT_MAXMVOLT 4150 /* maximum millivolts of battery */
58#define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in
59 minutes */
60
61extern void send_battery_level_event(void);
62extern int last_sent_battery_level;
63extern int battery_percent;
64
65static unsigned int battery_millivolts = BATT_MAXMVOLT;
66/* estimated remaining time in minutes */
67static int powermgmt_est_runningtime_min = BATT_MAXRUNTIME;
68
69static void battery_status_update(void)
70{
71 static time_t last_change = 0;
72 time_t now;
73
74 time(&now);
75
76 if (last_change < now) {
77 last_change = now;
78
79 battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) /
80 (BATT_MAXMVOLT - BATT_MINMVOLT);
81
82 powermgmt_est_runningtime_min =
83 battery_percent * BATT_MAXRUNTIME / 100;
84 }
85
86 send_battery_level_event();
87}
88
89void battery_read_info(int *voltage, int *level)
90{
91 battery_status_update();
92
93 if (voltage)
94 *voltage = battery_millivolts;
95
96 if (level)
97 *level = battery_percent;
98}
99
100unsigned int battery_voltage(void)
101{
102 battery_status_update();
103 return battery_millivolts;
104}
105
106int battery_level(void)
107{
108 battery_status_update();
109 return battery_percent;
110}
111
112int battery_time(void)
113{
114 battery_status_update();
115 return powermgmt_est_runningtime_min;
116}
117
118bool battery_level_safe(void)
119{
120 return battery_level() >= 10;
121}
122
123void set_battery_capacity(int capacity)
124{
125 (void)capacity;
126}
127
128#if BATTERY_TYPES_COUNT > 1
129void set_battery_type(int type)
130{
131 (void)type;
132}
133#endif