FreeCalypso > hg > freecalypso-citrine
comparison g23m-glue/gdi/power.c @ 0:75a11d740a02
initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 09 Jun 2016 00:02:41 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:75a11d740a02 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Project : GSM-PS | |
4 | Modul : DRV_PWR | |
5 +----------------------------------------------------------------------------- | |
6 | Copyright 2002 Texas Instruments Berlin, AG | |
7 | All rights reserved. | |
8 | | |
9 | This file is confidential and a trade secret of Texas | |
10 | Instruments Berlin, AG | |
11 | The receipt of or possession of this file does not convey | |
12 | any rights to reproduce or disclose its contents or to | |
13 | manufacture, use, or sell anything it may describe, in | |
14 | whole, or in part, without the specific written consent of | |
15 | Texas Instruments Berlin, AG. | |
16 +----------------------------------------------------------------------------- | |
17 | Purpose : This Module defines the power management device driver | |
18 | for the G23 protocol stack. | |
19 | | |
20 | This driver is used to control all power related functions | |
21 | such as charger and battery control. The driver does support | |
22 | multiple devices and therefore no open and close functionality | |
23 | is supported. The driver can be configured to signal different | |
24 | state transitions, for example battery level has reached the | |
25 | "battery low" level. This is done by setting an OS signal or | |
26 | calling a specified call-back function. | |
27 +----------------------------------------------------------------------------- | |
28 */ | |
29 | |
30 #ifndef DRV_PWR_C | |
31 #define DRV_PWR_C | |
32 #endif | |
33 | |
34 #include "config.h" | |
35 #include "fixedconf.h" | |
36 #include "condat-features.h" | |
37 | |
38 /*==== INCLUDES ===================================================*/ | |
39 #if defined (NEW_FRAME) | |
40 | |
41 #include <string.h> | |
42 #include "typedefs.h" | |
43 #include "gdi.h" | |
44 #include "pwr.h" | |
45 | |
46 #else | |
47 | |
48 #include <string.h> | |
49 #include "stddefs.h" | |
50 #include "gdi.h" | |
51 #include "pwr.h" | |
52 | |
53 #endif | |
54 /*==== EXPORT =====================================================*/ | |
55 #if defined (_TMS470_NOT_YET) | |
56 EXTERN void BAT_Init (void (*pwr_batlevel)(UBYTE level), | |
57 void (*pwr_batstatus)(UBYTE status)); | |
58 #else | |
59 LOCAL void BAT_Init (void (*pwr_batlevel)(UBYTE level), | |
60 void (*pwr_batstatus)(UBYTE status)); | |
61 #endif | |
62 | |
63 LOCAL void pwr_batlevel (UBYTE level); | |
64 LOCAL void pwr_batstatus (UBYTE status); | |
65 | |
66 /*==== VARIABLES ==================================================*/ | |
67 drv_SignalCB_Type pwr_signal_callback = NULL; | |
68 UBYTE pwr_act_level; | |
69 UBYTE pwr_act_status; | |
70 pwr_DCB_Type pwr_DCB; | |
71 pwr_Status_Type pwr_Status; | |
72 /*==== VARIABLES ==================================================*/ | |
73 | |
74 /*==== FUNCTIONS ==================================================*/ | |
75 | |
76 /*==== CONSTANTS ==================================================*/ | |
77 /* | |
78 +--------------------------------------------------------------------+ | |
79 | PROJECT : GSM-PS (6103) MODULE : DRV_PWR | | |
80 | STATE : code ROUTINE : pwr_Init | | |
81 +--------------------------------------------------------------------+ | |
82 | |
83 PURPOSE : The function initializes the driverīs internal data. | |
84 The function returns DRV_OK in case of a successful | |
85 completition. The function returns DRV_INITIALIZED if | |
86 the driver has already been initialized and is ready to | |
87 be used or is already in use. In case of an initialization | |
88 failure, which means the that the driver cannot be used, | |
89 the function returns DRV_INITFAILURE. | |
90 | |
91 */ | |
92 | |
93 GLOBAL UBYTE pwr_Init (drv_SignalCB_Type in_SignalCBPtr) | |
94 { | |
95 pwr_signal_callback = in_SignalCBPtr; /* store call-back function */ | |
96 pwr_DCB.RangeMin = 10; /* 10 Percent */ | |
97 pwr_DCB.RangeMax = 100; /* 100 Percent */ | |
98 pwr_DCB.Steps = 4; /* 4 Steps */ | |
99 | |
100 pwr_Status.Status = 0; | |
101 pwr_Status.BatteryLevel = 0; | |
102 pwr_Status.ChargeLevel = 0; | |
103 | |
104 /* | |
105 * Initialise TI driver with internal callback functions | |
106 * | |
107 * pwr_batlevel is called after change of battery level | |
108 * pwr_batstatus is called after change of external or charger | |
109 * unit | |
110 * | |
111 */ | |
112 BAT_Init (pwr_batlevel, pwr_batstatus); | |
113 | |
114 return DRV_OK; | |
115 } | |
116 | |
117 /* | |
118 +--------------------------------------------------------------------+ | |
119 | PROJECT : GSM-PS (6103) MODULE : DRV_PWR | | |
120 | STATE : code ROUTINE : pwr_Exit | | |
121 +--------------------------------------------------------------------+ | |
122 | |
123 PURPOSE : The function is used to indicate PWR that the driver | |
124 and its functionality isnīt needed anymore. | |
125 | |
126 */ | |
127 | |
128 GLOBAL void pwr_Exit (void) | |
129 { | |
130 pwr_signal_callback = NULL; | |
131 } | |
132 | |
133 /* | |
134 +--------------------------------------------------------------------+ | |
135 | PROJECT : GSM-PS (6103) MODULE : DRV_PWR | | |
136 | STATE : code ROUTINE : pwr_SetSignal | | |
137 +--------------------------------------------------------------------+ | |
138 | |
139 PURPOSE : This function is used to define a single signal or multiple | |
140 signals that is/are indicated to the process when the event | |
141 identified in the signal information data type as SignalType | |
142 occurs. | |
143 To remove a signal, call the function pwr_ResetSignal(). | |
144 If one of the parameters of the signal information data is | |
145 invalid, the function returns DRV_INVALID_PARAMS. | |
146 If no signal call-back function has been defined at the | |
147 time of initilization the driver returns DRV_SIGFCT_NOTAVAILABLE. | |
148 | |
149 */ | |
150 | |
151 GLOBAL UBYTE pwr_SetSignal (drv_SignalID_Type * in_SignalIDPtr) | |
152 { | |
153 return DRV_OK; | |
154 } | |
155 | |
156 /* | |
157 +--------------------------------------------------------------------+ | |
158 | PROJECT : GSM-PS (6103) MODULE : DRV_PWR | | |
159 | STATE : code ROUTINE : pwr_ResetSignal | | |
160 +--------------------------------------------------------------------+ | |
161 | |
162 PURPOSE : The function is used to remove a single or multiple signals | |
163 that has previously been set. The signals that are removed | |
164 are identified by the Signal Information Data element called | |
165 SignalType. All other elements of the Signal Information Data | |
166 must be identical to the signal(s) that is/are to be | |
167 removed. If the SignalID provided can not be found, the | |
168 function returns DRV_INVALID_PARAMS. | |
169 If no signal call-back function has beed defined at the | |
170 time of initialization, the driver returns DRV_SIGFCT_NOTAVAILABLE. | |
171 | |
172 */ | |
173 | |
174 GLOBAL UBYTE pwr_ResetSignal (drv_SignalID_Type * in_SignalIDPtr) | |
175 { | |
176 return DRV_OK; | |
177 } | |
178 | |
179 /* | |
180 +--------------------------------------------------------------------+ | |
181 | PROJECT : GSM-PS (6103) MODULE : DRV_PWR | | |
182 | STATE : code ROUTINE : pwr_SetConfig | | |
183 +--------------------------------------------------------------------+ | |
184 | |
185 PURPOSE : This function is used to configure the driver. | |
186 If any value of this configuration is out of range or | |
187 invalid in combination with any other value of the | |
188 configuration, the function returns DRV_INVALID_PARAMS. | |
189 Call the pwr_GetConfig() function to retrieve the drivers | |
190 configuration. | |
191 | |
192 */ | |
193 | |
194 GLOBAL UBYTE pwr_SetConfig (pwr_DCB_Type * in_DCBPtr) | |
195 { | |
196 memcpy (&pwr_DCB, in_DCBPtr, sizeof (pwr_DCB_Type)); | |
197 pwr_Status.BatteryLevel = 0; | |
198 pwr_Status.ChargeLevel = 0; | |
199 | |
200 return DRV_OK; | |
201 } | |
202 | |
203 /* | |
204 +--------------------------------------------------------------------+ | |
205 | PROJECT : GSM-PS (6103) MODULE : DRV_PWR | | |
206 | STATE : code ROUTINE : pwr_GetConfig | | |
207 +--------------------------------------------------------------------+ | |
208 | |
209 PURPOSE : The function is used to retrieve the configuration of | |
210 the driver. The configuration is returned in the driver | |
211 control block to which the pointer out_DCBPtr points. | |
212 If the driver is not configured, the function returns | |
213 DRV_NOTCONFIGURED. | |
214 Call the pwr_SetConfig() function to configure the driver. | |
215 | |
216 */ | |
217 | |
218 GLOBAL UBYTE pwr_GetConfig (pwr_DCB_Type * out_DCBPtr) | |
219 { | |
220 return DRV_OK; | |
221 } | |
222 | |
223 /* | |
224 +--------------------------------------------------------------------+ | |
225 | PROJECT : GSM-PS (6103) MODULE : DRV_PWR | | |
226 | STATE : code ROUTINE : pwr_GetStatus | | |
227 +--------------------------------------------------------------------+ | |
228 | |
229 PURPOSE : This function is used to retrieve the status of the driver | |
230 respectively the power unit. | |
231 In case of a successful completion the driver returns | |
232 DRV_OK and the current status of the driver in the buffer | |
233 out_StatusPtr points to. | |
234 In case the driver is not configured yet, it returns | |
235 DRV_NOTCONFIGURED. In this case the contents of the | |
236 buffer out_StatusPtr is invalid. | |
237 In case out_StatusPtr equals NULL the driver returns | |
238 DRV_INVALID_PARAMS. | |
239 | |
240 */ | |
241 | |
242 GLOBAL UBYTE pwr_GetStatus (pwr_Status_Type * out_StatusPtr) | |
243 { | |
244 if ( out_StatusPtr EQ NULL ) | |
245 { | |
246 return DRV_INVALID_PARAMS; | |
247 } | |
248 else | |
249 { | |
250 out_StatusPtr->Status = pwr_Status.Status; | |
251 out_StatusPtr->BatteryLevel = pwr_Status.BatteryLevel; | |
252 out_StatusPtr->ChargeLevel = pwr_Status.ChargeLevel; | |
253 } | |
254 | |
255 return DRV_OK; | |
256 } | |
257 | |
258 | |
259 | |
260 /* | |
261 +--------------------------------------------------------------------+ | |
262 | PROJECT : GSM-PS (6103) MODULE : DRV_PWR | | |
263 | STATE : code ROUTINE : pwr_BatLevel | | |
264 +--------------------------------------------------------------------+ | |
265 | |
266 PURPOSE : This function is called by the low level driver after | |
267 change of battery level. | |
268 */ | |
269 | |
270 LOCAL void pwr_batlevel (UBYTE level) | |
271 { | |
272 UBYTE calculated_level; | |
273 drv_SignalID_Type signal_params; | |
274 | |
275 pwr_Status.ChargeLevel = level; | |
276 | |
277 if (level <= pwr_DCB.RangeMin) | |
278 calculated_level = 0; | |
279 if (level >= pwr_DCB.RangeMax) | |
280 calculated_level = pwr_DCB.Steps +1; | |
281 if (level > pwr_DCB.RangeMin AND | |
282 level < pwr_DCB.RangeMax) | |
283 { | |
284 level -= pwr_DCB.RangeMin; | |
285 calculated_level = ((level * pwr_DCB.Steps) / | |
286 (pwr_DCB.RangeMax - pwr_DCB.RangeMin))+1; | |
287 } | |
288 | |
289 if (calculated_level EQ pwr_Status.BatteryLevel) | |
290 return; | |
291 | |
292 signal_params.SignalType = PWR_SIGTYPE_BATLEVEL; | |
293 #if defined (NEW_FRAME) | |
294 signal_params.UserData = (void*)&pwr_Status; | |
295 #else | |
296 signal_params.SignalValue = 0; | |
297 signal_params.UserData = (ULONG)&pwr_Status; | |
298 #endif | |
299 pwr_Status.BatteryLevel = calculated_level; | |
300 | |
301 if (pwr_signal_callback NEQ NULL) | |
302 (*pwr_signal_callback)(&signal_params); | |
303 } | |
304 | |
305 /* | |
306 +--------------------------------------------------------------------+ | |
307 | PROJECT : GSM-PS (6103) MODULE : DRV_PWR | | |
308 | STATE : code ROUTINE : pwr_batstatus | | |
309 +--------------------------------------------------------------------+ | |
310 | |
311 PURPOSE : This function is called by the low level driver after | |
312 detecting a status change. | |
313 */ | |
314 | |
315 LOCAL void pwr_batstatus (UBYTE status) | |
316 { | |
317 } | |
318 | |
319 /******************************************************************* | |
320 * * | |
321 * PART II: Simulation for Windows * | |
322 * * | |
323 *******************************************************************/ | |
324 | |
325 /*#if defined (WIN32)*/ | |
326 /* | |
327 * Dummies for driver calls | |
328 */ | |
329 LOCAL void BAT_Init (void (*pwr_batlevel)(UBYTE), | |
330 void (*pwr_batstatus)(UBYTE)) | |
331 { | |
332 } | |
333 | |
334 /*#endif*/ | |
335 | |
336 /* | |
337 +--------------------------------------------------------------------+ | |
338 | PROJECT : GSM-PS (6103) MODULE : DRV_PWR | | |
339 | STATE : code ROUTINE : pwr_PowerOffMobile | | |
340 +--------------------------------------------------------------------+ | |
341 | |
342 PURPOSE : This function is switching off the mobile | |
343 */ | |
344 | |
345 GLOBAL UBYTE pwr_PowerOffMobile (void) | |
346 { | |
347 | |
348 /* power off HW is not applicable in simulation */ | |
349 | |
350 | |
351 #if !defined (WIN32) | |
352 | |
353 /* power-off the board / HW */ | |
354 ABB_Power_Off(); | |
355 | |
356 //#endif /* _TARGET_ */ | |
357 #endif /* _TMS470 */ | |
358 | |
359 return 1; | |
360 } |