WINC1500 Power Profiling APP.
Copyright (c) 2017-2018 Microchip Technology Inc. and its subsidiaries.
#include "asf.h"
#include "driver/include/m2m_wifi.h"
#include "socket/include/socket.h"
#include "driver/include/m2m_periph.h"
#include "driver/source/nmasic.h"
#include "main.h"
#include "string.h"
Macros | |
#define | DOZE_MODE 3 |
#define | STRING_EOL "\r\n" |
#define | STRING_HEADER |
Functions | |
static void | configure_console (void) |
Configure UART console. More... | |
static int8_t | connect_to_server (char *ip_addr, int tcp_mode) |
Creates and connects to an secure socket to be used for SSL. More... | |
static void | disable_pullups (void) |
Disables pull-ups for the pins in WINC which are used for communication with host MCU. More... | |
static void | execute_state_machine (int server_mode, low_power_test_param *tp) |
State machine to connect and exchange data with a TCP, SSL or a UDP server. More... | |
static void | handle_tcp_socket_cb (SOCKET sock, uint8_t u8Msg, void *pvMsg) |
Handles Callback event for TCP client socket. More... | |
static void | handle_udp_client_socket_cb (SOCKET sock, uint8_t u8Msg, void *pvMsg) |
Handles Callback event for UDP client socket. More... | |
static void | handle_udp_serv_socket_cb (SOCKET sock, uint8_t u8Msg, void *pvMsg) |
Handles Callback event for UDP server socket. More... | |
int | main (void) |
Main application function. More... | |
static void | reset_start_time (void) |
Resets the timer. More... | |
static void | run_profiling_app (int enable_ssl, low_power_test_param *tp) |
Execute profiling App. More... | |
static void | run_provisioning (low_power_test_param *tp) |
Switch the WINC to provisioning mode. More... | |
static void | run_sample_test_app (int enable_ssl, low_power_test_param *tp) |
Execute Sample Test App - connect and transmit on button press. More... | |
static void | run_udp_client (uint32_t target_ip, uint32_t delay_btwn_packets, uint32_t packet_size) |
Run UDP client on WINC. More... | |
static void | run_udp_server (void) |
Run UDP server on WINC. More... | |
static void | set_state (app_states state) |
Set the application status. More... | |
static void | socket_cb (SOCKET sock, uint8_t u8Msg, void *pvMsg) |
Callback function for all socket events. More... | |
static void | start_low_power_mode_test (low_power_test_param *tp) |
Function to set the desired low power mode to WINC and execute UDP server in case of Auto deep sleep. More... | |
static void | start_receive_test (void) |
Execute Reception test by receiving UDP frames in UDP server mode. More... | |
static void | start_transmission_test (low_power_test_param *tp) |
Execute Transmission test by transmitting UDP frames continously. More... | |
void | SysTick_Handler (void) |
SysTick handler used to measure precise delay. More... | |
static void | test_init (void) |
Connect to a pre-configured AP and initialize the server address. More... | |
static void | wifi_cb (uint8_t u8MsgType, void *pvMsg) |
Callback to get the Wi-Fi status update. More... | |
static void | winc_init (void) |
Initialize WINC. More... | |
#define DOZE_MODE 3 |
Referenced by start_low_power_mode_test().
#define STRING_EOL "\r\n" |
#define STRING_HEADER |
Referenced by main().
|
static |
Configure UART console.
[in] | None |
References usart_config::baudrate, cdc_uart_module, usart_config::mux_setting, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, usart_enable(), and usart_get_config_defaults().
|
static |
Creates and connects to an secure socket to be used for SSL.
[in] | None. |
References _htons, AF_INET, close(), connect(), nmi_inet_addr(), printf, in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, SOCK_ERR_INVALID, SOCK_ERR_NO_ERROR, SOCK_STREAM, socket(), SOCKET_FLAGS_SSL, tcp_client_socket, TEST_SSL_SERVER_PORT, and TEST_TCP_SERVER_PORT.
Referenced by execute_state_machine(), and run_sample_test_app().
|
static |
Disables pull-ups for the pins in WINC which are used for communication with host MCU.
[in] | None |
References m2m_periph_pullup_ctrl(), M2M_PERIPH_PULLUP_DIS_HOST_WAKEUP, M2M_PERIPH_PULLUP_DIS_SD_CMD_SPI_SCK, and M2M_PERIPH_PULLUP_DIS_SD_DAT0_SPI_TXD.
Referenced by winc_init().
|
static |
State machine to connect and exchange data with a TCP, SSL or a UDP server.
[in] | server_mode | TCP(0), SSL(1) or UDP(2) server |
[in] | tp | Test parameter |
References app_state, connect_to_server(), low_power_test_param::dtim, fake_data, IDLE_STATE, low_power_test_param::listen_interval, m2m_wifi_enable_sntp(), m2m_wifi_set_lsn_int(), m2m_wifi_set_sleep_mode(), nmi_inet_addr(), port_pin_set_output_level(), printf, low_power_test_param::ps_mode, ret, run_udp_client(), send(), set_state(), SOCK_ERR_NO_ERROR, SOCKET_CONNECTION_STATE, tcp_client_socket, test_init(), TEST_SSL_TCP_IP, TX_PACKET_SIZE, tstrM2mLsnInt::u16LsnInt, WIFI_CONNECTION_STATE, and winc_init().
Referenced by run_profiling_app().
|
static |
Handles Callback event for TCP client socket.
[in] | sock | Socket for which event callback is called |
[in] | u8Msg | Event to be handled |
[in] | *pvMsg | Data related to the event |
References close(), fake_data, port_pin_set_output_level(), printf, recv(), tstrSocketRecvMsg::s16BufferSize, tstrSocketConnectMsg::s8Error, set_state(), SOCK_ERR_NO_ERROR, SOCKET_CONNECTION_STATE, SOCKET_MSG_CONNECT, SOCKET_MSG_RECV, SOCKET_MSG_SEND, tcp_client_socket, tcp_connected, TEST_SSL_UPLOAD_SIZE, TX_PACKET_SIZE, u32TotalBytesSent, and upload_completed.
Referenced by socket_cb().
|
static |
Handles Callback event for UDP client socket.
[in] | sock | Socket for which event callback is called |
[in] | u8Msg | Event to be handled |
[in] | *pvMsg | Data related to the event |
References SOCKET_MSG_SENDTO, and udp_keep_alive_sent.
Referenced by socket_cb().
|
static |
Handles Callback event for UDP server socket.
[in] | sock | Socket for which event callback is called |
[in] | u8Msg | Event to be handled |
[in] | *pvMsg | Data related to the event |
References gau8SocketTestBuffer, packetCnt, printf, tstrSocketRecvMsg::pu8Buffer, recvfrom(), tstrSocketRecvMsg::s16BufferSize, SOCK_ERR_TIMEOUT, SOCKET_MSG_BIND, SOCKET_MSG_RECVFROM, tstrSocketBindMsg::status, and TEST_WINC_RECEIVE_BUFFER.
Referenced by socket_cb().
int main | ( | void | ) |
Main application function.
Initialize system, UART console, WINC and start power profiling application.
References configure_console(), DEFAULT_DTIM_FLAG, DEFAULT_TX_POWER, low_power_test_param::dtim, dtim, low_power_test_param::listen_interval, listen_interval, M2M_PS_DEEP_AUTOMATIC, M2M_PS_MANUAL, m2m_wifi_deinit(), menu_number, nm_bsp_deinit(), NULL, printf, low_power_test_param::ps_mode, ps_mode, run_profiling_app(), run_provisioning(), run_sample_test_app(), socketDeinit(), ssl_enable, start_low_power_mode_test(), start_receive_test(), start_transmission_test(), STRING_HEADER, system_init(), transmit_pwr_mode, low_power_test_param::tx_pwr_mode, and winc_init().
|
static |
Resets the timer.
[in] | None |
References ms_ticks, and start_time.
Referenced by run_sample_test_app().
|
static |
Execute profiling App.
[in] | enable_ssl | To connect to a secure server |
[in] | tp | Test parameter |
References curr_button_state, execute_state_machine(), m2m_wifi_handle_events(), NULL, port_pin_get_input_level(), and prev_button_state.
Referenced by main().
|
static |
Switch the WINC to provisioning mode.
[in] | tp | test parameter |
References tstrM2MAPConfig::au8SSID, m2m_wifi_handle_events(), m2m_wifi_start_provision_mode(), NULL, and printf.
Referenced by main().
|
static |
Execute Sample Test App - connect and transmit on button press.
[in] | enable_ssl | To connect to a secure server |
[in] | tp | Test parameter |
References close(), connect_to_server(), curr_button_state, low_power_test_param::dtim, fake_data, gateway_ip, low_power_test_param::listen_interval, M2M_PS_MANUAL, M2M_WIFI_CONNECTED, m2m_wifi_enable_sntp(), m2m_wifi_handle_events(), m2m_wifi_request_sleep(), m2m_wifi_set_lsn_int(), m2m_wifi_set_sleep_mode(), NULL, port_pin_get_input_level(), prev_button_state, printf, low_power_test_param::ps_mode, reset_start_time(), ret, run_udp_client(), send(), send_cnt, SOCK_ERR_NO_ERROR, tcp_client_socket, tcp_connected, test_init(), TEST_SSL_TCP_IP, TEST_SSL_UPLOAD_SIZE, tstrM2mLsnInt::u16LsnInt, udp_keep_alive_sent, upload_completed, and wifi_connected.
Referenced by main().
|
static |
Run UDP client on WINC.
[in] | target_ip | IP address of the server |
[in] | delay_btwn_packets | delay between sending 2 packets |
[in] | packet_size | size of each packet |
References addr, AF_INET, gau8SocketTestBuffer, M2M_SUCCESS, M2M_WIFI_CONNECTED, m2m_wifi_handle_events(), ms_ticks, NULL, printf, ret, in_addr::s_addr, sendto(), set_state(), sockaddr_in::sin_addr, SOCK_DGRAM, socket(), SOCKET_CONNECTION_STATE, start_time, udp_client_socket, udp_keep_alive_sent, and wifi_connected.
Referenced by execute_state_machine(), run_sample_test_app(), and start_transmission_test().
|
static |
Run UDP server on WINC.
[in] | None |
References addr, AF_INET, bind(), M2M_WIFI_CONNECTED, m2m_wifi_handle_events(), NULL, printf, SOCK_DGRAM, socket(), udp_server_socket, and wifi_connected.
Referenced by start_low_power_mode_test(), and start_receive_test().
|
static |
Set the application status.
[in] | state | State value to be set |
References app_state, and state.
Referenced by execute_state_machine(), handle_tcp_socket_cb(), run_udp_client(), and wifi_cb().
|
static |
Callback function for all socket events.
[in] | sock | socket handler. |
[in] | u8Msg | Type of Socket notification |
[in] | pvMsg | A structure contains notification informations. |
References handle_tcp_socket_cb(), handle_udp_client_socket_cb(), handle_udp_serv_socket_cb(), tcp_client_socket, udp_client_socket, and udp_server_socket.
Referenced by winc_init().
|
static |
Function to set the desired low power mode to WINC and execute UDP server in case of Auto deep sleep.
[in] | tp | test parameter |
References DOZE_MODE, low_power_test_param::dtim, low_power_test_param::listen_interval, M2M_PS_MANUAL, M2M_WIFI_CONNECTED, m2m_wifi_enable_sntp(), m2m_wifi_handle_events(), m2m_wifi_request_sleep(), m2m_wifi_set_lsn_int(), m2m_wifi_set_sleep_mode(), NULL, low_power_test_param::ps_mode, run_udp_server(), test_init(), tstrM2mLsnInt::u16LsnInt, and wifi_connected.
Referenced by main().
|
static |
Execute Reception test by receiving UDP frames in UDP server mode.
[in] | None |
References m2m_wifi_enable_sntp(), run_udp_server(), and test_init().
Referenced by main().
|
static |
Execute Transmission test by transmitting UDP frames continously.
[in] | tp | test parameter |
References gateway_ip, m2m_wifi_enable_sntp(), run_udp_client(), test_init(), TX_DELAY_MS, and TX_PACKET_SIZE.
Referenced by main().
void SysTick_Handler | ( | void | ) |
SysTick handler used to measure precise delay.
[in] | None |
References ms_ticks.
|
static |
Connect to a pre-configured AP and initialize the server address.
[in] | None |
References _htons, addr, AF_INET, M2M_WIFI_CH_1, m2m_wifi_connect(), nmi_inet_addr(), port_pin_toggle_output_level(), in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, TEST_WINC_SERVER_IP, TEST_WINC_SERVER_PORT, TEST_WLAN_AUTH, TEST_WLAN_PSK, and TEST_WLAN_SSID.
Referenced by execute_state_machine(), run_sample_test_app(), start_low_power_mode_test(), start_receive_test(), and start_transmission_test().
|
static |
Callback to get the Wi-Fi status update.
[in] | u8MsgType | Type of Wi-Fi notification. |
[in] | pvMsg | A pointer to a buffer containing the notification parameters. |
AP_CONNECTION_TOGGLE
AP_CONNECTION_TOGGLE
References close(), gateway_ip, M2M_SUCCESS, M2M_WIFI_CONNECTED, M2M_WIFI_DISCONNECTED, M2M_WIFI_REQ_DHCP_CONF, M2M_WIFI_RESP_CON_STATE_CHANGED, M2M_WIFI_RESP_PROVISION_INFO, port_pin_toggle_output_level(), printf, set_state(), tcp_client_socket, tcp_connected, tstrM2MIPConfig::u32Gateway, tstrM2mWifiStateChanged::u8CurrState, tstrM2mWifiStateChanged::u8ErrCode, tstrM2MProvisionInfo::u8Status, udp_client_socket, udp_server_socket, wifi_connected, and WIFI_CONNECTION_STATE.
Referenced by winc_init().
|
static |
Initialize WINC.
[in] | None |
References disable_pullups(), M2M_SUCCESS, m2m_wifi_init(), nm_bsp_init(), NULL, tstrWifiInitParam::pfAppWifiCb, printf, registerSocketCallback(), ret, socket_cb(), socketInit(), and wifi_cb().
Referenced by execute_state_machine(), and main().
struct sockaddr_in addr |
|
static |
|
static |
UART module for debug.
Referenced by run_profiling_app(), and run_sample_test_app().
|
static |
Referenced by main().
|
static |
Referenced by execute_state_machine(), handle_tcp_socket_cb(), and run_sample_test_app().
|
static |
Referenced by run_sample_test_app(), start_transmission_test(), and wifi_cb().
|
static |
Test buffer.
Referenced by handle_udp_serv_socket_cb(), and run_udp_client().
|
static |
|
static |
Referenced by main().
|
static |
Referenced by main().
volatile uint32_t ms_ticks = 0 |
SysTick counter to avoid busy wait delay.
TLS read functionality.
SysTick counter for non busy wait delay.
|
static |
UDP packet count.
Referenced by handle_udp_serv_socket_cb().
Referenced by run_profiling_app(), and run_sample_test_app().
|
static |
Referenced by main().
|
static |
Referenced by run_sample_test_app().
|
static |
Referenced by main().
|
static |
Referenced by reset_start_time(), and run_udp_client().
|
static |
Client and Server socket handler.
Referenced by connect_to_server(), execute_state_machine(), handle_tcp_socket_cb(), run_sample_test_app(), socket_cb(), and wifi_cb().
Referenced by disconnect_cmd_handler(), handle_input_message(), handle_tcp_socket_cb(), run_sample_test_app(), socket_cb(), and wifi_cb().
|
static |
Referenced by main().
|
static |
Referenced by handle_tcp_socket_cb().
|
static |
Referenced by run_udp_client(), socket_cb(), and wifi_cb().
Referenced by handle_udp_client_socket_cb(), run_sample_test_app(), and run_udp_client().
|
static |
Referenced by run_udp_server(), socket_cb(), and wifi_cb().
Referenced by handle_tcp_socket_cb(), and run_sample_test_app().
|
static |
Referenced by run_sample_test_app(), run_udp_client(), run_udp_server(), start_low_power_mode_test(), and wifi_cb().