Skip to content

Commit af2d40a

Browse files
authored
Merge pull request ARMmbed#67 from linlingao/debug_dns
Rewrite code to put semaphore in a class
2 parents a0ca638 + 15bf819 commit af2d40a

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@
1717
#include "cc3200_simplelink.h"
1818
#include "CC3220SF_WiFiInterface.h"
1919

20-
Semaphore connect_sem(0, 1);
21-
Semaphore ip_set_sem(0, 1);
2220
#define CONNECT_TIMEOUT_MS 2000
2321
#define IP_SET_TIMEOUT_MS 2000
22+
CC3220SFInterface * CC3220SFInterface::cc3200sf_wifi_instance;
2423

2524
CC3220SFInterface::CC3220SFInterface():
2625
_initialized(false),
27-
_started(false)
26+
_started(false),
27+
_connect_sem(0, 1),
28+
_ip_set_sem(0, 1)
2829
{
2930
//memset(_cbs, 0, sizeof(_cbs));
3031
memset(_ssid, 0, sizeof(_ssid));
3132
memset(_pass, 0, sizeof(_pass));
3233
_security = NSAPI_SECURITY_UNKNOWN;
34+
cc3200sf_wifi_instance = this;
3335
_cc3200_simplelink.initialize();
3436
}
3537

@@ -85,11 +87,11 @@ nsapi_error_t CC3220SFInterface::connect()
8587
}
8688

8789
// Connect is async call. Wait till connection completes
88-
if (connect_sem.wait(CONNECT_TIMEOUT_MS) != 1)
90+
if (_connect_sem.wait(CONNECT_TIMEOUT_MS) != 1)
8991
{
9092
printf("Connection timed out\n");
9193
}
92-
if (ip_set_sem.wait(IP_SET_TIMEOUT_MS) != 1)
94+
if (_ip_set_sem.wait(IP_SET_TIMEOUT_MS) != 1)
9395
{
9496
printf("IP address set timed out\n");
9597
}
@@ -131,8 +133,8 @@ nsapi_error_t CC3220SFInterface::set_credentials(const char *ssid, const char *p
131133
}
132134
}
133135

134-
strncpy(_ssid, ssid, 255);;
135-
strncpy(_pass, pass, 255);
136+
strncpy(_ssid, ssid, sizeof(_ssid));
137+
strncpy(_pass, pass, sizeof(_pass));
136138
_security = security;
137139

138140
return NSAPI_ERROR_OK;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,5 +339,10 @@ class CC3220SFInterface: public NetworkStack, public WiFiInterface
339339

340340
nsapi_error_t _init(void);
341341
nsapi_error_t _startup(const int8_t wifi_mode);
342+
Semaphore _connect_sem;
343+
Semaphore _ip_set_sem;
344+
static CC3220SFInterface * cc3200sf_wifi_instance;
345+
friend void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent);
346+
friend void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent);
342347
};
343348
#endif

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@
5353
#include <stdarg.h>
5454
#include "rtos.h"
5555

56+
#include <CC3220SF_WiFiInterface.h>
5657
#include <ti/drivers/net/wifi/simplelink.h>
5758

58-
extern Semaphore connect_sem;
59-
extern Semaphore ip_set_sem;
60-
6159
#define HANDLER_TRACE_ENABLE 0
6260

6361
/****************************************************************************
@@ -119,8 +117,8 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
119117
pWlanEvent->Data.Connect.Bssid[3],pWlanEvent->Data.Connect.Bssid[4],
120118
pWlanEvent->Data.Connect.Bssid[5]);
121119
#endif
122-
connect_sem.release();
123-
}
120+
CC3220SFInterface::cc3200sf_wifi_instance->_connect_sem.release();
121+
}
124122
break;
125123

126124
case SL_WLAN_EVENT_DISCONNECT:
@@ -283,7 +281,7 @@ void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
283281
(unsigned int)SL_IPV4_BYTE(pEventData->Gateway,1),
284282
(unsigned int)SL_IPV4_BYTE(pEventData->Gateway,0));
285283
#endif
286-
ip_set_sem.release();
284+
CC3220SFInterface::cc3200sf_wifi_instance->_ip_set_sem.release();
287285
}
288286
break;
289287

0 commit comments

Comments
 (0)