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