comparison src/cs/drivers/drv_app/lcc/lcc.h @ 0:945cf7f506b2

src/cs: chipsetsw import from tcs211-fcmodem binary blobs and LCD demo files have been excluded, all line endings are LF only
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 25 Sep 2016 22:50:11 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:945cf7f506b2
1 /******************************************************************************
2 * Power Task (pwr)
3 * Design and coding by Svend Kristian Lindholm, skl@ti.com
4 *
5 * PWR Types and globals
6 *
7 * $Id: pwr.h 1.2 Wed, 20 Aug 2003 12:54:50 +0200 skl $
8 *
9 ******************************************************************************/
10
11 #ifndef _LCC_H_
12 #define _LCC_H_
13
14 #include "lcc/lcc_cfg.h"
15
16 #ifdef _RVF
17 #include "rvf/rvf_api.h"
18 #include "rv/rv_general.h"
19 #include "lcc/lcc_api.h"
20 #include "lcc/lcc_cfg_i.h"
21 #endif
22
23 #define PWRVERSION 0x0202
24
25 /******************************************************************************
26 * Types
27 ******************************************************************************/
28
29 #ifndef BASIC_TYPES
30 #define BASIC_TYPES
31 typedef signed char int8;
32 typedef unsigned char uint8;
33 typedef signed short int16;
34 typedef unsigned short uint16;
35 typedef signed int int32;
36 typedef unsigned int uint32;
37 #endif
38
39 typedef int8 epwr_t; // error type
40
41
42
43 /******************************************************************************
44 * RVF Types
45 ******************************************************************************/
46
47 // Mail namings (REQ,IND,RSP) according to RIV010
48
49 // Request mail
50 struct pwr_req_s {
51 T_RV_HDR header;
52 };
53
54 // Indication mail with ADC measurements
55 struct pwr_adc_ind_s {
56 T_RV_HDR header;
57 unsigned short data[9+1]; // ADC measurements + status of VRPCSTS register
58 };
59
60 // Response mail sent to ETM
61 struct pwr_tm_req_s {
62 T_RV_HDR header;
63 };
64
65 typedef epwr_t T_PWR_RET;
66 typedef struct pwr_req_s T_PWR_REQ;
67
68 typedef struct
69 {
70 uint16 alfa_num; // Slope numerator
71 uint16 alfa_denom; // Slope denominator
72 int16 beta; // Offset
73 } T_PWR_I2V_CAL_BLOCK;
74
75 typedef struct
76 {
77 uint16 alfa_num; // Slope numerator
78 uint16 alfa_denom; // Slope denominator
79 int16 beta; // Offset
80 } T_PWR_VBAT_CAL_BLOCK;
81
82 // Corresponds to /pwr/i2v.cal and /pwr/vbat.cal
83 typedef struct
84 {
85 T_PWR_I2V_CAL_BLOCK i2v;
86 T_PWR_VBAT_CAL_BLOCK vbat;
87 } T_PWR_CAL_BLOCK;
88
89 // Corresponds to /pwr/common.cfg
90 typedef struct
91 {
92 uint32 sampling; /* 4 */ // The sampling time [ms] used
93 uint32 mod_cycle; /* 4 */ // The modulation cycle time [ms] used when performing modulation (Lithium only)
94 uint8 pins; /* 1 */ // Number of battery pins 2 - 3 - 4
95 uint8 chg_dedic; /* 1 */ // Charging performed (TRUE) or not (FALSE) in dedicated mode
96 uint8 alfa1; /* 1 */ // The regulation parameter N (Exponentially Weighted Moving Average) for Vbat
97 uint8 alfa2; /* 1 */ // The regulation parameter N (Exponentially Weighted Moving Average) for Tbat
98 uint8 alfa3; /* 1 */ // The regulation parameter N (Exponentially Weighted Moving Average) for Trf
99 uint8 rise_thr; /* 1 */ // The battery rise temperature follows RF rise temperature threshold (Nickel only)
100 } T_PWR_COMMON_CFG_BLOCK;
101
102 // Corresponds to /pwr/bat/bat<N>.cfg
103 typedef struct
104 {
105 uint16 type; /* 2 */ // Battery type - Nickel or Lithium
106 uint16 rf_temp; /* 2 */ // Use rf temperature (TRUE) or not (FALSE) if no battery temperature is availlable
107 uint32 id_low; /* 4 */ // Low battery id limit - used for identification
108 uint32 id_high; /* 4 */ // High battery id limit - used for identification
109 uint16 cbat; /* 2 */ // Standard battery capacity [mAh]
110 uint16 ratio; /* 2 */ // Time ratio of charge current [C] (%) - ratio x cbat = max charger current
111 uint32 T1; /* 4 */ // The total time charging counter
112 uint32 T2; /* 4 */ // The CV charging complete timer (-Nickel)
113 uint32 T3; /* 4 */ // The re-charge attempt timer counter
114 uint16 chg_start_thr; /* 2 */ // The CV charge begin battery voltage threshold value (-Nickel)
115 uint16 chg_stop_thr; /* 2 */ // The (CI and CV) charge end (stop) battery voltage threshold value
116 uint16 chg_ctrl_thr; /* 2 */ // The minimal charge control ('k_min') value threshold
117 uint16 chg_again_thr; /* 2 */ // The charge again capacity threshold (t=20 degrees)
118 } T_PWR_BAT_CFG_BLOCK;
119
120 // Corresponds to /pwr/bat/temp<N>.cfg
121 typedef struct
122 {
123 int16 tbat_min; /* 2 */ // Minimum battery temperature allowed
124 int16 tbat_max; /* 2*/ // Maximum battery temperature allowed
125
126 uint16 a0; /* 2 */ // Capacity temperature compensation a0 (a2*t*t + a1*t +a0)
127 uint16 a1; /* 2 */ // Capacity temperature compensation a1 (a2*t*t + a1*t +a0)
128 uint16 a2; /* 2 */ // Capacity temperature compensation a2 (a2*t*t + a1*t +a0)
129 // Capacity compensation function relative to t=20 degrees
130 // C(t=0) = C(t=20) + capacity compensation function(t=-20)
131
132 uint16 cap[9+1]; /* 20 */ // Capacity as a function of voltage measured at t=20 degrees - C(t=20)
133 // Capacity vector : 100%, 90%, 80%, 70% ,60% ,50%, 40%, 30%, 20%, 10%
134
135 uint16 i_meas1; /* 2 */ // The choosen measurement current, i_measure (typically 10uA and 50uA)
136 uint16 i_meas2; /* 2 */ // The choosen measurement current, i_measure (typically 10uA and 50uA)
137 uint16 v2t_1[8+1]; /* 18 */ // The voltage to temperature mapper for i_measure
138 uint16 v2t_2[8+1]; /* 18 */ // The voltage to temperature mapper for i_measure
139 // Temperature vector : -20, -10, 0, 10 ,20 ,30, 40, 50, 60
140 // Interpolation is applied when mapping
141
142
143 } T_PWR_BAT_TEMP_CFG_BLOCK;
144
145 // Corresponds to /pwr/chg/chg<N>.cfg
146 typedef struct
147 {
148 uint16 type; /* 2 */ // Charger type - Regulated (CI or CV) or unregulated (UNREGULATED)
149 uint16 ichg_max; /* 2 */ // Maximum charger current [mA] - normally decides the fast charging current
150 uint16 vchg_low; /* 2 */ // Low charger voltage limit (Open circuit - used for identification )
151 uint16 vchg_high; /* 2 */ // High charger voltage limit (Open circuit- used for identification)
152 } T_PWR_CHG_CFG_BLOCK;
153
154 // The power data block - dynamical data collected
155 typedef struct
156 {
157 uint16 bat_id; // Measured battery ID
158 uint16 chg_id; // Measured charger ID
159
160 uint16 Vbat; // Latest measured battery voltage
161 uint16 Vbat_avg; // Latest _average_ battery voltage
162 uint16 Vbat_avg_mV; // Latest _average_ battery voltage
163
164 uint16 Tbat; // Latest measured battery temperature
165 uint16 Tbat_avg; // Latest _average_ battery temperature
166
167 uint16 T_rf; // Latest measured RF temperature
168 uint16 T_rf_avg; // Latest _average_ RF temperature
169
170 uint16 Vchg; // Latest measured charger voltage
171 uint16 Ichg; // Latest measured charger current
172
173 uint16 Cbat; // Battery capacity in %
174
175 char cfg_id; // Configuration ID (bat<n>.cfg)
176 char chg_cfg_id; // Charger Configuration ID (chg<n>.cfg)
177 char bforce; // Force usage of battery configuration
178 char cforce; // Force usage of charger configuration
179 uint16 k; // Modulation value
180 uint32 T4; // The modulation ON T4 timer counter (variable!!)
181 } T_PWR_DATA_BLOCK;
182
183 // The PWR control block - state and debug info
184 typedef struct
185 {
186 int state; // The battery & charging state of the PWR task
187 uint8 flag_chg_plugged; // Charger has been plugged (1) or not (0) flag
188 uint8 flag_chg_prev_plugged; // The previous charger poll said plugged (1) or not plugged (0) flag
189 uint8 flag_chg_cfg_read; // Charger configuration has been read (1) or not (0) flag
190 uint8 flag_cal_cfg_read; // Calibration files has been read (1) or not (0) flag
191 uint8 flag_bat_unknown; // Battery was unknown (1) - or not (0) - the MMI must be told
192 uint8 flag_chg_unknown; // Charger plugged was unknown (1) - or not (0) - the MMI must be told
193 uint8 flag_mmi_registered; // MMI has registered (1) or not (0)
194 uint8 flag_prechg_started; // Stay in precharge state PRE - Apply fast charging no matter what charger type
195 uint8 flag_chg_int_disabled; // Charger interrupts are disabled (1) or enabled (0)
196 uint8 flag_ini_virgo; // Entering INI state for the very first time - in order to control some very basic initialization
197 uint8 cfg_id; // Applied battery configuration id
198 uint8 chg_cfg_id; // Applied charger configuration id
199 uint8 count_bat_type; // The number of battery identification measurements reported in state INI
200 uint8 count_chg_type; // The number of charger identification measurements made in state SUP
201 uint8 chg_unplug_vec[CONSECUTIVE_CHG_UNPLUGS]; // The charger unplug vector keeps the latest polled values of charger unplug
202 uint8 index; // The current index of the charger unplug vector
203 uint16 capacity; // The current capacity : 0..100%
204
205 // Timers
206 UINT32 time_begin_T0; // T0: Sampling timer (constant but modulo ADC updates)
207 UINT32 time_elapsed_T0;
208 UINT32 time_begin_T1; // T1: The total charging time timer (constant)
209 UINT32 time_elapsed_T1;
210 UINT32 time_begin_T2; // T2: The total CV charging time timer (constant)
211 UINT32 time_elapsed_T2;
212 UINT32 time_begin_T3; // T3: The charge-again-without start-stop of charging (constant)
213 UINT32 time_elapsed_T3;
214 UINT32 time_begin_T4; // T4: The duty cycle timer
215 UINT32 time_elapsed_T4;
216 UINT32 time_begin_mod_cycle; // The modulation cycle timer
217 UINT32 time_elapsed_mod_cycle;
218 UINT32 time_begin_mmi_rep; // MMI repetition
219 UINT32 time_elapsed_mmi_rep;
220
221 UINT32 tmask; // The trace mask used for the PWR process - activated by test mode
222
223 T_RVF_ADDR_ID addr_id; // Task address id assigned by Riviera framework
224 T_RVF_MB_ID prim_id; // Memory bank id assigned by Riviera framework
225
226 T_RV_RETURN rpath; // Return path of the MMI - initialized in pwr_register
227 struct mmi_info_ind_s *mmi_ptr; // Pointer to mmi event memory assigned by the MMI
228 } T_PWR_CTRL_BLOCK;
229
230 // The PWR configuration block - common, charger and battery
231 typedef struct
232 {
233 T_PWR_CAL_BLOCK cal; // Calibration matrix
234 T_PWR_COMMON_CFG_BLOCK common; // Common configuration
235 T_PWR_BAT_CFG_BLOCK bat; // Battery configuration
236 T_PWR_BAT_TEMP_CFG_BLOCK temp; // Battery temperature configuration
237 T_PWR_CHG_CFG_BLOCK chg; // Charger configuration
238 T_PWR_MMI_CFG_BLOCK mmi; // MMI configuration
239 T_PWR_DATA_BLOCK data; // Data (dynamic) related to configuration
240 } T_PWR_CFG_BLOCK;
241
242 // Use these values if no FFS files are found
243 // Units: [ms], [mV] and [mA]
244 #ifndef PWR_FFS_CFG
245 #define PWR_T0_THR 10000
246 #define PWR_T1_THR 1800000 // 1/2 hour
247 #define PWR_T2_THR 25000
248 #define PWR_T3_THR 10000
249 #define PWR_MOD_CYCLE_THR 10000
250 #define PWR_MMI_REP_THR 60000
251 #define PWR_ICHG_MAX 400
252 #define EXP_MOVING_AVG_FILTER1 5
253 #define EXP_MOVING_AVG_FILTER2 10
254 #define EXP_MOVING_AVG_FILTER3 10
255 #define PWR_TEMPERATURE_LOW -20
256 #define PWR_TEMPERATURE_HIGH 45
257 #define PWR_CV_START_THR 4050
258 #define PWR_CHG_STOP_THR 4100
259 #define PWR_RISE_THR 4
260 #define PWR_MIN_K 20
261 #define PWR_MAX_K 200
262 #endif
263
264 #define TYPEN 0x0080 /* Enables the 10uA bias current for the main battery type reading */
265 #define THERMAL_SENSOR_10uA 0x0041 /* THSENS0 , THSENS1, THSENS2 = 0, 0, 0 MESBAT = 1 */
266 #define THERMAL_SENSOR_30uA 0x0051 /* THSENS0 , THSENS1, THSENS2 = 0, 1, 0 MESBAT = 1 */
267 #define THERMAL_SENSOR_50uA 0x0061 /* THSENS0 , THSENS1, THSENS2 = 0, 0, 1 MESBAT = 1 */
268 #define THERMAL_SENSOR_80uA 0x0079 /* THSENS0 , THSENS1, THSENS2 = 1, 1, 1 MESBAT = 1 */
269 #define MESBAT 0x0001 /* Resistive divider connected to main battery */
270 #define CHARGER_IT_MSK 0x0008 /* Mask the charger plug/unplug interrupts */
271 #define ALL_IT_UMSK 0x0000 /* Unmask all interrupt 2 register related interrupts */
272
273 // Convert functions
274 #define ADC_to_mV(ADC) ((pwr_cfg->cal.vbat.alfa_num*(ADC))/(pwr_cfg->cal.vbat.alfa_denom) + pwr_cfg->cal.vbat.beta)
275 #define ADC_to_mA(ADC) ((pwr_cfg->cal.i2v.alfa_num*(ADC))/(pwr_cfg->cal.i2v.alfa_denom) + pwr_cfg->cal.i2v.beta)
276
277 // Inverse convert functions
278 #define mV_to_ADC(V) (pwr_cfg->cal.vbat.alfa_num*((V)/pwr_cfg->cal.vbat.alfa_denom) - pwr_cfg->cal.vbat.beta)
279 #define mA_to_ADC(I) (pwr_cfg->cal.i2v.alfa_num*((I)/pwr_cfg->cal.i2v.alfa_denom) - pwr_cfg->cal.i2v.beta)
280
281 /******************************************************************************
282 * Errors
283 ******************************************************************************/
284
285 enum PWR_ERRORS {
286 EPWR_OK = 0 /* ok */
287 };
288
289 /******************************************************************************
290 * Enumerations
291 ******************************************************************************/
292
293 // Message IDs for all PWR module messages
294 typedef enum PWR_MESSAGES {
295 NOP = 0,
296
297 /* Requests */
298 /* ABB */
299 /* MMI */
300 MMI_REGISTER_REQ = 20,
301
302 /* Timers*/
303 TIMER_T1_EXPIRED = 30,
304 TIMER_T2_EXPIRED,
305 TIMER_T3_EXPIRED,
306 TIMER_T4_EXPIRED,
307 TIMER_MOD_CYCLE_EXPIRED,
308 TIMER_MMI_INFO_EXPIRED,
309
310 /* Indications */
311 /* PWR */
312 PWR_CHARGER_PLUGGED_IND = 40,
313 PWR_CHARGER_UNPLUGGED_IND,
314
315 /* Confirmations */
316
317 /* Test mode */
318 /* Request */
319 PWR_TM_READ_REQ = 70,
320 PWR_TM_WRITE_REQ,
321
322 /* Indications */
323 PWR_TM_READ_IND = 80,
324 PWR_TM_WRITE_IND,
325
326 PWR_ADC_IND = 90
327
328 } pwr_msg_e;
329
330 // See LCC Detailed Design Specification
331 typedef enum PWR_STATES {
332 CAL = 0, // Reading calibration file(s)
333 PRE = 1, // Pre-charging no matter which charger type
334 INI = 2, // Reading configuration files
335 SUP = 3, // No charging - supervision only
336 CCI = 4, // Charging using CI/CV charger
337 LCI = 5, // Charging using linear charger
338 CCV = 6, // Charging using CI/CV charger
339 LCV = 7 // Charging using linear charger
340 } pwr_states_e;
341
342 // See RD818
343 typedef enum CHG_TYPES {
344 CI = 1,
345 CV = 2,
346 UNREGULATED = 3
347 } chg_types_e;
348
349 // See RD818
350 typedef enum BAT_TYPES {
351 LITHIUM = 1,
352 NICKEL = 2
353 } bat_types_e;
354
355 // See RIV261
356 typedef enum CAUSE_TYPES {
357 BATTERY_TEMPERATURE_OK = 0,
358 BATTERY_TEMPERATURE_LOW = 1,
359 BATTERY_TEMPERATURE_HIGH = 2
360 } cause_types_e;
361
362 enum PWR_Errors {
363 // PWR Common Target Errors
364 PWR_OK = 0, // Ok
365 PWR_INDEX = -1, // Unknown index
366 PWR_OK_MORE = -63, // Ok, more data coming
367 PWR_PACKET = -62, // Packet error (checksum or other)
368 PWR_FATAL = -61, // System fatal error
369 PWR_NOSYS = -60, // Module or function not present
370 PWR_INVAL = -59, // Invalid parameter/argument
371 PWR_BADOP = -58, // Operation not possible in current context
372 PWR_AGAIN = -57, // Not ready, try again later
373 PWR_NOMEM = -56, // Out of memory
374 PWR_MESSAGE = -55, // Received unknown message
375
376 // Errors that are related to the Riv env.
377 PWR_RV_NOT_SUPPORTED = -51, //
378 PWR_RV_MEMORY_ERR = -50, //
379 PWR_RV_INTERNAL_ERR = -49, //
380 PWR_RV_FATAL = -48 //
381
382 };
383
384 #endif //_LCC_H_