|
1 /* |
|
2 * PowerSrvSM.c |
|
3 * |
|
4 * Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved. |
|
5 * All rights reserved. |
|
6 * |
|
7 * This program and the accompanying materials are made available under the |
|
8 * terms of the Eclipse Public License v1.0 or BSD License which accompanies |
|
9 * this distribution. The Eclipse Public License is available at |
|
10 * http://www.eclipse.org/legal/epl-v10.html and the BSD License is as below. |
|
11 * |
|
12 * Redistribution and use in source and binary forms, with or without |
|
13 * modification, are permitted provided that the following conditions |
|
14 * are met: |
|
15 * |
|
16 * * Redistributions of source code must retain the above copyright |
|
17 * notice, this list of conditions and the following disclaimer. |
|
18 * * Redistributions in binary form must reproduce the above copyright |
|
19 * notice, this list of conditions and the following disclaimer in |
|
20 * the documentation and/or other materials provided with the |
|
21 * distribution. |
|
22 * * Neither the name Texas Instruments nor the names of its |
|
23 * contributors may be used to endorse or promote products derived |
|
24 * from this software without specific prior written permission. |
|
25 * |
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
37 */ |
|
38 |
|
39 /** \file PowerSrvSM.c |
|
40 * \brief This is the PowerSrvSM module implementation. |
|
41 * \author Assaf Azulay |
|
42 * \date 19-OCT-2005 |
|
43 */ |
|
44 |
|
45 /**************************************************************************** |
|
46 * * |
|
47 * MODULE: PowerSrvSM * |
|
48 * PURPOSE: PowerSrvSM Module implementation. * |
|
49 * * |
|
50 ****************************************************************************/ |
|
51 |
|
52 #define __FILE_ID__ FILE_ID_114 |
|
53 #include "tidef.h" |
|
54 #include "osApi.h" |
|
55 #include "timer.h" |
|
56 #include "fsm.h" |
|
57 #include "report.h" |
|
58 #include "TWDriver.h" |
|
59 #include "PowerSrvSM.h" |
|
60 #include "CmdBld.h" |
|
61 |
|
62 |
|
63 /***************************************************************************** |
|
64 ** Defines ** |
|
65 *****************************************************************************/ |
|
66 |
|
67 |
|
68 /***************************************************************************** |
|
69 ** structs ** |
|
70 *****************************************************************************/ |
|
71 |
|
72 |
|
73 /***************************************************************************** |
|
74 ** Private Function prototypes ** |
|
75 *****************************************************************************/ |
|
76 |
|
77 static TI_STATUS powerSrvSmSMEvent(TI_UINT8* pCurrentState, |
|
78 TI_UINT8 event, |
|
79 TI_HANDLE hPowerSrvSM); |
|
80 static TI_STATUS powerSrvSmDoUpdateRequest(TI_HANDLE hPowerSrvSM); |
|
81 static TI_STATUS powerSrvSmDoEnterPowerSave(TI_HANDLE hPowerSrvSM); |
|
82 static TI_STATUS powerSrvSmDoExitPowerSave(TI_HANDLE hPowerSrvSM); |
|
83 static TI_STATUS powerSrvSmDoPending(TI_HANDLE hPowerSrvSM); |
|
84 static TI_STATUS powerSrvSmDoAllready(TI_HANDLE hPowerSrvSM); |
|
85 static TI_STATUS powerSrvSMActionUnexpected(TI_HANDLE hPowerSrvSM); |
|
86 static TI_STATUS powerSrvSMSendMBXConfiguration(TI_HANDLE hPowerSrvSM, TI_BOOL PS_disableEnable); |
|
87 static void powerSrvSMTimerExpired (TI_HANDLE hPowerSrvSM, TI_BOOL bTwdInitOccured); |
|
88 |
|
89 /*************************************************************************************** |
|
90 ** Public Function prototypes ** |
|
91 ****************************************************************************************/ |
|
92 |
|
93 |
|
94 /**************************************************************************************** |
|
95 * powerSrvSM_create * |
|
96 **************************************************************************************** |
|
97 DESCRIPTION: Power Server SM module creation function, called by the Power Server create in creation phase |
|
98 performs the following: |
|
99 - Allocate the Power Server SM handle |
|
100 - Creates the fsm. |
|
101 |
|
102 INPUT: - hOs - Handle to OS |
|
103 |
|
104 |
|
105 OUTPUT: |
|
106 |
|
107 RETURN: Handle to the Power Server SM module on success, NULL otherwise |
|
108 ****************************************************************************************/ |
|
109 TI_HANDLE powerSrvSM_create(TI_HANDLE hOsHandle) |
|
110 { |
|
111 PowerSrvSM_t *pPowerSrvSM = NULL; |
|
112 fsm_stateMachine_t *pFsm = NULL; |
|
113 TI_STATUS status; |
|
114 |
|
115 pPowerSrvSM = (PowerSrvSM_t*) os_memoryAlloc (hOsHandle, sizeof(PowerSrvSM_t),MemoryNormal); |
|
116 if ( pPowerSrvSM == NULL ) |
|
117 { |
|
118 WLAN_OS_REPORT(("%s(%d) - Memory Allocation Error!\n",__FUNCTION__,__LINE__)); |
|
119 return NULL; |
|
120 } |
|
121 |
|
122 os_memoryZero (hOsHandle, pPowerSrvSM, sizeof(PowerSrvSM_t)); |
|
123 |
|
124 pPowerSrvSM->hOS = hOsHandle; |
|
125 |
|
126 /* create the generic state-machine */ |
|
127 status = fsm_Create(hOsHandle, |
|
128 &pFsm, |
|
129 (TI_UINT8)POWER_SRV_SM_STATE_NUM, |
|
130 (TI_UINT8)POWER_SRV_SM_EVENT_NUM); |
|
131 if ( status != TI_OK ) |
|
132 { |
|
133 WLAN_OS_REPORT(("%s(%d) - Error in create FSM!\n",__FUNCTION__,__LINE__)); |
|
134 powerSrvSM_destroy(pPowerSrvSM); |
|
135 return NULL; |
|
136 } |
|
137 |
|
138 pPowerSrvSM->hFSM = (TI_HANDLE)pFsm; |
|
139 |
|
140 return pPowerSrvSM; |
|
141 } |
|
142 |
|
143 |
|
144 /**************************************************************************************** |
|
145 * powerSrvSM_destroy * |
|
146 **************************************************************************************** |
|
147 DESCRIPTION: Power Server SM module destroy function, |
|
148 - delete Power Server SM allocation |
|
149 |
|
150 |
|
151 INPUT: - hPowerSrvSM - Handle to the Power Server SM |
|
152 |
|
153 |
|
154 OUTPUT: |
|
155 |
|
156 RETURN: TI_STATUS - TI_OK on success else TI_NOK. |
|
157 ****************************************************************************************/ |
|
158 TI_STATUS powerSrvSM_destroy(TI_HANDLE hPowerSrvSM) |
|
159 { |
|
160 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
161 |
|
162 TI_HANDLE osHandle = pPowerSrvSM->hOS; |
|
163 |
|
164 /* free the timer */ |
|
165 if (pPowerSrvSM->hPwrSrvSmTimer) |
|
166 { |
|
167 tmr_DestroyTimer (pPowerSrvSM->hPwrSrvSmTimer); |
|
168 } |
|
169 |
|
170 /* free the generic SM */ |
|
171 if ( pPowerSrvSM->hFSM != NULL ) |
|
172 { |
|
173 fsm_Unload(osHandle, (fsm_stateMachine_t*)pPowerSrvSM->hFSM); |
|
174 } |
|
175 |
|
176 /* free the Power Save SRV object */ |
|
177 os_memoryFree(osHandle , pPowerSrvSM , sizeof(PowerSrvSM_t)); |
|
178 |
|
179 return TI_OK; |
|
180 } |
|
181 |
|
182 |
|
183 /**************************************************************************************** |
|
184 * powerSrvSM_init * |
|
185 **************************************************************************************** |
|
186 DESCRIPTION: Power Server SM module initialize function, called by the Power Server init in configure phase |
|
187 performs the following: |
|
188 - init the Stet machine states. |
|
189 - set Active as start state. |
|
190 |
|
191 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
192 - hReport - handle to the Report object. |
|
193 - hCmdBld - handle to the Command Builder object. |
|
194 - hTimer - handle to the Timer module object. |
|
195 |
|
196 OUTPUT: |
|
197 RETURN: TI_STATUS - TI_OK on success else TI_NOK. |
|
198 ****************************************************************************************/ |
|
199 TI_STATUS powerSrvSM_init (TI_HANDLE hPowerSrvSM, |
|
200 TI_HANDLE hReport, |
|
201 TI_HANDLE hCmdBld, |
|
202 TI_HANDLE hTimer) |
|
203 { |
|
204 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
205 |
|
206 fsm_actionCell_t smMatrix[POWER_SRV_SM_STATE_NUM][POWER_SRV_SM_EVENT_NUM] = |
|
207 { |
|
208 /* |
|
209 next state and transition action for POWER_SRV_STATE_ACTIVE state |
|
210 */ |
|
211 { |
|
212 /* POWER_SRV_EVENT_REQUEST_ACTIVE */ |
|
213 {POWER_SRV_STATE_ACTIVE , powerSrvSmDoAllready}, |
|
214 |
|
215 /* POWER_SRV_EVENT_REQUEST_PS */ |
|
216 {POWER_SRV_STATE_PEND_PS , powerSrvSmDoEnterPowerSave}, |
|
217 |
|
218 /* POWER_SRV_EVENT_SUCCESS */ |
|
219 {POWER_SRV_STATE_ACTIVE , powerSrvSMActionUnexpected}, |
|
220 |
|
221 /* POWER_SRV_EVENT_FAIL */ |
|
222 {POWER_SRV_STATE_ACTIVE , powerSrvSMActionUnexpected} |
|
223 |
|
224 }, |
|
225 |
|
226 /* |
|
227 next state and transition action for POWER_SRV_STATE_PEND_PS state |
|
228 */ |
|
229 { |
|
230 /* POWER_SRV_EVENT_REQUEST_ACTIVE */ |
|
231 {POWER_SRV_STATE_PEND_PS , powerSrvSmDoPending}, |
|
232 |
|
233 /* POWER_SRV_EVENT_REQUEST_PS */ |
|
234 {POWER_SRV_STATE_PEND_PS , powerSrvSmDoPending}, |
|
235 |
|
236 /* POWER_SRV_EVENT_SUCCESS */ |
|
237 {POWER_SRV_STATE_PS , powerSrvSmDoUpdateRequest}, |
|
238 |
|
239 /* POWER_SRV_EVENT_FAIL */ |
|
240 {POWER_SRV_STATE_ACTIVE , powerSrvSmDoUpdateRequest} |
|
241 |
|
242 }, |
|
243 /* |
|
244 next state and transition action for POWER_SRV_STATE_PS state |
|
245 */ |
|
246 { |
|
247 /* POWER_SRV_EVENT_REQUEST_ACTIVE */ |
|
248 {POWER_SRV_STATE_PEND_ACTIVE , powerSrvSmDoExitPowerSave}, |
|
249 |
|
250 /* POWER_SRV_EVENT_REQUEST_PS */ |
|
251 {POWER_SRV_STATE_PS , powerSrvSmDoAllready}, |
|
252 |
|
253 /* POWER_SRV_EVENT_SUCCESS */ |
|
254 {POWER_SRV_STATE_PS , powerSrvSMActionUnexpected}, |
|
255 |
|
256 /* POWER_SRV_EVENT_FAIL */ |
|
257 {POWER_SRV_STATE_PS , powerSrvSMActionUnexpected} |
|
258 |
|
259 }, |
|
260 /* |
|
261 next state and transition action for POWER_SRV_STATE_PEND_ACTIVE state |
|
262 */ |
|
263 { |
|
264 /* POWER_SRV_EVENT_REQUEST_ACTIVE */ |
|
265 {POWER_SRV_STATE_PEND_ACTIVE , powerSrvSmDoPending}, |
|
266 |
|
267 /* POWER_SRV_EVENT_REQUEST_PS */ |
|
268 {POWER_SRV_STATE_PEND_ACTIVE , powerSrvSmDoPending}, |
|
269 |
|
270 /* POWER_SRV_EVENT_SUCCESS */ |
|
271 {POWER_SRV_STATE_ACTIVE , powerSrvSmDoUpdateRequest}, |
|
272 |
|
273 /* POWER_SRV_EVENT_FAIL */ |
|
274 {POWER_SRV_STATE_ERROR_ACTIVE , powerSrvSmDoUpdateRequest} |
|
275 |
|
276 }, |
|
277 /* |
|
278 next state and transition action for POWER_SRV_STATE_ERROR_ACTIVE state |
|
279 */ |
|
280 { |
|
281 /* POWER_SRV_EVENT_REQUEST_ACTIVE */ |
|
282 {POWER_SRV_STATE_PEND_ACTIVE , powerSrvSmDoExitPowerSave}, |
|
283 |
|
284 /* POWER_SRV_EVENT_REQUEST_PS */ |
|
285 {POWER_SRV_STATE_PEND_PS , powerSrvSmDoEnterPowerSave}, |
|
286 |
|
287 /* POWER_SRV_EVENT_SUCCESS */ |
|
288 {POWER_SRV_STATE_ERROR_ACTIVE , powerSrvSMActionUnexpected}, |
|
289 |
|
290 /* POWER_SRV_EVENT_FAIL */ |
|
291 {POWER_SRV_STATE_ERROR_ACTIVE , powerSrvSMActionUnexpected} |
|
292 |
|
293 }, |
|
294 |
|
295 }; |
|
296 |
|
297 pPowerSrvSM->hReport = hReport; |
|
298 pPowerSrvSM->hCmdBld = hCmdBld; |
|
299 pPowerSrvSM->hTimer = hTimer; |
|
300 |
|
301 /* create the timer */ |
|
302 pPowerSrvSM->hPwrSrvSmTimer = tmr_CreateTimer (pPowerSrvSM->hTimer); |
|
303 if (pPowerSrvSM->hPwrSrvSmTimer == NULL) |
|
304 { |
|
305 TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_ERROR, "powerSrvSM_init(): Failed to create hPwrSrvSmTimer!\n"); |
|
306 return TI_NOK; |
|
307 } |
|
308 |
|
309 fsm_Config(pPowerSrvSM->hFSM, |
|
310 (fsm_Matrix_t)smMatrix, |
|
311 POWER_SRV_SM_STATE_NUM, |
|
312 POWER_SRV_SM_EVENT_NUM, |
|
313 powerSrvSmSMEvent, |
|
314 pPowerSrvSM->hOS); |
|
315 |
|
316 /* |
|
317 the PowerSrvSM start in active mode (POWER_SRV_STATE_ACTIVE) |
|
318 the PowerSrvSM::currentState must be sync with the PowerSrv::desiredPowerModeProfile (POWER_MODE_ACTIVE). |
|
319 */ |
|
320 pPowerSrvSM->currentState = POWER_SRV_STATE_ACTIVE; |
|
321 |
|
322 |
|
323 /* |
|
324 Null packet rate : 2,5.5 M |
|
325 Probe Request : Not PBCC modulation, Long Preamble */ |
|
326 pPowerSrvSM->NullPktRateModulation= (DRV_RATE_MASK_1_BARKER | DRV_RATE_MASK_2_BARKER); |
|
327 |
|
328 TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_INIT, "PowerSrvSM Initialized\n"); |
|
329 |
|
330 return TI_OK; |
|
331 } |
|
332 |
|
333 /**************************************************************************************** |
|
334 * powerSrvSM_config * |
|
335 **************************************************************************************** |
|
336 DESCRIPTION: Power Server SM module configuration function, called by the Power Server init in configure phase |
|
337 performs the following: |
|
338 - init the Stet machine states. |
|
339 - set Active as start state. |
|
340 |
|
341 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
342 - pPowerSrvInitParams - the Power Server initialize parameters. |
|
343 |
|
344 OUTPUT: |
|
345 RETURN: TI_STATUS - TI_OK on success else TI_NOK. |
|
346 ****************************************************************************************/ |
|
347 TI_STATUS powerSrvSM_config(TI_HANDLE hPowerSrvSM, |
|
348 TPowerSrvInitParams *pPowerSrvInitParams) |
|
349 { |
|
350 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
351 |
|
352 /* |
|
353 init PowerMgmtConfigration |
|
354 */ |
|
355 pPowerSrvSM->hangOverPeriod = pPowerSrvInitParams->hangOverPeriod; |
|
356 pPowerSrvSM->numNullPktRetries = pPowerSrvInitParams->numNullPktRetries; |
|
357 |
|
358 return TI_OK; |
|
359 } |
|
360 /**************************************************************************************** |
|
361 * powerSrvSM_SMApi * |
|
362 ***************************************************************************************** |
|
363 DESCRIPTION: This function triggers events from the outside of the module into the state machine. |
|
364 |
|
365 |
|
366 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
367 - theSMEvent - event from TWD. |
|
368 |
|
369 |
|
370 OUTPUT: |
|
371 RETURN: TI_STATUS TI_OK / PENDING / TI_NOK |
|
372 ****************************************************************************************/ |
|
373 TI_STATUS powerSrvSM_SMApi(TI_HANDLE hPowerSrvSM, |
|
374 PowerSrvSMEvents_e theSMEvent) |
|
375 { |
|
376 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
377 TI_STATUS status; |
|
378 |
|
379 switch ( theSMEvent ) |
|
380 { |
|
381 case POWER_SRV_EVENT_REQUEST_ACTIVE : |
|
382 case POWER_SRV_EVENT_REQUEST_PS : |
|
383 case POWER_SRV_EVENT_FAIL : |
|
384 case POWER_SRV_EVENT_SUCCESS : |
|
385 |
|
386 TRACE1(pPowerSrvSM->hReport, REPORT_SEVERITY_INFORMATION, "powerSrvSM_SMApi(%d) called - legal input parameter.\n",theSMEvent); |
|
387 break; |
|
388 |
|
389 default: |
|
390 TRACE1(pPowerSrvSM->hReport, REPORT_SEVERITY_WARNING, "powerSrvSM_SMApi(%d) called, input parameter is illegal.",theSMEvent); |
|
391 return TI_NOK; |
|
392 } |
|
393 |
|
394 |
|
395 status = powerSrvSmSMEvent((TI_UINT8*)&pPowerSrvSM->currentState, |
|
396 (TI_UINT8)theSMEvent, |
|
397 hPowerSrvSM); |
|
398 |
|
399 return status; |
|
400 } |
|
401 |
|
402 |
|
403 /**************************************************************************************** |
|
404 * powerSrvSm_setSmRequest * |
|
405 ***************************************************************************************** |
|
406 DESCRIPTION: This function sets the current SM working request. |
|
407 |
|
408 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
409 -powerSrvRequest_t* - pointer to the correct request in the Power server. |
|
410 |
|
411 OUTPUT: |
|
412 RETURN: TI_STATUS - TI_OK |
|
413 ****************************************************************************************/ |
|
414 TI_STATUS powerSrvSm_setSmRequest(TI_HANDLE hPowerSrvSM,powerSrvRequest_t* pSmRequest) |
|
415 { |
|
416 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
417 pPowerSrvSM->pSmRequest = pSmRequest; |
|
418 return TI_OK; |
|
419 } |
|
420 |
|
421 |
|
422 /**************************************************************************************** |
|
423 * powerSrvSM_getCurrentState * |
|
424 ***************************************************************************************** |
|
425 DESCRIPTION: This function returns the current state of the SM. |
|
426 |
|
427 |
|
428 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
429 |
|
430 |
|
431 OUTPUT: |
|
432 RETURN: PowerSrvSMStates_e current state |
|
433 ****************************************************************************************/ |
|
434 PowerSrvSMStates_e powerSrvSM_getCurrentState(TI_HANDLE hPowerSrvSM) |
|
435 { |
|
436 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
437 |
|
438 return pPowerSrvSM->currentState; |
|
439 } |
|
440 |
|
441 /**************************************************************************************** |
|
442 * powerSrvSM_setRateModulation * |
|
443 ***************************************************************************************** |
|
444 DESCRIPTION: This function sets the Rate Modulation |
|
445 |
|
446 |
|
447 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
448 - rateModulation - desired rate |
|
449 |
|
450 OUTPUT: |
|
451 RETURN: void |
|
452 ****************************************************************************************/ |
|
453 |
|
454 void powerSrvSM_setRateModulation(TI_HANDLE hPowerSrvSM, TI_UINT16 rateModulation) |
|
455 { |
|
456 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
457 pPowerSrvSM->NullPktRateModulation= rateModulation; |
|
458 } |
|
459 |
|
460 /**************************************************************************************** |
|
461 * powerSrvSM_getRateModulation * |
|
462 ***************************************************************************************** |
|
463 DESCRIPTION: This function sets the Rate Modulation |
|
464 |
|
465 |
|
466 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
467 |
|
468 OUTPUT: |
|
469 RETURN: - desired rate |
|
470 ****************************************************************************************/ |
|
471 |
|
472 TI_UINT32 powerSrvSM_getRateModulation(TI_HANDLE hPowerSrvSM) |
|
473 { |
|
474 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
475 return pPowerSrvSM->NullPktRateModulation; |
|
476 } |
|
477 |
|
478 /**************************************************************************************** |
|
479 * powerSrvSM_printObject * |
|
480 ***************************************************************************************** |
|
481 DESCRIPTION: This function prints the SM object |
|
482 |
|
483 |
|
484 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
485 |
|
486 |
|
487 OUTPUT: |
|
488 RETURN: void |
|
489 ****************************************************************************************/ |
|
490 void powerSrvSM_printObject(TI_HANDLE hPowerSrvSM) |
|
491 { |
|
492 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
493 char *pString; |
|
494 |
|
495 WLAN_OS_REPORT(("\n+++++ powerSrvSM_printObject +++++\n")); |
|
496 WLAN_OS_REPORT(("Handle to the CmdBld is 0x%08X\n", pPowerSrvSM->hCmdBld)); |
|
497 WLAN_OS_REPORT(("Handle to the OS is 0x%08X\n", pPowerSrvSM->hOS)); |
|
498 WLAN_OS_REPORT(("Handle to the Report is 0x%08X\n", pPowerSrvSM->hReport)); |
|
499 WLAN_OS_REPORT(("Handle to the FSM is 0x%08X\n", pPowerSrvSM->hFSM)); |
|
500 |
|
501 switch ( pPowerSrvSM->currentState ) |
|
502 { |
|
503 case POWER_SRV_STATE_ACTIVE: |
|
504 pString = "POWER_SRV_STATE_ACTIVE"; |
|
505 break; |
|
506 |
|
507 case POWER_SRV_STATE_PEND_PS: |
|
508 pString = "POWER_SRV_STATE_PEND_PS"; |
|
509 break; |
|
510 |
|
511 case POWER_SRV_STATE_PS: |
|
512 pString = "POWER_SRV_STATE_PS"; |
|
513 break; |
|
514 |
|
515 case POWER_SRV_STATE_PEND_ACTIVE: |
|
516 pString = "POWER_SRV_STATE_PEND_ACTIVE"; |
|
517 break; |
|
518 |
|
519 case POWER_SRV_STATE_ERROR_ACTIVE: |
|
520 pString = "POWER_SRV_STATE_ERROR_ACTIVE"; |
|
521 break; |
|
522 |
|
523 |
|
524 default: |
|
525 pString = "UNKWON PARAMETER"; |
|
526 break; |
|
527 } |
|
528 WLAN_OS_REPORT(("The current state of the state machine is %s (=%d)\n", |
|
529 pString, |
|
530 pPowerSrvSM->currentState)); |
|
531 |
|
532 } |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 /***************************************************************************** |
|
538 ** Private Function prototypes ** |
|
539 *****************************************************************************/ |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 /**************************************************************************************** |
|
547 * powerSrvSmDoEnterPowerSave * |
|
548 ***************************************************************************************** |
|
549 DESCRIPTION: This function is an action of the state machine to move from active state to PS |
|
550 |
|
551 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
552 |
|
553 OUTPUT: |
|
554 RETURN: TI_STATUS - TI_OK / TI_NOK |
|
555 ****************************************************************************************/ |
|
556 |
|
557 static TI_STATUS powerSrvSmDoEnterPowerSave(TI_HANDLE hPowerSrvSM) |
|
558 { |
|
559 TI_STATUS status; |
|
560 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
561 pPowerSrvSM->pSmRequest->requestState = RUNNING_REQUEST; |
|
562 status = powerSrvSMSendMBXConfiguration(hPowerSrvSM, TI_TRUE); |
|
563 return status; |
|
564 } |
|
565 |
|
566 |
|
567 /**************************************************************************************** |
|
568 * powerSrvSmDoExitPowerSave * |
|
569 ***************************************************************************************** |
|
570 DESCRIPTION: This function is an action of the state machine to move from PS state to Active |
|
571 |
|
572 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
573 |
|
574 OUTPUT: |
|
575 RETURN: TI_STATUS - TI_OK / TI_NOK |
|
576 ****************************************************************************************/ |
|
577 static TI_STATUS powerSrvSmDoExitPowerSave(TI_HANDLE hPowerSrvSM) |
|
578 { |
|
579 TI_STATUS status; |
|
580 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
581 pPowerSrvSM->pSmRequest->requestState = RUNNING_REQUEST; |
|
582 status = powerSrvSMSendMBXConfiguration(hPowerSrvSM, TI_FALSE); |
|
583 return status; |
|
584 } |
|
585 |
|
586 |
|
587 /**************************************************************************************** |
|
588 * powerSrvSmDoUpdateRequest * |
|
589 ***************************************************************************************** |
|
590 DESCRIPTION: This function is an action of the state machine to update a request when the SM |
|
591 is already in the requested state is already |
|
592 |
|
593 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
594 |
|
595 OUTPUT: |
|
596 RETURN: TI_STATUS - TI_OK / TI_NOK |
|
597 ****************************************************************************************/ |
|
598 |
|
599 static TI_STATUS powerSrvSmDoUpdateRequest(TI_HANDLE hPowerSrvSM) |
|
600 { |
|
601 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
602 |
|
603 /* request has completed - stop the guard timer */ |
|
604 tmr_StopTimer (pPowerSrvSM->hPwrSrvSmTimer); |
|
605 |
|
606 /*powerSrv_SetRequestState will update the correct request (acording to the current active request)*/ |
|
607 if ( pPowerSrvSM->pSmRequest->requestState == RUNNING_REQUEST ) |
|
608 { |
|
609 pPowerSrvSM->pSmRequest->requestState = HANDLED_REQUEST; |
|
610 } |
|
611 |
|
612 return TI_OK; |
|
613 } |
|
614 |
|
615 |
|
616 /**************************************************************************************** |
|
617 * powerSrvSmDoPending * |
|
618 ***************************************************************************************** |
|
619 DESCRIPTION: This function is an action of the state machine returns Pending in case that there is a request |
|
620 waiting to be finished (already sent to FW) |
|
621 |
|
622 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
623 |
|
624 OUTPUT: |
|
625 RETURN: TI_STATUS - PENDING |
|
626 ****************************************************************************************/ |
|
627 |
|
628 static TI_STATUS powerSrvSmDoPending(TI_HANDLE hPowerSrvSM) |
|
629 { |
|
630 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
631 |
|
632 /*powerSrv_SetRequestState will check the mode and will update the correct request (Driver of user)*/ |
|
633 pPowerSrvSM->pSmRequest->requestState = PENDING_REQUEST; |
|
634 return POWER_SAVE_802_11_PENDING; |
|
635 } |
|
636 |
|
637 |
|
638 |
|
639 /**************************************************************************************** |
|
640 * powerSrvSmDoAllready * |
|
641 ***************************************************************************************** |
|
642 DESCRIPTION: This function is an action of the state machine stays in the same state since it the requested |
|
643 one in the request |
|
644 |
|
645 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
646 |
|
647 OUTPUT: |
|
648 RETURN: TI_STATUS - TI_OK |
|
649 ****************************************************************************************/ |
|
650 static TI_STATUS powerSrvSmDoAllready(TI_HANDLE hPowerSrvSM) |
|
651 { |
|
652 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
653 |
|
654 /*powerSrv_SetRequestState will check the mode and will update the correct request (Driver of user)*/ |
|
655 pPowerSrvSM->pSmRequest->requestState = HANDLED_REQUEST; |
|
656 return POWER_SAVE_802_11_IS_CURRENT; |
|
657 } |
|
658 |
|
659 |
|
660 /**************************************************************************************** |
|
661 * powerSrvSMActionUnexpected * |
|
662 ***************************************************************************************** |
|
663 DESCRIPTION: This function is an action of the state machine stays in the same state and return that action |
|
664 was not expected |
|
665 |
|
666 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
667 |
|
668 OUTPUT: |
|
669 RETURN: TI_STATUS - TI_OK |
|
670 ****************************************************************************************/ |
|
671 static TI_STATUS powerSrvSMActionUnexpected(TI_HANDLE hPowerSrvSM) |
|
672 { |
|
673 #ifdef TI_DBG |
|
674 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
675 |
|
676 TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_ERROR, "called: powerSrvSMActionUnexpected"); |
|
677 #endif /* TI_DBG */ |
|
678 |
|
679 return TI_OK; |
|
680 } |
|
681 |
|
682 |
|
683 /**************************************************************************************** |
|
684 * powerSrvSmSMEvent * |
|
685 ***************************************************************************************** |
|
686 DESCRIPTION: This function is the manager of the state macine. its move the state machine |
|
687 from one state to the other depend on the receive event, and call to the appropriate |
|
688 action (function) for the move between the states. |
|
689 |
|
690 INPUT: - pCurrentState |
|
691 - event |
|
692 - hPowerSrvSM - handle to the PowerSrvSM object. |
|
693 |
|
694 OUTPUT: |
|
695 RETURN: TI_STATUS |
|
696 ****************************************************************************************/ |
|
697 static TI_STATUS powerSrvSmSMEvent(TI_UINT8* pCurrentState, |
|
698 TI_UINT8 event, |
|
699 TI_HANDLE hPowerSrvSM) |
|
700 { |
|
701 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
702 TI_STATUS status = TI_OK; |
|
703 TI_UINT8 nextState; |
|
704 |
|
705 status = fsm_GetNextState((fsm_stateMachine_t*)pPowerSrvSM->hFSM, |
|
706 (TI_UINT8)pPowerSrvSM->currentState, |
|
707 event, |
|
708 &nextState); |
|
709 if ( status != TI_OK ) |
|
710 { |
|
711 TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_SM, "PowerSrvSM - State machine error, failed getting next state\n"); |
|
712 return(status); |
|
713 } |
|
714 |
|
715 |
|
716 TRACE3( pPowerSrvSM->hReport, REPORT_SEVERITY_INFORMATION, "powerSrvSmSMEvent: <currentState = %d, event = %d> --> nextState = %d\n", *pCurrentState, event, nextState); |
|
717 |
|
718 status = fsm_Event(pPowerSrvSM->hFSM, |
|
719 pCurrentState, |
|
720 event, |
|
721 (void*)pPowerSrvSM); |
|
722 |
|
723 return status; |
|
724 } |
|
725 |
|
726 |
|
727 /**************************************************************************************** |
|
728 * powerSrvSMSendMBXConfiguration * |
|
729 ***************************************************************************************** |
|
730 DESCRIPTION: This function send configuration of the power save option that holds in the command |
|
731 mailbox inner sturcture. |
|
732 |
|
733 INPUT: - hPowerSrvSM - handle to the PowerSrvSM object. |
|
734 - PS_disableEnable - true = PS , false = active |
|
735 |
|
736 OUTPUT: |
|
737 RETURN: TI_STATUS |
|
738 ****************************************************************************************/ |
|
739 static TI_STATUS powerSrvSMSendMBXConfiguration(TI_HANDLE hPowerSrvSM, TI_BOOL PS_disableEnable) |
|
740 { |
|
741 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
742 TPowerSaveParams powerSaveParams; |
|
743 TI_STATUS status; |
|
744 |
|
745 /*setting the params for the Hal*/ |
|
746 powerSaveParams.hangOverPeriod = pPowerSrvSM->hangOverPeriod; |
|
747 powerSaveParams.numNullPktRetries = pPowerSrvSM->numNullPktRetries; |
|
748 powerSaveParams.NullPktRateModulation = pPowerSrvSM->NullPktRateModulation; |
|
749 powerSaveParams.needToSendNullData = pPowerSrvSM->pSmRequest->sendNullDataOnExit; |
|
750 powerSaveParams.ps802_11Enable = PS_disableEnable; |
|
751 |
|
752 /* start the FW guard timer, which is used to protect from FW stuck */ |
|
753 tmr_StartTimer (pPowerSrvSM->hPwrSrvSmTimer, |
|
754 powerSrvSMTimerExpired, |
|
755 (TI_HANDLE)pPowerSrvSM, |
|
756 POWER_SAVE_GUARD_TIME_MS, |
|
757 TI_FALSE); |
|
758 |
|
759 /* that command should be sent to FW just in case we moved from Active to one of the PS modes |
|
760 * and vice versa, it shoul not be sent when moving between different PS modes */ |
|
761 status = cmdBld_CmdSetPsMode (pPowerSrvSM->hCmdBld, |
|
762 &powerSaveParams, |
|
763 (void *)pPowerSrvSM->pSmRequest->powerSaveCmdResponseCB, |
|
764 (pPowerSrvSM->pSmRequest->powerSaveCmdResponseCB == NULL) ? NULL : pPowerSrvSM->pSmRequest->powerSaveCBObject); |
|
765 |
|
766 if ( status != TI_OK ) |
|
767 { |
|
768 TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_ERROR, "Error in configuring Power Manager paramters!\n"); |
|
769 } |
|
770 |
|
771 return status; |
|
772 } |
|
773 |
|
774 /**************************************************************************************** |
|
775 * powerSrvSMTimerExpired * |
|
776 ***************************************************************************************** |
|
777 DESCRIPTION: This function is called upon timer expiry - when the FW has not returned |
|
778 a response within the defined tme (50 ms) |
|
779 |
|
780 INPUT: hPowerSrvSM - handle to the PowerSrvSM object. |
|
781 bTwdInitOccured - Indicates if TWDriver recovery occured since timer started |
|
782 |
|
783 OUTPUT: None |
|
784 |
|
785 RETURN: None |
|
786 ****************************************************************************************/ |
|
787 static void powerSrvSMTimerExpired (TI_HANDLE hPowerSrvSM, TI_BOOL bTwdInitOccured) |
|
788 { |
|
789 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
790 |
|
791 /* Print an error message */ |
|
792 TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_ERROR, "PS guard timer expired!\n"); |
|
793 |
|
794 /* Call the error notification callback (triggering recovery) */ |
|
795 pPowerSrvSM->failureEventCB( pPowerSrvSM->hFailureEventObj ,POWER_SAVE_FAILURE ); |
|
796 } |
|
797 |
|
798 /**************************************************************************************** |
|
799 * powerSrvRegisterFailureEventCB * |
|
800 **************************************************************************************** |
|
801 DESCRIPTION: Registers a failure event callback for PS SM error notifications. |
|
802 |
|
803 |
|
804 INPUT: - hPowerSrv - handle to the PowerSrv object. |
|
805 - failureEventCB - the failure event callback function.\n |
|
806 - hFailureEventObj - handle to the object passed to the failure event callback function. |
|
807 |
|
808 OUTPUT: |
|
809 RETURN: void. |
|
810 ****************************************************************************************/ |
|
811 void powerSrvSM_RegisterFailureEventCB( TI_HANDLE hPowerSrvSM, |
|
812 void *failureEventCB, TI_HANDLE hFailureEventObj ) |
|
813 { |
|
814 PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM; |
|
815 |
|
816 pPowerSrvSM->failureEventCB = (TFailureEventCb)failureEventCB; |
|
817 pPowerSrvSM->hFailureEventObj = hFailureEventObj; |
|
818 } |
|
819 |