cc3200: Remove unneeded code from modwlan and optimize startup time.
These changes also help reduce the hibernate wake-up time to 1s.
This commit is contained in:
parent
ac4f6b804f
commit
c7fabe1f3e
@ -122,7 +122,7 @@ typedef struct _wlan_obj_t {
|
|||||||
#define MODWLAN_TIMEOUT_MS 5000
|
#define MODWLAN_TIMEOUT_MS 5000
|
||||||
#define MODWLAN_MAX_NETWORKS 20
|
#define MODWLAN_MAX_NETWORKS 20
|
||||||
#define MODWLAN_SCAN_PERIOD_S 300 // 5 minutes
|
#define MODWLAN_SCAN_PERIOD_S 300 // 5 minutes
|
||||||
#define MODWLAN_WAIT_FOR_SCAN_MS 950
|
#define MODWLAN_WAIT_FOR_SCAN_MS 1050
|
||||||
|
|
||||||
#define ASSERT_ON_ERROR( x ) ASSERT((x) >= 0 )
|
#define ASSERT_ON_ERROR( x ) ASSERT((x) >= 0 )
|
||||||
|
|
||||||
@ -150,7 +150,22 @@ typedef struct _wlan_obj_t {
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
DECLARE PRIVATE DATA
|
DECLARE PRIVATE DATA
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
STATIC wlan_obj_t wlan_obj;
|
STATIC wlan_obj_t wlan_obj = {
|
||||||
|
.callback = mp_const_none,
|
||||||
|
.mode = -1,
|
||||||
|
.status = 0,
|
||||||
|
.ip = 0,
|
||||||
|
.gateway = 0,
|
||||||
|
.dns = 0,
|
||||||
|
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||||
|
.servers_enabled = false,
|
||||||
|
#endif
|
||||||
|
.security = SL_SEC_TYPE_OPEN,
|
||||||
|
.ssid = {0},
|
||||||
|
.bssid = {0},
|
||||||
|
.mac = {0},
|
||||||
|
};
|
||||||
|
|
||||||
STATIC const mp_cb_methods_t wlan_cb_methods;
|
STATIC const mp_cb_methods_t wlan_cb_methods;
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
@ -356,12 +371,21 @@ void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
|
|||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
|
|
||||||
void wlan_init0 (void) {
|
void wlan_init0 (void) {
|
||||||
// Set the mode to an invalid one
|
// create the wlan lock
|
||||||
wlan_obj.mode = -1;
|
|
||||||
wlan_obj.base.type = NULL;
|
|
||||||
memset (wlan_obj.mac, 0, SL_MAC_ADDR_LEN);
|
|
||||||
ASSERT(OSI_OK == sl_LockObjCreate(&wlan_LockObj, "WlanLock"));
|
ASSERT(OSI_OK == sl_LockObjCreate(&wlan_LockObj, "WlanLock"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlan_first_start (void) {
|
||||||
|
// clear wlan data after checking any of the status flags
|
||||||
wlan_initialize_data();
|
wlan_initialize_data();
|
||||||
|
|
||||||
|
if (wlan_obj.mode < 0) {
|
||||||
|
wlan_obj.mode = sl_Start(0, 0, 0);
|
||||||
|
sl_LockObjUnlock (&wlan_LockObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the mac address
|
||||||
|
wlan_get_sl_mac();
|
||||||
}
|
}
|
||||||
|
|
||||||
modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ssid_len, uint8_t sec,
|
modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ssid_len, uint8_t sec,
|
||||||
@ -374,31 +398,9 @@ modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ss
|
|||||||
wlan_stop_servers();
|
wlan_stop_servers();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (wlan_obj.mode < 0) {
|
|
||||||
wlan_obj.mode = sl_Start(0, 0, 0);
|
|
||||||
sl_LockObjUnlock (&wlan_LockObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the mac address
|
// do a basic start fisrt
|
||||||
wlan_get_sl_mac();
|
wlan_first_start();
|
||||||
|
|
||||||
// stop the device if it's not in station mode
|
|
||||||
if (wlan_obj.mode != ROLE_STA) {
|
|
||||||
if (ROLE_AP == wlan_obj.mode) {
|
|
||||||
// if the device is in AP mode, we need to wait for this event
|
|
||||||
// before doing anything
|
|
||||||
while (!IS_IP_ACQUIRED(wlan_obj.status)) {
|
|
||||||
#ifndef SL_PLATFORM_MULTI_THREADED
|
|
||||||
_SlTaskEntry();
|
|
||||||
#endif
|
|
||||||
HAL_Delay (5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// switch to STA mode
|
|
||||||
ASSERT_ON_ERROR(sl_WlanSetMode(ROLE_STA));
|
|
||||||
// stop and start again
|
|
||||||
wlan_reenable(ROLE_STA);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Device in station-mode. Disconnect previous connection if any
|
// Device in station-mode. Disconnect previous connection if any
|
||||||
// The function returns 0 if 'Disconnected done', negative number if already
|
// The function returns 0 if 'Disconnected done', negative number if already
|
||||||
@ -413,13 +415,6 @@ modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ss
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear wlan data after checking any of the status flags
|
|
||||||
wlan_initialize_data ();
|
|
||||||
wlan_obj.security = sec;
|
|
||||||
|
|
||||||
// Set connection policy to Auto + SmartConfig (Device's default connection policy)
|
|
||||||
ASSERT_ON_ERROR(sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0));
|
|
||||||
|
|
||||||
// Remove all profiles
|
// Remove all profiles
|
||||||
ASSERT_ON_ERROR(sl_WlanProfileDel(0xFF));
|
ASSERT_ON_ERROR(sl_WlanProfileDel(0xFF));
|
||||||
|
|
||||||
@ -443,9 +438,6 @@ modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ss
|
|||||||
// Number between 0-15, as dB offset from max power - 0 will set max power
|
// Number between 0-15, as dB offset from max power - 0 will set max power
|
||||||
uint8_t ucPower = 0;
|
uint8_t ucPower = 0;
|
||||||
if (mode == ROLE_AP) {
|
if (mode == ROLE_AP) {
|
||||||
// Disable the scanning
|
|
||||||
ASSERT_ON_ERROR(sl_WlanPolicySet(SL_POLICY_SCAN, MODWLAN_SL_SCAN_DISABLE, NULL, 0));
|
|
||||||
|
|
||||||
// Switch to AP mode
|
// Switch to AP mode
|
||||||
ASSERT_ON_ERROR(sl_WlanSetMode(mode));
|
ASSERT_ON_ERROR(sl_WlanSetMode(mode));
|
||||||
ASSERT (ssid != NULL && key != NULL);
|
ASSERT (ssid != NULL && key != NULL);
|
||||||
@ -482,17 +474,18 @@ modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ss
|
|||||||
|
|
||||||
// Stop and start again
|
// Stop and start again
|
||||||
wlan_reenable(mode);
|
wlan_reenable(mode);
|
||||||
|
// save the security type
|
||||||
|
wlan_obj.security = sec;
|
||||||
}
|
}
|
||||||
// STA and P2P modes
|
// STA and P2P modes
|
||||||
else {
|
else {
|
||||||
ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER,
|
ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER,
|
||||||
sizeof(ucPower), (unsigned char *)&ucPower));
|
sizeof(ucPower), (unsigned char *)&ucPower));
|
||||||
if (mode == ROLE_P2P) {
|
|
||||||
// Switch to P2P mode
|
|
||||||
ASSERT_ON_ERROR(sl_WlanSetMode(mode));
|
ASSERT_ON_ERROR(sl_WlanSetMode(mode));
|
||||||
// Stop and start again
|
// stop and start again
|
||||||
wlan_reenable(mode);
|
wlan_reenable(mode);
|
||||||
}
|
// set connection policy to Auto + SmartConfig (Device's default connection policy)
|
||||||
|
ASSERT_ON_ERROR(sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0));
|
||||||
}
|
}
|
||||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||||
// Start the servers again
|
// Start the servers again
|
||||||
@ -511,7 +504,7 @@ void wlan_update(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// call this function to disable the complete WLAN subsystem in order to save power
|
// call this function to disable the complete WLAN subsystem before a system reset
|
||||||
void wlan_stop (void) {
|
void wlan_stop (void) {
|
||||||
if (wlan_obj.mode >= 0) {
|
if (wlan_obj.mode >= 0) {
|
||||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
||||||
@ -526,25 +519,6 @@ void wlan_stop (void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cal this function to reenable the WLAN susbsystem after a previous call to wlan_sl_disable()
|
|
||||||
// WLAN will remain configured as it was before being disabled
|
|
||||||
void wlan_start (void) {
|
|
||||||
if (wlan_obj.mode < 0) {
|
|
||||||
wlan_obj.mode = sl_Start(0, 0, 0);
|
|
||||||
sl_LockObjUnlock (&wlan_LockObj);
|
|
||||||
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
|
|
||||||
// Start the servers again
|
|
||||||
if (wlan_obj.servers_enabled) {
|
|
||||||
servers_enable();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SlWlanMode_t wlan_get_mode (void) {
|
|
||||||
return wlan_obj.mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wlan_get_mac (uint8_t *macAddress) {
|
void wlan_get_mac (uint8_t *macAddress) {
|
||||||
if (macAddress) {
|
if (macAddress) {
|
||||||
memcpy (macAddress, wlan_obj.mac, SL_MAC_ADDR_LEN);
|
memcpy (macAddress, wlan_obj.mac, SL_MAC_ADDR_LEN);
|
||||||
@ -939,14 +913,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_scan_obj, wlan_scan);
|
|||||||
|
|
||||||
/// \method callback(method, intmode, value, priority, pwrmode)
|
/// \method callback(method, intmode, value, priority, pwrmode)
|
||||||
/// Creates a callback object associated with WLAN
|
/// Creates a callback object associated with WLAN
|
||||||
/// min num of arguments is 1 (intmode)
|
/// min num of arguments is 1 (pwrmode)
|
||||||
STATIC mp_obj_t wlan_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t wlan_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
mp_arg_val_t args[mpcallback_INIT_NUM_ARGS];
|
mp_arg_val_t args[mpcallback_INIT_NUM_ARGS];
|
||||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mpcallback_INIT_NUM_ARGS, mpcallback_init_args, args);
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mpcallback_INIT_NUM_ARGS, mpcallback_init_args, args);
|
||||||
|
|
||||||
wlan_obj_t *self = pos_args[0];
|
wlan_obj_t *self = pos_args[0];
|
||||||
// check if any parameters were passed
|
// check if any parameters were passed
|
||||||
if (kw_args->used > 0 || self->callback == mp_const_none) {
|
if (kw_args->used > 0) {
|
||||||
// check the power mode
|
// check the power mode
|
||||||
if (args[4].u_int != PYB_PWR_MODE_LPDS) {
|
if (args[4].u_int != PYB_PWR_MODE_LPDS) {
|
||||||
// throw an exception since WLAN only supports LPDS mode
|
// throw an exception since WLAN only supports LPDS mode
|
||||||
|
@ -55,9 +55,8 @@ extern _SlLockObj_t wlan_LockObj;
|
|||||||
extern void wlan_init0 (void);
|
extern void wlan_init0 (void);
|
||||||
extern modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ssid_len, uint8_t sec,
|
extern modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ssid_len, uint8_t sec,
|
||||||
const char *key, uint8_t key_len, uint8_t channel);
|
const char *key, uint8_t key_len, uint8_t channel);
|
||||||
|
extern void wlan_first_start (void);
|
||||||
extern void wlan_stop (void);
|
extern void wlan_stop (void);
|
||||||
extern void wlan_start (void);
|
|
||||||
extern SlWlanMode_t wlan_get_mode (void);
|
|
||||||
extern void wlan_get_mac (uint8_t *macAddress);
|
extern void wlan_get_mac (uint8_t *macAddress);
|
||||||
extern void wlan_get_ip (uint32_t *ip);
|
extern void wlan_get_ip (uint32_t *ip);
|
||||||
extern void wlan_stop_servers (void);
|
extern void wlan_stop_servers (void);
|
||||||
|
@ -35,7 +35,11 @@
|
|||||||
#include "py/gc.h"
|
#include "py/gc.h"
|
||||||
#include "inc/hw_memmap.h"
|
#include "inc/hw_memmap.h"
|
||||||
#include "inc/hw_types.h"
|
#include "inc/hw_types.h"
|
||||||
|
#include "inc/hw_ints.h"
|
||||||
|
#include "inc/hw_memmap.h"
|
||||||
|
#include "rom_map.h"
|
||||||
#include "pin.h"
|
#include "pin.h"
|
||||||
|
#include "prcm.h"
|
||||||
#include "pybuart.h"
|
#include "pybuart.h"
|
||||||
#include "pybpin.h"
|
#include "pybpin.h"
|
||||||
#include "pybrtc.h"
|
#include "pybrtc.h"
|
||||||
@ -97,15 +101,9 @@ void TASK_Micropython (void *pvParameters) {
|
|||||||
// Initialize the garbage collector with the top of our stack
|
// Initialize the garbage collector with the top of our stack
|
||||||
uint32_t sp = gc_helper_get_sp();
|
uint32_t sp = gc_helper_get_sp();
|
||||||
gc_collect_init (sp);
|
gc_collect_init (sp);
|
||||||
bool safeboot;
|
bool safeboot = false;
|
||||||
FRESULT res;
|
FRESULT res;
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
safeboot = false;
|
|
||||||
#else
|
|
||||||
safeboot = mperror_safe_boot_requested();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mptask_pre_init();
|
mptask_pre_init();
|
||||||
|
|
||||||
soft_reset:
|
soft_reset:
|
||||||
@ -146,14 +144,26 @@ soft_reset:
|
|||||||
|
|
||||||
mperror_enable_heartbeat();
|
mperror_enable_heartbeat();
|
||||||
|
|
||||||
|
if (MAP_PRCMSysResetCauseGet() != PRCM_HIB_EXIT) {
|
||||||
|
// only if not comming out of hibernate
|
||||||
mptask_enter_ap_mode();
|
mptask_enter_ap_mode();
|
||||||
|
// don't check for safeboot when comming out of hibernate
|
||||||
// enable telnet and ftp servers
|
#ifndef DEBUG
|
||||||
servers_enable();
|
safeboot = mperror_safe_boot_requested();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// when waking up from hibernate we just want
|
||||||
|
// to enable simplelink and leave it as is
|
||||||
|
wlan_first_start();
|
||||||
|
}
|
||||||
|
|
||||||
// initialize the serial flash file system
|
// initialize the serial flash file system
|
||||||
mptask_init_sflash_filesystem();
|
mptask_init_sflash_filesystem();
|
||||||
|
|
||||||
|
// enable telnet and ftp servers
|
||||||
|
servers_enable();
|
||||||
|
|
||||||
// append the SFLASH paths to the system path
|
// append the SFLASH paths to the system path
|
||||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SFLASH));
|
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SFLASH));
|
||||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SFLASH_slash_LIB));
|
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SFLASH_slash_LIB));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user