Morse Micro IoT SDK  2.9.7
wnm_sleep.c File Reference

Detailed Description

Example utilizing WNM sleep to conserve power in between periodic transmissions.

Note
It is assumed that you have followed the steps in the Getting Started guide and are therefore familiar with how to build, flash, and monitor an application using the MM-IoT-SDK framework.

This file demonstrates an example of how WNM sleep can be utilized using the Morse Micro WLAN API. See WNM Sleep management for more details.

The application is based of the ping example application. The difference here is that we will enter WNM sleep after transmitting. We then sleep for a set amount of time before repeating. This can be used to conserve power if you have some data that only needs to be transferred periodically.

See Application helper routines for Wireless LAN interface for details of WLAN and IP stack configuration. Additional configuration options for this application can be found in the config.hjson file.

Definition in file wnm_sleep.c.

#include <string.h>
#include "mmhal.h"
#include "mmosal.h"
#include "mmwlan.h"
#include "mmping.h"
#include "mmconfig.h"
#include "mmipal.h"
#include "mm_app_common.h"
Include dependency graph for wnm_sleep.c:

Go to the source code of this file.

Macros

#define DEFAULT_PING_COUNT   10
 Number of ping requests to send. More...
 
#define DEFAULT_PING_DATA_SIZE   56
 Size of the ping request data, excluding 8-byte ICMP header. More...
 
#define DEFAULT_PING_INTERVAL_MS   1000
 Interval between successive ping requests. More...
 
#define DEFAULT_WNM_SLEEP_DURATION_MS   20000
 Duration to remain in wnm sleep between transmissions. More...
 
#define POST_PING_DELAY_MS   10000
 Delay in ms to wait before terminating connection on completion of ping. More...
 
#define UPDATE_INTERVAL_MS   (5000)
 Interval (in milliseconds) at which to provide updates when the receive count has not changed. More...
 

Enumerations

enum  debug_state {
  DEBUG_STATE_INIT = 0x00 , DEBUG_STATE_BOOTING_CHIP = 0x01 , DEBUG_STATE_CONNECTING = 0x03 , DEBUG_STATE_CONNECTED = 0x02 ,
  DEBUG_STATE_CONNECTED_IDLE = 0x00 , DEBUG_STATE_PINGING = 0x02 , DEBUG_STATE_PING_DONE = 0x03 , DEBUG_STATE_IDLE = 0x01 ,
  DEBUG_STATE_TERMINATING = 0x00 , DEBUG_STATE_INIT = 0x00 , DEBUG_STATE_CONNECTING = 0x01 , DEBUG_STATE_CONNECTED = 0x03 ,
  DEBUG_STATE_PINGING_0 = 0x02 , DEBUG_STATE_PING_0_DONE = 0x00 , DEBUG_STATE_WNM_SLEEP = 0x01 , DEBUG_STATE_EXITING_WNM_SLEEP = 0x03 ,
  DEBUG_STATE_WNM_SLEEP_DONE = 0x02 , DEBUG_STATE_PINGING_1 = 0x00 , DEBUG_STATE_PING_1_DONE = 0x01 , DEBUG_STATE_WNM_SLEEP_POWER_DOWN = 0x03 ,
  DEBUG_STATE_EXITING_WNM_SLEEP_POWER_DOWN = 0x02 , DEBUG_STATE_WNM_SLEEP_POWER_DOWN_DONE = 0x00 , DEBUG_STATE_TERMINATING = 0x01
}
 Enumeration of debug states that will be reflected on debug pins. More...
 

Functions

static void set_debug_state (enum debug_state state)
 Perform necessary operation (i.e., setting GPIO pins) upon entering the given debug state. More...
 
static void execute_ping_request (int iteration)
 Function to execute ping request. More...
 
static void execute_wnm_sleep (uint32_t wnm_sleep_duration_ms)
 Function to execute WNM sleep. More...
 
static void execute_wnm_sleep_ext (uint32_t wnm_sleep_duration_ms)
 Function to enter WNM Sleep and power off the MM chip while asleep. More...
 
void app_init (void)
 Main entry point to the application. More...
 

Macro Definition Documentation

◆ DEFAULT_PING_COUNT

#define DEFAULT_PING_COUNT   10

Number of ping requests to send.

Set to 0 to continue indefinitely.

Definition at line 42 of file wnm_sleep.c.

◆ DEFAULT_PING_DATA_SIZE

#define DEFAULT_PING_DATA_SIZE   56

Size of the ping request data, excluding 8-byte ICMP header.

Definition at line 46 of file wnm_sleep.c.

◆ DEFAULT_PING_INTERVAL_MS

#define DEFAULT_PING_INTERVAL_MS   1000

Interval between successive ping requests.

Definition at line 50 of file wnm_sleep.c.

◆ DEFAULT_WNM_SLEEP_DURATION_MS

#define DEFAULT_WNM_SLEEP_DURATION_MS   20000

Duration to remain in wnm sleep between transmissions.

Definition at line 54 of file wnm_sleep.c.

◆ POST_PING_DELAY_MS

#define POST_PING_DELAY_MS   10000

Delay in ms to wait before terminating connection on completion of ping.

Definition at line 58 of file wnm_sleep.c.

◆ UPDATE_INTERVAL_MS

#define UPDATE_INTERVAL_MS   (5000)

Interval (in milliseconds) at which to provide updates when the receive count has not changed.

Definition at line 63 of file wnm_sleep.c.

Enumeration Type Documentation

◆ debug_state

Enumeration of debug states that will be reflected on debug pins.

Note that due to limited availability of pins, the values are mapped to 2-bit codes and so are not unique. The code sequence has been chosen to be gray code like in that only one bit changes at a time, but it does not return to zero so a zero code can be used to identify the first state.

Enumerator
DEBUG_STATE_INIT 

Initial state at startup.

DEBUG_STATE_BOOTING_CHIP 

Indicates that we are booting the MM chip (note that this will also include the host MCU startup time.

DEBUG_STATE_CONNECTING 

Indicates we are connecting to the AP.

DEBUG_STATE_CONNECTED 

Indicates we are connected to the AP.

DEBUG_STATE_CONNECTED_IDLE 

Indicates that we have connected to the AP, but have not started the ping yet.

DEBUG_STATE_PINGING 

Indicates that the ping is in progress.

DEBUG_STATE_PING_DONE 

Indicates that the ping has completed.

DEBUG_STATE_IDLE 

Indicates that we are idling with WLAN still on.

DEBUG_STATE_TERMINATING 

Indicates that we are disconnecting from the AP.

DEBUG_STATE_INIT 

Initial state at startup.

DEBUG_STATE_CONNECTING 

Indicates we are connecting to the AP.

DEBUG_STATE_CONNECTED 

Indicates we are connected to the AP.

DEBUG_STATE_PINGING_0 

Indicates that the ping is in progress.

DEBUG_STATE_PING_0_DONE 

Indicates that the ping has completed.

DEBUG_STATE_WNM_SLEEP 

Indicates that WNM sleep is in progress.

DEBUG_STATE_EXITING_WNM_SLEEP 

Indicates that we are exiting WNM sleep.

DEBUG_STATE_WNM_SLEEP_DONE 

Indicates that WNM sleep has completed.

DEBUG_STATE_PINGING_1 

Indicates that the ping is in progress.

DEBUG_STATE_PING_1_DONE 

Indicates that the ping has completed.

DEBUG_STATE_WNM_SLEEP_POWER_DOWN 

Indicates that WNM sleep is in progress with chip powered down.

DEBUG_STATE_EXITING_WNM_SLEEP_POWER_DOWN 

Indicates that we are exiting WNM sleep with chip powered down.

DEBUG_STATE_WNM_SLEEP_POWER_DOWN_DONE 

Indicates that WNM sleep with chip powered down has completed.

DEBUG_STATE_TERMINATING 

Indicates that we are disconnecting from the AP.

Definition at line 72 of file wnm_sleep.c.

Function Documentation

◆ app_init()

void app_init ( void  )

Main entry point to the application.

This will be invoked in a thread once operating system and hardware initialization has completed. It may return, but it does not have to.

Definition at line 298 of file wnm_sleep.c.

◆ execute_ping_request()

static void execute_ping_request ( int  iteration)
static

Function to execute ping request.

This function will block until the ping operation has completed.

Parameters
iterationSpecifies which iteration (0 or 1) of ping this is so that we can select the correct debug state.

Definition at line 121 of file wnm_sleep.c.

◆ execute_wnm_sleep()

static void execute_wnm_sleep ( uint32_t  wnm_sleep_duration_ms)
static

Function to execute WNM sleep.

Parameters
wnm_sleep_duration_msDuration in milliseconds in WNM sleep.

Definition at line 204 of file wnm_sleep.c.

◆ execute_wnm_sleep_ext()

static void execute_wnm_sleep_ext ( uint32_t  wnm_sleep_duration_ms)
static

Function to enter WNM Sleep and power off the MM chip while asleep.

This will achieve lower power consumption during the sleep at the expense of a longer wake-up time.

Parameters
wnm_sleep_duration_msDuration in milliseconds in WNM sleep.

Definition at line 250 of file wnm_sleep.c.

◆ set_debug_state()

static void set_debug_state ( enum debug_state  state)
static

Perform necessary operation (i.e., setting GPIO pins) upon entering the given debug state.

Parameters
stateThe debug state to enter. See debug_state.

Definition at line 109 of file wnm_sleep.c.