Commit 760a6eca authored by Daniel Campora's avatar Daniel Campora
Browse files

cc3200: Minor refactorings on modwlan and pybsleep.

parent 4be44014
......@@ -191,8 +191,7 @@ STATIC void wlan_lpds_callback_disable (mp_obj_t self_in);
//! \return None
//!
//*****************************************************************************
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
{
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) {
if (!pWlanEvent) {
return;
}
......@@ -249,8 +248,7 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
//! \return None
//!
//*****************************************************************************
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
{
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) {
if(!pNetAppEvent) {
return;
}
......@@ -295,8 +293,7 @@ void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
//! \return None
//!
//****************************************************************************
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent, SlHttpServerResponse_t *pHttpResponse)
{
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent, SlHttpServerResponse_t *pHttpResponse) {
if (!pHttpEvent) {
return;
}
......@@ -320,8 +317,7 @@ void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent, SlHttpServerR
//! \return None
//!
//*****************************************************************************
void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent)
{
void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent) {
if (!pDevEvent) {
return;
}
......@@ -339,8 +335,7 @@ void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent)
//! \return None
//!
//*****************************************************************************
void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
{
void SimpleLinkSockEventHandler(SlSockEvent_t *pSock) {
if (!pSock) {
return;
}
......@@ -357,11 +352,11 @@ void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
case SL_SOCKET_ASYNC_EVENT:
switch(pSock->socketAsyncEvent.SockAsyncData.type) {
case SSL_ACCEPT:
//accept failed due to ssl issue ( tcp pass)
break;
case RX_FRAGMENTATION_TOO_BIG:
break;
case OTHER_SIDE_CLOSE_SSL_DATA_NOT_ENCRYPTED:
break;
default:
break;
}
......@@ -512,19 +507,27 @@ void wlan_update(void) {
#endif
}
// call this function to disable the complete WLAN subsystem before a system reset
void wlan_stop (uint32_t timeout) {
if (wlan_obj.mode >= 0) {
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
// Stop all other processes using the wlan engine
if ((wlan_obj.servers_enabled = servers_are_enabled())) {
servers_stop();
}
// Stop all other processes using the wlan engine
if ((wlan_obj.servers_enabled = servers_are_enabled())) {
servers_stop();
}
#endif
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
wlan_obj.mode = -1;
sl_Stop(MAX(timeout, SL_STOP_TIMEOUT));
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
sl_Stop(timeout);
wlan_obj.mode = -1;
}
void wlan_start (void) {
wlan_obj.mode = sl_Start(0, 0, 0);
sl_LockObjUnlock (&wlan_LockObj);
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
// start the servers if they were enabled before
if (wlan_obj.servers_enabled) {
servers_start();
}
#endif
}
void wlan_get_mac (uint8_t *macAddress) {
......@@ -554,8 +557,7 @@ STATIC void wlan_initialize_data (void) {
}
STATIC void wlan_reenable (SlWlanMode_t mode) {
// Stop and start again
wlan_obj.mode = -1;
// stop and start again
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
sl_Stop(SL_STOP_TIMEOUT);
wlan_obj.mode = sl_Start(0, 0, 0);
......@@ -566,13 +568,11 @@ STATIC void wlan_reenable (SlWlanMode_t mode) {
STATIC modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, const char* bssid, uint8_t sec,
const char* key, uint32_t key_len) {
SlSecParams_t secParams;
secParams.Key = (_i8*)key;
secParams.KeyLen = ((key != NULL) ? key_len : 0);
secParams.Type = sec;
if (0 == sl_WlanConnect((_i8*)ssid, ssid_len, (_u8*)bssid, &secParams, NULL)) {
// Wait for the WLAN Event
uint32_t waitForConnectionMs = 0;
while (!IS_CONNECTED(wlan_obj.status)) {
......@@ -584,10 +584,8 @@ STATIC modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, co
return MODWLAN_ERROR_TIMEOUT;
}
}
return MODWLAN_OK;
}
return MODWLAN_ERROR_INVALID_PARAMS;
}
......@@ -782,8 +780,7 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_connect_obj, 1, wlan_connect);
/// \method wlan_disconnect()
/// Closes the current WLAN connection
///
/// Close the current WLAN connection
STATIC mp_obj_t wlan_disconnect(mp_obj_t self_in) {
sl_WlanDisconnect();
return mp_const_none;
......@@ -791,8 +788,7 @@ STATIC mp_obj_t wlan_disconnect(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_disconnect_obj, wlan_disconnect);
/// \method is_connected()
/// Returns true if connected to the AP and an IP address has been assigned. False otherwise.
///
/// Return true if connected to the AP and an IP address has been assigned. False otherwise.
STATIC mp_obj_t wlan_isconnected(mp_obj_t self_in) {
if (GET_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION) &&
GET_STATUS_BIT(wlan_obj.status, STATUS_BIT_IP_ACQUIRED)) {
......@@ -803,7 +799,6 @@ STATIC mp_obj_t wlan_isconnected(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_isconnected_obj, wlan_isconnected);
STATIC mp_obj_t wlan_ifconfig (mp_obj_t self_in) {
unsigned char len = sizeof(SlNetCfgIpV4Args_t);
unsigned char dhcpIsOn;
SlNetCfgIpV4Args_t ipV4;
......@@ -870,7 +865,7 @@ STATIC mp_obj_t wlan_urn (uint n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_urn_obj, 1, 2, wlan_urn);
/// \method wlan_netlist()
/// Returns a list of tuples with all the acces points within range
/// Return a list of tuples with all the acces points within range
STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
Sl_WlanNetworkEntry_t wlanEntry;
uint8_t _index = 0;
......@@ -912,7 +907,7 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_scan_obj, wlan_scan);
/// \method callback(handler, pwrmode)
/// Creates a callback object associated with WLAN
/// Create a callback object associated with WLAN
/// 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) {
mp_arg_val_t args[mpcallback_INIT_NUM_ARGS];
......
......@@ -58,6 +58,7 @@ extern modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uin
const char *key, uint8_t key_len, uint8_t channel);
extern void wlan_first_start (void);
extern void wlan_stop (uint32_t timeout);
extern void wlan_start (void);
extern void wlan_get_mac (uint8_t *macAddress);
extern void wlan_get_ip (uint32_t *ip);
......
......@@ -114,14 +114,14 @@ typedef struct {
mp_obj_t timer_lpds_wake_cb;
mp_obj_t gpio_lpds_wake_cb;
uint timer_wake_pwrmode;
} pybsleep_wake_cb_t;
} pybsleep_data_t;
/******************************************************************************
DECLARE PRIVATE DATA
******************************************************************************/
STATIC const mp_obj_type_t pybsleep_type;
STATIC nvic_reg_store_t *nvic_reg_store;
STATIC pybsleep_wake_cb_t pybsleep_wake_cb = {NULL, NULL, NULL, 0};
STATIC pybsleep_data_t pybsleep_data = {NULL, NULL, NULL, 0};
volatile arm_cm4_core_regs_t vault_arm_registers;
STATIC pybsleep_reset_cause_t pybsleep_reset_cause = PYB_SLP_PWRON_RESET;
......@@ -211,19 +211,19 @@ void pybsleep_remove (const mp_obj_t obj) {
}
void pybsleep_set_wlan_lpds_callback (mp_obj_t cb_obj) {
pybsleep_wake_cb.wlan_lpds_wake_cb = cb_obj;
pybsleep_data.wlan_lpds_wake_cb = cb_obj;
}
void pybsleep_set_gpio_lpds_callback (mp_obj_t cb_obj) {
pybsleep_wake_cb.gpio_lpds_wake_cb = cb_obj;
pybsleep_data.gpio_lpds_wake_cb = cb_obj;
}
void pybsleep_set_timer_lpds_callback (mp_obj_t cb_obj) {
pybsleep_wake_cb.timer_lpds_wake_cb = cb_obj;
pybsleep_data.timer_lpds_wake_cb = cb_obj;
}
void pybsleep_configure_timer_wakeup (uint pwrmode) {
pybsleep_wake_cb.timer_wake_pwrmode = pwrmode;
pybsleep_data.timer_wake_pwrmode = pwrmode;
}
pybsleep_reset_cause_t pybsleep_get_reset_cause (void) {
......@@ -404,22 +404,22 @@ STATIC void PRCMInterruptHandler (void) {
// reading the interrupt status automatically clears the interrupt
if (PRCM_INT_SLOW_CLK_CTR == MAP_PRCMIntStatus()) {
// this interrupt is triggered during active mode
mpcallback_handler(pybsleep_wake_cb.timer_lpds_wake_cb);
mpcallback_handler(pybsleep_data.timer_lpds_wake_cb);
}
else {
// interrupt has been triggered while waking up from LPDS
switch (MAP_PRCMLPDSWakeupCauseGet()) {
case PRCM_LPDS_HOST_IRQ:
mpcallback_handler(pybsleep_wake_cb.wlan_lpds_wake_cb);
mpcallback_handler(pybsleep_data.wlan_lpds_wake_cb);
break;
case PRCM_LPDS_GPIO:
mpcallback_handler(pybsleep_wake_cb.gpio_lpds_wake_cb);
mpcallback_handler(pybsleep_data.gpio_lpds_wake_cb);
break;
case PRCM_LPDS_TIMER:
// disable the timer as a wake-up source
pybsleep_wake_cb.timer_wake_pwrmode &= ~PYB_PWR_MODE_LPDS;
pybsleep_data.timer_wake_pwrmode &= ~PYB_PWR_MODE_LPDS;
MAP_PRCMLPDSWakeupSourceDisable(PRCM_LPDS_TIMER);
mpcallback_handler(pybsleep_wake_cb.timer_lpds_wake_cb);
mpcallback_handler(pybsleep_data.timer_lpds_wake_cb);
break;
default:
break;
......@@ -567,24 +567,24 @@ STATIC mp_obj_t pyb_sleep_suspend (mp_obj_t self_in) {
nlr_buf_t nlr;
// check if we should enable timer wake-up
if (pybsleep_wake_cb.timer_wake_pwrmode & PYB_PWR_MODE_LPDS) {
if (pybsleep_data.timer_wake_pwrmode & PYB_PWR_MODE_LPDS) {
if (!setup_timer_lpds_wake()) {
// lpds entering is not possible, wait for the forced interrupt and return
pybsleep_wake_cb.timer_wake_pwrmode &= ~PYB_PWR_MODE_LPDS;
pybsleep_data.timer_wake_pwrmode &= ~PYB_PWR_MODE_LPDS;
HAL_Delay (FAILED_SLEEP_DELAY_MS);
return mp_const_none;
}
}
// check if we need to enable network wake-up
if (pybsleep_wake_cb.wlan_lpds_wake_cb) {
// do we need network wake-up?
if (pybsleep_data.wlan_lpds_wake_cb) {
MAP_PRCMLPDSWakeupSourceEnable (PRCM_LPDS_HOST_IRQ);
}
else {
MAP_PRCMLPDSWakeupSourceDisable (PRCM_LPDS_HOST_IRQ);
}
// entering and exiting suspend mode must be an atomic operation
// entering and exiting suspended mode must be an atomic operation
// therefore interrupts need to be disabled
uint primsk = disable_irq();
if (nlr_push(&nlr) == 0) {
......@@ -604,10 +604,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sleep_suspend_obj, pyb_sleep_suspend);
/// calling this method.
STATIC mp_obj_t pyb_sleep_hibernate (mp_obj_t self_in) {
// check if we should enable timer wake-up
if (pybsleep_wake_cb.timer_wake_pwrmode & PYB_PWR_MODE_HIBERNATE) {
if (pybsleep_data.timer_wake_pwrmode & PYB_PWR_MODE_HIBERNATE) {
if (!setup_timer_hibernate_wake()) {
// hibernating is not possible, wait for the forced interrupt and return
pybsleep_wake_cb.timer_wake_pwrmode &= ~PYB_PWR_MODE_HIBERNATE;
pybsleep_data.timer_wake_pwrmode &= ~PYB_PWR_MODE_HIBERNATE;
HAL_Delay (FAILED_SLEEP_DELAY_MS);
return mp_const_none;
}
......
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