Skip to content

Commit 13dbb67

Browse files
authored
Merge pull request #5649 from Archcady/realtek-PR-master
Fix greentea test mbed-os-tests-netsocket-connectivity
2 parents 227b034 + a4ce936 commit 13dbb67

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ typedef struct _wifi_scan_hdl {
3636

3737
#define MAX_SCAN_TIMEOUT (15000)
3838

39+
static bool _inited = false;
40+
3941
static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
4042
{
4143
wifi_scan_hdl *scan_handler = (wifi_scan_hdl *)malloced_scan_result->user_data;
4244
if (malloced_scan_result->scan_complete != RTW_TRUE) {
4345
if(scan_handler->ap_details && scan_handler->scan_num > scan_handler->ap_num){
44-
nsapi_wifi_ap_t ap;
46+
nsapi_wifi_ap_t ap;
4547
rtw_scan_result_t* record = &malloced_scan_result->ap_details;
46-
record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
48+
record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
4749
memset((void*)&ap, 0x00, sizeof(nsapi_wifi_ap_t));
4850
memcpy(ap.ssid, record->SSID.val, record->SSID.len);
4951
memcpy(ap.bssid, record->BSSID.octet, 6);
@@ -88,7 +90,7 @@ RTWInterface::RTWInterface(bool debug)
8890
{
8991
emac_interface_t *emac;
9092
int ret;
91-
extern u32 GlobalDebugEnable;
93+
extern u32 GlobalDebugEnable;
9294

9395
GlobalDebugEnable = debug?1:0;
9496
emac = wlan_emac_init_interface();
@@ -97,10 +99,13 @@ RTWInterface::RTWInterface(bool debug)
9799
return;
98100
}
99101
emac->ops.power_up(emac);
100-
ret = mbed_lwip_init(emac);
101-
if (ret != 0) {
102-
printf("Error init RTWInterface!(%d)\r\n", ret);
103-
return;
102+
if (_inited == false) {
103+
ret = mbed_lwip_init(emac);
104+
if (ret != 0) {
105+
printf("Error init RTWInterface!(%d)\r\n", ret);
106+
return;
107+
}
108+
_inited = true;
104109
}
105110
}
106111

@@ -177,7 +182,7 @@ nsapi_error_t RTWInterface::connect()
177182
break;
178183
case NSAPI_SECURITY_NONE:
179184
sec = RTW_SECURITY_OPEN;
180-
break;
185+
break;
181186
default:
182187
return NSAPI_ERROR_PARAMETER;
183188
}
@@ -186,7 +191,7 @@ nsapi_error_t RTWInterface::connect()
186191
uint8_t pscan_config = PSCAN_ENABLE;
187192
wifi_set_pscan_chan(&_channel, &pscan_config, 1);
188193
}
189-
194+
190195
ret = wifi_connect(_ssid, sec, _pass, strlen(_ssid), strlen(_pass), 0, (void *)NULL);
191196
if (ret != RTW_SUCCESS) {
192197
printf("failed: %d\r\n", ret);
@@ -237,7 +242,7 @@ int8_t RTWInterface::get_rssi()
237242
}
238243

239244
nsapi_error_t RTWInterface::connect(const char *ssid, const char *pass,
240-
nsapi_security_t security, uint8_t channel)
245+
nsapi_security_t security, uint8_t channel)
241246
{
242247
set_credentials(ssid, pass, security);
243248
set_channel(channel);
@@ -249,9 +254,10 @@ nsapi_error_t RTWInterface::disconnect()
249254
char essid[33];
250255

251256
wlan_emac_link_change(false);
257+
mbed_lwip_bringdown();
252258
if(wifi_is_connected_to_ap() != RTW_SUCCESS)
253259
return NSAPI_ERROR_NO_CONNECTION;
254-
if(wifi_disconnect()<0){
260+
if(wifi_disconnect()<0){
255261
return NSAPI_ERROR_DEVICE_ERROR;
256262
}
257263
while(1){

0 commit comments

Comments
 (0)