Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add REALTEK_RTL8195AM to mbed-os #4438

Merged
merged 69 commits into from
Jun 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
bc948ca
Create mbed_rtx.h
Archcady Feb 16, 2017
bbbecd7
Update targets.json
Archcady Feb 16, 2017
53e837b
add support for REALTEK_RTL8195AM
Archcady Feb 16, 2017
3d59643
Add lwipopts_conf.h
Archcady Feb 23, 2017
04ede46
Add rtl8195a_rom.so
Archcady Feb 23, 2017
c208094
Rename rtl8195a_rom.so to rtl8195a_rom.o
Archcady Feb 23, 2017
9e9878f
improve coding style
Archcady Feb 24, 2017
4d52f98
change proprietary headers (APACHE2.0)
Archcady Feb 24, 2017
5e47ad0
Fix headers issue in TARGET_AMEBA\sdk\common folder
Archcady Feb 24, 2017
49baa97
py coding style
Archcady Feb 24, 2017
3395ebc
update lib
Archcady Feb 24, 2017
c72257c
update other file headers
Archcady Feb 24, 2017
173315d
remove unused code
Archcady Feb 24, 2017
0d84a8d
move network Interface API out
Archcady Feb 27, 2017
41f20d6
remove useless definitions in device.h
Archcady Feb 27, 2017
ad85a14
Remove IPV4 from features in targets.json
Archcady Feb 28, 2017
d0488c1
Rename features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/target_real…
Archcady Feb 28, 2017
0894548
complete postbuild process for IAR
Archcady Feb 28, 2017
3e9dafa
remove "default_build" from targets.json
Archcady Mar 1, 2017
b20d635
fix the issue that GCC builds extra-large bin file
Archcady Mar 1, 2017
d75c5db
minor fixes
Archcady Mar 2, 2017
9514cf8
improve py code
Archcady Mar 2, 2017
6a47d01
Rename Lwipopts_conf.h to lwipopts_conf.h
Archcady Mar 6, 2017
7867a81
WiFi test fix for GCC
Archcady Mar 7, 2017
d461776
Fix postbuild for ARM & GCC
Archcady Mar 7, 2017
f8019f4
Mute RAM1 messages
Archcady Mar 8, 2017
9a0cb73
mute debug message in RAM1 (changed)
Archcady Mar 8, 2017
02687b5
A fix to enum issue
Archcady Mar 8, 2017
29e11a1
move REALTEK_RTL8195AM.py, remove progen in targets.json
Archcady Mar 9, 2017
8d20c35
Update lib (enum issue)
Archcady Mar 9, 2017
7c2e73d
Add Arduino pins
Archcady Mar 10, 2017
57f385a
mute some debug message in wlan lib
Archcady Mar 15, 2017
de8f2ad
switch off tcm_heap usage
Archcady Mar 17, 2017
d96de9c
update to lwip_stack issue
Archcady Mar 23, 2017
b1d9991
fix wifi example fail issue
ian-qian-ting Mar 27, 2017
dbcd36f
fix bugs found in CI test
Archcady Mar 29, 2017
3736313
Update RTWInterface.cpp
Archcady Mar 29, 2017
074dd9f
fix a bug brought by previous commit
Archcady Mar 30, 2017
00ffb04
move target specific scripts to tools/targets/
Archcady Mar 31, 2017
680dec5
fix a bug in PWM
Archcady Mar 31, 2017
1141c7a
fix C++11 warning
Archcady Mar 31, 2017
08489e4
Fix on Wifi
Archcady Apr 3, 2017
ba03499
reslove conflict UINT definition between basic_types.h & filesystem
Archcady Apr 5, 2017
2dd9415
Fold ADC0 into trng; delete comment code
Archcady Apr 5, 2017
f87eca8
remove sleep_api.c
Archcady Apr 6, 2017
15d5869
fold static variables in RTWInterface.cpp to .h, modify lwipopts.h TC…
Archcady Apr 7, 2017
0650ad1
greentea heap&stack fix
Archcady Apr 7, 2017
d18735d
code style fix
Archcady Apr 7, 2017
0430b94
code style fix #2
Archcady Apr 10, 2017
6f24e9e
Clear Wlan code in permissive-binary-license
Archcady Apr 12, 2017
c3bf1c5
remove unused class member from RTWInterface
Archcady Apr 18, 2017
f000eb3
Restore TCPIP_THREAD_STACKSIZE and thread_stack_main
Archcady Apr 20, 2017
6c82b51
an I2C fix
Archcady Apr 27, 2017
c160d5b
Ported code of CMSIS5/RTX2
Archcady May 12, 2017
e8fd5bb
move archives into target specific directories
Archcady May 22, 2017
005ce58
cmsis5\rtx5 put NVIC vector ops in mbed_boot.c
Archcady May 22, 2017
0c046a4
improve coding style
Archcady May 22, 2017
e289164
add comment for the delay in analogout_api.c
Archcady May 22, 2017
4eda93e
resolve RTWInterface initialization run after error issue
Archcady May 22, 2017
92ca664
Add support for mbed exporter
Archcady May 22, 2017
c31d547
fix multiple i2c peripherals possible conflicting issue
Archcady May 22, 2017
88d4d1d
exporter coding style fix
Archcady May 23, 2017
f71f578
Switch to rtx2
Archcady May 23, 2017
7602d27
remove unsupported device_name
Archcady May 25, 2017
b76c8a9
clean up GPL license with APACHE2.0
Archcady May 25, 2017
fdea7b1
fix icf file misspelling
Archcady May 31, 2017
3c3a9a6
fix STRINGIFY redefining issue
Archcady Jun 2, 2017
be35b3f
spi: Added default spi_master_block_write implementation to REALTEK_R…
sg- Jun 3, 2017
1fa30b7
Resolve conflict in builtin type names
sg- Jun 3, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Copyright (C) 2012 mbed.org, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef LWIPOPTS_CONF_H
#define LWIPOPTS_CONF_H

#define LWIP_TRANSPORT_ETHERNET 1
#define ETHMEM_SECTIO

//#define TCPIP_THREAD_STACKSIZE 2048

/* ---------- Pbuf options ---------- */
#define MEM_SIZE (10*1600)
#define TCP_SND_QUEUELEN 60
#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN
#define TCP_MSS 1460
#define TCP_SND_BUF (10 * TCP_MSS)
#define TCP_WND (6 * TCP_MSS)
#define PBUF_POOL_SIZE 10

#endif


16 changes: 8 additions & 8 deletions features/filesystem/bd/MBRBlockDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ MBED_PACKED(struct) mbr_table {
static inline uint32_t tole32(uint32_t a)
{
union {
uint32_t u32;
uint8_t u8[4];
} w;
uint32_t w;
uint8_t b[4];
} s;

w.u8[0] = a >> 0;
w.u8[1] = a >> 8;
w.u8[2] = a >> 16;
w.u8[3] = a >> 24;
s.b[0] = a >> 0;
s.b[1] = a >> 8;
s.b[2] = a >> 16;
s.b[3] = a >> 24;

return w.u32;
return s.w;
}

static inline uint32_t fromle32(uint32_t a)
Expand Down
284 changes: 284 additions & 0 deletions targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
/* Ameba implementation of NetworkInterfaceAPI
* Copyright (c) 2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "mbed.h"
#include "rtos.h"

#include "RTWInterface.h"
#include "mbed_interface.h"
#include "rtw_emac.h"

#include "wifi_constants.h"
#include "wifi_conf.h"
#include "lwip_stack.h"

#include "osdep_service.h"

typedef struct _wifi_scan_hdl {
void *scan_sema;
nsapi_size_t ap_num;
nsapi_size_t scan_num;
WiFiAccessPoint *ap_details;
} wifi_scan_hdl;

#define MAX_SCAN_TIMEOUT (15000)

static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
{
wifi_scan_hdl *scan_handler = (wifi_scan_hdl *)malloced_scan_result->user_data;
if (malloced_scan_result->scan_complete != RTW_TRUE) {
if(scan_handler->ap_details && scan_handler->scan_num > scan_handler->ap_num){
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[scan_handler->ap_num], accesspoint, sizeof(WiFiAccessPoint));
delete[] accesspoint;
}
scan_handler->ap_num++;
} else{
// scan done
rtw_up_sema(&scan_handler->scan_sema);
}
return RTW_SUCCESS;
}

RTWInterface::RTWInterface()
: _dhcp(true), _ip_address(), _netmask(), _gateway()
{
emac_interface_t *emac;
int ret;

emac = wlan_emac_init_interface();
if (!emac) {
printf("Error init RTWInterface!\r\n");
return;
}
emac->ops.power_up(emac);
ret = mbed_lwip_init(emac);
if (ret != 0) {
printf("Error init RTWInterface!(%d)\r\n", ret);
return;
}
}

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)
{
_dhcp = false;
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
return NSAPI_ERROR_OK;
}

nsapi_error_t RTWInterface::set_dhcp(bool dhcp)
{
_dhcp = dhcp;
return NSAPI_ERROR_OK;
}

/*
* we may call connect multiple times
*/
nsapi_error_t RTWInterface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)
{
strncpy(_ssid, ssid, 255);
strncpy(_pass, pass, 255);
_security = security;

return NSAPI_ERROR_OK;
}

nsapi_error_t RTWInterface::connect()
{
int ret;
rtw_security_t sec;

if (!_ssid || (!_pass && _security != NSAPI_SECURITY_NONE)) {
printf("Invalid credentials\r\n");
return NSAPI_ERROR_PARAMETER;
}

switch (_security) {
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;
}

if(_channel > 0 && _channel < 14){
uint8_t pscan_config = PSCAN_ENABLE;
wifi_set_pscan_chan(&_channel, &pscan_config, 1);
}

ret = wifi_connect(_ssid, sec, _pass, strlen(_ssid), strlen(_pass), 0, (void *)NULL);
if (ret != RTW_SUCCESS) {
printf("failed: %d\r\n", ret);
return NSAPI_ERROR_NO_CONNECTION;
}

wlan_emac_link_change(true);
return mbed_lwip_bringup(_dhcp,
_ip_address[0] ? _ip_address : 0,
_netmask[0] ? _netmask : 0,
_gateway[0] ? _gateway : 0);
}

nsapi_error_t RTWInterface::scan(WiFiAccessPoint *res, unsigned count)
{
static wifi_scan_hdl scan_handler;
scan_handler.ap_num = 0;
if(!scan_handler.scan_sema)
rtw_init_sema(&scan_handler.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_handler.scan_sema, MAX_SCAN_TIMEOUT ) == RTW_FALSE) {
printf("wifi scan timeout\r\n");
return NSAPI_ERROR_DEVICE_ERROR;
}
if(count <= 0 || count > scan_handler.ap_num)
count = scan_handler.ap_num;

return count;
}

nsapi_error_t RTWInterface::set_channel(uint8_t channel)
{
_channel = channel;
return NSAPI_ERROR_OK;
}

int8_t RTWInterface::get_rssi()
{
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];

wlan_emac_link_change(false);
if(wifi_is_connected_to_ap() != RTW_SUCCESS)
return NSAPI_ERROR_NO_CONNECTION;
if(wifi_disconnect()<0){
return NSAPI_ERROR_DEVICE_ERROR;
}
while(1){
if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) {
break;
}
}
return NSAPI_ERROR_OK;
}

int RTWInterface::is_connected()
{
// wifi_is_connected_to_ap return 0 on connected
return !wifi_is_connected_to_ap();
}

const char *RTWInterface::get_mac_address()
{
return mbed_lwip_get_mac_address();
}

const char *RTWInterface::get_ip_address()
{
if (mbed_lwip_get_ip_address(_ip_address, sizeof _ip_address)) {
return _ip_address;
}
return 0;
}

const char *RTWInterface::get_netmask()
{
if (mbed_lwip_get_netmask(_netmask, sizeof _netmask)) {
return _netmask;
}
return 0;
}

const char *RTWInterface::get_gateway()
{
if (mbed_lwip_get_gateway(_gateway, sizeof _gateway)) {
return _gateway;
}
return 0;
}

NetworkStack *RTWInterface::get_stack()
{
return nsapi_create_stack(&lwip_stack);
}
Loading