/******************************************************************************* Function: void WF_PsPollEnable(bool rxDtim, bool aggressive) Summary: Enables PS Poll mode. Description: Enables PS Poll mode. PS-Poll (Power-Save Poll) is a mode allowing for longer battery life. The MRF24W coordinates with the Access Point to go to sleep and wake up at periodic intervals to check for data messages, which the Access Point will buffer. The listenInterval in the Connection Algorithm defines the sleep interval. By default, PS-Poll mode is disabled. When PS Poll is enabled, the WF Host Driver will automatically force the MRF24W to wake up each time the Host sends Tx data or a control message to the MRF24W. When the Host message transaction is complete the MRF24W driver will automatically re-enable PS Poll mode. When the application is likely to experience a high volume of data traffic then PS-Poll mode should be disabled for two reasons: 1. No power savings will be realized in the presence of heavy data traffic. 2. Performance will be impacted adversely as the WiFi Host Driver continually activates and deactivates PS-Poll mode via SPI messages. Precondition: MACInit must be called first. Parameters: rxDtim - true if MRF24W should wake up periodically and check for buffered broadcast messages, else false Returns: None. Remarks: None. *****************************************************************************/ void WF_PsPollEnable(bool rxDtim, bool aggressive) { tWFPwrModeReq pwrModeReq; if (isWiFiVer1209OrLater() && !WFisConnected()) { // save caller parameters for later, when we can enable this mode g_rxDtim = rxDtim; g_aggressivePs = aggressive; SetAppPowerSaveMode(true); return; } /* fill in request structure and send message to MRF24W */ pwrModeReq.mode = PS_POLL_ENABLED; pwrModeReq.wake = 0; pwrModeReq.rcvDtims = rxDtim; pwrModeReq.reserved = aggressive; SendPowerModeMsg(&pwrModeReq); if (rxDtim == true) { SetPowerSaveState(WF_PS_PS_POLL_DTIM_ENABLED); } else { SetPowerSaveState(WF_PS_PS_POLL_DTIM_DISABLED); } WFConfigureLowPowerMode(WF_LOW_POWER_MODE_ON); SetAppPowerSaveMode(true); }
/******************************************************************************* Function: void WF_PsPollEnable(BOOL rxDtim, BOOL aggressive) Summary: Enables PS Poll mode. Description: Enables PS Poll mode. PS-Poll (Power-Save Poll) is a mode allowing for longer battery life. The MRF24W coordinates with the Access Point to go to sleep and wake up at periodic intervals to check for data messages, which the Access Point will buffer. The listenInterval in the Connection Algorithm defines the sleep interval. By default, PS-Poll mode is disabled. When PS Poll is enabled, the WF Host Driver will automatically force the MRF24W to wake up each time the Host sends Tx data or a control message to the MRF24W. When the Host message transaction is complete the MRF24W driver will automatically re-enable PS Poll mode. When the application is likely to experience a high volume of data traffic then PS-Poll mode should be disabled for two reasons: 1. No power savings will be realized in the presence of heavy data traffic. 2. Performance will be impacted adversely as the WiFi Host Driver continually activates and deactivates PS-Poll mode via SPI messages. Precondition: MACInit must be called first. Parameters: rxDtim - TRUE listens at the DTIM interval and FALSE listens at the CASetListenInterval Returns: None. Remarks: None. *****************************************************************************/ void WF_PsPollEnable(BOOL rxDtim) { #if defined(__18CXX) static tWFPwrModeReq pwrModeReq; #else tWFPwrModeReq pwrModeReq; #endif // if not currently connected #if !defined(MRF24WG) if (gRFModuleVer1209orLater && !WFisConnected()) #else if (!WFisConnected()) #endif { // save caller parameters for later, when we can enable this mode g_rxDtim = rxDtim; SetAppPowerSaveMode(TRUE); return; } /* fill in request structure and send message to MRF24W */ pwrModeReq.mode = PS_POLL_ENABLED; pwrModeReq.wake = 0; pwrModeReq.rcvDtims = rxDtim; SendPowerModeMsg(&pwrModeReq); if (rxDtim == TRUE) { SetPowerSaveState(WF_PS_PS_POLL_DTIM_ENABLED); } else { SetPowerSaveState(WF_PS_PS_POLL_DTIM_DISABLED); } WFConfigureLowPowerMode(WF_LOW_POWER_MODE_ON); SetAppPowerSaveMode(TRUE); }
/***************************************************************************** * * check_network_connected * * \param None * * \return TRUE if network ready, FALSE if not * * \brief Checks to see that network is still connected. * *****************************************************************************/ unsigned char check_network_connected(void) { int network_connected = 0; if (WFisConnected() != TRUE) { LED1_IO = 0; LED2_IO = 0; network_connected = 0; if (CFGCXT.type != WF_SOFT_AP && AppConfig.networkType == WF_INFRASTRUCTURE && network_connected == 0) { if (task_delay(TICK_MINUTE, 1)) wifi_fail_count++; } } if (DHCPIsBound(0)) network_connected = 1; else network_connected = 0; if (tcp_fail_count > 5 || unknown_status > 5) { LED1_IO = 0; LED2_IO = 0; } if (wifi_fail_count > 2) { wifi_fail_count = 0; // Reset(); } if (tcp_fail_count > 50 || unknown_status > 50) { tcp_fail_count = 0; unknown_status = 0; wifi_fail_count = 0; network_connected = 0; // Reset(); } return network_connected; }
/******************************************************************************* Function: void DRV_WIFI_PsPollEnable(DRV_WIFI_PS_POLL_CONTEXT *p_context); Summary: Enables PS Poll mode. Description: Enables PS Poll mode. PS-Poll (Power-Save Poll) is a mode allowing for longer battery life. The MRF24W coordinates with the Access Point to go to sleep and wake up at periodic intervals to check for data messages, which the Access Point will buffer. The listenInterval in the Connection Algorithm defines the sleep interval. By default, PS-Poll mode is disabled. When PS Poll is enabled, the WF Host Driver will automatically force the MRF24W to wake up each time the Host sends Tx data or a control message to the MRF24W. When the Host message transaction is complete the MRF24W driver will automatically re-enable PS Poll mode. When the application is likely to experience a high volume of data traffic then PS-Poll mode should be disabled for two reasons: 1. No power savings will be realized in the presence of heavy data traffic. 2. Performance will be impacted adversely as the WiFi Host Driver continually activates and deactivates PS-Poll mode via SPI messages. Parameters: p_context - Pointer to ps poll context. See DRV_WIFI_PS_POLL_CONTEXT structure. Returns: None. Remarks: None. *****************************************************************************/ void DRV_WIFI_PsPollEnable(DRV_WIFI_PS_POLL_CONTEXT *p_context) { t_wfPwrModeReq pwrModeReq; // if not currently connected if (!WFisConnected()) { // save caller parameters for later, when we can enable this mode g_savedPsPollContext.listenInterval = p_context->listenInterval; g_savedPsPollContext.dtimInterval = p_context->dtimInterval; g_savedPsPollContext.useDtim = p_context->useDtim; SetAppPowerSaveMode(true); return; } SetListenInterval(p_context->listenInterval); SetDtimInterval(p_context->dtimInterval); // fill in request structure and send message to MRF24WG pwrModeReq.mode = PS_POLL_ENABLED; pwrModeReq.wake = 0; pwrModeReq.rcvDtims = p_context->useDtim; SendPowerModeMsg(&pwrModeReq); if (p_context->useDtim) { SetPowerSaveState(DRV_WIFI_PS_PS_POLL_DTIM_ENABLED); } else { SetPowerSaveState(DRV_WIFI_PS_PS_POLL_DTIM_DISABLED); } WFConfigureLowPowerMode(WF_LOW_POWER_MODE_ON); SetAppPowerSaveMode(true); }
int main(void) #endif { static DWORD t = 0; static DWORD dwLastIP = 0; #if defined(WF_USE_POWER_SAVE_FUNCTIONS) BOOL PsPollEnabled; BOOL psConfDone = FALSE; #endif // Initialize application specific hardware InitializeBoard(); #if defined(USE_LCD) // Initialize and display the stack version on the LCD LCDInit(); DelayMs(100); strcpypgm2ram((char*)LCDText, "TCPStack " TCPIP_STACK_VERSION " " " "); LCDUpdate(); #endif // Initialize stack-related hardware components that may be // required by the UART configuration routines TickInit(); #if defined(STACK_USE_MPFS2) MPFSInit(); #endif // Initialize Stack and application related NV variables into AppConfig. InitAppConfig(); // Initiates board setup process if button is depressed // on startup if(BUTTON0_IO == 0u) { #if defined(EEPROM_CS_TRIS) || defined(SPIFLASH_CS_TRIS) // Invalidate the EEPROM contents if BUTTON0 is held down for more than 4 seconds DWORD StartTime = TickGet(); LED_PUT(0x00); while(BUTTON0_IO == 0u) { if(TickGet() - StartTime > 4*TICK_SECOND) { #if defined(EEPROM_CS_TRIS) XEEBeginWrite(0x0000); XEEWrite(0xFF); XEEWrite(0xFF); XEEEndWrite(); #elif defined(SPIFLASH_CS_TRIS) SPIFlashBeginWrite(0x0000); SPIFlashWrite(0xFF); SPIFlashWrite(0xFF); #endif #if defined(STACK_USE_UART) putrsUART("\r\n\r\nBUTTON0 held for more than 4 seconds. Default settings restored.\r\n\r\n"); #endif LED_PUT(0x0F); while((LONG)(TickGet() - StartTime) <= (LONG)(9*TICK_SECOND/2)); LED_PUT(0x00); while(BUTTON0_IO == 0u); Reset(); break; } } #endif #if defined(STACK_USE_UART) DoUARTConfig(); #endif } // Initialize core stack layers (MAC, ARP, TCP, UDP) and // application modules (HTTP, SNMP, etc.) StackInit(); #if defined(WF_CS_TRIS) WF_Connect(); #endif // Initialize any application-specific modules or functions/ // For this demo application, this only includes the // UART 2 TCP Bridge #if defined(STACK_USE_UART2TCP_BRIDGE) UART2TCPBridgeInit(); #endif #if defined(STACK_USE_ZEROCONF_LINK_LOCAL) ZeroconfLLInitialize(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) mDNSInitialize(MY_DEFAULT_HOST_NAME); mDNSServiceRegister( (const char *) "DemoWebServer", // base name of the service "_http._tcp.local", // type of the service 80, // TCP or UDP port, at which this service is available ((const BYTE *)"path=/index.htm"), // TXT info 1, // auto rename the service when if needed NULL, // no callback function NULL // no application context ); mDNSMulticastFilterRegister(); #endif // Now that all items are initialized, begin the co-operative // multitasking loop. This infinite loop will continuously // execute all stack-related tasks, as well as your own // application's functions. Custom functions should be added // at the end of this loop. // Note that this is a "co-operative mult-tasking" mechanism // where every task performs its tasks (whether all in one shot // or part of it) and returns so that other tasks can do their // job. // If a task needs very long time to do its job, it must be broken // down into smaller pieces so that other tasks can have CPU time. while(1) { //while (1) /*{ if(BUTTON0_IO == 0u && LED0_IO == 0) { LED0_IO =1; } if(BUTTON0_IO == 0u && LED0_IO ==1) { LED0_IO =0; } }*/ #if defined(WF_USE_POWER_SAVE_FUNCTIONS) if (!psConfDone && WFisConnected()) { PsPollEnabled = (MY_DEFAULT_PS_POLL == WF_ENABLED); if (!PsPollEnabled) { /* disable low power (PS-Poll) mode */ #if defined(STACK_USE_UART) putrsUART("Disable PS-Poll\r\n"); #endif WF_PsPollDisable(); } else { /* Enable low power (PS-Poll) mode */ #if defined(STACK_USE_UART) putrsUART("Enable PS-Poll\r\n"); #endif WF_PsPollEnable(TRUE); } psConfDone = TRUE; } #endif // Blink LED0 (right most one) every second. // if(TickGet() - t >= TICK_SECOND/2ul) // { // t = TickGet(); // LED0_IO ^= 1; // } // This task performs normal stack task including checking // for incoming packet, type of packet and calling // appropriate stack entity to process it. StackTask(); // This tasks invokes each of the core stack application tasks StackApplications(); #if defined(STACK_USE_ZEROCONF_LINK_LOCAL) ZeroconfLLProcess(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) mDNSProcess(); // Use this function to exercise service update function // HTTPUpdateRecord(); #endif // Process application specific tasks here. // For this demo app, this will include the Generic TCP // client and servers, and the SNMP, Ping, and SNMP Trap // demos. Following that, we will process any IO from // the inputs on the board itself. // Any custom modules or processing you need to do should // go here. #if defined(STACK_USE_GENERIC_TCP_CLIENT_EXAMPLE) GenericTCPClient(); #endif #if defined(STACK_USE_GENERIC_TCP_SERVER_EXAMPLE) GenericTCPServer(); #endif #if defined(STACK_USE_SMTP_CLIENT) SMTPDemo(); #endif #if defined(STACK_USE_ICMP_CLIENT) PingDemo(); #endif #if defined(STACK_USE_SNMP_SERVER) && !defined(SNMP_TRAP_DISABLED) //User should use one of the following SNMP demo // This routine demonstrates V1 or V2 trap formats with one variable binding. SNMPTrapDemo(); #if defined(SNMP_STACK_USE_V2_TRAP) || defined(SNMP_V1_V2_TRAP_WITH_SNMPV3) //This routine provides V2 format notifications with multiple (3) variable bindings //User should modify this routine to send v2 trap format notifications with the required varbinds. //SNMPV2TrapDemo(); #endif if(gSendTrapFlag) SNMPSendTrap(); #endif #if defined(STACK_USE_BERKELEY_API) BerkeleyTCPClientDemo(); BerkeleyTCPServerDemo(); BerkeleyUDPClientDemo(); #endif ProcessIO(); // If the local IP address has changed (ex: due to DHCP lease change) // write the new IP address to the LCD display, UART, and Announce // service if(dwLastIP != AppConfig.MyIPAddr.Val) { dwLastIP = AppConfig.MyIPAddr.Val; #if defined(STACK_USE_UART) putrsUART((ROM char*)"\r\nNew IP Address: "); #endif DisplayIPValue(AppConfig.MyIPAddr); #if defined(STACK_USE_UART) putrsUART((ROM char*)"\r\n"); #endif #if defined(STACK_USE_ANNOUNCE) AnnounceIP(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) mDNSFillHostRecord(); #endif } } }