Skip to content

Commit df3c21e

Browse files
authored
Merge pull request ARMmbed#58 from linlingao/sem_debug
Fixed porting errors in wifi driver, added event handler, removed eve…
2 parents 0ebe814 + f6bd275 commit df3c21e

File tree

8 files changed

+950
-167
lines changed

8 files changed

+950
-167
lines changed

targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/CC3220SF_LAUNCHXL.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,89 @@
5858
#include <ti/devices/cc32xx/driverlib/interrupt.h>
5959
#include <ti/devices/cc32xx/driverlib/wdt.h>
6060

61+
#include <ti/drivers/Power.h>
62+
#include <ti/drivers/power/PowerCC32XX.h>
63+
6164
#include "CC3220SF_LAUNCHXL.h"
65+
66+
/*
67+
* =============================== Power ===============================
68+
*/
69+
/*
70+
* This table defines the parking state to be set for each parkable pin
71+
* during LPDS. (Device pins must be parked during LPDS to achieve maximum
72+
* power savings.) If the pin should be left unparked, specify the state
73+
* PowerCC32XX_DONT_PARK. For example, for a UART TX pin, the device
74+
* will automatically park the pin in a high state during transition to LPDS,
75+
* so the Power Manager does not need to explictly park the pin. So the
76+
* corresponding entries in this table should indicate PowerCC32XX_DONT_PARK.
77+
*/
78+
PowerCC32XX_ParkInfo parkInfo[] = {
79+
/* PIN PARK STATE PIN ALIAS (FUNCTION)
80+
----------------- ------------------------------ -------------------- */
81+
{PowerCC32XX_PIN01, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO10 */
82+
{PowerCC32XX_PIN02, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO11 */
83+
{PowerCC32XX_PIN03, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO12 */
84+
{PowerCC32XX_PIN04, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO13 */
85+
{PowerCC32XX_PIN05, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO14 */
86+
{PowerCC32XX_PIN06, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO15 */
87+
{PowerCC32XX_PIN07, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO16 */
88+
{PowerCC32XX_PIN08, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO17 */
89+
{PowerCC32XX_PIN13, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* FLASH_SPI_DIN */
90+
{PowerCC32XX_PIN15, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO22 */
91+
{PowerCC32XX_PIN16, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* TDI (JTAG DEBUG) */
92+
{PowerCC32XX_PIN17, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* TDO (JTAG DEBUG) */
93+
{PowerCC32XX_PIN19, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* TCK (JTAG DEBUG) */
94+
{PowerCC32XX_PIN20, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* TMS (JTAG DEBUG) */
95+
{PowerCC32XX_PIN18, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO28 */
96+
{PowerCC32XX_PIN21, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* SOP2 */
97+
{PowerCC32XX_PIN29, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* ANTSEL1 */
98+
{PowerCC32XX_PIN30, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* ANTSEL2 */
99+
{PowerCC32XX_PIN45, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* DCDC_ANA2_SW_P */
100+
{PowerCC32XX_PIN50, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO0 */
101+
{PowerCC32XX_PIN52, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* RTC_XTAL_N */
102+
{PowerCC32XX_PIN53, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO30 */
103+
{PowerCC32XX_PIN55, PowerCC32XX_WEAK_PULL_UP_STD}, /* GPIO1 (XDS_UART_RX) */
104+
{PowerCC32XX_PIN57, PowerCC32XX_WEAK_PULL_UP_STD}, /* GPIO2 (XDS_UART_TX) */
105+
{PowerCC32XX_PIN58, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO3 */
106+
{PowerCC32XX_PIN59, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO4 */
107+
{PowerCC32XX_PIN60, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO5 */
108+
{PowerCC32XX_PIN61, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO6 */
109+
{PowerCC32XX_PIN62, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO7 */
110+
{PowerCC32XX_PIN63, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO8 */
111+
{PowerCC32XX_PIN64, PowerCC32XX_WEAK_PULL_DOWN_STD}, /* GPIO9 */
112+
};
113+
114+
/*
115+
* This structure defines the configuration for the Power Manager.
116+
*
117+
* In this configuration the Power policy is disabled by default (because
118+
* enablePolicy is set to false). The Power policy can be enabled dynamically
119+
* at runtime by calling Power_enablePolicy(), or at build time, by changing
120+
* enablePolicy to true in this structure.
121+
*/
122+
const PowerCC32XX_ConfigV1 PowerCC32XX_config = {
123+
.policyInitFxn = &PowerCC32XX_initPolicy,
124+
.policyFxn = &PowerCC32XX_sleepPolicy,
125+
.enterLPDSHookFxn = NULL,
126+
.resumeLPDSHookFxn = NULL,
127+
.enablePolicy = false,
128+
.enableGPIOWakeupLPDS = true,
129+
.enableGPIOWakeupShutdown = true,
130+
.enableNetworkWakeupLPDS = true,
131+
.wakeupGPIOSourceLPDS = PRCM_LPDS_GPIO13,
132+
.wakeupGPIOTypeLPDS = PRCM_LPDS_FALL_EDGE,
133+
.wakeupGPIOFxnLPDS = NULL,
134+
.wakeupGPIOFxnLPDSArg = 0,
135+
.wakeupGPIOSourceShutdown = PRCM_HIB_GPIO13,
136+
.wakeupGPIOTypeShutdown = PRCM_HIB_RISE_EDGE,
137+
.ramRetentionMaskLPDS = PRCM_SRAM_COL_1 | PRCM_SRAM_COL_2 |
138+
PRCM_SRAM_COL_3 | PRCM_SRAM_COL_4,
139+
.keepDebugActiveDuringLPDS = false,
140+
.ioRetentionShutdown = PRCM_IO_RET_GRP_1,
141+
.pinParkDefs = parkInfo,
142+
.numPins = sizeof(parkInfo) / sizeof(PowerCC32XX_ParkInfo)
143+
};
62144
/*
63145
* =============================== SPI ===============================
64146
*/
@@ -186,6 +268,7 @@ void CC3220SF_LAUNCHXL_initGeneral(void)
186268
MAP_IntMasterEnable();
187269
//MAP_IntEnable(FAULT_SYSTICK);
188270
PRCMCC3200MCUInit();
271+
//Power_init();
189272
}
190273

191274
#define __SF_DEBUG__

targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/CC3220SF_WiFiInterface.cpp

Lines changed: 145 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,155 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
16+
#include <assert.h>
1717
#include "mbed.h"
1818
#include "rtos.h"
1919

2020
#include "CC3220SF_WiFiInterface.h"
2121
#include "mbed_interface.h"
2222

2323
#include "ti/drivers/net/wifi/wlan.h"
24+
#include "ti/drivers/net/wifi/device.h"
2425
#include "ti/drivers/ti_SPI.h"
2526
#include "ti/drivers/dma/UDMACC32XX.h"
2627
#include "EMAC.h"
2728

2829
#include "OnboardNetworkStack.h"
2930
#include "EMACMemoryManager.h"
3031

31-
#define MAX_SCAN_TIMEOUT (15000)
32+
#define MAX_SCAN_TIMEOUT (15000)
33+
#define TASK_STACK_SIZE (2048)
34+
#define SL_STOP_TIMEOUT (200)
35+
36+
#define CHANNEL_MASK_ALL (0x1FFF)
37+
#define RSSI_TH_MAX (-95)
3238

3339
//static bool _inited = false;
3440
SlWlanNetworkEntry_t netEntries[10];
41+
static void sl_task_entry()
42+
{
43+
sl_Task(NULL);
44+
45+
}
46+
47+
/*****************************************************************************
48+
Local Functions
49+
*****************************************************************************/
50+
51+
/*!
52+
\brief Configure SimpleLink to default state.
53+
54+
This routine configures the device to a default state.
55+
It's important to note that this is one example for a 'restore to default state'
56+
function, which meet the needs of this application, 'Network Terminal'. User who
57+
wish to incorporate this function into he's app, must adjust the implementation
58+
and make sure it meets he's needs.
59+
60+
\return Upon successful completion, the function shall return 0.
61+
In case of failure, this function would return -1.
62+
63+
*/
64+
int32_t ConfigureSimpleLinkToDefaultState()
65+
{
66+
uint8_t ucConfigOpt;
67+
uint8_t ucPower;
68+
int32_t RetVal = -1;
69+
int32_t Mode = -1;
70+
uint32_t IfBitmap = 0;
71+
SlWlanScanParamCommand_t ScanDefault = {0};
72+
SlWlanRxFilterOperationCommandBuff_t RxFilterIdMask = {{0}};
73+
74+
/* Turn NWP on */
75+
Mode = sl_Start(0, 0, 0);
76+
if(Mode != ROLE_STA)
77+
{
78+
/* Set NWP role as STA */
79+
RetVal = sl_WlanSetMode(ROLE_STA);
80+
assert(RetVal == 0);
81+
82+
/* For changes to take affect, we restart the NWP */
83+
RetVal = sl_Stop(SL_STOP_TIMEOUT);
84+
assert(RetVal == 0);
85+
86+
Mode = sl_Start(0, 0, 0);
87+
assert(RetVal == 0);
88+
}
89+
90+
if(Mode != ROLE_STA)
91+
{
92+
printf("Failed to configure device to it's default state");
93+
return -1;
94+
}
95+
96+
/* Set policy to auto only */
97+
RetVal = sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY(1,0,0,0), NULL ,0);
98+
assert(RetVal == 0);
99+
100+
/* Disable Auto Provisioning */
101+
RetVal = sl_WlanProvisioning(SL_WLAN_PROVISIONING_CMD_STOP, 0xFF, 0, NULL, 0x0);
102+
assert(RetVal == 0);
103+
104+
/* Delete existing profiles */
105+
RetVal = sl_WlanProfileDel(0xFF);
106+
assert(RetVal == 0);
107+
108+
/* enable DHCP client */
109+
RetVal = sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE, SL_NETCFG_ADDR_DHCP, 0, 0);
110+
assert(RetVal == 0);
111+
112+
/* Disable ipv6 */
113+
IfBitmap = !(SL_NETCFG_IF_IPV6_STA_LOCAL | SL_NETCFG_IF_IPV6_STA_GLOBAL);
114+
RetVal = sl_NetCfgSet(SL_NETCFG_IF, SL_NETCFG_IF_STATE, sizeof(IfBitmap),(const unsigned char *)&IfBitmap);
115+
assert(RetVal == 0);
116+
117+
/* Configure scan parameters to default */
118+
ScanDefault.ChannelsMask = CHANNEL_MASK_ALL;
119+
ScanDefault.RssiThreshold = RSSI_TH_MAX;
120+
121+
RetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, SL_WLAN_GENERAL_PARAM_OPT_SCAN_PARAMS, sizeof(ScanDefault), (uint8_t *)&ScanDefault);
122+
assert(RetVal == 0);
123+
124+
/* Disable scans */
125+
ucConfigOpt = SL_WLAN_SCAN_POLICY(0, 0);
126+
RetVal = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN , ucConfigOpt, NULL, 0);
127+
assert(RetVal == 0);
128+
129+
/* Set TX power lvl to max */
130+
ucPower = 0;
131+
RetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, SL_WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (uint8_t *)&ucPower);
132+
assert(RetVal == 0);
133+
134+
/* Set NWP Power policy to 'normal' */
135+
RetVal = sl_WlanPolicySet(SL_WLAN_POLICY_PM, SL_WLAN_NORMAL_POLICY, NULL, 0);
136+
assert(RetVal == 0);
137+
138+
/* Unregister mDNS services */
139+
RetVal = sl_NetAppMDNSUnRegisterService(0, 0, 0);
140+
assert(RetVal == 0);
141+
142+
/* Remove all 64 RX filters (8*8) */
143+
memset(RxFilterIdMask.FilterBitmap , 0xFF, 8);
144+
145+
RetVal = sl_WlanSet(SL_WLAN_RX_FILTERS_ID, SL_WLAN_RX_FILTER_REMOVE, sizeof(SlWlanRxFilterOperationCommandBuff_t),(uint8_t *)&RxFilterIdMask);
146+
assert(RetVal == 0);
147+
148+
/* Set NWP role as STA */
149+
RetVal = sl_WlanSetMode(ROLE_STA);
150+
assert(RetVal == 0);
151+
152+
/* For changes to take affect, we restart the NWP */
153+
RetVal = sl_Stop(SL_STOP_TIMEOUT);
154+
assert(RetVal == 0);
155+
156+
Mode = sl_Start(0, 0, 0);
157+
if(ROLE_STA != Mode)
158+
{
159+
printf("Failed to configure device to its default state\n");
160+
return -1 ;
161+
}
162+
163+
return 0;
164+
}
35165
#if 0
36166
static cc3220_result_t scan_result_handler( cc3220_scan_handler_result_t* malloced_scan_result )
37167
{
@@ -94,9 +224,19 @@ CC3220SFInterface::CC3220SFInterface(CC3220_EMAC &get_cc3220_emac, OnboardNetwor
94224
_gateway(),
95225
_mac_address()
96226
{
97-
UDMACC32XX_init();
98-
SPI_init();
99-
sl_Start(NULL, NULL, NULL);
227+
int32_t ret_val = -1;
228+
229+
/* The SimpleLink host driver architecture mandate spawn thread to be created prior to calling Sl_start (turning the NWP on). */
230+
/* The purpose of this thread is to handle asynchronous events sent from the NWP.
231+
* Every event is classified and later handled by the Host driver event handlers. */
232+
Thread t(osPriorityNormal, TASK_STACK_SIZE, NULL, "sl_Task");
233+
if (t.start(sl_task_entry) == osOK)
234+
{
235+
UDMACC32XX_init();
236+
SPI_init();
237+
ret_val = ConfigureSimpleLinkToDefaultState();
238+
assert(ret_val >= 0);
239+
}
100240
}
101241

102242
CC3220SFInterface::~CC3220SFInterface()

0 commit comments

Comments
 (0)