Skip to content

Commit

Permalink
Merge pull request ARMmbed#58 from linlingao/sem_debug
Browse files Browse the repository at this point in the history
Fixed porting errors in wifi driver, added event handler, removed eve…
  • Loading branch information
linlingao authored Aug 27, 2018
2 parents 0ebe814 + f6bd275 commit df3c21e
Show file tree
Hide file tree
Showing 8 changed files with 950 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,89 @@
#include <ti/devices/cc32xx/driverlib/interrupt.h>
#include <ti/devices/cc32xx/driverlib/wdt.h>

#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC32XX.h>

#include "CC3220SF_LAUNCHXL.h"

/*
* =============================== Power ===============================
*/
/*
* This table defines the parking state to be set for each parkable pin
* during LPDS. (Device pins must be parked during LPDS to achieve maximum
* power savings.) If the pin should be left unparked, specify the state
* PowerCC32XX_DONT_PARK. For example, for a UART TX pin, the device
* will automatically park the pin in a high state during transition to LPDS,
* so the Power Manager does not need to explictly park the pin. So the
* corresponding entries in this table should indicate PowerCC32XX_DONT_PARK.
*/
PowerCC32XX_ParkInfo parkInfo[] = {
/* PIN PARK STATE PIN ALIAS (FUNCTION)
----------------- ------------------------------ -------------------- */
{PowerCC32XX_PIN01, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO10 */
{PowerCC32XX_PIN02, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO11 */
{PowerCC32XX_PIN03, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO12 */
{PowerCC32XX_PIN04, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO13 */
{PowerCC32XX_PIN05, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO14 */
{PowerCC32XX_PIN06, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO15 */
{PowerCC32XX_PIN07, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO16 */
{PowerCC32XX_PIN08, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO17 */
{PowerCC32XX_PIN13, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* FLASH_SPI_DIN */
{PowerCC32XX_PIN15, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO22 */
{PowerCC32XX_PIN16, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* TDI (JTAG DEBUG) */
{PowerCC32XX_PIN17, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* TDO (JTAG DEBUG) */
{PowerCC32XX_PIN19, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* TCK (JTAG DEBUG) */
{PowerCC32XX_PIN20, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* TMS (JTAG DEBUG) */
{PowerCC32XX_PIN18, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO28 */
{PowerCC32XX_PIN21, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* SOP2 */
{PowerCC32XX_PIN29, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* ANTSEL1 */
{PowerCC32XX_PIN30, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* ANTSEL2 */
{PowerCC32XX_PIN45, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* DCDC_ANA2_SW_P */
{PowerCC32XX_PIN50, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO0 */
{PowerCC32XX_PIN52, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* RTC_XTAL_N */
{PowerCC32XX_PIN53, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO30 */
{PowerCC32XX_PIN55, PowerCC32XX_WEAK_PULL_UP_STD}, /* GPIO1 (XDS_UART_RX) */
{PowerCC32XX_PIN57, PowerCC32XX_WEAK_PULL_UP_STD}, /* GPIO2 (XDS_UART_TX) */
{PowerCC32XX_PIN58, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO3 */
{PowerCC32XX_PIN59, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO4 */
{PowerCC32XX_PIN60, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO5 */
{PowerCC32XX_PIN61, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO6 */
{PowerCC32XX_PIN62, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO7 */
{PowerCC32XX_PIN63, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO8 */
{PowerCC32XX_PIN64, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO9 */
};

/*
* This structure defines the configuration for the Power Manager.
*
* In this configuration the Power policy is disabled by default (because
* enablePolicy is set to false). The Power policy can be enabled dynamically
* at runtime by calling Power_enablePolicy(), or at build time, by changing
* enablePolicy to true in this structure.
*/
const PowerCC32XX_ConfigV1 PowerCC32XX_config = {
.policyInitFxn = &PowerCC32XX_initPolicy,
.policyFxn = &PowerCC32XX_sleepPolicy,
.enterLPDSHookFxn = NULL,
.resumeLPDSHookFxn = NULL,
.enablePolicy = false,
.enableGPIOWakeupLPDS = true,
.enableGPIOWakeupShutdown = true,
.enableNetworkWakeupLPDS = true,
.wakeupGPIOSourceLPDS = PRCM_LPDS_GPIO13,
.wakeupGPIOTypeLPDS = PRCM_LPDS_FALL_EDGE,
.wakeupGPIOFxnLPDS = NULL,
.wakeupGPIOFxnLPDSArg = 0,
.wakeupGPIOSourceShutdown = PRCM_HIB_GPIO13,
.wakeupGPIOTypeShutdown = PRCM_HIB_RISE_EDGE,
.ramRetentionMaskLPDS = PRCM_SRAM_COL_1 | PRCM_SRAM_COL_2 |
PRCM_SRAM_COL_3 | PRCM_SRAM_COL_4,
.keepDebugActiveDuringLPDS = false,
.ioRetentionShutdown = PRCM_IO_RET_GRP_1,
.pinParkDefs = parkInfo,
.numPins = sizeof(parkInfo) / sizeof(PowerCC32XX_ParkInfo)
};
/*
* =============================== SPI ===============================
*/
Expand Down Expand Up @@ -186,6 +268,7 @@ void CC3220SF_LAUNCHXL_initGeneral(void)
MAP_IntMasterEnable();
//MAP_IntEnable(FAULT_SYSTICK);
PRCMCC3200MCUInit();
//Power_init();
}

#define __SF_DEBUG__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,155 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <assert.h>
#include "mbed.h"
#include "rtos.h"

#include "CC3220SF_WiFiInterface.h"
#include "mbed_interface.h"

#include "ti/drivers/net/wifi/wlan.h"
#include "ti/drivers/net/wifi/device.h"
#include "ti/drivers/ti_SPI.h"
#include "ti/drivers/dma/UDMACC32XX.h"
#include "EMAC.h"

#include "OnboardNetworkStack.h"
#include "EMACMemoryManager.h"

#define MAX_SCAN_TIMEOUT (15000)
#define MAX_SCAN_TIMEOUT (15000)
#define TASK_STACK_SIZE (2048)
#define SL_STOP_TIMEOUT (200)

#define CHANNEL_MASK_ALL (0x1FFF)
#define RSSI_TH_MAX (-95)

//static bool _inited = false;
SlWlanNetworkEntry_t netEntries[10];
static void sl_task_entry()
{
sl_Task(NULL);

}

/*****************************************************************************
Local Functions
*****************************************************************************/

/*!
\brief Configure SimpleLink to default state.
This routine configures the device to a default state.
It's important to note that this is one example for a 'restore to default state'
function, which meet the needs of this application, 'Network Terminal'. User who
wish to incorporate this function into he's app, must adjust the implementation
and make sure it meets he's needs.
\return Upon successful completion, the function shall return 0.
In case of failure, this function would return -1.
*/
int32_t ConfigureSimpleLinkToDefaultState()
{
uint8_t ucConfigOpt;
uint8_t ucPower;
int32_t RetVal = -1;
int32_t Mode = -1;
uint32_t IfBitmap = 0;
SlWlanScanParamCommand_t ScanDefault = {0};
SlWlanRxFilterOperationCommandBuff_t RxFilterIdMask = {{0}};

/* Turn NWP on */
Mode = sl_Start(0, 0, 0);
if(Mode != ROLE_STA)
{
/* Set NWP role as STA */
RetVal = sl_WlanSetMode(ROLE_STA);
assert(RetVal == 0);

/* For changes to take affect, we restart the NWP */
RetVal = sl_Stop(SL_STOP_TIMEOUT);
assert(RetVal == 0);

Mode = sl_Start(0, 0, 0);
assert(RetVal == 0);
}

if(Mode != ROLE_STA)
{
printf("Failed to configure device to it's default state");
return -1;
}

/* Set policy to auto only */
RetVal = sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY(1,0,0,0), NULL ,0);
assert(RetVal == 0);

/* Disable Auto Provisioning */
RetVal = sl_WlanProvisioning(SL_WLAN_PROVISIONING_CMD_STOP, 0xFF, 0, NULL, 0x0);
assert(RetVal == 0);

/* Delete existing profiles */
RetVal = sl_WlanProfileDel(0xFF);
assert(RetVal == 0);

/* enable DHCP client */
RetVal = sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE, SL_NETCFG_ADDR_DHCP, 0, 0);
assert(RetVal == 0);

/* Disable ipv6 */
IfBitmap = !(SL_NETCFG_IF_IPV6_STA_LOCAL | SL_NETCFG_IF_IPV6_STA_GLOBAL);
RetVal = sl_NetCfgSet(SL_NETCFG_IF, SL_NETCFG_IF_STATE, sizeof(IfBitmap),(const unsigned char *)&IfBitmap);
assert(RetVal == 0);

/* Configure scan parameters to default */
ScanDefault.ChannelsMask = CHANNEL_MASK_ALL;
ScanDefault.RssiThreshold = RSSI_TH_MAX;

RetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, SL_WLAN_GENERAL_PARAM_OPT_SCAN_PARAMS, sizeof(ScanDefault), (uint8_t *)&ScanDefault);
assert(RetVal == 0);

/* Disable scans */
ucConfigOpt = SL_WLAN_SCAN_POLICY(0, 0);
RetVal = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN , ucConfigOpt, NULL, 0);
assert(RetVal == 0);

/* Set TX power lvl to max */
ucPower = 0;
RetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, SL_WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (uint8_t *)&ucPower);
assert(RetVal == 0);

/* Set NWP Power policy to 'normal' */
RetVal = sl_WlanPolicySet(SL_WLAN_POLICY_PM, SL_WLAN_NORMAL_POLICY, NULL, 0);
assert(RetVal == 0);

/* Unregister mDNS services */
RetVal = sl_NetAppMDNSUnRegisterService(0, 0, 0);
assert(RetVal == 0);

/* Remove all 64 RX filters (8*8) */
memset(RxFilterIdMask.FilterBitmap , 0xFF, 8);

RetVal = sl_WlanSet(SL_WLAN_RX_FILTERS_ID, SL_WLAN_RX_FILTER_REMOVE, sizeof(SlWlanRxFilterOperationCommandBuff_t),(uint8_t *)&RxFilterIdMask);
assert(RetVal == 0);

/* Set NWP role as STA */
RetVal = sl_WlanSetMode(ROLE_STA);
assert(RetVal == 0);

/* For changes to take affect, we restart the NWP */
RetVal = sl_Stop(SL_STOP_TIMEOUT);
assert(RetVal == 0);

Mode = sl_Start(0, 0, 0);
if(ROLE_STA != Mode)
{
printf("Failed to configure device to its default state\n");
return -1 ;
}

return 0;
}
#if 0
static cc3220_result_t scan_result_handler( cc3220_scan_handler_result_t* malloced_scan_result )
{
Expand Down Expand Up @@ -94,9 +224,19 @@ CC3220SFInterface::CC3220SFInterface(CC3220_EMAC &get_cc3220_emac, OnboardNetwor
_gateway(),
_mac_address()
{
UDMACC32XX_init();
SPI_init();
sl_Start(NULL, NULL, NULL);
int32_t ret_val = -1;

/* The SimpleLink host driver architecture mandate spawn thread to be created prior to calling Sl_start (turning the NWP on). */
/* The purpose of this thread is to handle asynchronous events sent from the NWP.
* Every event is classified and later handled by the Host driver event handlers. */
Thread t(osPriorityNormal, TASK_STACK_SIZE, NULL, "sl_Task");
if (t.start(sl_task_entry) == osOK)
{
UDMACC32XX_init();
SPI_init();
ret_val = ConfigureSimpleLinkToDefaultState();
assert(ret_val >= 0);
}
}

CC3220SFInterface::~CC3220SFInterface()
Expand Down
Loading

0 comments on commit df3c21e

Please sign in to comment.