Skip to content

Commit 70b3160

Browse files
committed
cc3200: Introduce MICROPY_PORT_HAS_TELNET and MICROPY_PORT_HAS_FTP.
These definitions help on making modwlan.c usable by other ports with the CC3100.
1 parent 379a3fa commit 70b3160

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

cc3200/mods/modpyb.c

+2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ extern OsiTaskHandle xSimpleLinkSpawnTaskHndl;
7676
/// Resets the pyboard in a manner similar to pushing the external RESET
7777
/// button.
7878
STATIC mp_obj_t pyb_hard_reset(void) {
79+
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
7980
// disable wlan services
8081
wlan_stop_servers();
82+
#endif
8183
wlan_stop();
8284
// perform a SoC reset
8385
PRCMSOCReset();

cc3200/mods/modwlan.c

+39-15
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
#include "modnetwork.h"
3737
#include "modwlan.h"
3838
#include "pybioctl.h"
39-
#include "pybuart.h"
4039
#include "debug.h"
40+
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
4141
#include "serverstask.h"
42+
#endif
4243
#include "mpexception.h"
4344

4445

@@ -78,16 +79,19 @@ typedef struct _wlan_obj_t {
7879
mp_obj_base_t base;
7980
SlWlanMode_t mode;
8081
uint32_t status;
81-
uint8_t security;
82-
uint8_t mac[SL_MAC_ADDR_LEN];
83-
uint8_t ssid[33];
84-
uint8_t bssid[6];
8582

86-
// IPVv4 data
8783
uint32_t ip;
8884
uint32_t gateway;
8985
uint32_t dns;
9086

87+
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
88+
bool servers_enabled;
89+
#endif
90+
uint8_t security;
91+
uint8_t mac[SL_MAC_ADDR_LEN];
92+
uint8_t ssid[33];
93+
uint8_t bssid[6];
94+
9195
} wlan_obj_t;
9296

9397
/******************************************************************************
@@ -140,12 +144,12 @@ typedef struct _wlan_obj_t {
140144
ip[3] = addr.sa_data[5];
141145

142146
/******************************************************************************
143-
DECLARE PUBLIC DATA
147+
DECLARE PRIVATE DATA
144148
******************************************************************************/
145149
STATIC wlan_obj_t wlan_obj;
146150

147151
/******************************************************************************
148-
DECLARE EXPORTED DATA
152+
DECLARE PUBLIC DATA
149153
******************************************************************************/
150154
OsiLockObj_t wlan_LockObj;
151155

@@ -203,10 +207,10 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
203207
// If the user has initiated the 'Disconnect' request,
204208
//'reason_code' is SL_USER_INITIATED_DISCONNECTION
205209
if (SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code) {
206-
210+
// TODO ...
207211
}
208212
else {
209-
213+
// TODO: Maybe trow an exception?
210214
}
211215
memset(wlan_obj.ssid, 0, sizeof(wlan_obj.ssid));
212216
memset(wlan_obj.bssid, 0, sizeof(wlan_obj.bssid));
@@ -496,6 +500,12 @@ void wlan_update(void) {
496500
// call this function to disable the complete WLAN subsystem in order to save power
497501
void wlan_stop (void) {
498502
if (wlan_obj.mode >= 0) {
503+
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
504+
// Stop all other processes using the wlan engine
505+
if ((wlan_obj.servers_enabled = servers_are_enabled())) {
506+
wlan_stop_servers();
507+
}
508+
#endif
499509
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
500510
wlan_obj.mode = -1;
501511
sl_Stop(SL_STOP_TIMEOUT);
@@ -508,6 +518,12 @@ void wlan_start (void) {
508518
if (wlan_obj.mode < 0) {
509519
wlan_obj.mode = sl_Start(0, 0, 0);
510520
sl_LockObjUnlock (&wlan_LockObj);
521+
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
522+
// Start the servers again
523+
if (wlan_obj.servers_enabled) {
524+
servers_enable();
525+
}
526+
#endif
511527
}
512528
}
513529

@@ -532,10 +548,12 @@ void wlan_set_pm_policy (uint8_t policy) {
532548
}
533549

534550
void wlan_stop_servers (void) {
551+
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
535552
servers_disable();
536553
do {
537554
HAL_Delay (5);
538555
} while (servers_are_enabled());
556+
#endif
539557
}
540558

541559
//*****************************************************************************
@@ -657,11 +675,12 @@ STATIC mp_obj_t wlan_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
657675
// Get the mode
658676
SlWlanMode_t mode = mp_obj_get_int(args[0]);
659677

678+
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
660679
// Stop all other processes using the wlan engine
661-
bool servers_enabled;
662-
if ( (servers_enabled = servers_are_enabled()) ) {
680+
if ((wlan_obj.servers_enabled = servers_are_enabled())) {
663681
wlan_stop_servers();
664682
}
683+
#endif
665684
if (mode == ROLE_AP) {
666685
// start the peripheral
667686
mp_map_t kw_args;
@@ -677,11 +696,12 @@ STATIC mp_obj_t wlan_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
677696
else {
678697
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, mpexception_num_type_invalid_arguments));
679698
}
680-
699+
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
681700
// Start the servers again
682-
if (servers_enabled) {
683-
servers_enable ();
701+
if (wlan_obj.servers_enabled) {
702+
servers_enable();
684703
}
704+
#endif
685705
} else if (wlan_obj.mode < 0) {
686706
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, mpexception_num_type_invalid_arguments));
687707
}
@@ -928,6 +948,7 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
928948
}
929949
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_scan_obj, wlan_scan);
930950

951+
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
931952
STATIC mp_obj_t wlan_serversstart(mp_obj_t self_in) {
932953
servers_enable();
933954
return mp_const_none;
@@ -952,6 +973,7 @@ STATIC mp_obj_t wlan_serversuserpass(mp_obj_t self_in, mp_obj_t user, mp_obj_t p
952973
return mp_const_none;
953974
}
954975
STATIC MP_DEFINE_CONST_FUN_OBJ_3(wlan_serversuserpass_obj, wlan_serversuserpass);
976+
#endif
955977

956978
STATIC const mp_map_elem_t wlan_locals_dict_table[] = {
957979
{ MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&wlan_connect_obj },
@@ -962,10 +984,12 @@ STATIC const mp_map_elem_t wlan_locals_dict_table[] = {
962984
{ MP_OBJ_NEW_QSTR(MP_QSTR_isconnected), (mp_obj_t)&wlan_isconnected_obj },
963985
{ MP_OBJ_NEW_QSTR(MP_QSTR_ifconfig), (mp_obj_t)&wlan_ifconfig_obj },
964986
{ MP_OBJ_NEW_QSTR(MP_QSTR_urn), (mp_obj_t)&wlan_urn_obj },
987+
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
965988
{ MP_OBJ_NEW_QSTR(MP_QSTR_start_servers), (mp_obj_t)&wlan_serversstart_obj },
966989
{ MP_OBJ_NEW_QSTR(MP_QSTR_stop_servers), (mp_obj_t)&wlan_serversstop_obj },
967990
{ MP_OBJ_NEW_QSTR(MP_QSTR_servers_enabled), (mp_obj_t)&wlan_serversenabled_obj },
968991
{ MP_OBJ_NEW_QSTR(MP_QSTR_servers_userpass), (mp_obj_t)&wlan_serversuserpass_obj },
992+
#endif
969993

970994
// class constants
971995
{ MP_OBJ_NEW_QSTR(MP_QSTR_OPEN), MP_OBJ_NEW_SMALL_INT(SL_SEC_TYPE_OPEN) },

cc3200/mods/modwlan.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef SIMPLELINKTASK_H_
28-
#define SIMPLELINKTASK_H_
27+
#ifndef MODWLAN_H_
28+
#define MODWLAN_H_
2929

3030
/******************************************************************************
3131
DEFINE CONSTANTS
@@ -63,4 +63,4 @@ extern void wlan_get_ip (uint32_t *ip);
6363
extern void wlan_set_pm_policy (uint8_t policy);
6464
extern void wlan_stop_servers (void);
6565

66-
#endif /* SIMPLELINKTASK_H_ */
66+
#endif /* MODWLAN_H_ */

cc3200/mpconfigport.h

+2
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,7 @@ typedef long mp_off_t;
161161

162162
#define MICROPY_HAL_H "cc3200_hal.h"
163163
#define MICROPY_PIN_DEFS_PORT_H "pin_defs_cc3200.h"
164+
#define MICROPY_PORT_HAS_TELNET (1)
165+
#define MICROPY_PORT_HAS_FTP (1)
164166

165167
#endif // __INCLUDED_MPCONFIGPORT_H

0 commit comments

Comments
 (0)