Commit 495e7cfe authored by danicampora's avatar danicampora
Browse files

cc3200: Improve robustness of WLAN during sleep modes.

parent f5248a08
......@@ -106,8 +106,10 @@ void modusocket_enter_sleep (void) {
}
}
// wait for any of the sockets to become ready...
sl_Select(maxfd + 1, &socketset, NULL, NULL, NULL);
if (maxfd > 0) {
// wait for any of the sockets to become ready...
sl_Select(maxfd + 1, &socketset, NULL, NULL, NULL);
}
}
void modusocket_close_all_user_sockets (void) {
......
......@@ -149,8 +149,8 @@ STATIC wlan_obj_t wlan_obj = {
.ssid = MICROPY_PORT_WLAN_AP_SSID,
.key = MICROPY_PORT_WLAN_AP_KEY,
.mac = {0},
.ssid_o = {0},
.bssid = {0},
//.ssid_o = {0},
//.bssid = {0},
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
.servers_enabled = false,
#endif
......@@ -210,11 +210,11 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) {
{
case SL_WLAN_CONNECT_EVENT:
{
slWlanConnectAsyncResponse_t *pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;
//slWlanConnectAsyncResponse_t *pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;
// copy the new connection data
memcpy(wlan_obj.bssid, pEventData->bssid, SL_BSSID_LENGTH);
memcpy(wlan_obj.ssid_o, pEventData->ssid_name, pEventData->ssid_len);
wlan_obj.ssid_o[pEventData->ssid_len] = '\0';
//memcpy(wlan_obj.bssid, pEventData->bssid, SL_BSSID_LENGTH);
//memcpy(wlan_obj.ssid_o, pEventData->ssid_name, pEventData->ssid_len);
//wlan_obj.ssid_o[pEventData->ssid_len] = '\0';
SET_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION);
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
// we must reset the servers in case that the last connection
......@@ -228,15 +228,16 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) {
CLR_STATUS_BIT(wlan_obj.status, STATUS_BIT_IP_ACQUIRED);
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
servers_reset();
servers_wlan_cycle_power();
#endif
break;
case SL_WLAN_STA_CONNECTED_EVENT:
{
slPeerInfoAsyncResponse_t *pEventData = &pWlanEvent->EventData.APModeStaConnected;
//slPeerInfoAsyncResponse_t *pEventData = &pWlanEvent->EventData.APModeStaConnected;
// get the mac address and name of the connected device
memcpy(wlan_obj.bssid, pEventData->mac, SL_BSSID_LENGTH);
memcpy(wlan_obj.ssid_o, pEventData->go_peer_device_name, pEventData->go_peer_device_name_len);
wlan_obj.ssid_o[pEventData->go_peer_device_name_len] = '\0';
//memcpy(wlan_obj.bssid, pEventData->mac, SL_BSSID_LENGTH);
//memcpy(wlan_obj.ssid_o, pEventData->go_peer_device_name, pEventData->go_peer_device_name_len);
//wlan_obj.ssid_o[pEventData->go_peer_device_name_len] = '\0';
SET_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION);
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
// we must reset the servers in case that the last connection
......@@ -249,6 +250,7 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) {
CLR_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION);
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
servers_reset();
servers_wlan_cycle_power();
#endif
break;
case SL_WLAN_P2P_DEV_FOUND_EVENT:
......@@ -547,6 +549,12 @@ void wlan_set_current_time (uint32_t seconds_since_2000) {
sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION, SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME, sizeof(SlDateTime_t), (_u8 *)(&sl_datetime));
}
void wlan_off_on (void) {
// no need to lock the WLAN object on every API call since the servers and the MicroPtyhon
// task have the same priority
wlan_reenable(wlan_obj.mode);
}
//*****************************************************************************
// DEFINE STATIC FUNCTIONS
//*****************************************************************************
......@@ -554,8 +562,8 @@ void wlan_set_current_time (uint32_t seconds_since_2000) {
STATIC void wlan_clear_data (void) {
CLR_STATUS_BIT_ALL(wlan_obj.status);
wlan_obj.ip = 0;
memset(wlan_obj.ssid_o, 0, sizeof(wlan_obj.ssid));
memset(wlan_obj.bssid, 0, sizeof(wlan_obj.bssid));
//memset(wlan_obj.ssid_o, 0, sizeof(wlan_obj.ssid));
//memset(wlan_obj.bssid, 0, sizeof(wlan_obj.bssid));
}
STATIC void wlan_reenable (SlWlanMode_t mode) {
......
......@@ -95,6 +95,7 @@ extern void wlan_get_mac (uint8_t *macAddress);
extern void wlan_get_ip (uint32_t *ip);
extern bool wlan_is_connected (void);
extern void wlan_set_current_time (uint32_t seconds_since_2000);
extern void wlan_off_on (void);
extern int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family);
extern int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno);
......
......@@ -322,7 +322,7 @@ error:
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
}
STATIC mp_obj_t pyb_timer_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
// check arguments
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
......
......@@ -39,7 +39,8 @@
#include "pybwdt.h"
#include "modusocket.h"
#include "mpexception.h"
#include "modnetwork.h"
#include "modwlan.h"
/******************************************************************************
DEFINE PRIVATE TYPES
......@@ -50,13 +51,13 @@ typedef struct {
bool do_disable;
bool do_enable;
bool do_reset;
bool do_wlan_cycle_power;
} servers_data_t;
/******************************************************************************
DECLARE PRIVATE DATA
******************************************************************************/
static servers_data_t servers_data = {.timeout = SERVERS_DEF_TIMEOUT_MS, .enabled = false, .do_disable = false,
.do_enable = false, .do_reset = false};
static servers_data_t servers_data = {.timeout = SERVERS_DEF_TIMEOUT_MS};
static volatile bool sleep_sockets = false;
/******************************************************************************
......@@ -120,10 +121,16 @@ void TASK_Servers (void *pvParameters) {
}
if (sleep_sockets) {
sleep_sockets = false;
pybwdt_srv_sleeping(true);
modusocket_enter_sleep();
pybwdt_srv_sleeping(false);
mp_hal_delay_ms(SERVERS_CYCLE_TIME_MS * 2);
if (servers_data.do_wlan_cycle_power) {
servers_data.do_wlan_cycle_power = false;
wlan_off_on();
}
sleep_sockets = false;
}
// set the alive flag for the wdt
......@@ -152,6 +159,10 @@ void servers_reset (void) {
servers_data.do_reset = true;
}
void servers_wlan_cycle_power (void) {
servers_data.do_wlan_cycle_power = true;
}
bool servers_are_enabled (void) {
return servers_data.enabled;
}
......
......@@ -62,6 +62,7 @@ extern void TASK_Servers (void *pvParameters);
extern void servers_start (void);
extern void servers_stop (void);
extern void servers_reset (void);
extern void servers_wlan_cycle_power (void);
extern bool servers_are_enabled (void);
extern void servers_close_socket (int16_t *sd);
extern void servers_set_login (char *user, char *pass);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment