summaryrefslogtreecommitdiff
path: root/drivers/power/wmt_battery/gauge/ug31xx/uG31xx_API.h
blob: c601852c50b8f188c762413ec3dd8dff1a8df651 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
/// ===========================================
/// uG31xx_API.h
/// ===========================================

#ifndef _UG31XXAPI_H_
#define _UG31XXAPI_H_

#include "uG31xx_Platform.h"

#if defined (uG31xx_OS_WINDOWS)

  #include <windows.h>

#endif

#include "global.h"
#include "uG31xx.h"

#if defined (uG31xx_OS_WINDOWS)

  #include "../../uG31xx_I2C_DLL/uG3100Dll/uG31xx_I2C.h"
  #include <assert.h>
  
  #ifdef DEBUG_LOG
  
    #include "wDebug.h"
    
  #endif
  
#elif defined (uG31xx_OS_ANDROID)

  #ifdef  uG31xx_BOOT_LOADER

    #include <sys/types.h>
    #include <platform/timer.h>

    #include "ug31xx_boot_i2c.h"

  #else   ///< else of uG31xx_BOOT_LOADER

    #include <linux/module.h>
    #include <linux/slab.h>
    #include <linux/delay.h>
    #include <linux/time.h>
    #include <asm/div64.h>
    #include <linux/jiffies.h>
    #include <linux/types.h>
    #include <linux/fs.h>
    #include <asm/uaccess.h>

    #include "ug31xx_i2c.h"

  #endif  ///< end of uG31xx_BOOT_LOADER

#endif

#include "typeDefine.h"
#include "uG31xx_Reg_Def.h"
#include "uG31xx_API_Otp.h"
#include "uG31xx_API_System.h"
#include "uG31xx_API_Measurement.h"
#include "uG31xx_API_Capacity.h"
#include "uG31xx_API_Backup.h"

#define	UG31XX_API_RELEASE_VERSION	(20131108)

#define UG31XX_API_MAIN_VERSION     (13)
#define UG31XX_API_OTP_VERSION      ((UG31XX_OTP_VERSION_MAIN << 16) | UG31XX_OTP_VERSION_SUB)
#define UG31XX_API_SUB_VERSION      ((UG31XX_CAP_VERSION << 16) | (UG31XX_MEAS_VERSION << 8) | UG31XX_SYSTEM_VERSION)

#define UG31XX_I2C_HIGH_SPEED_MODE    (_UPI_FALSE_)
#define UG31XX_I2C_TEM_BITS_MODE      (_UPI_FALSE_)

#define UG31XX_MAX_TEMPERATURE_BEFORE_READY     (395)
#define UG31XX_MIN_TEMPERATURE_BEFORE_READY     (105)

#ifdef  UG31XX_DEBUG_ENABLE

  #if defined(uG31xx_OS_ANDROID)

    #ifdef  uG31xx_BOOT_LOADER
          
      #define __func__        

      #define UG31_LOGE(...)
      #define UG31_LOGI(...)
      #define UG31_LOGD(...)
      #define UG31_LOGV(...)

      extern int ug31_dprintk(int level, const char *fmt, ...);
      
    #else   ///< else of uG31xx_BOOT_LOADER
    
      #define LOG_NORMAL      (0)
      #define LOG_ERROR       (1)
      #define LOG_DATA        (2)
      #define LOG_VERBOSE     (3)
      
      #define UG31_TAG "UG31"
      #define UG31_LOGE(...)  ug31_printk(LOG_ERROR, "<"UG31_TAG"/E>"  __VA_ARGS__);
      #define UG31_LOGI(...)  ug31_printk(LOG_NORMAL, "<"UG31_TAG"/I>"  __VA_ARGS__);
      #define UG31_LOGD(...)  ug31_printk(LOG_DATA, "<"UG31_TAG"/D>"  __VA_ARGS__);
      #define UG31_LOGV(...)  ug31_printk(LOG_VERBOSE, "<"UG31_TAG"/V>"  __VA_ARGS__);
      
      extern int ug31_printk(int level, const char *fmt, ...); 

    #endif  ///< end of uG31xx_BOOT_LOADER
    
  #endif  ///< end of defined(uG31xx_OS_ANDROID)

  #if defined (uG31xx_OS_WINDOWS)

    #define DEBUG_FILE      (_T("uG3105"))
    #define __func__        (_T(__FUNCTION__))

    #define UG31_LOGE(...)  wDebug::LOGE(DEBUG_FILE, 0, _T(__VA_ARGS__));
    #define UG31_LOGI(...)  wDebug::LOGE(DEBUG_FILE, 0, _T(__VA_ARGS__));
    #define UG31_LOGD(...)  wDebug::LOGE(DEBUG_FILE, 0, _T(__VA_ARGS__));
    #define UG31_LOGV(...)  wDebug::LOGE(DEBUG_FILE, 0, _T(__VA_ARGS__));

  #endif  ///< end of defined (uG31xx_OS_WINDOWS)
  
#else   ///< else of UG31XX_DEBUG_ENABLE

  #define UG31_LOGE(...)
  #define UG31_LOGI(...)
  #define UG31_LOGD(...)
  #define UG31_LOGV(...)

#endif  ///< end of UG31XX_DEBUG_ENABLE

#if defined(uG31xx_OS_ANDROID)

  extern _upi_u32_ GetTickCount(void);
  extern _upi_u32_ GetSysTickCount(void);
  
#endif

/* data struct */
typedef enum _GGSTATUS{
  UG_SUCCESS                    = 0x00,
  UG_FAIL		                    = 0x01,
  UG_NOT_DEF                    = 0x02,
  UG_INIT_OCV_FAIL	            = 0x03,
  UG_READ_GGB_FAIL              = 0x04,
  UG_ACTIVE_FAIL                = 0x05,
  UG_INIT_SUCCESS               = 0x06,
  UG_OTP_ISEMPTY                = 0x07,
  UG_OTP_PRODUCT_DISMATCH       = 0x08,

  UG_I2C_INIT_FAIL              = 0x10,
  UG_I2C_READ_SUCCESS           = 0x11,
  UG_I2C_READ_FAIL              = 0x12,
  UG_I2C_WRITE_SUCCESS          = 0x13,
  UG_I2C_WRITE_FAIL             = 0x14,

  UG_READ_REG_SUCCESS           = 0x20,
  UG_READ_REG_FAIL              = 0x21,

  UG_READ_DEVICE_INFO_SUCCESS   = 0x22,
  UG_READ_DEVICE_INFO_FAIL      = 0x23,
  UG_READ_DEVICE_ALARM_SUCCESS  = 0x24,
  UG_READ_DEVICE_ALARM_FAIL     = 0x25,
  UG_READ_DEVICE_RID_SUCCESS	  = 0x26,
  UG_READ_DEVICE_RID_FAIL		    = 0x27,
  UG_READ_ADC_FAIL						  = 0x28,			//new add for filter ADC Error Code

  UG_TI_CMD_OVERFLOW            = 0x30,

  UG_MEAS_FAIL                  = 0x40,
  UG_MEAS_FAIL_BATTERY_REMOVED  = 0x41,
  UG_MEAS_FAIL_ADC_ABNORMAL     = 0x42,
  UG_MEAS_FAIL_NTC_SHORT        = 0x43,

  UG_CAP_DATA_READY             = 0x50,
  UG_CAP_DATA_NOT_READY         = 0x51,
}GGSTATUS;

/*
    GGSTATUS upiGG_Initial
    Description: Initial and active uG31xx function
    Input: .GGB(gas gauge battery) setting filename, need include complete path
	Output: UG_INIT_SUCCESS -> initial uG31xx success
	        UG_READ_GGB_FAIL -> read GGB file fail
			UG_INIT_I2C_FAIL -> initial I2C to open HID fail
			UG_ACTIVE_FAIL -> active uG31xx fail
*/
#if defined (uG31xx_OS_WINDOWS)

  EXPORTS GGSTATUS upiGG_Initial(char **pObj, const wchar_t* GGBFilename, const wchar_t* OtpFileName, const wchar_t* BackupFileName, char reset, unsigned char MaxETFixCnt);

#endif

#if defined(uG31xx_OS_ANDROID)

  GGSTATUS upiGG_Initial(char **pObj, GGBX_FILE_HEADER *pGGBXBuf, char reset, unsigned char MaxETFixCnt);

#endif

/*
    GGSTATUS upiGG_CountInitQmax
    Description:
    Input: None
	Output: None
*/
//EXPORTS void upiGG_CountInitQmax(void);

/*
    GGSTATUS upiGG_ReadDevieRegister
    Description: Read GG_USER_REG from device to global variable and output
    Input: Pointer of sturct GG_USER_REG 
	Output: UG_READ_REG_SUCCESS -> read success
	        UG_READ_REG_FAIL -> read fail
*/
EXPORTS GGSTATUS upiGG_ReadAllRegister(char *pObj,GG_USER_REG* pExtUserReg, GG_USER2_REG* pExtUserReg2);

/*
    GGSTATUS upiGG_ReadDeviceInfo
    Description: Read GG_USER_REG from device and calculate GG_DEVICE_INFO, then write to global variable and output
    Input: Pointer of struct GG_DEVICE_INFO
	Output: UG_READ_DEVICE_INFO_SUCCESS -> calculate derive information sucess
	        UG_READ_DEVICE_INFO_FAIL -> calculate derive information fail
*/
EXPORTS GGSTATUS upiGG_ReadDeviceInfo(char *pObj,GG_DEVICE_INFO* pExtDeviceInfo);

/* GGSTATUS upiGG_ReadCapacity
    Description:
    Input:
	Output: None
*/
EXPORTS void upiGG_ReadCapacity(char *pObj,GG_CAPACITY *pExtCapacity);

/**
 * @brief upiGG_GetAlarmStatus
 *
 *  Get alarm status
 *
 * @para  pAlarmStatus  address of alarm status
 * @return  UG_READ_DEVICE_ALARM_SUCCESS if success
 */
EXPORTS GGSTATUS upiGG_GetAlarmStatus(char *pObj, _upi_u8_ *pAlarmStatus);

/*
new add function for System suspend & wakeup

*/
EXPORTS GGSTATUS upiGG_PreSuspend(char *pObj);
EXPORTS GGSTATUS upiGG_Wakeup(char *pObj, int dc_in_before);

/**
 * @brief upiGG_DumpRegister
 *
 *  Dump whole register value
 *
 * @para  pBuf  address of register value buffer
 * @return  data size
 */
EXPORTS _upi_u16_ upiGG_DumpRegister(char *pObj, _upi_u8_ *pBuf);

/**
 * @brief upiGG_DumpCellTable
 *
 *  Dump cell NAC table
 *
 * @para  pTable address of cell table
 * @return  _UPI_NULL_
 */
EXPORTS void upiGG_DumpCellTable(char *pObj, CELL_TABLE *pTable);
EXPORTS GGSTATUS upiGG_UnInitial(char **pObj);
EXPORTS void upiGG_DumpParameter(char *pObj, CELL_PARAMETER *pTable);

#define upiGG_PrePowerOff (upiGG_PreSuspend)

#ifdef ENABLE_BQ27520_SW_CMD

/**
 * @brief upiGG_AccessMeasurementParameter
 *
 *  Access measurement parameter
 *
 * @para  read  set _UPI_TRUE_ to read data from API
 * @para  pMeasPara pointer of GG_MEAS_PARA_TYPE
 * @return  GGSTATUS
 */
EXPORTS GGSTATUS upiGG_AccessMeasurementParameter(char *pObj, _upi_bool_ read, GG_MEAS_PARA_TYPE *pMeasPara);

#define UG_STD_CMD_CNTL     (0x00)
  #define UG_STD_CMD_CNTL_CONTROL_STATUS    (0x0000)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_DLOGEN     (1<<15)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_FAS        (1<<14)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_SS         (1<<13)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_CSV        (1<<12)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_CCA        (1<<11)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_BCA        (1<<10)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_OCVCMDCOMP (1<<9)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_OCVFAIL    (1<<8)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_INITCOMP   (1<<7)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_HIBERNATE  (1<<6)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_SNOOZE     (1<<5)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_SLEEP      (1<<4)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_LDMD       (1<<3)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_RUP_DIS    (1<<2)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_VOK        (1<<1)
    #define UG_STD_CMD_CNTL_CONTROL_STATUS_QEN        (1<<0)
  #define UG_STD_CMD_CNTL_DEVICE_TYPE       (0x0001)
  #define UG_STD_CMD_CNTL_FW_VERSION        (0x0002)
  #define UG_STD_CMD_CNTL_PREV_MACWRITE     (0x0007)
  #define UG_STD_CMD_CNTL_CHEM_ID           (0x0008)
  #define UG_STD_CMD_CNTL_OCV_CMD           (0x000C)      ///< [AT-PM] : Not implemented ; 10/11/2012
  #define UG_STD_CMD_CNTL_BAT_INSERT        (0x000D)
  #define UG_STD_CMD_CNTL_BAT_REMOVE        (0x000E)
  #define UG_STD_CMD_CNTL_SET_HIBERNATE     (0x0011)
  #define UG_STD_CMD_CNTL_CLEAR_HIBERNATE   (0x0012)
  #define UG_STD_CMD_CNTL_SET_SLEEP_PLUS    (0x0013)
  #define UG_STD_CMD_CNTL_CLEAR_SLEEP_PLUS  (0x0014)
  #define UG_STD_CMD_CNTL_FACTORY_RESTORE   (0x0015)
  #define UG_STD_CMD_CNTL_ENABLE_DLOG       (0x0018)
  #define UG_STD_CMD_CNTL_DISABLE_DLOG      (0x0019)
  #define UG_STD_CMD_CNTL_DF_VERSION        (0x001F)
  #define UG_STD_CMD_CNTL_SEALED            (0x0020)
  #define UG_STD_CMD_CNTL_RESET             (0x0041)
#define UG_STD_CMD_AR       (0x02)
#define UG_STD_CMD_ARTTE    (0x04)
#define UG_STD_CMD_TEMP     (0x06)
#define UG_STD_CMD_VOLT     (0x08)
#define UG_STD_CMD_FLAGS    (0x0A)
  #define UG_STD_CMD_FLAGS_OTC            (1<<15)
  #define UG_STD_CMD_FLAGS_OTD            (1<<14)
  #define UG_STD_CMD_FLAGS_RSVD13         (1<<13)
  #define UG_STD_CMD_FLAGS_RSVD12         (1<<12)
  #define UG_STD_CMD_FLAGS_CHG_INH        (1<<11)
  #define UG_STD_CMD_FLAGS_XCHG           (1<<10)
  #define UG_STD_CMD_FLAGS_FC             (1<<9)
  #define UG_STD_CMD_FLAGS_CHG            (1<<8)
  #define UG_STD_CMD_FLAGS_RSVD7          (1<<7)
  #define UG_STD_CMD_FLAGS_RSVD6          (1<<6)
  #define UG_STD_CMD_FLAGS_OCV_GD         (1<<5)
  #define UG_STD_CMD_FLAGS_WAIT_ID        (1<<4)
  #define UG_STD_CMD_FLAGS_BAT_DET        (1<<3)
  #define UG_STD_CMD_FLAGS_SOC1           (1<<2)
  #define UG_STD_CMD_FLAGS_SYSDOWN        (1<<1)
  #define UG_STD_CMD_FLAGS_DSG            (1<<0)
#define UG_STD_CMD_NAC      (0x0C)
#define UG_STD_CMD_FAC      (0x0E)
#define UG_STD_CMD_RM       (0x10)
#define UG_STD_CMD_FCC      (0x12)
#define UG_STD_CMD_AI       (0x14)
#define UG_STD_CMD_TTE      (0x16)
#define UG_STD_CMD_TTF      (0x18)
#define UG_STD_CMD_SI       (0x1A)
#define UG_STD_CMD_STTE     (0x1C)
#define UG_STD_CMD_MLI      (0x1E)
#define UG_STD_CMD_MLTTE    (0x20)
#define UG_STD_CMD_AE       (0x22)
#define UG_STD_CMD_AP       (0x24)
#define UG_STD_CMD_TTECP    (0x26)
#define UG_STD_CMD_SOH      (0x28)
  #define UG_STD_CMD_SOH_VALUE_MASK   (0x00FF)
  #define UG_STD_CMD_SOH_STATUS_MASK  (0xFF00)
    #define UG_STD_CMD_SOH_STATUS_NOT_VALID     (0x0000)
    #define UG_STD_CMD_SOH_STATUS_INSTANT_READY (0x0100)
    #define UG_STD_CMD_SOH_STATUS_INITIAL_READY (0x0200)
    #define UG_STD_CMD_SOH_STATUS_READY         (0x0300)
#define UG_STD_CMD_CC       (0x2A)
#define UG_STD_CMD_SOC      (0x2C)
#define UG_STD_CMD_NIC      (0x2E)      ///< [AT-PM] : Not implemented ; 10/11/2012
#define UG_STD_CMD_ICR      (0x30)
#define UG_STD_CMD_DLI      (0x32)
#define UG_STD_CMD_DLB      (0x34)
#define UG_STD_CMD_ITEMP    (0x36)
#define UG_STD_CMD_OPCFG    (0x3A)
  #define UG_STD_CMD_OPCFG_RESCAP     (1<<31)
  #define UG_STD_CMD_OPCFG_BATG_OVR   (1<<30)
  #define UG_STD_CMD_OPCFG_INT_BERM   (1<<29)
  #define UG_STD_CMD_OPCFG_PFC_CFG1   (1<<28)
  #define UG_STD_CMD_OPCFG_PFC_CFG0   (1<<27)
  #define UG_STD_CMD_OPCFG_IWAKE      (1<<26)
  #define UG_STD_CMD_OPCFG_RSNS1      (1<<25)
  #define UG_STD_CMD_OPCFG_RSNS0      (1<<24)
  #define UG_STD_CMD_OPCFG_INT_FOCV   (1<<23)
  #define UG_STD_CMD_OPCFG_IDSELEN    (1<<22)
  #define UG_STD_CMD_OPCFG_SLEEP      (1<<21)
  #define UG_STD_CMD_OPCFG_RMFCC      (1<<20)
  #define UG_STD_CMD_OPCFG_SOCI_POL   (1<<19)
  #define UG_STD_CMD_OPCFG_BATG_POL   (1<<18)
  #define UG_STD_CMD_OPCFG_BATL_POL   (1<<17)
  #define UG_STD_CMD_OPCFG_TEMPS      (1<<16)
  #define UG_STD_CMD_OPCFG_WRTEMP     (1<<15)
  #define UG_STD_CMD_OPCFG_BIE        (1<<14)
  #define UG_STD_CMD_OPCFG_BL_INT     (1<<13)
  #define UG_STD_CMD_OPCFG_GNDSEL     (1<<12)
  #define UG_STD_CMD_OPCFG_FCE        (1<<11)
  #define UG_STD_CMD_OPCFG_DFWRINDBL  (1<<10)
  #define UG_STD_CMD_OPCFG_RFACTSTEP  (1<<9)
  #define UG_STD_CMD_OPCFG_INDFACRES  (1<<8)
  #define UG_STD_CMD_OPCFG_BATGSPUEN  (1<<7)
  #define UG_STD_CMD_OPCFG_BATGWPUEN  (1<<6)
  #define UG_STD_CMD_OPCFG_BATLSPUEN  (1<<5)
  #define UG_STD_CMD_OPCFG_BATLWSPUEN (1<<4)
  #define UG_STD_CMD_OPCFG_RSVD3      (1<<3)
  #define UG_STD_CMD_OPCFG_SLPWKCHG   (1<<2)
  #define UG_STD_CMD_OPCFG_DELTAVOPT1 (1<<1)
  #define UG_STD_CMD_OPCFG_DELTAVOPT0 (1<<0)
#define UG_EXT_CMD_DCAP     (0x3C)

/**
 * @brief upiGG_FetchDataCommand
 *
 *  Fetch bq27520 like command
 *
 * @para  read  set _UPI_TRUE_ to read data from API
 * @para  pMeasPara pointer of GG_MEAS_PARA_TYPE
 * @return  GGSTATUS
 */
EXPORTS GGSTATUS upiGG_FetchDataCommand(char *pObj, _upi_u8_ CommandCode, _upi_u16_ *pData);

typedef struct GG_FETCH_DATA_PARA_ST {
  _upi_s8_ FCSet;
  _upi_s8_ FCClear;
  _upi_u8_ Soc1Set;
  _upi_u8_ Soc1Clear;
  _upi_s8_ InitSI;
  _upi_s16_ InitMaxLoadCurrent;
  _upi_u16_ CCThreshold;
  _upi_u32_ Opcfg;
  _upi_u16_ Dcap;
#if defined(uG31xx_OS_ANDROID)
}__attribute__((packed)) GG_FETCH_DATA_PARA_TYPE;
#else   ///< else of defined(uG31xx_OS_ANDROID)
} GG_FETCH_DATA_PARA_TYPE;
#endif  ///< end of defined(uG31xx_OS_ANDROID)

/**
 * @brief upiGG_FetchDataParameter
 *
 *  Set the parameter for bq27520 like command
 *
 * @para  data  parameters of GG_FETCH_DATA_PARA_TYPE
 * @return  GGSTATUS
 */
EXPORTS GGSTATUS upiGG_FetchDataParameter(char *pObj, GG_FETCH_DATA_PARA_TYPE data);

#endif     //endif ENABLE_BQ27520_SW_CMD

typedef struct GG_FETCH_DEBUG_DATA_ST {
  /// [AT-PM] : Driver version ; 01/30/2013
  int versionMain;
  int versionOtp;
  int versionSub;

  /// [AT-PM] : Capacity related ; 01/30/2013
  int capStatus;
  int capSelfHour;
  int capSelfMin;
  int capSelfSec;
  int capSelfMilliSec;
  int capTPTime;
  int capDelta;
  int capDsgCharge;
  int capDsgChargeStart;
  int capDsgChargeTime;
  int capPreDsgCharge;
  int capTableUpdateIdx;

  /// [AT-PM] : Measurement related ; 01/30/2013
  int measCodeBat1;
  int measCodeCurrent;
  int measCodeIT;
  int measCodeET;
  int measCharge;
  int measCCOffset;
  int measAdc1ConvertTime;
  int measAdc1Gain;
  int measAdc1Offset;
  int measAdc2Gain;
  int measAdc2Offset;
  int measLastCounter;
  int measLastTimeTick;
  int measLastDeltaQ;
  
#if defined(uG31xx_OS_ANDROID)
  }__attribute__((packed)) GG_FETCH_DEBUG_DATA_TYPE;
#else   ///< else of defined(uG31xx_OS_ANDROID)
  } GG_FETCH_DEBUG_DATA_TYPE;
#endif  ///< end of defined(uG31xx_OS_ANDROID)

/**
 * @brief upiGG_FetchDebugData
 *
 *  Fetch debug information data
 *
 * @para  pObj  address of memory buffer
 * @para  data  address of GG_FETCH_CAP_DATA_TYPE
 * @return  _UPI_NULL_
 */
EXPORTS void upiGG_FetchDebugData(char *pObj, GG_FETCH_DEBUG_DATA_TYPE *data);

/**
 * @brief upiGG_DebugSwitch
 *
 *  Enable/disable debug information to UART
 *
 * @para  Enable  set _UPI_TRUE_ to enable it
 * @return  NULL
 */
EXPORTS void upiGG_DebugSwitch(_upi_bool_ enable);

#define	UPI_CHECK_BACKUP_FILE_FAIL	(0)
#define	UPI_CHECK_BACKUP_FILE_EXIST	(1)
#define	UPI_CHECK_BACKUP_FILE_MISMATCH	(2)

EXPORTS _upi_u8_ upiGG_CheckBackupFile(char *pObj);

EXPORTS void upiGG_ForceTaper(char *pObj, int charger_full, int dc_in_before, int dc_in_now);

#endif  ///< end of _UG31XXAPI_H_

/// ===========================================
/// End of uG31xx_API.h
/// ===========================================