diff options
| author | Daniel Campora | 2015-05-17 14:04:03 +0200 |
|---|---|---|
| committer | Daniel Campora | 2015-05-17 14:05:44 +0200 |
| commit | a379b6ed111a7e9a6e20e9701f8681b497987615 (patch) | |
| tree | 8bd440878a54364645db702a3ebc045d35dbb3bd | |
| parent | fb9e4cf4634ce62479e5d40659a19ba84a59bbb4 (diff) | |
cc3200: Add optional timeout param to WLAN.connect().
| -rw-r--r-- | cc3200/mods/modwlan.c | 13 | ||||
| -rw-r--r-- | cc3200/mods/pybpin.c | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index c00145ec3..aedd4e2a9 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -187,7 +187,7 @@ STATIC void wlan_servers_start (void); STATIC void wlan_servers_stop (void); STATIC void wlan_get_sl_mac (void); 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); + const char* key, uint32_t key_len, uint32_t timeout); STATIC void wlan_lpds_callback_enable (mp_obj_t self_in); STATIC void wlan_lpds_callback_disable (mp_obj_t self_in); STATIC bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid); @@ -579,7 +579,7 @@ STATIC void wlan_servers_stop (void) { } 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) { + const char* key, uint32_t key_len, uint32_t timeout) { SlSecParams_t secParams; secParams.Key = (_i8*)key; secParams.KeyLen = ((key != NULL) ? key_len : 0); @@ -591,7 +591,7 @@ STATIC modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, co while (!IS_CONNECTED(wlan_obj.status)) { HAL_Delay (5); wlan_update(); - if (++waitForConnectionMs >= MODWLAN_TIMEOUT_MS) { + if (++waitForConnectionMs >= timeout) { return MODWLAN_ERROR_TIMEOUT; } } @@ -735,6 +735,7 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ { MP_QSTR_security, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = SL_SEC_TYPE_OPEN} }, { MP_QSTR_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_bssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = MODWLAN_TIMEOUT_MS} }, }; // check for correct wlan mode @@ -775,6 +776,9 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ bssid = mp_obj_str_get_str(args[3].u_obj); } + // get the timeout + uint32_t timeout = MAX(args[4].u_int, 0); + if (GET_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION)) { if (0 == sl_WlanDisconnect()) { while (IS_CONNECTED(wlan_obj.status)) { @@ -786,8 +790,7 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ // connect to the requested access point modwlan_Status_t status; - status = wlan_do_connect (ssid, ssid_len, bssid, sec, key, key_len); - // TODO: make the timeout a parameter so that is configurable + status = wlan_do_connect (ssid, ssid_len, bssid, sec, key, key_len, timeout); if (status == MODWLAN_ERROR_TIMEOUT) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_operation_failed)); } diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c index 76545525d..521579d00 100644 --- a/cc3200/mods/pybpin.c +++ b/cc3200/mods/pybpin.c @@ -755,7 +755,7 @@ STATIC void EXTI_Handler(uint port) { MAP_GPIOIntClear(port, bits); // might be that we have more than one Pin interrupt triggered at the same time - // therefore we must loop through all the 8 possible bits + // therefore we must loop through all of the 8 possible bits for (int i = 0; i < 8; i++) { uint32_t bit = (1 << i); if (bit & bits) { |
