Commit a3acaa00 authored by Daniel Campora's avatar Daniel Campora
Browse files

cc3200: Add antenna selection feature to WLAN.

parent 098f5ae2
......@@ -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 \
......
......@@ -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
......
......@@ -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
......
......@@ -42,6 +42,7 @@ BOOT_CC3100_SRC_C = $(addprefix drivers/cc3100/,\
)
BOOT_MISC_SRC_C = $(addprefix misc/,\
antenna.c \
mperror.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();
......
......@@ -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
//*****************************************************************************
......
......@@ -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))
//*****************************************************************************
//
......
......@@ -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();
......
......@@ -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);
......
......@@ -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_
......@@ -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);
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment