cc3200: New WLAN API including test.

This commit is contained in:
Daniel Campora 2015-09-26 22:55:24 +02:00
parent dbdcb58d64
commit 57fa14b5be
14 changed files with 814 additions and 468 deletions

View File

@ -130,7 +130,7 @@ socket_error:
arg_error:
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 1, mod_ssl_wrap_socket);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 0, mod_ssl_wrap_socket);
STATIC const mp_map_elem_t mp_module_ussl_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_ussl) },

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,8 @@
#define MODWLAN_WIFI_EVENT_ANY 0x01
#define MODWLAN_SSID_LEN_MAX 32
/******************************************************************************
DEFINE TYPES
******************************************************************************/
@ -55,12 +57,12 @@ typedef struct _wlan_obj_t {
uint32_t ip;
int8_t mode;
uint8_t security;
uint8_t auth;
uint8_t channel;
uint8_t antenna;
// my own ssid, key and mac
uint8_t ssid[33];
uint8_t ssid[(MODWLAN_SSID_LEN_MAX + 1)];
uint8_t key[65];
uint8_t mac[SL_MAC_ADDR_LEN];
@ -84,12 +86,11 @@ extern _SlLockObj_t wlan_LockObj;
DECLARE PUBLIC FUNCTIONS
******************************************************************************/
extern void wlan_pre_init (void);
extern void wlan_sl_enable (int8_t mode, const char *ssid, uint8_t ssid_len, uint8_t sec,
const char *key, uint8_t key_len, uint8_t channel, bool append_mac);
extern void wlan_sl_init (int8_t mode, const char *ssid, uint8_t ssid_len, uint8_t auth, const char *key, uint8_t key_len,
uint8_t channel, uint8_t antenna, bool add_mac);
extern void wlan_first_start (void);
extern void wlan_update(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);
extern bool wlan_is_connected (void);

View File

@ -414,7 +414,7 @@ STATIC mp_obj_t pyb_i2c_readfrom_into(mp_uint_t n_args, const mp_obj_t *pos_args
// return the number of bytes received
return mp_obj_new_int(vstr.len);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_into_obj, 3, pyb_i2c_readfrom_into);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_into_obj, 1, pyb_i2c_readfrom_into);
STATIC mp_obj_t pyb_i2c_writeto(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC const mp_arg_t pyb_i2c_writeto_args[] = {
@ -442,7 +442,7 @@ STATIC mp_obj_t pyb_i2c_writeto(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
// return the number of bytes written
return mp_obj_new_int(bufinfo.len);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_obj, 3, pyb_i2c_writeto);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_obj, 1, pyb_i2c_writeto);
STATIC mp_obj_t pyb_i2c_readfrom_mem(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC const mp_arg_t pyb_i2c_readfrom_mem_args[] = {
@ -460,7 +460,7 @@ STATIC mp_obj_t pyb_i2c_readfrom_mem(mp_uint_t n_args, const mp_obj_t *pos_args,
pyb_i2c_readmem_into (args, &vstr);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_obj, 4, pyb_i2c_readfrom_mem);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_obj, 1, pyb_i2c_readfrom_mem);
STATIC const mp_arg_t pyb_i2c_readfrom_mem_into_args[] = {
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, },
@ -479,7 +479,7 @@ STATIC mp_obj_t pyb_i2c_readfrom_mem_into(mp_uint_t n_args, const mp_obj_t *pos_
pyb_i2c_readmem_into (args, &vstr);
return mp_obj_new_int(vstr.len);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_into_obj, 4, pyb_i2c_readfrom_mem_into);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_into_obj, 1, pyb_i2c_readfrom_mem_into);
STATIC mp_obj_t pyb_i2c_writeto_mem(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// parse args
@ -507,7 +507,7 @@ STATIC mp_obj_t pyb_i2c_writeto_mem(mp_uint_t n_args, const mp_obj_t *pos_args,
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_operation_failed));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_mem_obj, 4, pyb_i2c_writeto_mem);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_mem_obj, 1, pyb_i2c_writeto_mem);
STATIC const mp_map_elem_t pyb_i2c_locals_dict_table[] = {
// instance methods

View File

@ -164,7 +164,7 @@ void pybsleep_init0 (void) {
MAP_PRCMHibernateWakeupSourceDisable(PRCM_HIB_SLOW_CLK_CTR | PRCM_HIB_GPIO2 | PRCM_HIB_GPIO4 | PRCM_HIB_GPIO13 |
PRCM_HIB_GPIO17 | PRCM_HIB_GPIO11 | PRCM_HIB_GPIO24 | PRCM_HIB_GPIO26);
// store the reset casue (if it's soft reset, leave it as it is)
// check the reset casue (if it's soft reset, leave it as it is)
if (pybsleep_reset_cause != PYB_SLP_SOFT_RESET) {
switch (MAP_PRCMSysResetCauseGet()) {
case PRCM_POWER_ON:
@ -188,6 +188,7 @@ void pybsleep_init0 (void) {
switch (MAP_PRCMHibernateWakeupCauseGet()) {
case PRCM_HIB_WAKEUP_CAUSE_SLOW_CLOCK:
pybsleep_wake_reason = PYB_SLP_WAKED_BY_RTC;
// TODO repeat the alarm
break;
case PRCM_HIB_WAKEUP_CAUSE_GPIO:
pybsleep_wake_reason = PYB_SLP_WAKED_BY_GPIO;

View File

@ -446,7 +446,7 @@ error:
}
STATIC const mp_arg_t pyb_uart_init_args[] = {
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 9600} },
{ MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} },
{ MP_QSTR_parity, MP_ARG_OBJ, {.u_obj = mp_const_none} },
@ -462,7 +462,7 @@ STATIC mp_obj_t pyb_uart_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t
// work out the uart id
uint uart_id;
if (args[0].u_obj == mp_const_none) {
if (args[0].u_obj == MP_OBJ_NULL) {
if (args[5].u_obj != MP_OBJ_NULL) {
mp_obj_t *pins;
mp_uint_t n_pins = 2;

View File

@ -207,7 +207,6 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
#define MICROPY_HAL_H "cc3200_hal.h"
#define MICROPY_PORT_HAS_TELNET (1)
#define MICROPY_PORT_HAS_FTP (1)
#define MICROPY_PORT_WLAN_URN (0)
#define MICROPY_PY_SYS_PLATFORM "WiPy"
#define MICROPY_PORT_WLAN_AP_SSID "wipy-wlan"

View File

@ -68,6 +68,7 @@
#include "mpirq.h"
#include "updater.h"
#include "moduos.h"
#include "antenna.h"
/******************************************************************************
DECLARE PRIVATE CONSTANTS
@ -360,11 +361,11 @@ STATIC void mptask_init_sflash_filesystem (void) {
STATIC void mptask_enter_ap_mode (void) {
// append the mac only if it's not the first boot
bool append_mac = !PRCMGetSpecialBit(PRCM_FIRST_BOOT_BIT);
bool add_mac = !PRCMGetSpecialBit(PRCM_FIRST_BOOT_BIT);
// enable simplelink in ap mode (use the MAC address to make the ssid unique)
wlan_sl_enable (ROLE_AP, MICROPY_PORT_WLAN_AP_SSID, strlen(MICROPY_PORT_WLAN_AP_SSID), MICROPY_PORT_WLAN_AP_SECURITY,
MICROPY_PORT_WLAN_AP_KEY, strlen(MICROPY_PORT_WLAN_AP_KEY), MICROPY_PORT_WLAN_AP_CHANNEL, append_mac);
wlan_sl_init (ROLE_AP, MICROPY_PORT_WLAN_AP_SSID, strlen(MICROPY_PORT_WLAN_AP_SSID),
MICROPY_PORT_WLAN_AP_SECURITY, MICROPY_PORT_WLAN_AP_KEY, strlen(MICROPY_PORT_WLAN_AP_KEY),
MICROPY_PORT_WLAN_AP_CHANNEL, ANTENNA_TYPE_INTERNAL, add_mac);
}
STATIC void mptask_create_main_py (void) {

View File

@ -176,6 +176,7 @@ Q(pins)
// for RTC class
Q(RTC)
Q(id)
Q(init)
Q(alarm)
Q(alarm_left)
@ -262,11 +263,15 @@ Q(server_timeout)
// for WLAN class
Q(WLAN)
Q(iwconfig)
Q(id)
Q(init)
Q(mode)
Q(key)
Q(security)
Q(auth)
Q(ssid)
Q(bssid)
Q(mac)
Q(antenna)
Q(scan)
Q(connect)
Q(isconnected)
@ -274,26 +279,17 @@ Q(disconnect)
Q(channel)
Q(rssi)
Q(ifconfig)
Q(info)
Q(connections)
#if MICROPY_PORT_WLAN_URN
Q(urn)
#endif
Q(mode)
Q(ip)
Q(subnet)
Q(gateway)
Q(dns)
Q(mac)
Q(antenna)
Q(config)
//Q(connections)
//Q(urn)
Q(STA)
Q(AP)
Q(OPEN)
Q(WEP)
Q(WPA)
Q(WPA2)
Q(INTERNAL)
Q(EXTERNAL)
Q(INT_ANT)
Q(EXT_ANT)
Q(ANY_EVENT)
// for WDT class

View File

@ -144,7 +144,7 @@ void TASK_Servers (void *pvParameters) {
void servers_start (void) {
servers_data.do_enable = true;
HAL_Delay (SERVERS_CYCLE_TIME_MS * 5);
HAL_Delay (SERVERS_CYCLE_TIME_MS * 3);
}
void servers_stop (void) {
@ -152,7 +152,7 @@ void servers_stop (void) {
do {
HAL_Delay (SERVERS_CYCLE_TIME_MS);
} while (servers_are_enabled());
HAL_Delay (SERVERS_CYCLE_TIME_MS * 5);
HAL_Delay (SERVERS_CYCLE_TIME_MS * 3);
}
void servers_reset (void) {

12
tests/wipy/reset/reset.py Normal file
View File

@ -0,0 +1,12 @@
'''
Reset script for the cc3200 boards
This is needed to force the board to reboot
with the default WLAN AP settings
'''
from pyb import WDT
import time
wdt = WDT(timeout=1000)
print(wdt)
time.sleep_ms(900)

View File

@ -0,0 +1 @@
<WDT>

166
tests/wipy/wlan/wlan.py Normal file
View File

@ -0,0 +1,166 @@
'''
WLAN test for the CC3200 based boards.
'''
from network import WLAN
import os
import time
import testconfig
import pyb
machine = os.uname().machine
if not 'LaunchPad' in machine and not 'WiPy' in machine:
raise Exception('Board not supported!')
def wait_for_connection(wifi, timeout=10):
while not wifi.isconnected() and timeout > 0:
time.sleep(1)
timeout -= 1
if wifi.isconnected():
print('Connected')
else:
print('Connection failed!')
wifi = WLAN()
print(wifi.mode() == WLAN.STA)
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(mode=WLAN.AP)
print(wifi.mode() == WLAN.AP)
print(wifi.channel() == 1)
print(wifi.auth() == None)
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(0, mode=WLAN.AP, ssid='test-wlan', auth=(WLAN.WPA, '123456abc'), channel=7)
print(wifi.mode() == WLAN.AP)
print(wifi.channel() == 7)
print(wifi.ssid() == 'test-wlan')
print(wifi.auth() == (WLAN.WPA, '123456abc'))
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(mode=WLAN.STA)
print(wifi.mode() == WLAN.STA)
scan_r = wifi.scan()
print(len(scan_r) > 3)
for net in scan_r:
if net.ssid == testconfig.wlan_ssid:
print('Network found')
break
wifi.mode(WLAN.STA)
print(wifi.mode() == WLAN.STA)
wifi.channel(7)
print(wifi.channel() == 7)
wifi.ssid('t-wlan')
print(wifi.ssid() == 't-wlan')
wifi.auth(None)
print(wifi.auth() == None)
wifi.auth((WLAN.WEP, '11223344556677889900'))
print(wifi.auth() == (WLAN.WEP, '11223344556677889900'))
wifi.antenna(WLAN.INT_ANT)
print(wifi.antenna() == WLAN.INT_ANT)
wifi.antenna(WLAN.EXT_ANT)
print(wifi.antenna() == WLAN.EXT_ANT)
scan_r = wifi.scan()
print(len(scan_r) > 3)
for net in scan_r:
if net.ssid == testconfig.wlan_ssid:
print('Network found')
break
wifi.antenna(WLAN.INT_ANT)
wifi.mode(WLAN.STA)
print(wifi.mode() == WLAN.STA)
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=10000)
wait_for_connection(wifi)
wifi.ifconfig(config='dhcp')
wait_for_connection(wifi)
print('0.0.0.0' not in wifi.ifconfig())
wifi.ifconfig(0, ('192.168.178.109', '255.255.255.0', '192.168.178.1', '8.8.8.8'))
wait_for_connection(wifi)
print(wifi.ifconfig(0) == ('192.168.178.109', '255.255.255.0', '192.168.178.1', '8.8.8.8'))
wait_for_connection(wifi)
print(wifi.isconnected() == True)
wifi.disconnect()
print(wifi.isconnected() == False)
t0 = time.ticks_ms()
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=0)
print(time.ticks_ms() - t0 < 500)
wifi.disconnect()
print(wifi.isconnected() == False)
# test init again
wifi.init(WLAN.AP, ssid='www.wipy.io', auth=None, channel=5, antenna=WLAN.INT_ANT)
# next ones MUST raise
try:
wifi.init(mode=12345)
except:
print('Exception')
try:
wifi.init(1, mode=WLAN.AP)
except:
print('Exception')
try:
wifi.init(mode=WLAN.AP, ssid=None)
except:
print('Exception')
try:
wifi = WLAN(mode=WLAN.AP, channel=12)
except:
print('Exception')
try:
wifi.antenna(2)
except:
print('Exception')
try:
wifi.mode(10)
except:
print('Exception')
try:
wifi.ssid('11111sdfasdfasdfasdf564sdf654asdfasdf123451245ssdgfsdf1111111111111111111111111234123412341234asdfasdf')
except:
print('Exception')
try:
wifi.auth((0))
except:
print('Exception')
try:
wifi.auth((0, None))
except:
print('Exception')
try:
wifi.auth((10, 10))
except:
print('Exception')
try:
wifi.channel(0)
except:
print('Exception')
try:
wifi.ifconfig(1, 'dhcp')
except:
print('Exception')
try:
wifi.ifconfig(config=())
except:
print('Exception')

View File

@ -0,0 +1,47 @@
True
True
True
True
True
True
True
True
True
True
True
True
True
Network found
True
True
True
True
True
True
True
True
Network found
True
Connected
Connected
True
Connected
True
Connected
True
True
True
True
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception