From 08489e4f18e481b48b9116d9dbe4a0bcf662f541 Mon Sep 17 00:00:00 2001 From: Yuguo Zou Date: Mon, 3 Apr 2017 18:31:43 +0800 Subject: [PATCH] Fix on Wifi --- .../TARGET_AMEBA/RTWInterface.cpp | 259 ++++++++-------- .../TARGET_AMEBA/RTWInterface.h | 7 +- .../device/TOOLCHAIN_IAR/rtl8195a.icf | 286 ++++++++---------- .../TARGET_Realtek/TARGET_AMEBA/rtw_emac.cpp | 71 +---- .../TARGET_Realtek/TARGET_AMEBA/rtw_emac.h | 5 +- .../sdk/common/api/wifi/wifi_conf.c | 15 +- .../wlan/realtek/src/osdep/lwip_intf.c | 44 ++- 7 files changed, 293 insertions(+), 394 deletions(-) diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp b/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp index 4219ef9b2c..766a026489 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp +++ b/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp @@ -27,24 +27,86 @@ #include "osdep_service.h" -struct netif *xnetif[2]; -static struct netif lwap_netif; -extern struct netif *netif_default; +typedef struct _wifi_scan_hdl { + int scan_num; + WiFiAccessPoint *ap_details; +} wifi_scan_hdl; + +#define MAX_SCAN_TIMEOUT (15000) +static void *scan_sema = NULL; +static signed int ApNum = 0; + +static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result ) +{ + if (malloced_scan_result->scan_complete != RTW_TRUE) { + wifi_scan_hdl *scan_handler = (wifi_scan_hdl *)malloced_scan_result->user_data; + if(scan_handler->ap_details && scan_handler->scan_num > ApNum){ + nsapi_wifi_ap_t ap; + rtw_scan_result_t* record = &malloced_scan_result->ap_details; + record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */ + memset((void*)&ap, 0x00, sizeof(nsapi_wifi_ap_t)); + memcpy(ap.ssid, record->SSID.val, record->SSID.len); + memcpy(ap.bssid, record->BSSID.octet, 6); + switch (record->security){ + case RTW_SECURITY_OPEN: + ap.security = NSAPI_SECURITY_NONE; + break; + case RTW_SECURITY_WEP_PSK: + case RTW_SECURITY_WEP_SHARED: + ap.security = NSAPI_SECURITY_WEP; + break; + case RTW_SECURITY_WPA_TKIP_PSK: + case RTW_SECURITY_WPA_AES_PSK: + ap.security = NSAPI_SECURITY_WPA; + break; + case RTW_SECURITY_WPA2_AES_PSK: + case RTW_SECURITY_WPA2_TKIP_PSK: + case RTW_SECURITY_WPA2_MIXED_PSK: + ap.security = NSAPI_SECURITY_WPA2; + break; + case RTW_SECURITY_WPA_WPA2_MIXED: + ap.security = NSAPI_SECURITY_WPA_WPA2; + break; + default: + ap.security = NSAPI_SECURITY_UNKNOWN; + break; + } + ap.rssi = record->signal_strength; + ap.channel = record->channel; + WiFiAccessPoint *accesspoint = new WiFiAccessPoint(ap); + memcpy(&scan_handler->ap_details[ApNum], accesspoint, sizeof(WiFiAccessPoint)); + delete[] accesspoint; + } + ApNum++; + } else{ + // scan done + rtw_up_sema(&scan_sema); + } + return RTW_SUCCESS; +} RTWInterface::RTWInterface() : _dhcp(true), _ip_address(), _netmask(), _gateway() { - nsapi_error_t ret; - ret = init(); - if (ret != NSAPI_ERROR_OK){ - printf("Error init RTWInterface!(%d)\r\n", ret); - } + emac_interface_t *emac; + int ret; + + emac = wlan_emac_init_interface(); + if (!emac) { + printf("Error init RTWInterface!\r\n"); + } + emac->ops.power_up(emac); + ret = mbed_lwip_init(emac); + if (ret != 0) { + printf("Error init RTWInterface!(%d)\r\n", ret); + } } -static void *scan_sema; -static const signed int maxApNum = 4; -static signed int ApNum; -static WiFiAccessPoint *SCANED_AP[maxApNum]; /*maximum store 15 APs*/ +RTWInterface::~RTWInterface() +{ + wlan_emac_link_change(false); + mbed_lwip_bringdown(); +} nsapi_error_t RTWInterface::set_network(const char *ip_address, const char *netmask, const char *gateway) { @@ -61,31 +123,6 @@ nsapi_error_t RTWInterface::set_dhcp(bool dhcp) return NSAPI_ERROR_OK; } -nsapi_error_t RTWInterface::init() -{ - emac_interface_t *emac; - int ret; - - //printf("\r\nInitializing emac ...\r\n"); - emac = wlan_emac_init_interface(); - 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; -} - -nsapi_error_t RTWInterface::deinit() -{ - return mbed_lwip_bringdown(); -} - /* * we may call connect multiple times */ @@ -109,16 +146,27 @@ nsapi_error_t RTWInterface::connect() } switch (_security) { - case NSAPI_SECURITY_WPA2: - sec = RTW_SECURITY_WPA2_MIXED_PSK; - break; - case NSAPI_SECURITY_NONE: - default: - sec = RTW_SECURITY_OPEN; - break; + case NSAPI_SECURITY_WPA: + case NSAPI_SECURITY_WPA2: + case NSAPI_SECURITY_WPA_WPA2: + sec = RTW_SECURITY_WPA_WPA2_MIXED; + break; + case NSAPI_SECURITY_WEP: + sec = RTW_SECURITY_WEP_PSK; + break; + case NSAPI_SECURITY_NONE: + sec = RTW_SECURITY_OPEN; + break; + default: + return NSAPI_ERROR_PARAMETER; } - printf("Connecting to: %s ... \r\n", _ssid); + if(_channel > 0 && _channel < 14){ + uint8_t pscan_config = PSCAN_ENABLE; + wifi_set_pscan_chan(&_channel, &pscan_config, 1); + } + + //printf("Connecting to: %s ... \r\n", _ssid); ret = wifi_connect(_ssid, sec, _pass, strlen(_ssid), strlen(_pass), 0, (void *)NULL); if (ret != RTW_SUCCESS) { printf("failed: %d\r\n", ret); @@ -126,117 +174,74 @@ nsapi_error_t RTWInterface::connect() } //printf("connected\r\n"); - wlan_emac_link_up(0); + wlan_emac_link_change(true); return mbed_lwip_bringup(_dhcp, _ip_address[0] ? _ip_address : 0, _netmask[0] ? _netmask : 0, _gateway[0] ? _gateway : 0); } -static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result ) -{ - 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>maxApNum) - return RTW_SUCCESS; - nsapi_wifi_ap_t ap; - - memset((void*)&ap, 0x00, sizeof(nsapi_wifi_ap_t)); - memcpy(ap.ssid, record->SSID.val, record->SSID.len); - memcpy(ap.bssid, record->BSSID.octet, 6); - ap.security = (record->security == RTW_SECURITY_OPEN)?NSAPI_SECURITY_NONE : - (record->security == RTW_SECURITY_WEP_PSK)?NSAPI_SECURITY_WEP: - (record->security == RTW_SECURITY_WPA_TKIP_PSK || record->security == RTW_SECURITY_WPA_AES_PSK)? NSAPI_SECURITY_WPA: - (record->security == RTW_SECURITY_WPA2_AES_PSK || \ - record->security == RTW_SECURITY_WPA2_TKIP_PSK || \ - record->security == RTW_SECURITY_WPA2_MIXED_PSK)?NSAPI_SECURITY_WPA2: - (record->security == RTW_SECURITY_WPA_WPA2_MIXED)?NSAPI_SECURITY_WPA_WPA2:NSAPI_SECURITY_UNKNOWN; - ap.rssi = record->signal_strength; - ap.channel = record->channel; - - - SCANED_AP[ApNum++] = new WiFiAccessPoint(ap); - - } else{ - // scan done - - rtw_up_sema(&scan_sema); - } - return RTW_SUCCESS; -} - 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; - goto error; - } - - if(rtw_down_timeout_sema( &scan_sema, 15000 ) == RTW_FALSE) { - printf("wifi scan timeout\r\n"); - //return NSAPI_ERROR_DEVICE_ERROR; - goto error; - } - rtw_free_sema(&scan_sema); - return ApNum; - }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]; - } - return (signed int)count; - } - return NSAPI_ERROR_OK; -error: - rtw_free_sema(&scan_sema); - return NSAPI_ERROR_DEVICE_ERROR; + static wifi_scan_hdl scan_handler; + ApNum = 0; + if(!scan_sema) + rtw_init_sema(&scan_sema, 0); + scan_handler.scan_num = count; + scan_handler.ap_details = res; + if(wifi_scan_networks(scan_result_handler, (void *)&scan_handler) != RTW_SUCCESS){ + printf("wifi scan failed\n\r"); + return NSAPI_ERROR_DEVICE_ERROR; + } + if(rtw_down_timeout_sema( &scan_sema, MAX_SCAN_TIMEOUT ) == RTW_FALSE) { + printf("wifi scan timeout\r\n"); + return NSAPI_ERROR_DEVICE_ERROR; + } + if(count <= 0 || count > ApNum) + count = ApNum; + + return count; } nsapi_error_t RTWInterface::set_channel(uint8_t channel) { - if(wifi_set_channel(channel) == 0) - return NSAPI_ERROR_OK; - return NSAPI_ERROR_DEVICE_ERROR; + _channel = channel; + return NSAPI_ERROR_OK; } int8_t RTWInterface::get_rssi() { - return NSAPI_ERROR_UNSUPPORTED; + int rssi = 0; + if(wifi_get_rssi(&rssi) == 0) + return (int8_t)rssi; + return NSAPI_ERROR_OK; } nsapi_error_t RTWInterface::connect(const char *ssid, const char *pass, nsapi_security_t security, uint8_t channel) { set_credentials(ssid, pass, security); + set_channel(channel); return connect(); } nsapi_error_t RTWInterface::disconnect() { - char essid[33]; + char essid[33]; + wlan_emac_link_change(false); if(wifi_is_connected_to_ap() != RTW_SUCCESS) - return NSAPI_ERROR_NO_CONNECTION; - printf("Deassociating AP ...\r\n"); - if(wifi_disconnect()<0){ - return NSAPI_ERROR_DEVICE_ERROR; - } - - while(1){ - if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) { - printf("WIFI disconnected\n\r"); - break; - } - } - + return NSAPI_ERROR_NO_CONNECTION; + //printf("Deassociating AP ...\r\n"); + if(wifi_disconnect()<0){ + return NSAPI_ERROR_DEVICE_ERROR; + } + while(1){ + if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) { + //printf("WIFI disconnected\n\r"); + break; + } + } return NSAPI_ERROR_OK; } diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.h b/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.h index 43982d277d..09b5cfd1ed 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.h @@ -35,9 +35,7 @@ public: /** RTWWlanInterface lifetime */ RTWInterface(); - - virtual nsapi_error_t init(); - virtual nsapi_error_t deinit(); + ~RTWInterface(); /** Set a static IP address * @@ -108,7 +106,7 @@ public: * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error * see @a nsapi_error */ - virtual nsapi_error_t scan(WiFiAccessPoint *res, unsigned count); + virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, unsigned count); virtual nsapi_error_t set_channel(uint8_t channel); virtual int8_t get_rssi(); @@ -156,6 +154,7 @@ protected: char _ssid[256]; char _pass[256]; nsapi_security_t _security; + uint8_t _channel; char _ip_address[IPADDR_STRLEN_MAX]; char _netmask[NSAPI_IPv4_SIZE]; char _gateway[NSAPI_IPv4_SIZE]; diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/rtl8195a.icf b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/rtl8195a.icf index 598910f6a3..57609aea3e 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/rtl8195a.icf +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/rtl8195a.icf @@ -2,9 +2,9 @@ /*-Editor annotation file-*/ /* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ /*-Specials-*/ +//define symbol __ICFEDIT_intvec_start__ = 0x00000000; - - +//include "main.icf"; /*-Memory Regions-*/ define symbol __ICFEDIT_region_ROM_start__ = 0x00000000; @@ -13,51 +13,50 @@ define symbol __ICFEDIT_region_TCM_start__ = 0x1FFF0000; define symbol __ICFEDIT_region_TCM_end__ = 0x1FFFFFFF; define symbol __ICFEDIT_region_ROM_USED_RAM_start__ = 0x10000000; define symbol __ICFEDIT_region_ROM_USED_RAM_end__ = 0x10005FFF; - - - -define symbol __ICFEDIT_region_BD_RAM_start__ = 0x10006000; - - -define symbol __ICFEDIT_region_BD_RAM_end__ = 0x1006FFFF; - +//define symbol __ICFEDIT_region_RECY_RAM_start__ = 0x10002090; +//define symbol __ICFEDIT_region_RECY_RAM_end__ = 0x100037FF; +if( !isdefinedsymbol( __ICFEDIT_region_BD_RAM_start__ ) ) { + define symbol __ICFEDIT_region_BD_RAM_start__ = 0x10006000; +} +if( !isdefinedsymbol( __ICFEDIT_region_BD_RAM_end__ ) ) { + define symbol __ICFEDIT_region_BD_RAM_end__ = 0x1006FFFF; +} define symbol __ICFEDIT_region_SDRAM_RAM_start__ = 0x30000000; define symbol __ICFEDIT_region_SDRAM_RAM_end__ = 0x301FFFFF; /*-Sizes-*/ -define symbol __ICFEDIT_size_cstack__ = 0x1000; -define symbol __ICFEDIT_size_heap__ = 0x10000; +/*define symbol __ICFEDIT_size_cstack__ = 0x400;*/ +define symbol __ICFEDIT_size_heap__ = 0x19000; /**** End of ICF editor section. ###ICF###*/ define memory mem with size = 4G; -define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; +define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; define region TCM_region = mem:[from __ICFEDIT_region_TCM_start__ to __ICFEDIT_region_TCM_end__]; define region ROM_USED_RAM_region = mem:[from __ICFEDIT_region_ROM_USED_RAM_start__ to __ICFEDIT_region_ROM_USED_RAM_end__]; +//define region RECY_RAM_region = mem:[from __ICFEDIT_region_RECY_RAM_start__ to __ICFEDIT_region_RECY_RAM_end__]; +define region BD_RAM_region = mem:[from __ICFEDIT_region_BD_RAM_start__ to __ICFEDIT_region_BD_RAM_end__]; +define region SDRAM_RAM_region = mem:[from __ICFEDIT_region_SDRAM_RAM_start__ to __ICFEDIT_region_SDRAM_RAM_end__]; -define region BD_RAM_region = mem:[from __ICFEDIT_region_BD_RAM_start__ to __ICFEDIT_region_BD_RAM_end__]; - - -define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; +/*define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };*/ define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; //initialize by copy { readwrite }; +//initialize by copy with packing = none { section __DLIB_PERTHREAD }; // Required in a multi-threaded application + +//do not initialize { section * }; + +//place at address mem:__ICFEDIT_intvec_start__ { readonly section .vectors_table }; -do not initialize { section .noinit }; - - - - - - +/*place in RAM_region { readwrite, block CSTACK, block HEAP };*/ +//place in TCM_region { readwrite }; /**************************************** * ROM Section config * ****************************************/ -//keep { section .rom }; -//place at start of ROM_region { readonly, section .rom }; -place at start of ROM_region {section .rom }; +keep { section .rom }; +place at start of ROM_region { section .rom }; /**************************************** * BD RAM Section config * @@ -71,61 +70,49 @@ define block .user_vector_table with fixed order{section .ram_user_define_irq_ta keep { section .ram_user_define_data_table* }; define block .user_data_table with fixed order{section .ram_user_define_data_table*}; -define block .rom.bss with fixed order{ section .hal.ram.bss* object hal_misc.o, - section .hal.ram.bss* object hal_pinmux.o, - section .hal.ram.bss* object diag.o, - section .hal.ram.bss* object rtl8195a_ssi_rom.o, - section .hal.ram.bss* object rtl8195a_gpio.o, - - section .hal.ram.bss*, - section .timer2_7_vector_table.data*, - - - section .infra.ram.bss*, - section .mon.ram.bss*, - section .wlan_ram_map* object rom_wlan_ram_map.o, - - - section .wlan_ram_map*, - section .libc.ram.bss*, +define block .rom.bss with fixed order{ section .hal.ram.bss* object hal_misc.o, + section .hal.ram.bss* object hal_pinmux.o, + section .hal.ram.bss* object diag.o, + section .hal.ram.bss* object rtl8195a_ssi_rom.o, + section .hal.ram.bss* object rtl8195a_gpio.o, + section .hal.ram.bss*, + section .timer2_7_vector_table.data*, + section .infra.ram.bss*, + section .mon.ram.bss*, + section .wlan_ram_map* object rom_wlan_ram_map.o, + section .wlan_ram_map*, + section .libc.ram.bss*, }; keep { section .start.ram.data* }; define block .ram.start.table with fixed order{ section .start.ram.data* }; keep { section .image1.validate.rodata* }; -//keep { section .infra.ram.data* }; -//keep { section .timer.ram.data* }; +keep { section .infra.ram.data* }; +keep { section .timer.ram.data* }; keep { section .hal.ram.data* }; define block .ram_image1.data with fixed order{ section .image1.validate.rodata*, section .infra.ram.data*, - - //section .timer.ram.data*, + section .timer.ram.data*, section .cutb.ram.data*, section .hal.ram.data* object rom.o, // for standard libaray __impure_data_ptr section .cutc.ram.data*, section .hal.ram.data* }; -//define block .ram_image1.bss with fixed order{ //section .hal.flash.data*, - - -// section .hal.sdrc.data* -// }; +define block .ram_image1.bss with fixed order{ //section .hal.flash.data*, + section .hal.sdrc.data* + }; define block .ram_image1.text with fixed order{ section .hal.ram.text*, - -// //section .hal.sdrc.text*, -// //section .text* object startup.o, + section .hal.sdrc.text*, + //section .text* object startup.o, section .infra.ram.text*, }; define block IMAGE1 with fixed order { section LOADER }; -define block IMAGE1_DBG with fixed order { block .ram.start.table, - block .ram_image1.data, - //block .ram_image1.bss, - block .ram_image1.text }; +define block IMAGE1_DBG with fixed order { block .ram.start.table, block .ram_image1.data, block .ram_image1.bss, block .ram_image1.text }; -place at start of ROM_USED_RAM_region { //readwrite, +place at start of ROM_USED_RAM_region { block .vector_table, block .user_vector_table, block .user_data_table, @@ -133,136 +120,103 @@ place at start of ROM_USED_RAM_region { //readwrite, block IMAGE1 }; -/** - IMAGE2 -**/ keep { section .image2.ram.data* }; define block .image2.start.table1 with fixed order{ section .image2.ram.data* }; keep { section .image2.validate.rodata*, section .custom.validate.rodata* }; define block .image2.start.table2 with fixed order{ section .image2.validate.rodata*, section .custom.validate.rodata* }; - -/* define block SHT$$PREINIT_ARRAY { preinit_array }; define block SHT$$INIT_ARRAY { init_array }; -define block CPP_INIT with fixed order { block SHT$$PREINIT_ARRAY, - block SHT$$INIT_ARRAY }; -*/ +define block CPP_INIT with alignment = 8, fixed order { + block SHT$$PREINIT_ARRAY, + block SHT$$INIT_ARRAY + }; +define block FPB_REMAP with alignment = 256,fixed order { + section .fpb.remap* + }; define block .ram_image2.text with fixed order{ section .infra.ram.start*, section .rodata*, - //block CPP_INIT, + block CPP_INIT, section .mon.ram.text*, section .hal.flash.text*, section .hal.gpio.text*, section .text* object main.o, section .text*, - + section .wlan.text, + section .wps.text, section CODE, section .otg.rom.text, section Veneer object startup.o, - - - - section __DLIB_PERTHREAD + section __DLIB_PERTHREAD, + section .iar.dynexit*, + //section .mdns.text }; - -define block .ram.data with fixed order{ section .data*, - section DATA, - section .iar.init_table, - section .data object vector_table_M.o - }; -define block IMAGE2 with fixed order { block .image2.start.table1, - block .image2.start.table2, - block .ram_image2.text, - block .ram.data, - readonly, - }; + +define block .ram.data with fixed order{ readwrite, readonly, + section .data*, + section .wlan.data, + section .wps.data, + section DATA, + section .ram.otg.data.a, + section .iar.init_table, + //section .mdns.data + }; + +define block IMAGE2 with fixed order { block .image2.start.table1, block .image2.start.table2, block .ram_image2.text, block .ram.data }; + define block .ram.bss with fixed order{ section .bss*, - //section .ssl_ram_map, - section .hal.flash.data*, - section .hal.gpio.data*, - section COMMON, - section .bdsram.data*, - }; - - - - - - - - - - - -place at start of BD_RAM_region { - block IMAGE2, - readwrite, - block .ram.bss, - }; -place at end of BD_RAM_region{ - block HEAP, - //block CSTACK - }; - - - - - - - - - - -/**************************************** - * BD RAM Section config * - ****************************************/ + section .ssl_ram_map, + section .hal.flash.data*, + section .hal.gpio.data*, + section COMMON, + section .bdsram.data*, + section .bss* object heap_4.o + }; +define block .bf_data with fixed order{ section .bfsram.data* }; define block .heap with fixed order{ section .heap* }; define block .stack_dummy with fixed order { section .stack }; +place at start of BD_RAM_region { + block IMAGE2, + //block IMAGE1_DBG, + block .ram.bss, + //block .bf_data, + }; + +//place at address mem:0x10052b00 { readwrite, +place at end of BD_RAM_region { + block .bf_data, + block HEAP, + }; + +define block SDRAM with fixed order{ section .sdram.text*, + section .sdram.data*, + section .mdns.text*, + section .mdns.data*, + block FPB_REMAP + }; +define block SDRBSS with fixed order{ + section .sdram.bss* + }; + +place at start of SDRAM_RAM_region { + block SDRAM, + block SDRBSS, + //block IMAGE1_DBG + }; - - - - - - - - - - - - - - - - - - - - - - - - -/*TCM placement */ -define overlay TCM_overlay { //section .tcm.heap, - //section .bss object mem.o, - //section .bss object memp.o, - - - block .heap, - block .stack_dummy +/* TCM placement */ +define overlay TCM_overlay { + section .tcm.heap, + section .bss object mem.o, + section .bss object memp.o, + block .heap, + block .stack_dummy }; /* dummy code placement */ define overlay TCM_overlay { block IMAGE1_DBG }; -place at start of TCM_region { //readwrite, - overlay TCM_overlay - }; - -/* modify by Ian - for mbed stack isr start address setting*/ -place at end of TCM_region { block CSTACK }; +place at start of TCM_region { overlay TCM_overlay }; define exported symbol __rom_bss_start__ = 0x10000300; // use in rom define exported symbol __rom_bss_end__ = 0x10000bc8; // use in rom @@ -270,5 +224,5 @@ define exported symbol __ram_start_table_start__= 0x10000bc8; // use in rom define exported symbol __image1_validate_code__= 0x10000bdc; // needed by ram code define exported symbol _rtl_impure_ptr = 0x10001c60; // for standard library - - +define exported symbol __sdio_rom_bss_start__ = 0x1006D000; +define exported symbol __sdio_rom_bss_end__ = 0x1006fa10; diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.cpp b/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.cpp index f4cb9f522c..248468e081 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.cpp +++ b/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.cpp @@ -30,28 +30,23 @@ #include "wifi_constants.h" #include "wifi_conf.h" +#define RTW_EMAC_MTU_SIZE (1500U) + static emac_interface_t *_emac; static emac_link_input_fn link_input_cb; 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) { - return 1500U; + return RTW_EMAC_MTU_SIZE; } static void wlan_get_ifname(emac_interface_t *emac, char *name, uint8_t size) { MBED_ASSERT(name != NULL); - memcpy((void*)name, "r0", 2); + strncpy(name, "r0", size); } static uint8_t wlan_get_hwaddr_size(emac_interface_t *emac) @@ -61,16 +56,6 @@ 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); - if (hwaddr == NULL) { - return; - } - - memcpy(addr, hwaddr, ETHARP_HWADDR_LEN); -#else char mac[20]; if(RTW_SUCCESS == wifi_get_mac_address(mac)) { @@ -79,7 +64,6 @@ static void wlan_get_hwaddr(emac_interface_t *emac, uint8_t *addr) }else{ printf("Get HW address failed\r\n"); } -#endif } static void wlan_set_hwaddr(emac_interface_t *emac, uint8_t *addr) @@ -122,7 +106,7 @@ static bool wlan_link_out(emac_interface_t *emac, emac_stack_mem_t *buf) static bool wlan_power_up(emac_interface_t *emac) { - printf("Powering up WiFi ...\r\n"); + //printf("Powering up WiFi ...\r\n"); wifi_on(RTW_MODE_STA); wait_ms(1000); return true; @@ -130,7 +114,7 @@ static bool wlan_power_up(emac_interface_t *emac) static void wlan_power_down(emac_interface_t *emac) { - printf("Powering down WiFi ...\r\n"); + //printf("Powering down WiFi ...\r\n"); wifi_off(); } @@ -170,7 +154,7 @@ void wlan_emac_recv(struct netif *netif, int len) for (; p != NULL && sg_len < MAX_ETH_DRV_SG; p = p->next) { sg_list[sg_len].buf = (uint32_t) p->payload; sg_list[sg_len].len = p->len; - sg_len++; + sg_len++; } rltk_wlan_recv(0, sg_list, sg_len); @@ -206,60 +190,29 @@ void mbed_default_mac_address(char *mac) { return; } - 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"); + printf("Get HW address failed\r\n"); + mbed_default_mac_address(mac); } -#endif } -void wlan_emac_link_down(uint8_t i) +void wlan_emac_link_change(bool up) { - if (i > 1) { - return; - } - - //xnetif[i]->flags &= ~NETIF_FLAG_LINK_UP; if (link_state_cb) { - link_state_cb(link_state_data, false); + link_state_cb(link_state_data, up); } } -void wlan_emac_link_up(uint8_t i) -{ - if (i > 1) { - return; - } - - //xnetif[i]->flags |= NETIF_FLAG_LINK_UP; - if (link_state_cb) { - link_state_cb(link_state_data, true); - } -} - -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; diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.h b/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.h index e7470d65fb..1e6165b49d 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.h @@ -18,11 +18,8 @@ #include "emac_api.h" +extern void wlan_emac_link_change(bool up); extern emac_interface_t *wlan_emac_init_interface(); -extern void wlan_emac_init_mem(); -extern void wlan_emac_init_netif(); -extern void wlan_emac_link_up(uint8_t i); -extern void wlan_emac_link_down(uint8_t i); extern void wlan_emac_recv(struct netif *netif, uint32_t len); #endif diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.c index 6913a4162c..4aa147ad60 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.c @@ -61,8 +61,7 @@ extern int inic_stop(void); * Variables Declarations ******************************************************/ #if DEVICE_EMAC -extern struct netif *xnetif[]; - +//extern struct netif *xnetif[]; #else extern struct netif xnetif[NET_IF_NUM]; #endif @@ -1004,11 +1003,6 @@ int wifi_off(void) // TODO: #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 @@ -1682,7 +1676,7 @@ int wifi_restart_ap( ip_addr_t netmask; ip_addr_t gw; #if DEVICE_EMAC - struct netif * pnetif = xnetif[0]; + //struct netif * pnetif = xnetif[0]; #else struct netif * pnetif = &xnetif[0]; #endif @@ -1708,10 +1702,13 @@ int wifi_restart_ap( else #endif { +#if DEVICE_EMAC +#else IP4_ADDR(&ipaddr, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3); IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); netif_set_addr(pnetif, &ipaddr, &netmask,&gw); +#endif wifi_off(); rtw_msleep_os(20); wifi_on(RTW_MODE_AP); @@ -1753,7 +1750,7 @@ int wifi_restart_ap( #endif #if DEVICE_EMAC // start dhcp server - dhcps_init(xnetif[idx]); + //dhcps_init(xnetif[idx]); #else // start dhcp server dhcps_init(&xnetif[idx]); diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.c index d850d48e50..ec59d63aa4 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.c @@ -158,11 +158,9 @@ 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; + return 1; #else - struct netif *pnetif = &xnetif[idx]; -#endif + struct netif *pnetif = &xnetif[idx]; ip_addr_t addr = { 0 }; @@ -196,49 +194,45 @@ int netif_is_valid_IP(int idx, unsigned char *ip_dest) else #endif return 0; +#endif } +#if DEVICE_EMAC + +#else int netif_get_idx(struct netif *pnetif) { #if (CONFIG_LWIP_LAYER == 1) -#if DEVICE_EMAC - if (pnetif == xnetif[0]) - return 0; -#else - int idx = pnetif - xnetif; - - switch(idx) { - case 0: - return 0; - case 1: - return 1; - default: - return -1; - } -#endif + int idx = pnetif - xnetif; + + switch(idx) { + case 0: + return 0; + case 1: + return 1; + default: + return -1; + } #else - return -1; + return -1; #endif } unsigned char *netif_get_hwaddr(int idx_wlan) { #if (CONFIG_LWIP_LAYER == 1) -#if DEVICE_EMAC - return xnetif[idx_wlan]->hwaddr; -#else return xnetif[idx_wlan].hwaddr; -#endif #else return NULL; #endif } +#endif void netif_rx(int idx, unsigned int len) { #if (CONFIG_LWIP_LAYER == 1) #if DEVICE_EMAC - wlan_emac_recv(xnetif[idx], len); + wlan_emac_recv(NULL, len); #else ethernetif_recv(&xnetif[idx], len); #endif