From a3acaa000c0835c0b4e8c3f488071b0ff2caa58b Mon Sep 17 00:00:00 2001 From: Daniel Campora Date: Sat, 6 Jun 2015 18:42:51 +0200 Subject: [PATCH] cc3200: Add antenna selection feature to WLAN. --- cc3200/application.mk | 1 + cc3200/boards/LAUNCHXL/mpconfigboard.h | 1 + cc3200/boards/WIPY/mpconfigboard.h | 1 + cc3200/bootmgr/bootloader.mk | 1 + cc3200/bootmgr/main.c | 8 ++++++ cc3200/hal/pin.c | 9 ------- cc3200/hal/pin.h | 7 +++++ cc3200/main.c | 8 ++++++ cc3200/misc/mperror.c | 23 +++++++--------- cc3200/misc/mperror.h | 2 -- cc3200/mods/modwlan.c | 24 +++++++++++++++++ cc3200/mods/pybsleep.c | 36 +++++++++++++++----------- cc3200/mptask.c | 3 --- cc3200/qstrdefsport.h | 3 +++ 14 files changed, 84 insertions(+), 43 deletions(-) diff --git a/cc3200/application.mk b/cc3200/application.mk index da34413c04..71bbb72ba9 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -75,6 +75,7 @@ APP_HAL_SRC_C = $(addprefix hal/,\ ) APP_MISC_SRC_C = $(addprefix misc/,\ + antenna.c \ FreeRTOSHooks.c \ pin_named_pins.c \ help.c \ diff --git a/cc3200/boards/LAUNCHXL/mpconfigboard.h b/cc3200/boards/LAUNCHXL/mpconfigboard.h index 0dc2caf6a1..bf46b880d3 100644 --- a/cc3200/boards/LAUNCHXL/mpconfigboard.h +++ b/cc3200/boards/LAUNCHXL/mpconfigboard.h @@ -33,6 +33,7 @@ #define MICROPY_HW_HAS_SDCARD (0) #define MICROPY_HW_ENABLE_RNG (1) #define MICROPY_HW_ENABLE_RTC (1) +#define MICROPY_HW_ANTENNA_DIVERSITY (0) #define MICROPY_STDIO_UART 1 #define MICROPY_STDIO_UART_BAUD 115200 diff --git a/cc3200/boards/WIPY/mpconfigboard.h b/cc3200/boards/WIPY/mpconfigboard.h index c7036710eb..3246fce3e1 100644 --- a/cc3200/boards/WIPY/mpconfigboard.h +++ b/cc3200/boards/WIPY/mpconfigboard.h @@ -33,6 +33,7 @@ #define MICROPY_HW_HAS_SDCARD (1) #define MICROPY_HW_ENABLE_RNG (1) #define MICROPY_HW_ENABLE_RTC (1) +#define MICROPY_HW_ANTENNA_DIVERSITY (1) #define MICROPY_SYS_LED_PRCM PRCM_GPIOA3 #define MICROPY_SAFE_BOOT_PRCM PRCM_GPIOA3 diff --git a/cc3200/bootmgr/bootloader.mk b/cc3200/bootmgr/bootloader.mk index 1de0e72f0c..f8ce0095cc 100644 --- a/cc3200/bootmgr/bootloader.mk +++ b/cc3200/bootmgr/bootloader.mk @@ -42,6 +42,7 @@ BOOT_CC3100_SRC_C = $(addprefix drivers/cc3100/,\ ) BOOT_MISC_SRC_C = $(addprefix misc/,\ + antenna.c \ mperror.c \ ) diff --git a/cc3200/bootmgr/main.c b/cc3200/bootmgr/main.c index ece1bf276b..6c8be9a0c7 100644 --- a/cc3200/bootmgr/main.c +++ b/cc3200/bootmgr/main.c @@ -53,6 +53,7 @@ #include "cc3200_hal.h" #include "debug.h" #include "mperror.h" +#include "antenna.h" //***************************************************************************** @@ -151,6 +152,13 @@ static void bootmgr_board_init(void) { mperror_bootloader_check_reset_cause(); +#if MICROPY_HW_ANTENNA_DIVERSITY + // configure the antenna selection pins + antenna_init0(); + // select the internal antenna + antenna_select(ANTENNA_TYPE_INTERNAL); +#endif + // Enable the Data Hashing Engine CRYPTOHASH_Init(); diff --git a/cc3200/hal/pin.c b/cc3200/hal/pin.c index 779e287066..4130a43f05 100644 --- a/cc3200/hal/pin.c +++ b/cc3200/hal/pin.c @@ -49,15 +49,6 @@ #include "inc/hw_ocp_shared.h" #include "pin.h" -//***************************************************************************** -// Macros -//***************************************************************************** -#define PAD_MODE_MASK 0x0000000F -#define PAD_STRENGTH_MASK 0x000000E0 -#define PAD_TYPE_MASK 0x00000310 -#define PAD_CONFIG_BASE ((OCP_SHARED_BASE + \ - OCP_SHARED_O_GPIO_PAD_CONFIG_0)) - //***************************************************************************** // PIN to PAD matrix //***************************************************************************** diff --git a/cc3200/hal/pin.h b/cc3200/hal/pin.h index 11a2370e89..784e9f4635 100644 --- a/cc3200/hal/pin.h +++ b/cc3200/hal/pin.h @@ -143,6 +143,13 @@ extern "C" #define PIN_TYPE_OD_PD 0x00000210 #define PIN_TYPE_ANALOG 0x10000000 +//***************************************************************************** +// Macros for mode and type +//***************************************************************************** +#define PAD_MODE_MASK 0x0000000F +#define PAD_STRENGTH_MASK 0x000000E0 +#define PAD_TYPE_MASK 0x00000310 +#define PAD_CONFIG_BASE ((OCP_SHARED_BASE + OCP_SHARED_O_GPIO_PAD_CONFIG_0)) //***************************************************************************** // diff --git a/cc3200/main.c b/cc3200/main.c index e38fd37286..6856cbfaf0 100644 --- a/cc3200/main.c +++ b/cc3200/main.c @@ -34,6 +34,7 @@ #include "simplelink.h" #include "pybwdt.h" #include "debug.h" +#include "antenna.h" #include "mperror.h" /****************************************************************************** @@ -65,6 +66,13 @@ int main (void) { // Initialize the clocks and the interrupt system HAL_SystemInit(); +#if MICROPY_HW_ANTENNA_DIVERSITY + // configure the antenna selection pins + antenna_init0(); + // select the internal antenna + antenna_select(ANTENNA_TYPE_INTERNAL); +#endif + // Init the watchdog pybwdt_init0(); diff --git a/cc3200/misc/mperror.c b/cc3200/misc/mperror.c index 7f5964daff..ca729b2a23 100644 --- a/cc3200/misc/mperror.c +++ b/cc3200/misc/mperror.c @@ -91,6 +91,7 @@ void mperror_init0 (void) { // configure the system led pin_config ((pin_obj_t *)&MICROPY_SYS_LED_GPIO, PIN_MODE_0, GPIO_DIR_MODE_OUT, PIN_TYPE_STD, PIN_STRENGTH_6MA); #endif + mperror_heart_beat.enabled = true; mperror_heartbeat_switch_off(); } @@ -132,25 +133,19 @@ void mperror_signal_error (void) { } } -void mperror_enable_heartbeat (void) { - mperror_heart_beat.enabled = true; -} - void mperror_heartbeat_switch_off (void) { - mperror_heart_beat.on_time = 0; - mperror_heart_beat.off_time = 0; - MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, 0); -} - -void mperror_disable_heartbeat (void) { - mperror_heart_beat.do_disable = true; + if (mperror_heart_beat.enabled) { + mperror_heart_beat.on_time = 0; + mperror_heart_beat.off_time = 0; + MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, 0); + } } void mperror_heartbeat_signal (void) { if (mperror_heart_beat.do_disable) { - mperror_heart_beat.enabled = false; mperror_heart_beat.do_disable = false; mperror_heartbeat_switch_off(); + mperror_heart_beat.enabled = false; } else if (mperror_heart_beat.enabled) { if (!mperror_heart_beat.beating) { @@ -206,7 +201,7 @@ void nlr_jump_fail(void *val) { /// \function enable() /// Enables the heartbeat signal STATIC mp_obj_t pyb_enable_heartbeat(mp_obj_t self) { - mperror_enable_heartbeat (); + mperror_heart_beat.enabled = true; return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_enable_heartbeat_obj, pyb_enable_heartbeat); @@ -214,7 +209,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_enable_heartbeat_obj, pyb_enable_heartbeat) /// \function disable() /// Disables the heartbeat signal STATIC mp_obj_t pyb_disable_heartbeat(mp_obj_t self) { - mperror_disable_heartbeat (); + mperror_heart_beat.do_disable = true; return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_disable_heartbeat_obj, pyb_disable_heartbeat); diff --git a/cc3200/misc/mperror.h b/cc3200/misc/mperror.h index 2c443f449e..7f0a634d80 100644 --- a/cc3200/misc/mperror.h +++ b/cc3200/misc/mperror.h @@ -38,9 +38,7 @@ void mperror_init0 (void); void mperror_bootloader_check_reset_cause (void); void mperror_deinit_sfe_pin (void); void mperror_signal_error (void); -void mperror_enable_heartbeat (void); void mperror_heartbeat_switch_off (void); -void mperror_disable_heartbeat (void); void mperror_heartbeat_signal (void); #endif // MPERROR_H_ diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index 19d6dcae9d..6aecaecc66 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -46,6 +46,7 @@ #include "mpexception.h" #include "mpcallback.h" #include "pybsleep.h" +#include "antenna.h" /****************************************************************************** @@ -1047,6 +1048,24 @@ STATIC mp_obj_t wlan_connections (mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_connections_obj, wlan_connections); +#if MICROPY_HW_ANTENNA_DIVERSITY +/// \method antenna() +/// select the antenna type to use (internal or external) +STATIC mp_obj_t wlan_antenna (mp_obj_t self_in, mp_obj_t antenna_o) { + antenna_type_t _antenna = mp_obj_get_int(antenna_o); + + if (_antenna != ANTENNA_TYPE_INTERNAL && _antenna != ANTENNA_TYPE_EXTERNAL) { + // invalid antenna type + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments)); + } + + antenna_select (_antenna); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(wlan_antenna_obj, wlan_antenna); +#endif + STATIC const mp_map_elem_t wlan_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&wlan_connect_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_scan), (mp_obj_t)&wlan_scan_obj }, @@ -1055,6 +1074,9 @@ STATIC const mp_map_elem_t wlan_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_ifconfig), (mp_obj_t)&wlan_ifconfig_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&wlan_info_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_connections), (mp_obj_t)&wlan_connections_obj }, +#if MICROPY_HW_ANTENNA_DIVERSITY + { MP_OBJ_NEW_QSTR(MP_QSTR_antenna), (mp_obj_t)&wlan_antenna_obj }, +#endif #if MICROPY_PORT_WLAN_URN { MP_OBJ_NEW_QSTR(MP_QSTR_urn), (mp_obj_t)&wlan_urn_obj }, #endif @@ -1070,6 +1092,8 @@ STATIC const mp_map_elem_t wlan_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_STA), MP_OBJ_NEW_SMALL_INT(ROLE_STA) }, { MP_OBJ_NEW_QSTR(MP_QSTR_AP), MP_OBJ_NEW_SMALL_INT(ROLE_AP) }, { MP_OBJ_NEW_QSTR(MP_QSTR_P2P), MP_OBJ_NEW_SMALL_INT(ROLE_P2P) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_INT_ANTENNA), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_INTERNAL) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_EXT_ANTENNA), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_EXTERNAL) }, }; STATIC MP_DEFINE_CONST_DICT(wlan_locals_dict, wlan_locals_dict_table); diff --git a/cc3200/mods/pybsleep.c b/cc3200/mods/pybsleep.c index ea35f3f772..a84c6aefd6 100644 --- a/cc3200/mods/pybsleep.c +++ b/cc3200/mods/pybsleep.c @@ -136,7 +136,7 @@ STATIC NORETURN void pybsleep_suspend_enter (void); void pybsleep_suspend_exit (void); STATIC void pybsleep_obj_wakeup (void); STATIC void PRCMInterruptHandler (void); -STATIC void pybsleep_iopark (void); +STATIC void pybsleep_iopark (bool hibernate); STATIC bool setup_timer_lpds_wake (void); STATIC bool setup_timer_hibernate_wake (void); @@ -339,7 +339,7 @@ STATIC NORETURN void pybsleep_suspend_enter (void) { mperror_heartbeat_switch_off(); // park the gpio pins - pybsleep_iopark(); + pybsleep_iopark(false); // store the cpu registers sleep_store(); @@ -450,31 +450,29 @@ STATIC void pybsleep_obj_wakeup (void) { } } -STATIC void pybsleep_iopark (void) { +STATIC void pybsleep_iopark (bool hibernate) { mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)&pin_cpu_pins_locals_dict); for (uint i = 0; i < named_map->used; i++) { pin_obj_t * pin = (pin_obj_t *)named_map->table[i].value; // skip the sflash pins since these are shared with the network processor switch (pin->pin_num) { - case PIN_11: - case PIN_12: - case PIN_13: - case PIN_14: #ifdef DEBUG - // also skip the JTAG pins + // skip the JTAG pins case PIN_16: case PIN_17: case PIN_19: case PIN_20: -#endif break; +#endif default: // enable a weak pull-down if the pin is unused if (!pin->isused) { MAP_PinConfigSet(pin->pin_num, pin->strength, PIN_TYPE_STD_PD); } - // make it an input - MAP_PinDirModeSet(pin->pin_num, PIN_DIR_MODE_IN); + if (hibernate) { + // make it an input + MAP_PinDirModeSet(pin->pin_num, PIN_DIR_MODE_IN); + } break; } } @@ -489,9 +487,17 @@ STATIC void pybsleep_iopark (void) { HWREG(0x4402E0F4) &= ~(0x3 << 8); HWREG(0x4402E0F4) |= (0x1 << 8); - // park the antenna selection pins - HWREG(0x4402E108) = 0x00000E61; - HWREG(0x4402E10C) = 0x00000E61; + // if the board has antenna diversity, only park the antenna + // selection pins when going into hibernation +#if MICROPY_HW_ANTENNA_DIVERSITY + if (hibernate) { +#endif + // park the antenna selection pins + HWREG(0x4402E108) = 0x00000E61; + HWREG(0x4402E10C) = 0x00000E61; +#if MICROPY_HW_ANTENNA_DIVERSITY + } +#endif } STATIC bool setup_timer_lpds_wake (void) { @@ -632,7 +638,7 @@ STATIC mp_obj_t pyb_sleep_hibernate (mp_obj_t self_in) { wlan_stop(SL_STOP_TIMEOUT); pybsleep_flash_powerdown(); // must be done just before entering hibernate mode - pybsleep_iopark(); + pybsleep_iopark(true); MAP_PRCMHibernateEnter(); return mp_const_none; } diff --git a/cc3200/mptask.c b/cc3200/mptask.c index 621fc3f6c3..aa4632c453 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -133,9 +133,6 @@ soft_reset: rng_init0(); #endif - // we are alive, so let the world know it - mperror_enable_heartbeat(); - #ifdef LAUNCHXL // configure the stdio uart pins with the correct alternate functions // param 3 ("mode") is DON'T CARE" for AFs others than GPIO diff --git a/cc3200/qstrdefsport.h b/cc3200/qstrdefsport.h index 8219e03bb2..caafd75c44 100644 --- a/cc3200/qstrdefsport.h +++ b/cc3200/qstrdefsport.h @@ -263,6 +263,7 @@ Q(subnet) Q(gateway) Q(dns) Q(mac) +Q(antenna) Q(STA) Q(AP) Q(P2P) @@ -272,6 +273,8 @@ Q(WPA_WPA2) Q(WPA_ENT) Q(WPS_PBC) Q(WPS_PIN) +Q(INT_ANTENNA) +Q(EXT_ANTENNA) // for WDT class Q(WDT)