Skip to content

Commit 760a6ec

Browse files
author
Daniel Campora
committed
cc3200: Minor refactorings on modwlan and pybsleep.
1 parent 4be4401 commit 760a6ec

3 files changed

Lines changed: 47 additions & 51 deletions

File tree

cc3200/mods/modwlan.c

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ STATIC void wlan_lpds_callback_disable (mp_obj_t self_in);
191191
//! \return None
192192
//!
193193
//*****************************************************************************
194-
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
195-
{
194+
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) {
196195
if (!pWlanEvent) {
197196
return;
198197
}
@@ -249,8 +248,7 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
249248
//! \return None
250249
//!
251250
//*****************************************************************************
252-
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
253-
{
251+
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) {
254252
if(!pNetAppEvent) {
255253
return;
256254
}
@@ -295,8 +293,7 @@ void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
295293
//! \return None
296294
//!
297295
//****************************************************************************
298-
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent, SlHttpServerResponse_t *pHttpResponse)
299-
{
296+
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent, SlHttpServerResponse_t *pHttpResponse) {
300297
if (!pHttpEvent) {
301298
return;
302299
}
@@ -320,8 +317,7 @@ void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent, SlHttpServerR
320317
//! \return None
321318
//!
322319
//*****************************************************************************
323-
void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent)
324-
{
320+
void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent) {
325321
if (!pDevEvent) {
326322
return;
327323
}
@@ -339,8 +335,7 @@ void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent)
339335
//! \return None
340336
//!
341337
//*****************************************************************************
342-
void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
343-
{
338+
void SimpleLinkSockEventHandler(SlSockEvent_t *pSock) {
344339
if (!pSock) {
345340
return;
346341
}
@@ -357,11 +352,11 @@ void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
357352
case SL_SOCKET_ASYNC_EVENT:
358353
switch(pSock->socketAsyncEvent.SockAsyncData.type) {
359354
case SSL_ACCEPT:
360-
//accept failed due to ssl issue ( tcp pass)
361355
break;
362356
case RX_FRAGMENTATION_TOO_BIG:
363357
break;
364358
case OTHER_SIDE_CLOSE_SSL_DATA_NOT_ENCRYPTED:
359+
break;
365360
default:
366361
break;
367362
}
@@ -512,19 +507,27 @@ void wlan_update(void) {
512507
#endif
513508
}
514509

515-
// call this function to disable the complete WLAN subsystem before a system reset
516510
void wlan_stop (uint32_t timeout) {
517-
if (wlan_obj.mode >= 0) {
518511
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
519-
// Stop all other processes using the wlan engine
520-
if ((wlan_obj.servers_enabled = servers_are_enabled())) {
521-
servers_stop();
522-
}
512+
// Stop all other processes using the wlan engine
513+
if ((wlan_obj.servers_enabled = servers_are_enabled())) {
514+
servers_stop();
515+
}
523516
#endif
524-
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
525-
wlan_obj.mode = -1;
526-
sl_Stop(MAX(timeout, SL_STOP_TIMEOUT));
517+
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
518+
sl_Stop(timeout);
519+
wlan_obj.mode = -1;
520+
}
521+
522+
void wlan_start (void) {
523+
wlan_obj.mode = sl_Start(0, 0, 0);
524+
sl_LockObjUnlock (&wlan_LockObj);
525+
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
526+
// start the servers if they were enabled before
527+
if (wlan_obj.servers_enabled) {
528+
servers_start();
527529
}
530+
#endif
528531
}
529532

530533
void wlan_get_mac (uint8_t *macAddress) {
@@ -554,8 +557,7 @@ STATIC void wlan_initialize_data (void) {
554557
}
555558

556559
STATIC void wlan_reenable (SlWlanMode_t mode) {
557-
// Stop and start again
558-
wlan_obj.mode = -1;
560+
// stop and start again
559561
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
560562
sl_Stop(SL_STOP_TIMEOUT);
561563
wlan_obj.mode = sl_Start(0, 0, 0);
@@ -566,13 +568,11 @@ STATIC void wlan_reenable (SlWlanMode_t mode) {
566568
STATIC modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, const char* bssid, uint8_t sec,
567569
const char* key, uint32_t key_len) {
568570
SlSecParams_t secParams;
569-
570571
secParams.Key = (_i8*)key;
571572
secParams.KeyLen = ((key != NULL) ? key_len : 0);
572573
secParams.Type = sec;
573574

574575
if (0 == sl_WlanConnect((_i8*)ssid, ssid_len, (_u8*)bssid, &secParams, NULL)) {
575-
576576
// Wait for the WLAN Event
577577
uint32_t waitForConnectionMs = 0;
578578
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
584584
return MODWLAN_ERROR_TIMEOUT;
585585
}
586586
}
587-
588587
return MODWLAN_OK;
589588
}
590-
591589
return MODWLAN_ERROR_INVALID_PARAMS;
592590
}
593591

@@ -782,17 +780,15 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
782780
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_connect_obj, 1, wlan_connect);
783781

784782
/// \method wlan_disconnect()
785-
/// Closes the current WLAN connection
786-
///
783+
/// Close the current WLAN connection
787784
STATIC mp_obj_t wlan_disconnect(mp_obj_t self_in) {
788785
sl_WlanDisconnect();
789786
return mp_const_none;
790787
}
791788
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_disconnect_obj, wlan_disconnect);
792789

793790
/// \method is_connected()
794-
/// Returns true if connected to the AP and an IP address has been assigned. False otherwise.
795-
///
791+
/// Return true if connected to the AP and an IP address has been assigned. False otherwise.
796792
STATIC mp_obj_t wlan_isconnected(mp_obj_t self_in) {
797793
if (GET_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION) &&
798794
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) {
803799
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_isconnected_obj, wlan_isconnected);
804800

805801
STATIC mp_obj_t wlan_ifconfig (mp_obj_t self_in) {
806-
807802
unsigned char len = sizeof(SlNetCfgIpV4Args_t);
808803
unsigned char dhcpIsOn;
809804
SlNetCfgIpV4Args_t ipV4;
@@ -870,7 +865,7 @@ STATIC mp_obj_t wlan_urn (uint n_args, const mp_obj_t *args) {
870865
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_urn_obj, 1, 2, wlan_urn);
871866

872867
/// \method wlan_netlist()
873-
/// Returns a list of tuples with all the acces points within range
868+
/// Return a list of tuples with all the acces points within range
874869
STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
875870
Sl_WlanNetworkEntry_t wlanEntry;
876871
uint8_t _index = 0;
@@ -912,7 +907,7 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
912907
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_scan_obj, wlan_scan);
913908

914909
/// \method callback(handler, pwrmode)
915-
/// Creates a callback object associated with WLAN
910+
/// Create a callback object associated with WLAN
916911
/// min num of arguments is 1 (pwrmode)
917912
STATIC mp_obj_t wlan_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
918913
mp_arg_val_t args[mpcallback_INIT_NUM_ARGS];

cc3200/mods/modwlan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ extern modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uin
5858
const char *key, uint8_t key_len, uint8_t channel);
5959
extern void wlan_first_start (void);
6060
extern void wlan_stop (uint32_t timeout);
61+
extern void wlan_start (void);
6162
extern void wlan_get_mac (uint8_t *macAddress);
6263
extern void wlan_get_ip (uint32_t *ip);
6364

cc3200/mods/pybsleep.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ typedef struct {
114114
mp_obj_t timer_lpds_wake_cb;
115115
mp_obj_t gpio_lpds_wake_cb;
116116
uint timer_wake_pwrmode;
117-
} pybsleep_wake_cb_t;
117+
} pybsleep_data_t;
118118

119119
/******************************************************************************
120120
DECLARE PRIVATE DATA
121121
******************************************************************************/
122122
STATIC const mp_obj_type_t pybsleep_type;
123123
STATIC nvic_reg_store_t *nvic_reg_store;
124-
STATIC pybsleep_wake_cb_t pybsleep_wake_cb = {NULL, NULL, NULL, 0};
124+
STATIC pybsleep_data_t pybsleep_data = {NULL, NULL, NULL, 0};
125125
volatile arm_cm4_core_regs_t vault_arm_registers;
126126
STATIC pybsleep_reset_cause_t pybsleep_reset_cause = PYB_SLP_PWRON_RESET;
127127

@@ -211,19 +211,19 @@ void pybsleep_remove (const mp_obj_t obj) {
211211
}
212212

213213
void pybsleep_set_wlan_lpds_callback (mp_obj_t cb_obj) {
214-
pybsleep_wake_cb.wlan_lpds_wake_cb = cb_obj;
214+
pybsleep_data.wlan_lpds_wake_cb = cb_obj;
215215
}
216216

217217
void pybsleep_set_gpio_lpds_callback (mp_obj_t cb_obj) {
218-
pybsleep_wake_cb.gpio_lpds_wake_cb = cb_obj;
218+
pybsleep_data.gpio_lpds_wake_cb = cb_obj;
219219
}
220220

221221
void pybsleep_set_timer_lpds_callback (mp_obj_t cb_obj) {
222-
pybsleep_wake_cb.timer_lpds_wake_cb = cb_obj;
222+
pybsleep_data.timer_lpds_wake_cb = cb_obj;
223223
}
224224

225225
void pybsleep_configure_timer_wakeup (uint pwrmode) {
226-
pybsleep_wake_cb.timer_wake_pwrmode = pwrmode;
226+
pybsleep_data.timer_wake_pwrmode = pwrmode;
227227
}
228228

229229
pybsleep_reset_cause_t pybsleep_get_reset_cause (void) {
@@ -404,22 +404,22 @@ STATIC void PRCMInterruptHandler (void) {
404404
// reading the interrupt status automatically clears the interrupt
405405
if (PRCM_INT_SLOW_CLK_CTR == MAP_PRCMIntStatus()) {
406406
// this interrupt is triggered during active mode
407-
mpcallback_handler(pybsleep_wake_cb.timer_lpds_wake_cb);
407+
mpcallback_handler(pybsleep_data.timer_lpds_wake_cb);
408408
}
409409
else {
410410
// interrupt has been triggered while waking up from LPDS
411411
switch (MAP_PRCMLPDSWakeupCauseGet()) {
412412
case PRCM_LPDS_HOST_IRQ:
413-
mpcallback_handler(pybsleep_wake_cb.wlan_lpds_wake_cb);
413+
mpcallback_handler(pybsleep_data.wlan_lpds_wake_cb);
414414
break;
415415
case PRCM_LPDS_GPIO:
416-
mpcallback_handler(pybsleep_wake_cb.gpio_lpds_wake_cb);
416+
mpcallback_handler(pybsleep_data.gpio_lpds_wake_cb);
417417
break;
418418
case PRCM_LPDS_TIMER:
419419
// disable the timer as a wake-up source
420-
pybsleep_wake_cb.timer_wake_pwrmode &= ~PYB_PWR_MODE_LPDS;
420+
pybsleep_data.timer_wake_pwrmode &= ~PYB_PWR_MODE_LPDS;
421421
MAP_PRCMLPDSWakeupSourceDisable(PRCM_LPDS_TIMER);
422-
mpcallback_handler(pybsleep_wake_cb.timer_lpds_wake_cb);
422+
mpcallback_handler(pybsleep_data.timer_lpds_wake_cb);
423423
break;
424424
default:
425425
break;
@@ -567,24 +567,24 @@ STATIC mp_obj_t pyb_sleep_suspend (mp_obj_t self_in) {
567567
nlr_buf_t nlr;
568568

569569
// check if we should enable timer wake-up
570-
if (pybsleep_wake_cb.timer_wake_pwrmode & PYB_PWR_MODE_LPDS) {
570+
if (pybsleep_data.timer_wake_pwrmode & PYB_PWR_MODE_LPDS) {
571571
if (!setup_timer_lpds_wake()) {
572572
// lpds entering is not possible, wait for the forced interrupt and return
573-
pybsleep_wake_cb.timer_wake_pwrmode &= ~PYB_PWR_MODE_LPDS;
573+
pybsleep_data.timer_wake_pwrmode &= ~PYB_PWR_MODE_LPDS;
574574
HAL_Delay (FAILED_SLEEP_DELAY_MS);
575575
return mp_const_none;
576576
}
577577
}
578578

579-
// check if we need to enable network wake-up
580-
if (pybsleep_wake_cb.wlan_lpds_wake_cb) {
579+
// do we need network wake-up?
580+
if (pybsleep_data.wlan_lpds_wake_cb) {
581581
MAP_PRCMLPDSWakeupSourceEnable (PRCM_LPDS_HOST_IRQ);
582582
}
583583
else {
584584
MAP_PRCMLPDSWakeupSourceDisable (PRCM_LPDS_HOST_IRQ);
585585
}
586586

587-
// entering and exiting suspend mode must be an atomic operation
587+
// entering and exiting suspended mode must be an atomic operation
588588
// therefore interrupts need to be disabled
589589
uint primsk = disable_irq();
590590
if (nlr_push(&nlr) == 0) {
@@ -604,10 +604,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sleep_suspend_obj, pyb_sleep_suspend);
604604
/// calling this method.
605605
STATIC mp_obj_t pyb_sleep_hibernate (mp_obj_t self_in) {
606606
// check if we should enable timer wake-up
607-
if (pybsleep_wake_cb.timer_wake_pwrmode & PYB_PWR_MODE_HIBERNATE) {
607+
if (pybsleep_data.timer_wake_pwrmode & PYB_PWR_MODE_HIBERNATE) {
608608
if (!setup_timer_hibernate_wake()) {
609609
// hibernating is not possible, wait for the forced interrupt and return
610-
pybsleep_wake_cb.timer_wake_pwrmode &= ~PYB_PWR_MODE_HIBERNATE;
610+
pybsleep_data.timer_wake_pwrmode &= ~PYB_PWR_MODE_HIBERNATE;
611611
HAL_Delay (FAILED_SLEEP_DELAY_MS);
612612
return mp_const_none;
613613
}

0 commit comments

Comments
 (0)