update to lwip_stack issue

pull/4438/head
Yuguo Zou 2017-03-23 18:57:41 +08:00 committed by Martin Kojtal
parent de8f2ad1f1
commit d96de9c21a
7 changed files with 84 additions and 19 deletions

View File

@ -27,6 +27,10 @@
#include "osdep_service.h"
struct netif *xnetif[2];
static struct netif lwap_netif;
extern struct netif *netif_default;
RTWInterface::RTWInterface()
: _dhcp(true), _ip_address(), _netmask(), _gateway()
{
@ -38,9 +42,9 @@ RTWInterface::RTWInterface()
}
static void *scan_sema;
static const signed int maxApNum = 4;
static signed int ApNum;
static WiFiAccessPoint *SCANED_AP[15]; /*maximum store 15 APs*/
static WiFiAccessPoint *SCANED_AP[maxApNum]; /*maximum store 15 APs*/
nsapi_error_t RTWInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
{
@ -67,13 +71,13 @@ nsapi_error_t RTWInterface::init()
if (!emac) {
return NSAPI_ERROR_DEVICE_ERROR;
}
emac->ops.power_up(emac);
//printf("Initializing lwip ...\r\n");
ret = mbed_lwip_init(emac);
if (ret != 0) {
return ret;
}
xnetif[0] = netif_default;
return NSAPI_ERROR_OK;
}
@ -134,7 +138,7 @@ static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_sca
if (malloced_scan_result->scan_complete != RTW_TRUE) {
rtw_scan_result_t* record = &malloced_scan_result->ap_details;
record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
if(ApNum>15)
if(ApNum>maxApNum)
return RTW_SUCCESS;
nsapi_wifi_ap_t ap;
@ -167,20 +171,24 @@ nsapi_error_t RTWInterface::scan(WiFiAccessPoint *res, unsigned count)
// blocked
if(count == 0){
ApNum = 0;
rtw_init_sema(&scan_sema, 0);
if(wifi_scan_networks(scan_result_handler, NULL) != RTW_SUCCESS){
printf("wifi scan failed\n\r");
return NSAPI_ERROR_DEVICE_ERROR;
//return NSAPI_ERROR_DEVICE_ERROR;
goto error;
}
if(rtw_down_timeout_sema( &scan_sema, 15000 ) == RTW_FALSE) {
printf("wifi scan timeout\r\n");
return NSAPI_ERROR_DEVICE_ERROR;
//return NSAPI_ERROR_DEVICE_ERROR;
goto error;
}
rtw_free_sema(&scan_sema);
return ApNum;
}else if(count > 0 && res != NULL){
count = count < 15 ? count : 15;
}else if(count > 0 && res != NULL){
count = count < maxApNum ? count : maxApNum;
for(int i = 0; i < count; i++){
memcpy(&res[i], SCANED_AP[i], sizeof(WiFiAccessPoint));
delete[] SCANED_AP[i];
@ -188,6 +196,9 @@ nsapi_error_t RTWInterface::scan(WiFiAccessPoint *res, unsigned count)
return (signed int)count;
}
return NSAPI_ERROR_OK;
error:
rtw_free_sema(&scan_sema);
return NSAPI_ERROR_DEVICE_ERROR;
}
nsapi_error_t RTWInterface::set_channel(uint8_t channel)

View File

@ -25,8 +25,8 @@ define symbol __ICFEDIT_region_SDRAM_RAM_start__ = 0x30000000;
define symbol __ICFEDIT_region_SDRAM_RAM_end__ = 0x301FFFFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x2000; // 8K
define symbol __ICFEDIT_size_heap__ = 0x8000; // 60K
define symbol __ICFEDIT_size_cstack__ = 0x1000;
define symbol __ICFEDIT_size_heap__ = 0x10000;
/**** End of ICF editor section. ###ICF###*/

View File

@ -36,10 +36,12 @@ static emac_link_state_change_fn link_state_cb;
static void *link_input_data;
static void *link_state_data;
#if 0
struct netif *xnetif[2];
extern struct netif lwip_netif;
static struct netif lwap_netif;
extern uint8_t *netif_get_hwaddr(int idx);
#endif
static uint32_t wlan_get_mtu_size(emac_interface_t *emac)
{
@ -59,6 +61,7 @@ static uint8_t wlan_get_hwaddr_size(emac_interface_t *emac)
static void wlan_get_hwaddr(emac_interface_t *emac, uint8_t *addr)
{
#if 0
uint8_t *hwaddr;
hwaddr = netif_get_hwaddr(0);
@ -67,6 +70,16 @@ static void wlan_get_hwaddr(emac_interface_t *emac, uint8_t *addr)
}
memcpy(addr, hwaddr, ETHARP_HWADDR_LEN);
#else
char mac[20];
if(RTW_SUCCESS == wifi_get_mac_address(mac))
{
if (sscanf(mac, "%x:%x:%x:%x:%x:%x", &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6)
printf("Get HW address failed\r\n");
}else{
printf("Get HW address failed\r\n");
}
#endif
}
static void wlan_set_hwaddr(emac_interface_t *emac, uint8_t *addr)
@ -196,9 +209,21 @@ void mbed_default_mac_address(char *mac) {
void mbed_mac_address(char *mac)
{
#if 0
//wlan_get_hwaddr((emac_interface_t *)NULL, (uint8_t *)mac);
mbed_default_mac_address(mac);
#else
char hwaddr[20];
if(RTW_SUCCESS == wifi_get_mac_address(hwaddr))
{
if (sscanf(hwaddr, "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 6)
printf("Get HW address failed\r\n");
}else{
printf("Get HW address failed\r\n");
}
#endif
}
void wlan_emac_link_down(uint8_t i)
@ -207,7 +232,7 @@ void wlan_emac_link_down(uint8_t i)
return;
}
xnetif[i]->flags &= ~NETIF_FLAG_LINK_UP;
//xnetif[i]->flags &= ~NETIF_FLAG_LINK_UP;
if (link_state_cb) {
link_state_cb(link_state_data, false);
}
@ -219,7 +244,7 @@ void wlan_emac_link_up(uint8_t i)
return;
}
xnetif[i]->flags |= NETIF_FLAG_LINK_UP;
//xnetif[i]->flags |= NETIF_FLAG_LINK_UP;
if (link_state_cb) {
link_state_cb(link_state_data, true);
}
@ -231,9 +256,10 @@ void wlan_emac_init_mem(void)
emac_interface_t *wlan_emac_init_interface()
{
#if 0
xnetif[0] = &lwip_netif;
xnetif[1] = &lwap_netif;
#endif
if (_emac == NULL) {
_emac = new emac_interface_t();
_emac->hw = NULL;

View File

@ -43,6 +43,13 @@
#include <stdint.h>
#include "diag.h"
#define strsep(str, delim) _strsep(str, delim)
#elif defined (__CC_ARM)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "diag.h"
#define strsep(str, delim) _strsep(str, delim)
#else
#include <stdio.h>

View File

@ -60,9 +60,12 @@ extern int inic_stop(void);
/******************************************************
* Variables Declarations
******************************************************/
#if DEVICE_EMAC
extern struct netif *xnetif[];
#else
extern struct netif xnetif[NET_IF_NUM];
#endif
/******************************************************
* Variables Definitions
******************************************************/
@ -969,11 +972,14 @@ int wifi_on(rtw_mode_t mode)
}
#if CONFIG_LWIP_LAYER
#if DEVICE_EMAC
#else
netif_set_up(&xnetif[0]);
if(mode == RTW_MODE_STA_AP) {
netif_set_up(&xnetif[1]);
}
#endif
#endif
#if CONFIG_INIC_EN
inic_start();
@ -999,9 +1005,14 @@ int wifi_off(void)
#else
LwIP_DHCP(0, DHCP_STOP);
#endif
#if DEVICE_EMAC
netif_set_down(xnetif[0]);
netif_set_down(xnetif[1]);
#else
netif_set_down(&xnetif[0]);
netif_set_down(&xnetif[1]);
#endif
#endif
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
if((wifi_mode == RTW_MODE_AP) || (wifi_mode == RTW_MODE_STA_AP))
wpas_wps_deinit();
@ -1670,7 +1681,11 @@ int wifi_restart_ap(
ip_addr_t ipaddr;
ip_addr_t netmask;
ip_addr_t gw;
#if DEVICE_EMAC
struct netif * pnetif = xnetif[0];
#else
struct netif * pnetif = &xnetif[0];
#endif
#ifdef CONFIG_CONCURRENT_MODE
rtw_wifi_setting_t setting;
int sta_linked = 0;
@ -1736,9 +1751,13 @@ int wifi_restart_ap(
#if (INCLUDE_uxTaskGetStackHighWaterMark == 1)
printf("\r\nWebServer Thread: High Water Mark is %ld\n", uxTaskGetStackHighWaterMark(NULL));
#endif
#if DEVICE_EMAC
// start dhcp server
dhcps_init(xnetif[idx]);
#else
// start dhcp server
dhcps_init(&xnetif[idx]);
#endif
return 0;
}

View File

@ -55,7 +55,8 @@ void rltk_wlan_set_netif_info(int idx_wlan, void * dev, unsigned char * dev_addr
{
#if (CONFIG_LWIP_LAYER == 1)
#if DEVICE_EMAC
rtw_memcpy(xnetif[idx_wlan]->hwaddr, dev_addr, 6);
//rtw_memcpy(xnetif[idx_wlan]->hwaddr, dev_addr, 6);
//set netif hwaddr later
#else
rtw_memcpy(xnetif[idx_wlan].hwaddr, dev_addr, 6);
xnetif[idx_wlan].state = dev;
@ -158,6 +159,7 @@ int netif_is_valid_IP(int idx, unsigned char *ip_dest)
#if CONFIG_LWIP_LAYER == 1
#if DEVICE_EMAC
struct netif *pnetif = xnetif[idx];
return 1;
#else
struct netif *pnetif = &xnetif[idx];
#endif

View File

@ -100,7 +100,7 @@ u8* _rtx_malloc(u32 sz)
{
_func_enter_;
void *p = NULL;
p = malloc(sz);
p = (void *)malloc(sz);
if(p != NULL){
#if USE_HEAP_INFO
osFreeBytesRemaining-=sz;