summaryrefslogtreecommitdiff
path: root/board/wmt/wmt_battery/gauge/upi/uG31xx_API_System.h
blob: f1579dc98e3957a7158f31e70704665a622dc05c (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
/**
 * @filename  uG31xx_API_System.h
 *
 *  Interface of ug31xx system control
 *
 * @author  AllenTeng <allen_teng@upi-semi.com>
 */

#define UG31XX_SYSTEM_VERSION     (6)

typedef unsigned char   _sys_u8_;
typedef signed char     _sys_s8_;
typedef unsigned short  _sys_u16_;
typedef signed short    _sys_s16_;
typedef unsigned long   _sys_u32_;
typedef signed long     _sys_s32_;
typedef char            _sys_bool_;

typedef enum _SYSTEM_RTN_CODE {
  SYSTEM_RTN_PASS = 0,
  SYSTEM_RTN_READ_GGB_FAIL,
  SYSTEM_RTN_I2C_FAIL,
} SYSTEM_RTN_CODE;

typedef struct AlarmDataST {
  _sys_u16_ alarmThrd;
  _sys_u16_ releaseThrd;
  _sys_bool_ state;
#if defined(uG31xx_OS_ANDROID)
    } __attribute__ ((aligned(4))) AlarmDataType;
#else   ///< else of defined(uG31xx_OS_ANDROID)	      
    } AlarmDataType;
#endif  ///< end of defined(uG31xx_OS_ANDROID)

typedef struct SystemDataST {

  #if defined (uG31xx_OS_WINDOWS)
    const wchar_t* ggbFilename;
    const wchar_t* otpFileName;
    const wchar_t* backupFileName;
  #elif defined(uG31xx_OS_ANDROID)
    GGBX_FILE_HEADER *ggbXBuf;
  #endif
  
  CELL_PARAMETER *ggbParameter;
  CELL_TABLE *ggbCellTable;
  OtpDataType *otpData;
  
  ADC_CHECK adcCheckData;			//add for adc error check 20121025/jacky

  _sys_u16_ voltage;
  
  _sys_u16_ preITAve;
  _sys_u8_ cellNum;

  _sys_u16_ rmFromIC;
  _sys_u16_ fccFromIC;
  _sys_u8_ rsocFromIC;
  _sys_u32_ timeTagFromIC;
  _sys_u8_ tableUpdateIdxFromIC;
  _sys_s16_ deltaCapFromIC;
  _sys_u16_ adc1ConvTime;
  
  _sys_u16_ rmFromICBackup;
  _sys_u16_ fccFromICBackup;
  _sys_u8_ rsocFromICBackup;

  AlarmDataType uvAlarm;
  AlarmDataType oetAlarm;
  AlarmDataType uetAlarm;
  _sys_u16_ alarmSts;
#if defined(uG31xx_OS_ANDROID)
  } __attribute__ ((aligned(4))) SystemDataType;
#else   ///< else of defined(uG31xx_OS_ANDROID)	      
  } SystemDataType;
#endif  ///< end of defined(uG31xx_OS_ANDROID)

/**
 * @brief UpiInitSystemData
 *
 *  Initialize system data
 *
 * @para  data  address of BootDataType
 * @return  _UPI_NULL_
 */
extern SYSTEM_RTN_CODE UpiInitSystemData(SystemDataType *data);

/**
 * @brief UpiCheckICActive
 *
 *  Check IC is actived or not
 *
 * @return  _UPI_TRUE_ if uG31xx is not actived
 */
extern _upi_bool_ UpiCheckICActive(void);

/**
 * @brief UpiActiveUg31xx
 *
 *  Active uG31xx
 *
 * @return  SYSTEM_RTN_CODE
 */
extern SYSTEM_RTN_CODE UpiActiveUg31xx(void);

/**
 * @brief UpiSetupAdc
 *
 *  Setup ADC configurations
 *
 * @para  data  address of SystemDataType
 * @return  _UPI_NULL_
 */
extern void UpiSetupAdc(SystemDataType *data);

/**
 * @brief UpiDecimateRst
 *
 *  Decimate reset filter of ADC
 *
 * @return  _UPI_NULL_
 */
extern void UpiDecimateRst(void);

/**
 * @brief UpiSetupSystem
 *
 *  Setup uG31xx system
 *
 * @para  data  address of SystemDataType
 * @return  _UPI_NULL_
 */
extern void UpiSetupSystem(SystemDataType *data);

/**
 * @brief UpiCalibrationOsc
 *
 *  OSC calibration
 *    oscCnt25[9:0] = oscCntTarg[9:0] + oscDeltaCode25[7:0]
 *    oscCnt80[9:0] = oscCntTarg[9:0] + oscDeltaCode80[7:0]
 *    oscCnt[9:0] = m*ITcode[15:8] + C[9:0]
 *    m = (oscCnt80[9:0]-oscCnt25[9:0])/(iTcode80[7:0]-iTcode25[7:0])
 *    c = oscCnt25[9:0] - m*ITcode25[7:0]
 *    write oscCnt[9:0] to register 0x97-98
 *
 * @para  data  address of SystemDataType
 * @return  _UPI_NULL_
 */
extern void UpiCalibrationOsc(SystemDataType *data);

/**
 * @brief UpiAdcStatus
 *
 *  Check ADC status
 *
 * @para  data  address of SystemDataType
 * @return  _UPI_NULL_
 */
extern void UpiAdcStatus(SystemDataType *data);

/**
 * @brief UpiLoadBatInfoFromIC
 *
 *  Load battery information from uG31xx
 *
 * @para  data  address of SystemDataType
 * @return  _UPI_NULL_
 */
extern void UpiLoadBatInfoFromIC(SystemDataType *data);

/**
 * @brief UpiUpdateBatInfoFromIC
 *
 *  Update battery information from uG31xx
 *
 * @para  data  address of SystemDataType
 * @para  deltaQ  delta capacity from coulomb counter
 * @return  _UPI_NULL_
 */
extern void UpiUpdateBatInfoFromIC(SystemDataType *data, _sys_s16_ deltaQ);

/**
 * @brief UpiSaveBatInfoTOIC
 *
 *  Save battery information from uG31xx
 *
 * @para  data  address of SystemDataType
 * @return  _UPI_NULL_
 */
extern void UpiSaveBatInfoTOIC(SystemDataType *data);

/**
 * @brief UpiInitAlarm
 *
 *  Initialize alarm function of uG3105
 *
 * @para  data  address of SystemDataType
 * @return  NULL
 */
extern void UpiInitAlarm(SystemDataType *data);

/**
 * @brief UpiAlarmStatus
 *
 *  Get alarm status
 *
 * @para  data  address of SystemDataType
 * @return  NULL
 */
extern _sys_u8_ UpiAlarmStatus(SystemDataType *data);