Skip to content

Commit 633888d

Browse files
committed
update to lwip_stack issue
1 parent ac00d7c commit 633888d

File tree

7 files changed

+84
-19
lines changed

7 files changed

+84
-19
lines changed

targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727

2828
#include "osdep_service.h"
2929

30+
struct netif *xnetif[2];
31+
static struct netif lwap_netif;
32+
extern struct netif *netif_default;
33+
3034
RTWInterface::RTWInterface()
3135
: _dhcp(true), _ip_address(), _netmask(), _gateway()
3236
{
@@ -38,9 +42,9 @@ RTWInterface::RTWInterface()
3842
}
3943

4044
static void *scan_sema;
41-
45+
static const signed int maxApNum = 4;
4246
static signed int ApNum;
43-
static WiFiAccessPoint *SCANED_AP[15]; /*maximum store 15 APs*/
47+
static WiFiAccessPoint *SCANED_AP[maxApNum]; /*maximum store 15 APs*/
4448

4549
nsapi_error_t RTWInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
4650
{
@@ -67,13 +71,13 @@ nsapi_error_t RTWInterface::init()
6771
if (!emac) {
6872
return NSAPI_ERROR_DEVICE_ERROR;
6973
}
70-
74+
emac->ops.power_up(emac);
7175
//printf("Initializing lwip ...\r\n");
7276
ret = mbed_lwip_init(emac);
7377
if (ret != 0) {
7478
return ret;
7579
}
76-
80+
xnetif[0] = netif_default;
7781
return NSAPI_ERROR_OK;
7882
}
7983

@@ -134,7 +138,7 @@ static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_sca
134138
if (malloced_scan_result->scan_complete != RTW_TRUE) {
135139
rtw_scan_result_t* record = &malloced_scan_result->ap_details;
136140
record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
137-
if(ApNum>15)
141+
if(ApNum>maxApNum)
138142
return RTW_SUCCESS;
139143
nsapi_wifi_ap_t ap;
140144

@@ -167,27 +171,34 @@ nsapi_error_t RTWInterface::scan(WiFiAccessPoint *res, unsigned count)
167171
// blocked
168172
if(count == 0){
169173
ApNum = 0;
170-
174+
171175
rtw_init_sema(&scan_sema, 0);
172176
if(wifi_scan_networks(scan_result_handler, NULL) != RTW_SUCCESS){
173177
printf("wifi scan failed\n\r");
174-
return NSAPI_ERROR_DEVICE_ERROR;
178+
//return NSAPI_ERROR_DEVICE_ERROR;
179+
goto error;
175180
}
176181

177182
if(rtw_down_timeout_sema( &scan_sema, 15000 ) == RTW_FALSE) {
178183
printf("wifi scan timeout\r\n");
179-
return NSAPI_ERROR_DEVICE_ERROR;
184+
//return NSAPI_ERROR_DEVICE_ERROR;
185+
goto error;
180186
}
187+
rtw_free_sema(&scan_sema);
181188
return ApNum;
182-
}else if(count > 0 && res != NULL){
183-
count = count < 15 ? count : 15;
189+
190+
}else if(count > 0 && res != NULL){
191+
count = count < maxApNum ? count : maxApNum;
184192
for(int i = 0; i < count; i++){
185193
memcpy(&res[i], SCANED_AP[i], sizeof(WiFiAccessPoint));
186194
delete[] SCANED_AP[i];
187195
}
188196
return (signed int)count;
189197
}
190198
return NSAPI_ERROR_OK;
199+
error:
200+
rtw_free_sema(&scan_sema);
201+
return NSAPI_ERROR_DEVICE_ERROR;
191202
}
192203

193204
nsapi_error_t RTWInterface::set_channel(uint8_t channel)

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/rtl8195a.icf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ define symbol __ICFEDIT_region_SDRAM_RAM_start__ = 0x30000000;
2525
define symbol __ICFEDIT_region_SDRAM_RAM_end__ = 0x301FFFFF;
2626

2727
/*-Sizes-*/
28-
define symbol __ICFEDIT_size_cstack__ = 0x2000; // 8K
29-
define symbol __ICFEDIT_size_heap__ = 0x8000; // 60K
28+
define symbol __ICFEDIT_size_cstack__ = 0x1000;
29+
define symbol __ICFEDIT_size_heap__ = 0x10000;
3030
/**** End of ICF editor section. ###ICF###*/
3131

3232

targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ static emac_link_state_change_fn link_state_cb;
3636
static void *link_input_data;
3737
static void *link_state_data;
3838

39+
#if 0
3940
struct netif *xnetif[2];
4041
extern struct netif lwip_netif;
4142
static struct netif lwap_netif;
4243
extern uint8_t *netif_get_hwaddr(int idx);
44+
#endif
4345

4446
static uint32_t wlan_get_mtu_size(emac_interface_t *emac)
4547
{
@@ -59,6 +61,7 @@ static uint8_t wlan_get_hwaddr_size(emac_interface_t *emac)
5961

6062
static void wlan_get_hwaddr(emac_interface_t *emac, uint8_t *addr)
6163
{
64+
#if 0
6265
uint8_t *hwaddr;
6366

6467
hwaddr = netif_get_hwaddr(0);
@@ -67,6 +70,16 @@ static void wlan_get_hwaddr(emac_interface_t *emac, uint8_t *addr)
6770
}
6871

6972
memcpy(addr, hwaddr, ETHARP_HWADDR_LEN);
73+
#else
74+
char mac[20];
75+
if(RTW_SUCCESS == wifi_get_mac_address(mac))
76+
{
77+
if (sscanf(mac, "%x:%x:%x:%x:%x:%x", &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6)
78+
printf("Get HW address failed\r\n");
79+
}else{
80+
printf("Get HW address failed\r\n");
81+
}
82+
#endif
7083
}
7184

7285
static void wlan_set_hwaddr(emac_interface_t *emac, uint8_t *addr)
@@ -196,9 +209,21 @@ void mbed_default_mac_address(char *mac) {
196209

197210
void mbed_mac_address(char *mac)
198211
{
212+
#if 0
199213
//wlan_get_hwaddr((emac_interface_t *)NULL, (uint8_t *)mac);
200214

201215
mbed_default_mac_address(mac);
216+
#else
217+
char hwaddr[20];
218+
219+
if(RTW_SUCCESS == wifi_get_mac_address(hwaddr))
220+
{
221+
if (sscanf(hwaddr, "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 6)
222+
printf("Get HW address failed\r\n");
223+
}else{
224+
printf("Get HW address failed\r\n");
225+
}
226+
#endif
202227
}
203228

204229
void wlan_emac_link_down(uint8_t i)
@@ -207,7 +232,7 @@ void wlan_emac_link_down(uint8_t i)
207232
return;
208233
}
209234

210-
xnetif[i]->flags &= ~NETIF_FLAG_LINK_UP;
235+
//xnetif[i]->flags &= ~NETIF_FLAG_LINK_UP;
211236
if (link_state_cb) {
212237
link_state_cb(link_state_data, false);
213238
}
@@ -219,7 +244,7 @@ void wlan_emac_link_up(uint8_t i)
219244
return;
220245
}
221246

222-
xnetif[i]->flags |= NETIF_FLAG_LINK_UP;
247+
//xnetif[i]->flags |= NETIF_FLAG_LINK_UP;
223248
if (link_state_cb) {
224249
link_state_cb(link_state_data, true);
225250
}
@@ -231,9 +256,10 @@ void wlan_emac_init_mem(void)
231256

232257
emac_interface_t *wlan_emac_init_interface()
233258
{
259+
#if 0
234260
xnetif[0] = &lwip_netif;
235261
xnetif[1] = &lwap_netif;
236-
262+
#endif
237263
if (_emac == NULL) {
238264
_emac = new emac_interface_t();
239265
_emac->hw = NULL;

targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/platform/platform_stdlib.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@
4343
#include <stdint.h>
4444
#include "diag.h"
4545

46+
#define strsep(str, delim) _strsep(str, delim)
47+
#elif defined (__CC_ARM)
48+
#include <stdio.h>
49+
#include <stdlib.h>
50+
#include <string.h>
51+
#include <stdint.h>
52+
#include "diag.h"
4653
#define strsep(str, delim) _strsep(str, delim)
4754
#else
4855
#include <stdio.h>

targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ extern int inic_stop(void);
6060
/******************************************************
6161
* Variables Declarations
6262
******************************************************/
63+
#if DEVICE_EMAC
64+
extern struct netif *xnetif[];
6365

66+
#else
6467
extern struct netif xnetif[NET_IF_NUM];
65-
68+
#endif
6669
/******************************************************
6770
* Variables Definitions
6871
******************************************************/
@@ -969,11 +972,14 @@ int wifi_on(rtw_mode_t mode)
969972
}
970973

971974
#if CONFIG_LWIP_LAYER
975+
#if DEVICE_EMAC
976+
#else
972977
netif_set_up(&xnetif[0]);
973978
if(mode == RTW_MODE_STA_AP) {
974979
netif_set_up(&xnetif[1]);
975980
}
976981
#endif
982+
#endif
977983

978984
#if CONFIG_INIC_EN
979985
inic_start();
@@ -999,9 +1005,14 @@ int wifi_off(void)
9991005
#else
10001006
LwIP_DHCP(0, DHCP_STOP);
10011007
#endif
1008+
#if DEVICE_EMAC
1009+
netif_set_down(xnetif[0]);
1010+
netif_set_down(xnetif[1]);
1011+
#else
10021012
netif_set_down(&xnetif[0]);
10031013
netif_set_down(&xnetif[1]);
10041014
#endif
1015+
#endif
10051016
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
10061017
if((wifi_mode == RTW_MODE_AP) || (wifi_mode == RTW_MODE_STA_AP))
10071018
wpas_wps_deinit();
@@ -1670,7 +1681,11 @@ int wifi_restart_ap(
16701681
ip_addr_t ipaddr;
16711682
ip_addr_t netmask;
16721683
ip_addr_t gw;
1684+
#if DEVICE_EMAC
1685+
struct netif * pnetif = xnetif[0];
1686+
#else
16731687
struct netif * pnetif = &xnetif[0];
1688+
#endif
16741689
#ifdef CONFIG_CONCURRENT_MODE
16751690
rtw_wifi_setting_t setting;
16761691
int sta_linked = 0;
@@ -1736,9 +1751,13 @@ int wifi_restart_ap(
17361751
#if (INCLUDE_uxTaskGetStackHighWaterMark == 1)
17371752
printf("\r\nWebServer Thread: High Water Mark is %ld\n", uxTaskGetStackHighWaterMark(NULL));
17381753
#endif
1754+
#if DEVICE_EMAC
1755+
// start dhcp server
1756+
dhcps_init(xnetif[idx]);
1757+
#else
17391758
// start dhcp server
17401759
dhcps_init(&xnetif[idx]);
1741-
1760+
#endif
17421761
return 0;
17431762
}
17441763

targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ void rltk_wlan_set_netif_info(int idx_wlan, void * dev, unsigned char * dev_addr
5555
{
5656
#if (CONFIG_LWIP_LAYER == 1)
5757
#if DEVICE_EMAC
58-
rtw_memcpy(xnetif[idx_wlan]->hwaddr, dev_addr, 6);
58+
//rtw_memcpy(xnetif[idx_wlan]->hwaddr, dev_addr, 6);
59+
//set netif hwaddr later
5960
#else
6061
rtw_memcpy(xnetif[idx_wlan].hwaddr, dev_addr, 6);
6162
xnetif[idx_wlan].state = dev;
@@ -158,6 +159,7 @@ int netif_is_valid_IP(int idx, unsigned char *ip_dest)
158159
#if CONFIG_LWIP_LAYER == 1
159160
#if DEVICE_EMAC
160161
struct netif *pnetif = xnetif[idx];
162+
return 1;
161163
#else
162164
struct netif *pnetif = &xnetif[idx];
163165
#endif

targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/rtx/rtx_service.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ u8* _rtx_malloc(u32 sz)
100100
{
101101
_func_enter_;
102102
void *p = NULL;
103-
p = malloc(sz);
103+
p = (void *)malloc(sz);
104104
if(p != NULL){
105105
#if USE_HEAP_INFO
106106
osFreeBytesRemaining-=sz;

0 commit comments

Comments
 (0)