TI's CC3100. A test demo with very little testing done!

Dependencies:   mbed

Fork of cc3100_Test_Demo2 by 高 杨

Committer:
dflet
Date:
Sun Feb 22 18:33:10 2015 +0000
Revision:
3:b89198ac2efe
Parent:
0:e89ba455dbcf
Child:
5:d3b320ebd469
Removed more debug.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 0:e89ba455dbcf 1 /*
dflet 0:e89ba455dbcf 2 * main.c - sample application to switch to AP mode and ping client
dflet 0:e89ba455dbcf 3 *
dflet 0:e89ba455dbcf 4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
dflet 0:e89ba455dbcf 5 *
dflet 0:e89ba455dbcf 6 *
dflet 0:e89ba455dbcf 7 * Redistribution and use in source and binary forms, with or without
dflet 0:e89ba455dbcf 8 * modification, are permitted provided that the following conditions
dflet 0:e89ba455dbcf 9 * are met:
dflet 0:e89ba455dbcf 10 *
dflet 0:e89ba455dbcf 11 * Redistributions of source code must retain the above copyright
dflet 0:e89ba455dbcf 12 * notice, this list of conditions and the following disclaimer.
dflet 0:e89ba455dbcf 13 *
dflet 0:e89ba455dbcf 14 * Redistributions in binary form must reproduce the above copyright
dflet 0:e89ba455dbcf 15 * notice, this list of conditions and the following disclaimer in the
dflet 0:e89ba455dbcf 16 * documentation and/or other materials provided with the
dflet 0:e89ba455dbcf 17 * distribution.
dflet 0:e89ba455dbcf 18 *
dflet 0:e89ba455dbcf 19 * Neither the name of Texas Instruments Incorporated nor the names of
dflet 0:e89ba455dbcf 20 * its contributors may be used to endorse or promote products derived
dflet 0:e89ba455dbcf 21 * from this software without specific prior written permission.
dflet 0:e89ba455dbcf 22 *
dflet 0:e89ba455dbcf 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 0:e89ba455dbcf 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 0:e89ba455dbcf 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 0:e89ba455dbcf 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 0:e89ba455dbcf 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 0:e89ba455dbcf 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 0:e89ba455dbcf 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 0:e89ba455dbcf 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 0:e89ba455dbcf 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 0:e89ba455dbcf 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 0:e89ba455dbcf 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 0:e89ba455dbcf 34 *
dflet 0:e89ba455dbcf 35 */
dflet 0:e89ba455dbcf 36
dflet 0:e89ba455dbcf 37 /*
dflet 0:e89ba455dbcf 38 * Application Name - Getting started with Wi-Fi Access-Point mode
dflet 0:e89ba455dbcf 39 * Application Overview - This sample application demonstrates how
dflet 0:e89ba455dbcf 40 * to configure CC3100 in Access-Point mode. Any
dflet 0:e89ba455dbcf 41 * WLAN station in its range can connect/communicate
dflet 0:e89ba455dbcf 42 * to/with it as per the standard networking protocols.
dflet 0:e89ba455dbcf 43 * On a successful connection, the device ping's the
dflet 0:e89ba455dbcf 44 * connected station.
dflet 0:e89ba455dbcf 45 * Application Details - http://processors.wiki.ti.com/index.php/CC31xx_Getting_Started_with_WLAN_AP
dflet 0:e89ba455dbcf 46 * doc\examples\getting_started_with_wlan_ap.pdf
dflet 0:e89ba455dbcf 47 */
dflet 0:e89ba455dbcf 48
dflet 0:e89ba455dbcf 49 #include "cc3100_simplelink.h"
dflet 0:e89ba455dbcf 50 #include "cc3100_sl_common.h"
dflet 0:e89ba455dbcf 51
dflet 0:e89ba455dbcf 52 #include "fPtr_func.h"
dflet 3:b89198ac2efe 53 #include "cc3100.h"
dflet 0:e89ba455dbcf 54 #include "cc3100_spi.h"
dflet 0:e89ba455dbcf 55 #include "myBoardInit.h"
dflet 0:e89ba455dbcf 56
dflet 0:e89ba455dbcf 57 using namespace mbed_cc3100;
dflet 0:e89ba455dbcf 58
dflet 0:e89ba455dbcf 59 #if (THIS_BOARD == MBED_BOARD_LPC1768)
dflet 0:e89ba455dbcf 60 //cc3100 _cc3100(p9, p10, p8, SPI(p5, p6, p7));//LPC1768 irq, nHib, cs, mosi, miso, sck
dflet 0:e89ba455dbcf 61 cc3100 _cc3100(p9, p10, p8, SPI(p11, p12, p13));//LPC1768 irq, nHib, cs, mosi, miso, sck
dflet 0:e89ba455dbcf 62 Serial pc(USBTX, USBRX);//lpc1768
dflet 0:e89ba455dbcf 63 #elif (THIS_BOARD == ST_MBED_NUCLEOF411)
dflet 0:e89ba455dbcf 64 cc3100 _cc3100(PA_9, PC_7, PB_6, SPI(PA_7, PA_6, PA_5));//nucleoF411 irq, nHib, cs, mosi, miso, sck
dflet 0:e89ba455dbcf 65 Serial pc(SERIAL_TX, SERIAL_RX);//nucleoF411
dflet 0:e89ba455dbcf 66 #elif (THIS_BOARD == ST_MBED_NUCLEOF401)
dflet 0:e89ba455dbcf 67 cc3100 _cc3100(PA_9, PC_7, PB_6, SPI(PA_7, PA_6, PA_5));//nucleoF401 irq, nHib, cs, mosi, miso, sck
dflet 0:e89ba455dbcf 68 Serial pc(SERIAL_TX, SERIAL_RX);//nucleoF401
dflet 0:e89ba455dbcf 69 #elif (THIS_BOARD == EA_MBED_LPC4088)
dflet 0:e89ba455dbcf 70 cc3100 _cc3100(p9, p10, p8, SPI(p5, p6, p7));//LPC4088 irq, nHib, cs, mosi, miso, sck
dflet 0:e89ba455dbcf 71 Serial pc(USBTX, USBRX);//EA_lpc4088
dflet 0:e89ba455dbcf 72 #elif (THIS_BOARD == ST_MBED_NUCLEOF103)
dflet 0:e89ba455dbcf 73 cc3100 _cc3100(PA_9, PC_7, PB_6, SPI(PA_7, PA_6, PA_5));//nucleoF103 irq, nHib, cs, mosi, miso, sck
dflet 0:e89ba455dbcf 74 Serial pc(SERIAL_TX, SERIAL_RX);
dflet 0:e89ba455dbcf 75 #else
dflet 0:e89ba455dbcf 76
dflet 0:e89ba455dbcf 77 #endif
dflet 0:e89ba455dbcf 78
dflet 0:e89ba455dbcf 79 #define APPLICATION_VERSION "1.1.0"
dflet 0:e89ba455dbcf 80
dflet 0:e89ba455dbcf 81 /*
dflet 0:e89ba455dbcf 82 * GLOBAL VARIABLES -- Start
dflet 0:e89ba455dbcf 83 */
dflet 3:b89198ac2efe 84 int32_t demo = 0;
dflet 0:e89ba455dbcf 85
dflet 0:e89ba455dbcf 86 /*
dflet 0:e89ba455dbcf 87 * GLOBAL VARIABLES -- End
dflet 0:e89ba455dbcf 88 */
dflet 0:e89ba455dbcf 89
dflet 0:e89ba455dbcf 90
dflet 0:e89ba455dbcf 91 /*
dflet 0:e89ba455dbcf 92 * STATIC FUNCTION DEFINITIONS -- Start
dflet 0:e89ba455dbcf 93 */
dflet 0:e89ba455dbcf 94
dflet 0:e89ba455dbcf 95 static void displayBanner();
dflet 0:e89ba455dbcf 96 /*
dflet 0:e89ba455dbcf 97 * STATIC FUNCTION DEFINITIONS -- End
dflet 0:e89ba455dbcf 98 */
dflet 0:e89ba455dbcf 99
dflet 0:e89ba455dbcf 100 void station_app(void);
dflet 0:e89ba455dbcf 101 void AP_app(void);
dflet 0:e89ba455dbcf 102
dflet 0:e89ba455dbcf 103 /*
dflet 0:e89ba455dbcf 104 * Application's entry point
dflet 0:e89ba455dbcf 105 */
dflet 0:e89ba455dbcf 106
dflet 0:e89ba455dbcf 107
dflet 0:e89ba455dbcf 108 int main(void) {
dflet 0:e89ba455dbcf 109
dflet 0:e89ba455dbcf 110 pc.baud(115200);
dflet 0:e89ba455dbcf 111
dflet 0:e89ba455dbcf 112 int32_t retVal = -1;
dflet 0:e89ba455dbcf 113
dflet 0:e89ba455dbcf 114 retVal = _cc3100.initializeAppVariables();
dflet 0:e89ba455dbcf 115 ASSERT_ON_ERROR(retVal);
dflet 0:e89ba455dbcf 116
dflet 0:e89ba455dbcf 117 displayBanner();
dflet 0:e89ba455dbcf 118
dflet 0:e89ba455dbcf 119 _cc3100.CLR_STATUS_BIT(g_Status, STATUS_BIT_PING_DONE);
dflet 0:e89ba455dbcf 120 g_PingPacketsRecv = 0;
dflet 3:b89198ac2efe 121
dflet 0:e89ba455dbcf 122 /*
dflet 0:e89ba455dbcf 123 * Following function configures the device to default state by cleaning
dflet 0:e89ba455dbcf 124 * the persistent settings stored in NVMEM (viz. connection profiles &
dflet 0:e89ba455dbcf 125 * policies, power policy etc)
dflet 0:e89ba455dbcf 126 *
dflet 0:e89ba455dbcf 127 * Applications may choose to skip this step if the developer is sure
dflet 0:e89ba455dbcf 128 * that the device is in its default state at start of application
dflet 0:e89ba455dbcf 129 *
dflet 0:e89ba455dbcf 130 * Note that all profiles and persistent settings that were done on the
dflet 0:e89ba455dbcf 131 * device will be lost
dflet 0:e89ba455dbcf 132 */
dflet 0:e89ba455dbcf 133 retVal = _cc3100.configureSimpleLinkToDefaultState();
dflet 0:e89ba455dbcf 134
dflet 0:e89ba455dbcf 135 if(retVal < 0) {
dflet 0:e89ba455dbcf 136 if (DEVICE_NOT_IN_STATION_MODE == retVal)
dflet 0:e89ba455dbcf 137 printf(" Failed to configure the device to its default state \n\r");
dflet 0:e89ba455dbcf 138
dflet 0:e89ba455dbcf 139 LOOP_FOREVER();
dflet 0:e89ba455dbcf 140 }
dflet 0:e89ba455dbcf 141
dflet 0:e89ba455dbcf 142 printf(" Device is configured in it's default state \n\r");
dflet 0:e89ba455dbcf 143
dflet 0:e89ba455dbcf 144 /*
dflet 0:e89ba455dbcf 145 * Assumption is that the device is configured in station mode already
dflet 0:e89ba455dbcf 146 * and it is in its default state
dflet 0:e89ba455dbcf 147 */
dflet 0:e89ba455dbcf 148 /* Initializing the CC3100 device */
dflet 0:e89ba455dbcf 149
dflet 0:e89ba455dbcf 150 if(!(demo ==1)){
dflet 0:e89ba455dbcf 151 retVal = _cc3100.sl_Start(0, 0, 0);
dflet 0:e89ba455dbcf 152
dflet 0:e89ba455dbcf 153 if ((retVal < 0) || (ROLE_STA != retVal) ){
dflet 0:e89ba455dbcf 154 printf(" Failed to start the device \n\r");
dflet 0:e89ba455dbcf 155 LOOP_FOREVER();
dflet 0:e89ba455dbcf 156 }
dflet 0:e89ba455dbcf 157
dflet 0:e89ba455dbcf 158 printf(" Device started as STATION \n\r");
dflet 0:e89ba455dbcf 159 }
dflet 0:e89ba455dbcf 160
dflet 0:e89ba455dbcf 161 if(demo == 0 ){
dflet 0:e89ba455dbcf 162 station_app();
dflet 0:e89ba455dbcf 163 }else{
dflet 0:e89ba455dbcf 164 AP_app();
dflet 0:e89ba455dbcf 165 }
dflet 0:e89ba455dbcf 166 return 0;
dflet 0:e89ba455dbcf 167 }
dflet 0:e89ba455dbcf 168
dflet 0:e89ba455dbcf 169 /*!
dflet 0:e89ba455dbcf 170 \brief This function displays the application's banner
dflet 0:e89ba455dbcf 171
dflet 0:e89ba455dbcf 172 \param None
dflet 0:e89ba455dbcf 173
dflet 0:e89ba455dbcf 174 \return None
dflet 0:e89ba455dbcf 175 */
dflet 0:e89ba455dbcf 176 static void displayBanner()
dflet 0:e89ba455dbcf 177 {
dflet 0:e89ba455dbcf 178 if(!demo){
dflet 0:e89ba455dbcf 179 printf("\n\r\n\r");
dflet 0:e89ba455dbcf 180 printf(" Getting started with WLAN access-point application - Version ");
dflet 0:e89ba455dbcf 181 printf("%s",APPLICATION_VERSION);
dflet 0:e89ba455dbcf 182 printf("\n\r*******************************************************************************\n\r");
dflet 0:e89ba455dbcf 183
dflet 0:e89ba455dbcf 184 }else{
dflet 0:e89ba455dbcf 185 printf("\n\r\n\r");
dflet 0:e89ba455dbcf 186 printf(" Getting started with station application - Version ");
dflet 0:e89ba455dbcf 187 printf(" %s", APPLICATION_VERSION);
dflet 0:e89ba455dbcf 188 printf("\n\r*******************************************************************************\n\r");
dflet 0:e89ba455dbcf 189 }
dflet 0:e89ba455dbcf 190 }
dflet 0:e89ba455dbcf 191
dflet 0:e89ba455dbcf 192 void AP_app(void){
dflet 0:e89ba455dbcf 193
dflet 0:e89ba455dbcf 194 SlPingStartCommand_t PingParams = {0};
dflet 0:e89ba455dbcf 195 SlPingReport_t Report = {0};
dflet 0:e89ba455dbcf 196 SlNetCfgIpV4Args_t ipV4 = {0};
dflet 0:e89ba455dbcf 197 SlNetAppDhcpServerBasicOpt_t dhcpParams = {0};
dflet 0:e89ba455dbcf 198
dflet 0:e89ba455dbcf 199 uint8_t SecType = 0;
dflet 0:e89ba455dbcf 200 int32_t role = ROLE_STA;
dflet 0:e89ba455dbcf 201 int32_t retVal = -1;
dflet 0:e89ba455dbcf 202
dflet 0:e89ba455dbcf 203 /*
dflet 0:e89ba455dbcf 204 * Assumption is that the device is configured in station mode already
dflet 0:e89ba455dbcf 205 * and it is in its default state
dflet 0:e89ba455dbcf 206 */
dflet 0:e89ba455dbcf 207 role = _cc3100.sl_Start(0, 0, 0);
dflet 0:e89ba455dbcf 208 if (ROLE_AP == role) {
dflet 0:e89ba455dbcf 209 /* If the device is in AP mode, we need to wait for this event before doing anything */
dflet 0:e89ba455dbcf 210 while(!_cc3100.IS_IP_ACQUIRED(g_Status,STATUS_BIT_IP_ACQUIRED)) {
dflet 3:b89198ac2efe 211 _cc3100._nonos._SlNonOsMainLoopTask();
dflet 0:e89ba455dbcf 212 }
dflet 0:e89ba455dbcf 213 } else {
dflet 0:e89ba455dbcf 214 /* Configure CC3100 to start in AP mode */
dflet 3:b89198ac2efe 215 retVal = _cc3100._wlan.sl_WlanSetMode(ROLE_AP);
dflet 0:e89ba455dbcf 216 if(retVal < 0)
dflet 0:e89ba455dbcf 217 LOOP_FOREVER();
dflet 0:e89ba455dbcf 218
dflet 0:e89ba455dbcf 219 retVal = _cc3100.sl_Stop(SL_STOP_TIMEOUT);
dflet 0:e89ba455dbcf 220 if(retVal < 0)
dflet 0:e89ba455dbcf 221 LOOP_FOREVER();
dflet 0:e89ba455dbcf 222
dflet 0:e89ba455dbcf 223 _cc3100.CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);
dflet 0:e89ba455dbcf 224
dflet 0:e89ba455dbcf 225 role = _cc3100.sl_Start(0, 0, 0);
dflet 0:e89ba455dbcf 226 if (ROLE_AP == role) {
dflet 0:e89ba455dbcf 227 /* If the device is in AP mode, we need to wait for this event before doing anything */
dflet 0:e89ba455dbcf 228 while(!_cc3100.IS_IP_ACQUIRED(g_Status,STATUS_BIT_IP_ACQUIRED)) {
dflet 3:b89198ac2efe 229 _cc3100._nonos._SlNonOsMainLoopTask();
dflet 0:e89ba455dbcf 230 }
dflet 0:e89ba455dbcf 231 } else {
dflet 0:e89ba455dbcf 232 printf(" Device couldn't be configured in AP mode \n\r");
dflet 0:e89ba455dbcf 233 LOOP_FOREVER();
dflet 0:e89ba455dbcf 234 }
dflet 0:e89ba455dbcf 235 }
dflet 0:e89ba455dbcf 236
dflet 0:e89ba455dbcf 237 printf(" Ready to configue SSID\r\n");
dflet 0:e89ba455dbcf 238
dflet 0:e89ba455dbcf 239 /* Configure the SSID of the CC3100 */
dflet 3:b89198ac2efe 240 retVal = _cc3100._wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID, strlen(SSID_AP_MODE), (uint8_t *)SSID_AP_MODE);
dflet 0:e89ba455dbcf 241 if(retVal < 0)
dflet 0:e89ba455dbcf 242 LOOP_FOREVER();
dflet 0:e89ba455dbcf 243
dflet 0:e89ba455dbcf 244 SecType = SEC_TYPE_AP_MODE;
dflet 0:e89ba455dbcf 245 /* Configure the Security parameter the AP mode */
dflet 3:b89198ac2efe 246 retVal = _cc3100._wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1, (uint8_t *)&SecType);
dflet 0:e89ba455dbcf 247 if(retVal < 0)
dflet 0:e89ba455dbcf 248 LOOP_FOREVER();
dflet 0:e89ba455dbcf 249
dflet 3:b89198ac2efe 250 retVal = _cc3100._wlan.sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_PASSWORD, strlen(PASSWORD_AP_MODE), (uint8_t *)PASSWORD_AP_MODE);
dflet 0:e89ba455dbcf 251 if(retVal < 0){
dflet 0:e89ba455dbcf 252 LOOP_FOREVER();
dflet 0:e89ba455dbcf 253 }
dflet 0:e89ba455dbcf 254
dflet 3:b89198ac2efe 255 ipV4.ipV4 = _cc3100._netcfg.SL_IPV4_VAL(192,168,0,1);//CONFIG_IP;
dflet 3:b89198ac2efe 256 ipV4.ipV4Mask = _cc3100._netcfg.SL_IPV4_VAL(255,255,255,0);//CONFIG_MASK;
dflet 3:b89198ac2efe 257 ipV4.ipV4Gateway = _cc3100._netcfg.SL_IPV4_VAL(192,168,0,1);//CONFIG_GATEWAY;
dflet 3:b89198ac2efe 258 ipV4.ipV4DnsServer = _cc3100._netcfg.SL_IPV4_VAL(192,168,0,1);//CONFIG_DNS;
dflet 0:e89ba455dbcf 259
dflet 0:e89ba455dbcf 260 /* Configure the Static IP */
dflet 3:b89198ac2efe 261 retVal = _cc3100._netcfg.sl_NetCfgSet(SL_IPV4_AP_P2P_GO_STATIC_ENABLE,1,sizeof(SlNetCfgIpV4Args_t), (uint8_t *)&ipV4);
dflet 0:e89ba455dbcf 262 if(retVal < 0)
dflet 0:e89ba455dbcf 263 LOOP_FOREVER();
dflet 0:e89ba455dbcf 264
dflet 0:e89ba455dbcf 265 dhcpParams.lease_time = IP_LEASE_TIME;
dflet 3:b89198ac2efe 266 dhcpParams.ipv4_addr_start = _cc3100._netcfg.SL_IPV4_VAL(192,168,0,100);//DHCP_START_IP;
dflet 3:b89198ac2efe 267 dhcpParams.ipv4_addr_last = _cc3100._netcfg.SL_IPV4_VAL(192,168,0,200);//DHCP_END_IP;
dflet 0:e89ba455dbcf 268
dflet 3:b89198ac2efe 269 retVal = _cc3100._netapp.sl_NetAppSet(SL_NET_APP_DHCP_SERVER_ID, NETAPP_SET_DHCP_SRV_BASIC_OPT, sizeof(SlNetAppDhcpServerBasicOpt_t), (uint8_t*)&dhcpParams);
dflet 0:e89ba455dbcf 270 if(retVal < 0)
dflet 0:e89ba455dbcf 271 LOOP_FOREVER();
dflet 0:e89ba455dbcf 272
dflet 0:e89ba455dbcf 273 /* Restart the CC3100 */
dflet 0:e89ba455dbcf 274 retVal = _cc3100.sl_Stop(SL_STOP_TIMEOUT);
dflet 0:e89ba455dbcf 275 if(retVal < 0)
dflet 0:e89ba455dbcf 276 LOOP_FOREVER();
dflet 0:e89ba455dbcf 277
dflet 0:e89ba455dbcf 278 g_Status = 0;
dflet 0:e89ba455dbcf 279
dflet 0:e89ba455dbcf 280 role = _cc3100.sl_Start(0, 0, 0);
dflet 0:e89ba455dbcf 281
dflet 0:e89ba455dbcf 282 if (ROLE_AP == role) {
dflet 0:e89ba455dbcf 283 /* If the device is in AP mode, we need to wait for this event before doing anything */
dflet 0:e89ba455dbcf 284 while(!_cc3100.IS_IP_ACQUIRED(g_Status,STATUS_BIT_IP_ACQUIRED)) {
dflet 3:b89198ac2efe 285 _cc3100._nonos._SlNonOsMainLoopTask();
dflet 0:e89ba455dbcf 286 }
dflet 0:e89ba455dbcf 287 } else {
dflet 0:e89ba455dbcf 288 printf(" Device couldn't enter AP mode \n\r");
dflet 0:e89ba455dbcf 289 LOOP_FOREVER();
dflet 0:e89ba455dbcf 290 }
dflet 0:e89ba455dbcf 291 printf(" Device started as Access Point\n\r");
dflet 0:e89ba455dbcf 292
dflet 0:e89ba455dbcf 293 /* Wait */
dflet 0:e89ba455dbcf 294 printf(" Waiting for clients to connect...!\n\r");
dflet 0:e89ba455dbcf 295 while((!_cc3100.IS_IP_LEASED(g_Status,STATUS_BIT_IP_LEASED)) || (!_cc3100.IS_STA_CONNECTED(g_Status,STATUS_BIT_STA_CONNECTED))) {
dflet 3:b89198ac2efe 296 _cc3100._nonos._SlNonOsMainLoopTask();
dflet 0:e89ba455dbcf 297 }
dflet 0:e89ba455dbcf 298 printf(" Client connected to the device \n\r");
dflet 0:e89ba455dbcf 299 printf(" Pinging...! \n\r");
dflet 0:e89ba455dbcf 300
dflet 0:e89ba455dbcf 301 /* Set the ping parameters */
dflet 0:e89ba455dbcf 302 PingParams.PingIntervalTime = PING_INTERVAL;
dflet 0:e89ba455dbcf 303 PingParams.PingSize = PING_SIZE;
dflet 0:e89ba455dbcf 304 PingParams.PingRequestTimeout = PING_TIMEOUT;
dflet 0:e89ba455dbcf 305 PingParams.TotalNumberOfAttempts = PING_ATTEMPTS;
dflet 0:e89ba455dbcf 306 PingParams.Flags = 0;
dflet 0:e89ba455dbcf 307 PingParams.Ip = g_StationIP; /* Fill the station IP address connected to CC3100 */
dflet 0:e89ba455dbcf 308
dflet 0:e89ba455dbcf 309 /* Ping client connected to CC3100 */
dflet 3:b89198ac2efe 310 retVal = _cc3100._netapp.sl_NetAppPingStart((SlPingStartCommand_t*)&PingParams, SL_AF_INET, (SlPingReport_t*)&Report, &SimpleLinkPingReport);
dflet 0:e89ba455dbcf 311 if(retVal < 0)
dflet 0:e89ba455dbcf 312 LOOP_FOREVER();
dflet 0:e89ba455dbcf 313
dflet 0:e89ba455dbcf 314 /* Wait */
dflet 0:e89ba455dbcf 315 while(!_cc3100.IS_PING_DONE(g_Status,STATUS_BIT_PING_DONE)) {
dflet 3:b89198ac2efe 316 _cc3100._nonos._SlNonOsMainLoopTask();
dflet 0:e89ba455dbcf 317 }
dflet 0:e89ba455dbcf 318
dflet 0:e89ba455dbcf 319 if (0 == g_PingPacketsRecv) {
dflet 0:e89ba455dbcf 320 printf(" A STATION couldn't connect to the device \n\r");
dflet 0:e89ba455dbcf 321 //ASSERT_ON_ERROR(LAN_CONNECTION_FAILED);
dflet 0:e89ba455dbcf 322 printf(" ERROR code %d\n\r", LAN_CONNECTION_FAILED);
dflet 0:e89ba455dbcf 323 }
dflet 0:e89ba455dbcf 324
dflet 0:e89ba455dbcf 325 printf(" Device and the station are successfully connected \n\r");
dflet 0:e89ba455dbcf 326 //return SUCCESS;
dflet 0:e89ba455dbcf 327 }
dflet 0:e89ba455dbcf 328
dflet 0:e89ba455dbcf 329 void station_app(void){
dflet 0:e89ba455dbcf 330
dflet 0:e89ba455dbcf 331 int32_t retVal = -1;
dflet 0:e89ba455dbcf 332
dflet 0:e89ba455dbcf 333 /* Connecting to WLAN AP */
dflet 0:e89ba455dbcf 334 retVal = _cc3100.establishConnectionWithAP();
dflet 0:e89ba455dbcf 335 if(retVal < 0)
dflet 0:e89ba455dbcf 336 {
dflet 0:e89ba455dbcf 337 printf(" Failed to establish connection w/ an AP \n\r");
dflet 0:e89ba455dbcf 338 LOOP_FOREVER();
dflet 0:e89ba455dbcf 339 }
dflet 0:e89ba455dbcf 340
dflet 0:e89ba455dbcf 341 printf(" Connection established w/ AP and IP is acquired \n\r");
dflet 0:e89ba455dbcf 342 printf(" Pinging...! \n\r");
dflet 0:e89ba455dbcf 343 retVal = _cc3100.checkLanConnection();
dflet 0:e89ba455dbcf 344 if(retVal < 0)
dflet 0:e89ba455dbcf 345 {
dflet 0:e89ba455dbcf 346 printf(" Device couldn't connect to LAN \n\r");
dflet 0:e89ba455dbcf 347 LOOP_FOREVER();
dflet 0:e89ba455dbcf 348 }
dflet 0:e89ba455dbcf 349
dflet 0:e89ba455dbcf 350 retVal = _cc3100.checkInternetConnection();
dflet 0:e89ba455dbcf 351 if(retVal < 0)
dflet 0:e89ba455dbcf 352 {
dflet 0:e89ba455dbcf 353 printf(" Device couldn't connect to the internet \n\r");
dflet 0:e89ba455dbcf 354 LOOP_FOREVER();
dflet 0:e89ba455dbcf 355 }
dflet 0:e89ba455dbcf 356
dflet 0:e89ba455dbcf 357 printf(" Device successfully connected to the LAN and internet \n\r");
dflet 0:e89ba455dbcf 358 }
dflet 0:e89ba455dbcf 359
dflet 0:e89ba455dbcf 360