?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /******************************************************************************
2  
3 MRF24WB0M Driver Power Save functions
4 Module for Microchip TCP/IP Stack
5 -Provides access to MRF24WB0M WiFi controller
6 -Reference: MRF24WB0M Data sheet, IEEE 802.11 Standard
7  
8 *******************************************************************************
9 FileName: WFPowerSave.c
10 Dependencies: TCP/IP Stack header files
11 Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32
12 Compiler: Microchip C32 v1.10b or higher
13 Microchip C30 v3.22 or higher
14 Microchip C18 v3.34 or higher
15 Company: Microchip Technology, Inc.
16  
17 Software License Agreement
18  
19 Copyright (C) 2002-2010 Microchip Technology Inc. All rights reserved.
20  
21 Microchip licenses to you the right to use, modify, copy, and distribute:
22 (i) the Software when embedded on a Microchip microcontroller or digital
23 signal controller product ("Device") which is integrated into
24 Licensee's product; or
25 (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h,
26 ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device used in
27 conjunction with a Microchip ethernet controller for the sole purpose
28 of interfacing with the ethernet controller.
29  
30 You should refer to the license agreement accompanying this Software for
31 additional information regarding your rights and obligations.
32  
33 THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
34 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY
35 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
36 NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR ANY INCIDENTAL,
37 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST
38 OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS BY
39 THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS
40 FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON
41 THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR
42 OTHERWISE.
43  
44  
45 Author Date Comment
46 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47 KH 27 Jan 2010 Created for MRF24WB0M
48 ******************************************************************************/
49  
50 /*
51 *********************************************************************************************************
52 * INCLUDES
53 *********************************************************************************************************
54 */
55  
56 #include "TCPIP Stack/WFMac.h"
57 #if defined(WF_CS_TRIS) && defined(WF_USE_POWER_SAVE_FUNCTIONS)
58  
59  
60 /*
61 *********************************************************************************************************
62 * DEFINES
63 *********************************************************************************************************
64 */
65  
66 /* used for assertions */
67 #ifdef WF_DEBUG
68 #define WF_MODULE_NUMBER WF_MODULE_WF_POWER_SAVE
69 #endif
70  
71 #define REG_ENABLE_LOW_POWER_MASK ((UINT16)(0x01))
72  
73 /*
74 *********************************************************************************************************
75 * LOCAL DATA TYPES
76 *********************************************************************************************************
77 */
78  
79 /* Enumeration of valid values for WFSetPowerSaveMode() */
80 typedef enum
81 {
82 PS_POLL_ENABLED = 0, /* power save mode enabled */
83 PS_POLL_DISABLED /* power save mode disabled */
84 } tWFPsPwrMode;
85  
86 typedef struct pwrModeRequestStruct
87 {
88 UINT8 mode;
89 UINT8 wake;
90 UINT8 rcvDtims;
91 UINT8 reserved; /* pad byte */
92 } tWFPwrModeReq;
93  
94  
95 /*
96 *********************************************************************************************************
97 * LOCAL GLOBAL VARIABLES
98 *********************************************************************************************************
99 */
100  
101 static UINT8 g_powerSaveState = WF_PS_OFF;
102 static BOOL g_psPollActive = FALSE;
103  
104 /*
105 *********************************************************************************************************
106 * LOCAL FUNCTION PROTOTYPES
107 *********************************************************************************************************
108 */
109  
110 static void SendPowerModeMsg(tWFPwrModeReq *p_powerMode);
111 static void SetPowerSaveState(UINT8 powerSaveState);
112  
113  
114 /*******************************************************************************
115 Function:
116 void WFConfigureLowPowerMode(UINT8 action)
117  
118 Summary:
119 Driver function to configure PS Poll mode.
120  
121 Description:
122 This function is only used by the driver, not the application. This
123 function, other than at initialization, is only used when the application
124 has enabled PS-Poll mode. This function is used to temporarily deactivate
125 PS-Poll mode when there is mgmt or data message tx/rx and then, when message
126 activity has ceased, to again activate PS-Poll mode.
127  
128 Precondition:
129 MACInit must be called first.
130  
131 Parameters:
132 action - Can be either:
133 * WF_LOW_POWER_MODE_ON
134 * WF_LOW_POWER_MODE_OFF
135  
136 Returns:
137 None.
138  
139 Remarks:
140 None.
141 *****************************************************************************/
142 void WFConfigureLowPowerMode(UINT8 action)
143 {
144 UINT16 lowPowerStatusRegValue;
145  
146 /*--------------------------------------*/
147 /* if activating PS-Poll mode on MRF24WB0M */
148 /*--------------------------------------*/
149 if (action == WF_LOW_POWER_MODE_ON)
150 {
151 Write16BitWFRegister(WF_PSPOLL_H_REG, REG_ENABLE_LOW_POWER_MASK);
152 g_psPollActive = TRUE;
153 }
154 /*---------------------------------------------------------------------------------------------*/
155 /* else deactivating PS-Poll mode on MRF24WB0M (taking it out of low-power mode and waking it up) */
156 /*---------------------------------------------------------------------------------------------*/
157 else /* action == WF_LOW_POWER_MODE_OFF */
158 {
159 Write16BitWFRegister(WF_PSPOLL_H_REG, 0x00);
160 g_psPollActive = FALSE;
161  
162 /* poll the response bit that indicates when the MRF24WB0M has come out of low power mode */
163 do
164 {
165 /* set the index register to the register we wish to read (kWFCOMRegLoPwrStatusReg) */
166 Write16BitWFRegister(WF_INDEX_ADDR_REG, WF_LOW_POWER_STATUS_REG);
167 lowPowerStatusRegValue = Read16BitWFRegister(WF_INDEX_DATA_REG);
168  
169 } while (lowPowerStatusRegValue & REG_ENABLE_LOW_POWER_MASK);
170 }
171 }
172  
173 /*******************************************************************************
174 Function:
175 void WF_PsPollEnable(BOOL rxDtim)
176  
177 Summary:
178 Enables PS Poll mode.
179  
180 Description:
181 Enables PS Poll mode. PS-Poll (Power-Save Poll) is a mode allowing for
182 longer battery life. The MRF24WB0M coordinates with the Access Point to go
183 to sleep and wake up at periodic intervals to check for data messages, which
184 the Access Point will buffer. The listenInterval in the Connection
185 Algorithm defines the sleep interval. By default, PS-Poll mode is disabled.
186  
187 When PS Poll is enabled, the WF Host Driver will automatically force the
188 MRF24WB0M to wake up each time the Host sends Tx data or a control message
189 to the MRF24WB0M. When the Host message transaction is complete the
190 MRF24WB0M driver will automatically re-enable PS Poll mode.
191  
192 When the application is likely to experience a high volume of data traffic
193 then PS-Poll mode should be disabled for two reasons:
194 1. No power savings will be realized in the presence of heavy data traffic.
195 2. Performance will be impacted adversely as the WiFi Host Driver
196 continually activates and deactivates PS-Poll mode via SPI messages.
197  
198 Precondition:
199 MACInit must be called first.
200  
201 Parameters:
202 rxDtim -- TRUE if MRF24WB0M should wake up periodically and check for
203 buffered broadcast messages, else FALSE
204  
205 Returns:
206 None.
207  
208 Remarks:
209 None.
210 *****************************************************************************/
211 void WF_PsPollEnable(BOOL rxDtim)
212 {
213 tWFPwrModeReq pwrModeReq;
214  
215 /* fill in request structure and send message to MRF24WB0M */
216 pwrModeReq.mode = PS_POLL_ENABLED;
217 pwrModeReq.wake = 0;
218 pwrModeReq.rcvDtims = rxDtim;
219 SendPowerModeMsg(&pwrModeReq);
220  
221 if (rxDtim == TRUE)
222 {
223 SetPowerSaveState(WF_PS_PS_POLL_DTIM_ENABLED);
224 }
225 else
226 {
227 SetPowerSaveState(WF_PS_PS_POLL_DTIM_DISABLED);
228 }
229  
230 WFConfigureLowPowerMode(WF_LOW_POWER_MODE_ON);
231 }
232  
233 /*******************************************************************************
234 Function:
235 void WF_PsPollDisable(void)
236  
237 Summary:
238 Disables PS-Poll mode.
239  
240 Description:
241 Disables PS Poll mode. The MRF24WB0M will stay active and not go sleep.
242  
243 Precondition:
244 MACInit must be called first.
245  
246 Parameters:
247 None.
248  
249 Returns:
250 None.
251  
252 Remarks:
253 None.
254 *****************************************************************************/
255 void WF_PsPollDisable(void)
256 {
257 tWFPwrModeReq pwrModeReq;
258  
259 pwrModeReq.mode = PS_POLL_DISABLED;
260 pwrModeReq.wake = 1;
261 pwrModeReq.rcvDtims = 1;
262 SendPowerModeMsg(&pwrModeReq);
263  
264 SetPowerSaveState(WF_PS_OFF);
265 WFConfigureLowPowerMode(WF_LOW_POWER_MODE_OFF);
266 }
267  
268 /*******************************************************************************
269 Function:
270 void WF_GetPowerSaveState(UINT8 *p_powerSaveState)
271  
272 Summary:
273 Returns current power-save state.
274  
275 Description:
276 Returns the current MRF24WB0M power save state.
277  
278 <table>
279 Value Definition
280 ----- ----------
281 WF_PS_HIBERNATE MRF24WB0M in hibernate state
282 WF_PS_PS_POLL_DTIM_ENABLED MRF24WB0M in PS-Poll mode with DTIM enabled
283 WF_PS_PS_POLL_DTIM_DISABLED MRF24WB0M in PS-Poll mode with DTIM disabled
284 WF_PS_POLL_OFF MRF24WB0M is not in any power-save state
285 </table>
286  
287 Precondition:
288 MACInit must be called first.
289  
290 Parameters:
291 p_powerSaveState -- pointer to where power state is written
292  
293 Returns:
294 None.
295  
296 Remarks:
297 None.
298 *****************************************************************************/
299 void WF_GetPowerSaveState(UINT8 *p_powerSaveState)
300 {
301 *p_powerSaveState = g_powerSaveState;
302 }
303  
304 /*******************************************************************************
305 Function:
306 BOOL WFisPsPollEnabled(void)
307  
308 Summary:
309 Determines if application has enable PS-Poll mode.
310  
311 Description:
312  
313 Precondition:
314 MACInit must be called first.
315  
316 Parameters:
317 None.
318  
319 Returns:
320 TRUE if application has enabled PS-Poll mode, else returns FALSE
321  
322 Remarks:
323 None.
324 *****************************************************************************/
325 BOOL WFisPsPollEnabled(void)
326 {
327 if ((g_powerSaveState == WF_PS_PS_POLL_DTIM_ENABLED) || (g_powerSaveState == WF_PS_PS_POLL_DTIM_DISABLED))
328 {
329 return TRUE;
330 }
331 else
332 {
333 return FALSE;
334 }
335 }
336  
337 /*******************************************************************************
338 Function:
339 BOOL WFIsPsPollActive(void)
340  
341 Summary: Determine if PS Poll is currently active.
342  
343 Description:
344 This function is only called when PS-Poll mode has been enabled by the
345 application. When transmitting or receiving data or mgmt messages the
346 driver will temporarily disable PS-Poll. This function is used by the
347 driver to determine if PS-Poll is active or has been temporarily disabled.
348  
349 Precondition:
350 MACInit must be called first.
351  
352 Parameters:
353 None.
354  
355 Returns:
356 TRUE if driver has enabled PS-Poll, else FALSE
357  
358 Remarks:
359 None.
360 *****************************************************************************/
361 BOOL WFIsPsPollActive(void)
362 {
363 return g_psPollActive;
364 }
365  
366 /*******************************************************************************
367 Function:
368 void EnsureWFisAwake()
369  
370 Summary:
371 If PS-Poll is active or the MRF24WB0M is asleep, ensure that it is woken up.
372  
373 Description:
374 Called by the WiFi driver when it needs to transmit or receive a data or
375 mgmt message. If the application has enabled PS-Poll mode and the WiFi
376 driver has activated PS-Poll mode then this function will deactivate PS-Poll
377 mode and wake up the MRF24WB0M.
378  
379 Precondition:
380 MACInit must be called first.
381  
382 Parameters:
383 None.
384  
385 Returns:
386 None.
387  
388 Remarks:
389 None.
390 *****************************************************************************/
391 void EnsureWFisAwake()
392 {
393 /* if the application desires the MRF24WB0M to be in PS-Poll mode (PS-Poll with DTIM enabled or disabled */
394 if ((g_powerSaveState == WF_PS_PS_POLL_DTIM_ENABLED) || (g_powerSaveState == WF_PS_PS_POLL_DTIM_DISABLED))
395 {
396 /* if the WF driver has activated PS-Poll */
397 if (g_psPollActive == TRUE)
398 {
399 /* wake up MRF24WB0M */
400 WFConfigureLowPowerMode(WF_LOW_POWER_MODE_OFF);
401 }
402 }
403 }
404  
405 /*******************************************************************************
406 Function:
407 void WF_HibernateEnable()
408  
409 Summary:
410 Puts the MRF24WB0M into hibernate mode.
411  
412 Description:
413 Enables Hibernate mode on the MRF24WB0M, which effectively turns off the
414 device for maximum power savings.
415  
416 MRF24WB0M state is not maintained when it transitions to hibernate mode.
417 To remove the MRF24WB0M from hibernate mode call WF_Init().
418  
419 Precondition:
420 MACInit must be called first.
421  
422 Parameters:
423 None.
424  
425 Returns:
426 None.
427  
428 Remarks:
429 Note that because the MRF24WB0M does not save state, there will be a
430 disconnect between the TCP/IP stack and the MRF24B0M state. If it is
431 desired by the application to use hibernate, additional measures must be
432 taken to save application state. Then the host should be reset. This will
433 ensure a clean connection between MRF24WB0M and TCP/IP stack
434  
435 Future versions of the stack might have the ability to save stack context
436 as well, ensuring a clean wake up for the MRF24WB0M without needing a host
437 reset.
438 *****************************************************************************/
439 void WF_HibernateEnable()
440 {
441 WF_SetCE_N(WF_HIGH); /* set XCEN33 pin high, which puts MRF24WB0M in hibernate mode */
442  
443 SetPowerSaveState(WF_PS_HIBERNATE);
444 }
445  
446 /*******************************************************************************
447 Function:
448 static void SendPowerModeMsg(tWFPwrModeReq *p_powerMode)
449  
450 Summary:
451 Send power mode management message to the MRF24WB0M.
452  
453 Description:
454  
455 Precondition:
456 MACInit must be called first.
457  
458 Parameters:
459 p_powerMode -- pointer to tWFPwrModeReq structure to send to MRF24WB0M.
460  
461 Returns:
462 None.
463  
464 Remarks:
465 None.
466 *****************************************************************************/
467 static void SendPowerModeMsg(tWFPwrModeReq *p_powerMode)
468 {
469 UINT8 hdr[2];
470  
471 hdr[0] = WF_MGMT_REQUEST_TYPE;
472 hdr[1] = WF_SET_POWER_MODE_SUBTYPE;
473  
474 SendMgmtMsg(hdr,
475 sizeof(hdr),
476 (UINT8 *)p_powerMode,
477 sizeof(tWFPwrModeReq));
478  
479 /* wait for mgmt response, free buffer after it comes in (no data to read) */
480 WaitForMgmtResponse(WF_SET_POWER_MODE_SUBTYPE, FREE_MGMT_BUFFER);
481  
482 }
483  
484 /*******************************************************************************
485 Function:
486 static void SetPowerSaveState(UINT8 powerSaveState)
487  
488 Summary:
489 Sets the desired power save state of the MRF24WB0M.
490  
491 Description:
492  
493 Precondition:
494 MACInit must be called first.
495  
496 Parameters:
497 powerSaveState -- value of the power save state desired.
498  
499 <table>
500 Value Definition
501 ----- ----------
502 WF_PS_HIBERNATE MRF24WB0M in hibernate state
503 WF_PS_PS_POLL_DTIM_ENABLED MRF24WB0M in PS-Poll mode with DTIM enabled
504 WF_PS_PS_POLL_DTIM_DISABLED MRF24WB0M in PS-Poll mode with DTIM disabled
505 WF_PS_POLL_OFF MRF24WB0M is not in any power-save state
506 </table>
507  
508 Returns:
509 None.
510  
511 Remarks:
512 None.
513 *****************************************************************************/
514 static void SetPowerSaveState(UINT8 powerSaveState)
515 {
516 g_powerSaveState = powerSaveState;
517 }
518 #endif /* WF_CS_TRIS && WF_USE_POWER_SAVE_FUNCTIONS */
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3